161 lines
5.5 KiB
C#
161 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Moq;
|
|
using Xunit;
|
|
using LCU.API.Collections.CollectionsApi.Services;
|
|
using LCU.API.Collections.CollectionsApi.Exceptions;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Collections.CollectionsApi.Dao;
|
|
using LCU.API.Collections.CollectionsApiLib.Models;
|
|
using LCU.API.Collections.TemenosApiWrapper.Services;
|
|
using LCU.API.Collections.CollectionsApi.Models.TemenosApiWrapper;
|
|
|
|
namespace LCU.API.Collections.CollectionsApiTests.ServiceTests
|
|
{
|
|
public class AccountServiceTest
|
|
{
|
|
private Mock<ITemenosAccountDao> _mockTemenosAccountDao;
|
|
private AccountService _accountService;
|
|
private Mock<ITemenosApiWrapperService> _mockTemenosApiWrapperService;
|
|
|
|
public AccountServiceTest()
|
|
{
|
|
_mockTemenosAccountDao = new Mock<ITemenosAccountDao>();
|
|
_mockTemenosApiWrapperService = new Mock<ITemenosApiWrapperService>();
|
|
_accountService = new AccountService(_mockTemenosAccountDao.Object, _mockTemenosApiWrapperService.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListByAccountNo_Ok()
|
|
{
|
|
//setup
|
|
_mockTemenosAccountDao.Setup(dao => dao.ListByAccountNoAsync(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync(
|
|
new List<CollectionsApiLib.Models.TemenosAccount>()
|
|
{
|
|
new CollectionsApiLib.Models.TemenosAccount()
|
|
{
|
|
AccountId = 1234,
|
|
AccountNumber = "123"
|
|
}
|
|
});
|
|
|
|
_mockTemenosApiWrapperService.Setup(service => service.AccountSearch(It.IsAny<AccountSearchRequest>())).ReturnsAsync(
|
|
new List<AccountSearchResponse>()
|
|
{
|
|
new AccountSearchResponse()
|
|
{
|
|
InternalAccountNumber = "232354254425443",
|
|
AccountAccountNumber = "123"
|
|
}
|
|
});
|
|
|
|
var result = await _accountService.ListByAccountNoAsync("123");
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Single(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListByAccountNoTemenosApiWrapperService_Exception()
|
|
{
|
|
//setup
|
|
_mockTemenosApiWrapperService.Setup(service => service.AccountSearch(It.IsAny<AccountSearchRequest>()))
|
|
.Throws(new Exception("Oops"));
|
|
|
|
var exc = await Assert.ThrowsAsync<AggregateException>(() => _accountService.ListByAccountNoAsync("123"));
|
|
|
|
Assert.NotNull(exc);
|
|
}
|
|
|
|
[Fact]
|
|
public async void ListByAccountNo_Exception()
|
|
{
|
|
//setup
|
|
_mockTemenosAccountDao.Setup(dao => dao.ListByAccountNoAsync(It.IsAny<string>(), It.IsAny<string>()))
|
|
.Throws(new Exception("Oops"));
|
|
|
|
var exc = await Assert.ThrowsAsync<Exception>(() => _accountService.ListByAccountNoAsync("123"));
|
|
|
|
Assert.NotNull(exc);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_OK()
|
|
{
|
|
//setup
|
|
_mockTemenosAccountDao.Setup(dao => dao.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(
|
|
new CollectionsApiLib.Models.TemenosAccount()
|
|
{
|
|
AccountId = 1234,
|
|
AccountNumber = "123"
|
|
}
|
|
);
|
|
|
|
var result = await _accountService.FindByIdAsync(123);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Equal(1234, result.AccountId);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_Server_Exception()
|
|
{
|
|
//setup
|
|
_mockTemenosAccountDao.Setup(dao => dao.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("Oops"));
|
|
var result = await Assert.ThrowsAsync<ServerErrorException>(() => _accountService.FindByIdAsync(123));
|
|
|
|
Assert.NotNull(result);
|
|
}
|
|
|
|
[Fact]
|
|
public async void Get_NotFound()
|
|
{
|
|
//setup
|
|
_mockTemenosAccountDao.Setup(dao => dao.FindByIdAsync(It.IsAny<int>()))
|
|
.Returns(Task.FromResult<CollectionsApiLib.Models.TemenosAccount>(null));
|
|
|
|
var result = await Assert.ThrowsAsync<NotFoundException>(() => _accountService.FindByIdAsync(123));
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Equal("Account with id 123 not found.", result.Message);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public async void GetHistory_OK()
|
|
{
|
|
const int accountId = 111;
|
|
//setup
|
|
_mockTemenosAccountDao.Setup(dao => dao.FindCommentsAsync(accountId)).ReturnsAsync(
|
|
new List<TemenosHistory>()
|
|
{
|
|
new TemenosHistory()
|
|
{
|
|
Created = DateTime.Now,
|
|
Message = "Comment",
|
|
Type = HistoryType.Comment,
|
|
UserId = 10
|
|
}
|
|
}
|
|
);
|
|
|
|
_mockTemenosAccountDao.Setup(dao => dao.FindHistoryAsync(accountId)).ReturnsAsync(
|
|
new List<TemenosHistory>()
|
|
{
|
|
new TemenosHistory()
|
|
{
|
|
Created = DateTime.Now,
|
|
Message = "Workflow",
|
|
Type = HistoryType.Workflow,
|
|
UserId = 10
|
|
}
|
|
}
|
|
);
|
|
|
|
var result = await _accountService.GetHistoryByAccountIdAsync(accountId);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.Equal(2, result.Count);
|
|
}
|
|
}
|
|
} |