Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TechnologiesControllerTests.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Diligent.WebAPI.Contracts.DTOs.Technology;
  2. using Diligent.WebAPI.Contracts.Exceptions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Diligent.WebAPI.Tests.Controllers
  9. {
  10. public class TechnologiesControllerTests
  11. {
  12. private ITechnologyService _technologyService = Substitute.For<ITechnologyService>();
  13. private List<TechnologyResponseDto> _technologies = new();
  14. private TechnologyResponseDto _technology = new();
  15. public TechnologiesControllerTests()
  16. {
  17. _technology = new TechnologyResponseDto
  18. {
  19. TechnologyId = 1,
  20. Name = ".NET",
  21. TechnologyType = "Backend"
  22. };
  23. _technologies.Add(_technology);
  24. }
  25. [Fact]
  26. public async Task GetAll_ShouldReturn200OK_WhenCalled()
  27. {
  28. _technologyService.GetAllAsync().Returns(_technologies);
  29. TechnologiesController technologiesController = new(_technologyService);
  30. var result = await technologiesController.GetAll();
  31. (result as OkObjectResult).StatusCode.Should().Be(200);
  32. }
  33. [Fact]
  34. public async Task GetById_ShouldReturn200OK_WhenTechnologyExists()
  35. {
  36. _technologyService.GetByIdAsync(Arg.Any<int>()).Returns(_technology);
  37. TechnologiesController technologiesController = new(_technologyService);
  38. var result = await technologiesController.GetById(1);
  39. (result as OkObjectResult).StatusCode.Should().Be(200);
  40. }
  41. [Fact]
  42. public async Task GetById_ShouldThrowEntityNotFoundException_WhenTechnologyDontExists()
  43. {
  44. _technologyService.When(x => x.GetByIdAsync(Arg.Any<int>())).Do(x => { throw new EntityNotFoundException(); });
  45. TechnologiesController technologiesController = new(_technologyService);
  46. await Assert.ThrowsAsync<EntityNotFoundException>(() => technologiesController.GetById(1000));
  47. }
  48. }
  49. }