Adding
This commit is contained in:
+127
@@ -0,0 +1,127 @@
|
||||
using LCU.Library.Internal.CoreApiWrapperLib.CoreDbUtilities;
|
||||
using LCU.Library.Internal.CoreApiWrapperLib.DataAccess;
|
||||
using LCU.Library.Internal.CoreApiWrapperModel.CoreModels.MemberAgreements;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LCU.Api.Internal.CoreApiWrapperTest.DataAccess
|
||||
{
|
||||
public class AgreeDaoTest
|
||||
{
|
||||
private AgreeDao _agreeDao;
|
||||
private Mock<ICoreDbExecution> _mockCoreDbExecution;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockCoreDbExecution = new Mock<ICoreDbExecution>();
|
||||
_agreeDao = new AgreeDao(_mockCoreDbExecution.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindAgreeUsersByAccountNumbers_OK()
|
||||
{
|
||||
_mockCoreDbExecution
|
||||
.Setup(x => x.ExecuteQuery<AgreeUserAccount, object>(It.IsAny<string>(),
|
||||
It.IsAny<Dictionary<string, object>>()))
|
||||
.ReturnsAsync(new List<AgreeUserAccount>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
AccountNumber = 20001,
|
||||
AgreeNumber = 2000,
|
||||
UserId = "12000"
|
||||
}
|
||||
}).Verifiable();
|
||||
|
||||
var testAccountNumbers = new List<string>() { "20001" };
|
||||
var results = await _agreeDao.FindAgreeUsersByAccountNumbers(testAccountNumbers);
|
||||
|
||||
Assert.NotNull(results);
|
||||
var firstResult = results.FirstOrDefault();
|
||||
Assert.AreEqual(20001, firstResult.AccountNumber);
|
||||
Assert.AreEqual(2000, firstResult.AgreeNumber);
|
||||
Assert.AreEqual("12000", firstResult.UserId);
|
||||
|
||||
_mockCoreDbExecution.Verify(x =>
|
||||
x.ExecuteQuery<AgreeUserAccount, Dictionary<string, object>>(
|
||||
It.Is<string>(str => str.Contains(":param0")),
|
||||
It.IsAny<Dictionary<string, object>>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindByUserId_Exception()
|
||||
{
|
||||
_mockCoreDbExecution
|
||||
.Setup(x => x.ExecuteQuery<AgreeUserAccount, object>(It.IsAny<string>(),
|
||||
It.IsAny<Dictionary<string, object>>()))
|
||||
.ThrowsAsync(new Exception("Ah oh Error"));
|
||||
|
||||
|
||||
var testAccountNumbers = new List<string>() { "20001" };
|
||||
Assert.ThrowsAsync<Exception>(async () =>
|
||||
await _agreeDao.FindAgreeUsersByAccountNumbers(testAccountNumbers));
|
||||
|
||||
_mockCoreDbExecution.Verify(x =>
|
||||
x.ExecuteQuery<AgreeUserAccount, Dictionary<string, object>>(
|
||||
It.Is<string>(str => str.Contains(":param0")),
|
||||
It.IsAny<Dictionary<string, object>>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindAgreeUserByPersonNumber_OK()
|
||||
{
|
||||
_mockCoreDbExecution
|
||||
.Setup(x => x.ExecuteQuery<string, object>(It.IsAny<string>(), It.IsAny<object>()))
|
||||
.ReturnsAsync(new List<string> { "5436" }).Verifiable();
|
||||
|
||||
var result = await _agreeDao.FindAgreeUserByPersonNumber(12355L);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("5436", result.FirstOrDefault());
|
||||
_mockCoreDbExecution.Verify();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindAgreeUserByPersonNumber_Exception()
|
||||
{
|
||||
_mockCoreDbExecution
|
||||
.Setup(x => x.ExecuteQuery<string, object>(It.IsAny<string>(), It.IsAny<object>()))
|
||||
.ThrowsAsync(new Exception("Error thrown from unit test"));
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async () => await _agreeDao.FindAgreeUserByPersonNumber(123L));
|
||||
|
||||
_mockCoreDbExecution.Verify();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FindAgreeUserByOrganizationNumber_OK()
|
||||
{
|
||||
_mockCoreDbExecution
|
||||
.Setup(x => x.ExecuteQuery<string, object>(It.IsAny<string>(), It.IsAny<object>()))
|
||||
.ReturnsAsync(new List<string> { "5436" }).Verifiable();
|
||||
|
||||
var result = await _agreeDao.FindAgreeUserByOrganizationNumber(12355L);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual("5436", result);
|
||||
_mockCoreDbExecution.Verify();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindAgreeUserByOrganizationNumber_Exception()
|
||||
{
|
||||
_mockCoreDbExecution
|
||||
.Setup(x => x.ExecuteQuery<string, object>(It.IsAny<string>(), It.IsAny<object>()))
|
||||
.ThrowsAsync(new Exception("Error thrown from unit test"));
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async () => await _agreeDao.FindAgreeUserByOrganizationNumber(123L));
|
||||
|
||||
_mockCoreDbExecution.Verify();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user