97 lines
4.8 KiB
C#
97 lines
4.8 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using Moq;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.CoreApiUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.Configuration;
|
|
using LCU.Library.Internal.CoreApiWrapperLib.Utilities;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.Persons;
|
|
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.CoreRequests;
|
|
|
|
namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess
|
|
{
|
|
public class PersonDaoTest
|
|
{
|
|
private readonly PersonDao _personDao;
|
|
private readonly Mock<ICoreRequest> _mockCoreRequest;
|
|
private readonly Mock<ICoreDbExecution> _mockCoreDbExecution;
|
|
|
|
public PersonDaoTest()
|
|
{
|
|
_mockCoreDbExecution = new Mock<ICoreDbExecution>();
|
|
_mockCoreRequest = new Mock<ICoreRequest>();
|
|
|
|
var coreConfiguration = new CoreConfiguration
|
|
{
|
|
CoreApiConfiguration = new CoreApiConfiguration
|
|
{
|
|
CoreEndPointConfiguration = new CoreEndPointConfiguration
|
|
{
|
|
PersonsQueryName = "Test"
|
|
}
|
|
}
|
|
};
|
|
|
|
_personDao = new PersonDao(_mockCoreRequest.Object,
|
|
_mockCoreDbExecution.Object,
|
|
coreConfiguration);
|
|
}
|
|
|
|
[Test]
|
|
public async Task FindPersons_Returns_Null()
|
|
{
|
|
var coreRequestParameters = new CoreRequestParameters();
|
|
var personRequest = new PersonNameRequest();
|
|
CoreApiMessage<IEnumerable<Person>> personsJsonResponse = null;
|
|
|
|
_mockCoreRequest.Setup(x => x.PostRequestObject<CoreApiMessage<IEnumerable<Person>>>(It.IsAny<string>(),
|
|
It.IsAny<Dictionary<string,string>>(),
|
|
It.IsAny<string>())).ReturnsAsync(personsJsonResponse);
|
|
var result = await _personDao.FindByPersonsName(coreRequestParameters, personRequest);
|
|
|
|
Assert.IsNull(result);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetPersonNumbersByNameLike_AllCases_ExecutesPersonNumberByNameLikeQueryWithNameAndLimitParameters()
|
|
{
|
|
var query = QueryUtilities.GetQuery("Person/PersonNumberByNameLikeQuery");
|
|
var firstName = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var middleName = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var lastName = 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() };
|
|
_mockCoreDbExecution
|
|
.Setup(c => c.ExecuteQuery<long, dynamic>(query, It.Is<object>(q => q.GetPropertyValue<string>("firstName") == firstName.ToLowerInvariant() && q.GetPropertyValue<string>("middleName") == middleName.ToLowerInvariant() && q.GetPropertyValue<string>("lastName") == lastName.ToLowerInvariant() && q.GetPropertyValue<int>("limit") == limit)))
|
|
.Returns(Task.FromResult<IEnumerable<long>>(results));
|
|
|
|
var organizationNumbers = await _personDao.GetPersonNumbersByNameLike(firstName, middleName, lastName, limit);
|
|
|
|
Assert.AreSame(results, organizationNumbers);
|
|
}
|
|
|
|
[Test]
|
|
public async Task CountPersonsByNameLike_AllCases_ExecutesPersonByNameLikeCountWithNameParameters()
|
|
{
|
|
var query = QueryUtilities.GetQuery("Person/PersonByNameLikeCount");
|
|
var firstName = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var middleName = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var lastName = Guid.NewGuid().ToString().ToUpperInvariant();
|
|
var count = DateTime.Now.Millisecond;
|
|
var results = new long[]{ count };
|
|
_mockCoreDbExecution
|
|
.Setup(c => c.ExecuteQuery<long, dynamic>(query, It.Is<object>(q => q.GetPropertyValue<string>("firstName") == firstName.ToLowerInvariant() && q.GetPropertyValue<string>("middleName") == middleName.ToLowerInvariant() && q.GetPropertyValue<string>("lastName") == lastName.ToLowerInvariant())))
|
|
.Returns(Task.FromResult<IEnumerable<long>>(results));
|
|
|
|
var organizationCount = await _personDao.CountPersonsByNameLike(firstName, middleName, lastName);
|
|
|
|
Assert.AreEqual(count, organizationCount);
|
|
}
|
|
}
|
|
}
|