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 _mockService; private readonly ConfigurationController _controller; public ConfigurationControllerTest() { _mockService = new Mock(); _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); } } }