using LCU.API.Internal.CoreSoapApiWrapper.Controllers; using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities; using LCU.API.Internal.CoreSoapApiWrapper.Services; using Moq; using System.Web.Http.Results; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using LCU.API.Internal.CoreSoapApiWrapper.Models.Requests; using System.Collections.Generic; namespace LCU.API.Internal.CoreSoapApiWrapperTest.Controllers { [TestClass] public class PersonAgreementControllerTest { private PersonAgreementController _controller; private Mock _mockPersonAgreementService; public PersonAgreementControllerTest() { _mockPersonAgreementService = new Mock(); _controller = new PersonAgreementController(_mockPersonAgreementService.Object); } [TestMethod] public void PutPersonAgreementsDetailTypes_Null_BadRequest() { _mockPersonAgreementService.Verify(x => x.UpdatePersonAgreementsDetailTypes( It.IsAny()), Times.Never); var result = _controller.PutPersonAgreementsDetailTypes(null); Assert.IsNotNull(result); var okResult = result as BadRequestErrorMessageResult; Assert.IsNotNull(okResult); _mockPersonAgreementService.Verify(x => x.UpdatePersonAgreementsDetailTypes( It.IsAny()), Times.Never); } [TestMethod] public void PutPersonAgreementsDetailTypes_Exception() { var request = new PersonAgreementDetailTypeRequest() { PersonNumber = 1, AgreeNumber = 2, DetailTypes = new List() { new DetailType() { DetailTypeCode = "Stat", DetailValue = "CLOS" } } }; _mockPersonAgreementService.Setup(x => x.UpdatePersonAgreementsDetailTypes(request)) .Throws(new Exception("Error thrown in unit test.")).Verifiable(); var result = _controller.PutPersonAgreementsDetailTypes(request); Assert.IsNotNull(result); var okResult = result as BadRequestErrorMessageResult; Assert.IsNotNull(okResult); _mockPersonAgreementService.Verify(); } } }