| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<ITechnologyService>();
- private List<TechnologyResponseDto> _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<int>()).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<int>())).Do(x => { throw new EntityNotFoundException(); });
-
- TechnologiesController technologiesController = new(_technologyService);
-
- await Assert.ThrowsAsync<EntityNotFoundException>(() => technologiesController.GetById(1000));
- }
- }
- }
|