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 _mockService; private CaseController _controller; public CaseControllerTest() { _mockService = new Mock(); _controller = new CaseController(_mockService.Object); } [Fact] public async void Get_Case_By_CaseID_OK() { //arrange _mockService.Setup(service => service.GetCaseByIdAsync(It.IsAny())).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())).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() { 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; Assert.NotNull(resultAccount); } } }