143 lines
5.7 KiB
C#
143 lines
5.7 KiB
C#
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.Constants;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Organizations;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.PostalAddresses;
|
|
using Moq;
|
|
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess
|
|
{
|
|
public class OrganizationDaoTest
|
|
{
|
|
private readonly OrganizationDao _organizationDao;
|
|
private readonly Mock<ICoreRequest> _mockCoreRequest;
|
|
private readonly Mock<ICoreDbExecution> _coreDb;
|
|
|
|
public OrganizationDaoTest()
|
|
{
|
|
_mockCoreRequest = new Mock<ICoreRequest>();
|
|
_coreDb = new Mock<ICoreDbExecution>();
|
|
|
|
var coreConfiguration = new CoreConfiguration
|
|
{
|
|
CoreApiConfiguration = new CoreApiConfiguration
|
|
{
|
|
CoreEndPointConfiguration = new CoreEndPointConfiguration
|
|
{
|
|
PersonsQueryName = "Test"
|
|
}
|
|
}
|
|
};
|
|
|
|
_organizationDao = new OrganizationDao
|
|
(
|
|
_mockCoreRequest.Object,
|
|
coreConfiguration,
|
|
_coreDb.Object
|
|
);
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindOrganizationByMemberAgreeNbr()
|
|
{
|
|
// Arrange
|
|
var listOfIncludes = new List<string>
|
|
{
|
|
RequestIncludeConstants.AllAddresses
|
|
};
|
|
var coreRequestParameters = new CoreRequestParameters(listOfIncludes);
|
|
var organizationRequest = new MemberNbrRequest
|
|
{
|
|
MemberNbr = 100,
|
|
};
|
|
|
|
var testPostalAddress = new PostalAddress
|
|
{
|
|
AddressUseCode = AddressConstants.PrimaryUseCode,
|
|
AddressNumber = 11,
|
|
AddressLine1 = "Test Street",
|
|
AddressLine2 = "",
|
|
AddressLine3 = "",
|
|
CityName = "City Test",
|
|
PostalCode = "53183",
|
|
ZipPlus = "3123",
|
|
CountrySubdivisionCode = "WI"
|
|
};
|
|
var testPostalAddressList = new List<PostalAddress> { testPostalAddress };
|
|
var testOrganization = new Organization
|
|
{
|
|
MemberAgreementNumber = 111111111,
|
|
Name = "Test Organization Name",
|
|
OrganizationNumber = 123,
|
|
PostalAddressList = testPostalAddressList
|
|
};
|
|
|
|
var header = new CoreMessageHeader();
|
|
CoreApiMessage<Organization> organizationApiMessage =
|
|
new CoreApiMessage<Organization>(header, testOrganization);
|
|
|
|
var organizationJson = JsonConvert.SerializeObject(testOrganization);
|
|
|
|
_mockCoreRequest.Setup(x => x.PostRequestObject<CoreApiMessage<Organization>>(It.IsAny<string>(),
|
|
It.IsAny<Dictionary<string, string>>(),
|
|
It.IsAny<string>())).ReturnsAsync(organizationApiMessage);
|
|
|
|
// Act
|
|
var results = _organizationDao.FindOrganizationByMemberAgreeNbr(coreRequestParameters, organizationRequest);
|
|
|
|
// Assert
|
|
Assert.NotNull(results);
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindOrganizationNumbersByNameSearch_AllCases_ExecutesOrganizationNumberByNameLikeQueryWithNameAndLimitParameters()
|
|
{
|
|
var query = QueryUtilities.GetQuery("Organization/OrganizationNumberByNameLikeQuery");
|
|
var name = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var limit = DateTime.Now.Millisecond;
|
|
var resultSeries = new Random(DateTime.Now.Millisecond);
|
|
var results = new long[]{ resultSeries.Next(), resultSeries.Next(), resultSeries.Next() };
|
|
_coreDb
|
|
.Setup(c => c.ExecuteQuery<long, dynamic>(query, It.Is<object>(q => q.GetPropertyValue<string>("organizationName") == name.ToLowerInvariant() && q.GetPropertyValue<int>("limit") == limit)))
|
|
.Returns(Task.FromResult<IEnumerable<long>>(results));
|
|
|
|
var organizationNumbers = await _organizationDao.FindOrganizationNumbersByNameSearch(name, limit);
|
|
|
|
Assert.AreSame(results, organizationNumbers);
|
|
}
|
|
|
|
[Test]
|
|
public async Task CountOrganizationNumbersByName_AllCases_ExecutesOrganizationByNameLikeCountWithNameParameter()
|
|
{
|
|
var query = QueryUtilities.GetQuery("Organization/OrganizationByNameLikeCount");
|
|
var name = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var count = DateTime.Now.Millisecond;
|
|
var results = new long[]{ count };
|
|
_coreDb
|
|
.Setup(c => c.ExecuteQuery<long, dynamic>(query, It.Is<object>(q => q.GetPropertyValue<string>("organizationName") == name.ToLowerInvariant())))
|
|
.Returns(Task.FromResult<IEnumerable<long>>(results));
|
|
|
|
var organizationCount = await _organizationDao.CountOrganizationNumbersByName(name);
|
|
|
|
Assert.AreEqual(count, organizationCount);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static class ObjectPropertyExtension
|
|
{
|
|
public static T GetPropertyValue<T>(this object obj, string propertyName)
|
|
{
|
|
return (T) obj.GetType().GetProperty(propertyName).GetValue(obj, null);
|
|
}
|
|
} |