Files
2026-03-13 12:58:13 -05:00

70 lines
2.3 KiB
C#

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<ITaxService> _mockTaxService;
public TaxControllerTest()
{
_mockTaxService = new Mock<ITaxService>();
_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<GetTaxIdDataResponse>;
Assert.IsNotNull(okResult);
Assert.IsTrue((bool)okResult.Content.WasSuccessful);
_mockTaxService.Verify();
}
[TestMethod]
public void GetTaxIdData_LongIsZero_BadRequest()
{
_mockTaxService.Verify(x => x.GetTaxIdData(It.IsAny<long>()),
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<long>()), 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();
}
}
}