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; namespace LCU.API.Internal.CoreSoapApiWrapperTest.Controllers { [TestClass] public class TaxControllerTest { private TaxController _controller; private Mock _mockTaxService; public TaxControllerTest() { _mockTaxService = new Mock(); _controller = new TaxController(_mockTaxService.Object); } [TestMethod] public void GetTaxIdData_OK() { var maintenanceResponse = new GetTaxIdDataResponse { WasSuccessful = true }; _mockTaxService.Setup(x => x.GetTaxIdData(100L)).Returns(maintenanceResponse).Verifiable(); var result = _controller.GetTaxIdData(100L); Assert.IsNotNull(result); var okResult = result as OkNegotiatedContentResult; Assert.IsNotNull(okResult); Assert.IsTrue((bool)okResult.Content.WasSuccessful); _mockTaxService.Verify(); } [TestMethod] public void GetTaxIdData_LongIsZero_BadRequest() { _mockTaxService.Verify(x => x.GetTaxIdData(It.IsAny()), Times.Never); var result = _controller.GetTaxIdData(0); Assert.IsNotNull(result); var okResult = result as BadRequestErrorMessageResult; Assert.IsNotNull(okResult); _mockTaxService.Verify(x => x.GetTaxIdData(It.IsAny()), Times.Never); } [TestMethod] public void GetTaxIdData_Exception() { _mockTaxService.Setup(x => x.GetTaxIdData(100L)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); var result = _controller.GetTaxIdData(100); Assert.IsNotNull(result); var okResult = result as BadRequestErrorMessageResult; Assert.IsNotNull(okResult); _mockTaxService.Verify(); } } }