Adding
This commit is contained in:
+134
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using LCU.API.Collections.CollectionsApi.Controllers;
|
||||
using LCU.API.Collections.CollectionsApi.Exceptions;
|
||||
using LCU.API.Collections.CollectionsApi.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.CollectionsApiTests.ControllerTests
|
||||
{
|
||||
public class AccountControllerTest
|
||||
{
|
||||
private Mock<IAccountService> _mockService;
|
||||
private AccountController _controller;
|
||||
|
||||
public AccountControllerTest()
|
||||
{
|
||||
_mockService = new Mock<IAccountService>();
|
||||
_controller = new AccountController(_mockService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Accounts_By_Id_OK()
|
||||
{
|
||||
_mockService.Setup(service => service.FindByIdAsync(It.IsAny<int>())).ReturnsAsync(new CollectionsApiLib.Models.TemenosAccount()
|
||||
{
|
||||
AccountId = 12345,
|
||||
AccountIdentifier = "Identifier"
|
||||
});
|
||||
|
||||
//arrange
|
||||
|
||||
//act
|
||||
var result = await _controller.GetAccountByAccountId(12345);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultAccount = okResult.Value as CollectionsApiLib.Models.TemenosAccount;
|
||||
Assert.NotNull(resultAccount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Accounts_By_AccountNo_OK()
|
||||
{
|
||||
//arrange
|
||||
_mockService.Setup(service => service.ListByAccountNoAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new List<CollectionsApiLib.Models.TemenosAccount>(){
|
||||
new CollectionsApiLib.Models.TemenosAccount()
|
||||
{
|
||||
AccountNumber = "54444143",
|
||||
AccountId = 12345,
|
||||
AccountIdentifier = "Identifier"
|
||||
}
|
||||
});
|
||||
|
||||
//act
|
||||
var result = await _controller.GetAccountByAccountNo("54444143");
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultAccount = okResult.Value as List<CollectionsApiLib.Models.TemenosAccount>;
|
||||
Assert.NotNull(resultAccount);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void Get_Accounts_By_Id_400()
|
||||
{
|
||||
//arrange
|
||||
_mockService.Setup(service => service.FindByIdAsync(It.IsAny<int>())).Throws(new NotFoundException("Oops"));
|
||||
|
||||
//act
|
||||
var result = await _controller.GetAccountByAccountId(12345);
|
||||
Assert.NotNull(result);
|
||||
var NFResult = result as NotFoundObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(NFResult);
|
||||
Assert.Equal(404, NFResult.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Accounts_By_Id_500()
|
||||
{
|
||||
//arrange
|
||||
_mockService.Setup(service => service.FindByIdAsync(It.IsAny<int>())).Throws(new System.Exception("Oops"));
|
||||
|
||||
//act
|
||||
var result = await _controller.GetAccountByAccountId(12345);
|
||||
Assert.NotNull(result);
|
||||
var result500 = result as StatusCodeResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result500);
|
||||
Assert.Equal(500, result500.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_History_By_Id_OK()
|
||||
{
|
||||
//arrange
|
||||
const int accountId = 12345;
|
||||
_mockService.Setup(service => service.GetHistoryByAccountIdAsync(accountId)).ReturnsAsync(new List<TemenosHistory>()
|
||||
{
|
||||
new TemenosHistory()
|
||||
{
|
||||
Created = DateTime.Now,
|
||||
Message = "controllertest",
|
||||
Type = HistoryType.Workflow,
|
||||
UserId = 10
|
||||
}
|
||||
});
|
||||
|
||||
//act
|
||||
var result = await _controller.GetHistoryByAccountId(accountId);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultAccount = okResult.Value as IReadOnlyCollection<TemenosHistory>;
|
||||
Assert.NotNull(resultAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Collections.CollectionsApi.Controllers;
|
||||
using LCU.API.Collections.CollectionsApi.Services;
|
||||
using LCU.API.Collections.CollectionsApiLib.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.CollectionsApiTests.ControllerTests
|
||||
{
|
||||
public class CaseControllerTest
|
||||
{
|
||||
private Mock<ICaseService> _mockService;
|
||||
private CaseController _controller;
|
||||
|
||||
public CaseControllerTest()
|
||||
{
|
||||
_mockService = new Mock<ICaseService>();
|
||||
_controller = new CaseController(_mockService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Case_By_CaseID_OK()
|
||||
{
|
||||
//arrange
|
||||
_mockService.Setup(service => service.GetCaseByIdAsync(It.IsAny<int>())).ReturnsAsync(
|
||||
new CollectionsApiLib.Models.TemenosCase()
|
||||
{
|
||||
CaseId = 1234
|
||||
});
|
||||
|
||||
//act
|
||||
var result = await _controller.GetCaseByCaseId(1234);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultAccount = okResult.Value as CollectionsApiLib.Models.TemenosCase;
|
||||
Assert.NotNull(resultAccount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Case_By_CaseNo_OK()
|
||||
{
|
||||
//arrange
|
||||
_mockService.Setup(service => service.GetCaseByCaseNoAsync(It.IsAny<string>())).ReturnsAsync(
|
||||
new CollectionsApiLib.Models.TemenosCase()
|
||||
{
|
||||
CaseId = 1234,
|
||||
CaseNumber = "123123-123"
|
||||
});
|
||||
|
||||
//act
|
||||
var result = await _controller.GetCaseByCaseNo("123123-123");
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultAccount = okResult.Value as CollectionsApiLib.Models.TemenosCase;
|
||||
Assert.NotNull(resultAccount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_History_By_Id_OK()
|
||||
{
|
||||
//arrange
|
||||
const int caseId = 12345;
|
||||
_mockService.Setup(service => service.GetHistoryByAccountIdAsync(caseId)).ReturnsAsync(new List<TemenosHistory>()
|
||||
{
|
||||
new TemenosHistory()
|
||||
{
|
||||
Created = DateTime.Now,
|
||||
Message = "controllertest",
|
||||
Type = HistoryType.Workflow,
|
||||
UserId = 10
|
||||
}
|
||||
});
|
||||
|
||||
//act
|
||||
var result = await _controller.GetHistoryByCaseId(caseId);
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultAccount = okResult.Value as IReadOnlyCollection<TemenosHistory>;
|
||||
Assert.NotNull(resultAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
using LCU.API.Collections.CollectionsApi.Controllers;
|
||||
using LCU.API.Collections.CollectionsApi.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace LCU.API.Collections.CollectionsApiTests.ControllerTests
|
||||
{
|
||||
public class ConfigurationControllerTest
|
||||
{
|
||||
private readonly Mock<IConfigurationService> _mockService;
|
||||
private readonly ConfigurationController _controller;
|
||||
|
||||
public ConfigurationControllerTest()
|
||||
{
|
||||
_mockService = new Mock<IConfigurationService>();
|
||||
_controller = new ConfigurationController(_mockService.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Get_Configurations_OK()
|
||||
{
|
||||
_mockService.Setup(service => service.GetAsync()).ReturnsAsync(new CollectionsApiLib.Models.TemenosConfiguration());
|
||||
|
||||
//arrange
|
||||
|
||||
//act
|
||||
var result = await _controller.Get();
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(okResult);
|
||||
Assert.Equal(200, okResult.StatusCode);
|
||||
var resultConfig = okResult.Value as CollectionsApiLib.Models.TemenosConfiguration;
|
||||
Assert.NotNull(resultConfig);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void Get_Config_500()
|
||||
{
|
||||
//arrange
|
||||
_mockService.Setup(service => service.GetAsync()).Throws(new System.Exception("Oops"));
|
||||
|
||||
//act
|
||||
var result = await _controller.Get();
|
||||
Assert.NotNull(result);
|
||||
var result500 = result as StatusCodeResult;
|
||||
|
||||
// assert
|
||||
Assert.NotNull(result500);
|
||||
Assert.Equal(500, result500.StatusCode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user