using LCU.API.Internal.CoreSoapApiWrapper.CoreSoapUtilities; using LCU.API.Internal.CoreSoapApiWrapper.DataAccess; using LCU.API.Internal.CoreSoapApiWrapper.Models.Requests; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LCU.API.Internal.CoreSoapApiWrapperTest.DataAccess { [TestClass] public class CollateralMaintenanceDaoTest { private CollateralMaintenanceDao _dao; private Mock _mockCoreSoapRequest; public CollateralMaintenanceDaoTest() { _mockCoreSoapRequest = new Mock(); _dao = new CollateralMaintenanceDao(_mockCoreSoapRequest.Object); } [TestMethod] public void FindPropertyByPropertyNumber_OK() { var response = new CollateralSearchResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(It.Is(req => req.PropertyCollateral.PropertyNumber == 100000))).Returns(response).Verifiable(); var result = _dao.FindCollateralMaintenanceByPropertyNumber(100000); _mockCoreSoapRequest.Verify(); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); } [TestMethod] public void FindPropertyByPropertyNumber_Exception() { _mockCoreSoapRequest.Setup(x => x.SubmitRequest(It.IsAny())).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.FindCollateralMaintenanceByPropertyNumber(100000)); _mockCoreSoapRequest.Verify(); } [TestMethod] public void AddCollateralMaintenanceRequest_OK() { UserFieldRequest request = new UserFieldRequest() { PropertyNumber = 1, UserFieldCode = "Test", Value = "Test" }; var maintenanceRequest = CreateCollateralMaintenanceRequest.CreateMaintenanceRequest(request); var maintenanceResponse = new CollateralMaintenanceResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(It.IsAny())).Returns(maintenanceResponse).Verifiable(); var result = _dao.AddCollateralMaintenanceByPropertyNumber(maintenanceRequest); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); _mockCoreSoapRequest.Verify(); } [TestMethod] public void AddCollateralMaintenanceRequest_Exception() { UserFieldRequest request = new UserFieldRequest() { PropertyNumber = 1, UserFieldCode = "Test", Value = "Test" }; var maintenanceRequest = CreateCollateralMaintenanceRequest.CreateMaintenanceRequest(request); _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.AddCollateralMaintenanceByPropertyNumber(maintenanceRequest)); _mockCoreSoapRequest.Verify(); } [TestMethod] public void UpdateCollateralMaintenanceRequest_OK() { UserFieldRequest request = new UserFieldRequest() { PropertyNumber = 1, UserFieldCode = "Test", Value = "Test" }; var maintenanceRequest = CreateCollateralMaintenanceRequest.CreateMaintenanceRequest(request); var maintenanceResponse = new CollateralMaintenanceResponse { WasSuccessful = true }; _mockCoreSoapRequest.Setup(x => x.SubmitRequest(It.IsAny())).Returns(maintenanceResponse).Verifiable(); var result = _dao.UpdateCollateralMaintenanceByPropertyNumber(maintenanceRequest); Assert.IsNotNull(result); Assert.IsTrue((bool)result.WasSuccessful); _mockCoreSoapRequest.Verify(); } [TestMethod] public void UpdateCollateralMaintenanceRequest_Exception() { UserFieldRequest request = new UserFieldRequest() { PropertyNumber = 1, UserFieldCode = "Test", Value = "Test" }; var maintenanceRequest = CreateCollateralMaintenanceRequest.CreateMaintenanceRequest(request); _mockCoreSoapRequest.Setup(x => x.SubmitRequest(maintenanceRequest)).Throws(new Exception("Error thrown in unit test.")).Verifiable(); Assert.ThrowsException(() => _dao.UpdateCollateralMaintenanceByPropertyNumber(maintenanceRequest)); _mockCoreSoapRequest.Verify(); } } }