using Diligent.WebAPI.Contracts.DTOs.Technology; using Diligent.WebAPI.Contracts.Exceptions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Diligent.WebAPI.Tests.Controllers { public class TechnologiesControllerTests { private ITechnologyService _technologyService = Substitute.For(); private List _technologies = new(); private TechnologyResponseDto _technology = new(); public TechnologiesControllerTests() { _technology = new TechnologyResponseDto { TechnologyId = 1, Name = ".NET", TechnologyType = "Backend" }; _technologies.Add(_technology); } [Fact] public async Task GetAll_ShouldReturn200OK_WhenCalled() { _technologyService.GetAllAsync().Returns(_technologies); TechnologiesController technologiesController = new(_technologyService); var result = await technologiesController.GetAll(); (result as OkObjectResult).StatusCode.Should().Be(200); } [Fact] public async Task GetById_ShouldReturn200OK_WhenTechnologyExists() { _technologyService.GetByIdAsync(Arg.Any()).Returns(_technology); TechnologiesController technologiesController = new(_technologyService); var result = await technologiesController.GetById(1); (result as OkObjectResult).StatusCode.Should().Be(200); } [Fact] public async Task GetById_ShouldThrowEntityNotFoundException_WhenTechnologyDontExists() { _technologyService.When(x => x.GetByIdAsync(Arg.Any())).Do(x => { throw new EntityNotFoundException(); }); TechnologiesController technologiesController = new(_technologyService); await Assert.ThrowsAsync(() => technologiesController.GetById(1000)); } } }