This commit is contained in:
Zeeshaun
2026-03-17 11:20:00 -05:00
parent 6e7edcfe1b
commit de9ddd5001
130 changed files with 268474 additions and 0 deletions
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="Moq" Version="4.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LCU.API.Collections.CollectionsApi\LCU.API.Collections.CollectionsApi.csproj" />
</ItemGroup>
</Project>
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- additional settings used during the dotnet test execution step in the azure dev ops pipeline -->
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<CompanyNames>
<Exclude>
<CompanyName>.*microsoft.*</CompanyName>
</Exclude>
</CompanyNames>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>