Adding
This commit is contained in:
+161
@@ -0,0 +1,161 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
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;
|
||||
|
||||
namespace LCU.API.Collections.CollectionsApiTests.ServiceTests
|
||||
{
|
||||
public class CaseServiceTest
|
||||
{
|
||||
private Mock<ITemenosCaseDao> _mockTemenosCaseDao;
|
||||
private CaseService _caseService;
|
||||
|
||||
public CaseServiceTest()
|
||||
{
|
||||
_mockTemenosCaseDao = new Mock<ITemenosCaseDao>();
|
||||
_caseService = new CaseService( _mockTemenosCaseDao.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCaseByID_OK()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new CollectionsApiLib.Models.TemenosCase()
|
||||
{
|
||||
CaseId = 1234,
|
||||
CaseTitle = "Case"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _caseService.GetCaseByIdAsync(1234);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1234, result.CaseId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCaseByID_Server_Exception()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindByIdAsync(It.IsAny<int>())).ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await Assert.ThrowsAsync<ServerErrorException>(() => _caseService.GetCaseByIdAsync(1234));
|
||||
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCaseByID_NotFound()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindByIdAsync(It.IsAny<int>())).Returns(Task.FromResult<CollectionsApiLib.Models.TemenosCase>(null));
|
||||
|
||||
var result = await Assert.ThrowsAsync<NotFoundException>(() => _caseService.GetCaseByIdAsync(123));
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Case with id 123 not found.", result.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCaseByNO_OK()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindByCaseNoAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new CollectionsApiLib.Models.TemenosCase()
|
||||
{
|
||||
CaseId = 1234,
|
||||
CaseNumber = "12345",
|
||||
CaseTitle = "Case"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _caseService.GetCaseByCaseNoAsync("1234");
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1234, result.CaseId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCaseByNo_Server_Exception()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindByCaseNoAsync(It.IsAny<string>())).ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await Assert.ThrowsAsync<ServerErrorException>(() => _caseService.GetCaseByCaseNoAsync("12345"));
|
||||
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetCaseByNO_NotFound()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindByCaseNoAsync(It.IsAny<string>())).Returns(Task.FromResult<CollectionsApiLib.Models.TemenosCase>(null));
|
||||
|
||||
var result = await Assert.ThrowsAsync<NotFoundException>(() => _caseService.GetCaseByCaseNoAsync("1234"));
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("Case with case no 1234 not found.", result.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetHistory_OK()
|
||||
{
|
||||
const int caseId = 111;
|
||||
//setup
|
||||
_mockTemenosCaseDao.Setup(dao => dao.FindCommentsAsync(caseId)).ReturnsAsync(
|
||||
new List<TemenosHistory>()
|
||||
{
|
||||
new TemenosHistory()
|
||||
{
|
||||
Created = DateTime.Now,
|
||||
Message = "Comment",
|
||||
|
||||
Type = HistoryType.Comment,
|
||||
UserId = 10
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _caseService.GetHistoryByAccountIdAsync(caseId);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(1, result.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using LCU.API.Collections.CollectionsApi.Services;
|
||||
using LCU.API.Collections.CollectionsApi.Exceptions;
|
||||
using LCU.API.Collections.CollectionsApi.Dao;
|
||||
|
||||
namespace LCU.API.Collections.CollectionsApiTests.ServiceTests
|
||||
{
|
||||
public class ConfigurationServiceTest
|
||||
{
|
||||
private Mock<ITemenosConfigurationDao> _mockTemenosConfigurationDao;
|
||||
private ConfigurationService _configurationService;
|
||||
|
||||
public ConfigurationServiceTest()
|
||||
{
|
||||
_mockTemenosConfigurationDao = new Mock<ITemenosConfigurationDao>();
|
||||
_configurationService = new ConfigurationService(_mockTemenosConfigurationDao.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_OK()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosConfigurationDao.Setup(dao => dao.GetAsync()).ReturnsAsync(
|
||||
new CollectionsApiLib.Models.TemenosConfiguration()
|
||||
);
|
||||
|
||||
var result = await _configurationService.GetAsync();
|
||||
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Server_Exception()
|
||||
{
|
||||
//setup
|
||||
_mockTemenosConfigurationDao.Setup(dao => dao.GetAsync()).ThrowsAsync(new Exception("Oops"));
|
||||
var result = await Assert.ThrowsAsync<ServerErrorException>(() => _configurationService.GetAsync());
|
||||
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user