using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; using Moq; using NUnit.Framework; using LCU.Library.Internal.CoreApiWrapperLib.DataAccess; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels; using LCU.Library.Internal.CoreApiWrapperLib.Configuration; using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities; using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Tax; namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess { public class TaxDaoTest { private TaxDao _taxDao; private Mock _mockCoreRequest; private CoreConfiguration _coreConfiguration; [SetUp] public void SetUp() { _mockCoreRequest = new Mock(); _coreConfiguration = new CoreConfiguration { CoreApiConfiguration = new CoreApiConfiguration { CoreEndPointConfiguration = new CoreEndPointConfiguration { GetOrganizationsDataByTaxId = "test/Organization/Query/TaxId", GetPersonsDataByTaxId = "test/Person/Query/TaxId" } } }; _taxDao = new TaxDao(_mockCoreRequest.Object, _coreConfiguration); } [Test] public async Task GetPersonTaxIdData_Returns_Success() { var header = new CoreMessageHeader { UpdateKey = null, MessageId = null }; var body = new List{ new() { FirstName = "Greg", MiddleInitial = "H", LastName = "Stevens", Suffix = "Jr.", NameFull = "Greg H. Stevens Jr.", PersonNumber = 123 } }; var personTaxIdDataResponse = new CoreApiMessage>(header, body); _mockCoreRequest.Setup(x => x.PostRequestObject>>(It.Is(url => url.Equals("test/Person/Query/TaxId")), It.IsAny>() ,It.Is(x => x.Contains("123")))).ReturnsAsync(personTaxIdDataResponse).Verifiable(); var results = await _taxDao.GetPersonTaxIdData(new CoreRequestParameters(), "123"); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); _mockCoreRequest.Verify(); } [Test] public async Task GetOrganizationTaxIdData_Returns_Success() { var header = new CoreMessageHeader { UpdateKey = null, MessageId = null }; var body = new List{ new() { Name = "Organization", OrganizationNumber = 123 } }; var personTaxIdDataResponse = new CoreApiMessage>(header, body); _mockCoreRequest.Setup(x => x.PostRequestObject>>(It.Is(url => url.Equals("test/Organization/Query/TaxId")), It.IsAny>() ,It.Is(url => url.Contains("123")))).ReturnsAsync(personTaxIdDataResponse).Verifiable(); var results = await _taxDao.GetOrganizationTaxIdData(new CoreRequestParameters(), "123"); Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); _mockCoreRequest.Verify(); } } }