Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TechnologyServiceTests.cs 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using AutoMapper;
  2. using Diligent.WebAPI.Business.MappingProfiles;
  3. using Diligent.WebAPI.Business.Services;
  4. using Diligent.WebAPI.Contracts.DTOs.Technology;
  5. using Diligent.WebAPI.Contracts.Exceptions;
  6. using Diligent.WebAPI.Data.Entities;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace Diligent.WebAPI.Tests.Services
  13. {
  14. public class TechnologyServiceTests
  15. {
  16. private readonly IMapper _mapper;
  17. private readonly List<Technology> _technologies = new();
  18. private readonly Technology _technology;
  19. public TechnologyServiceTests()
  20. {
  21. var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
  22. new List<Profile>
  23. {
  24. new TechnologyMappingProfile()
  25. }));
  26. _mapper = new Mapper(configuration);
  27. _technology = new Technology
  28. {
  29. TechnologyId = 1,
  30. Name = ".NET",
  31. TechnologyType = TechnologyTypes.Backend
  32. };
  33. _technologies.Add(_technology);
  34. }
  35. [Fact]
  36. public async Task GetAll_ShouldReturnListOfTechnologies_WhenCalled()
  37. {
  38. var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
  39. TechnologyService tehnologyService = new(_mapper, databaseContext);
  40. var result = await tehnologyService.GetAllAsync();
  41. Assert.Equal(result.Count, 1);
  42. }
  43. [Fact]
  44. public async Task GetById_ShouldReturnTechnology_WhenTechnologyExists()
  45. {
  46. var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
  47. TechnologyService tehnologyService = new(_mapper, databaseContext);
  48. var result = await tehnologyService.GetByIdAsync(1);
  49. result.Should().BeEquivalentTo(_mapper.Map<TechnologyResponseDto>(_technology));
  50. }
  51. [Fact]
  52. public async Task GetById_ShouldThrowEntityNotFoundException_WhenTechnologyDontExists()
  53. {
  54. var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
  55. TechnologyService tehnologyService = new(_mapper, databaseContext);
  56. await Assert.ThrowsAsync<EntityNotFoundException>(async () => await tehnologyService.GetByIdAsync(1000));
  57. }
  58. [Fact]
  59. public async Task GetEntityById_ShouldReturnTechnology_WhenTechnologyExists()
  60. {
  61. var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
  62. TechnologyService tehnologyService = new(_mapper, databaseContext);
  63. var result = await tehnologyService.GetEntityByIdAsync(1);
  64. result.Should().BeEquivalentTo(_technology);
  65. }
  66. [Fact]
  67. public async Task GetEntityById_ShouldThrowEntityNotFoundException_WhenTechnologyDontExists()
  68. {
  69. var databaseContext = await Helpers<Technology>.GetDatabaseContext(_technologies);
  70. TechnologyService tehnologyService = new(_mapper, databaseContext);
  71. await Assert.ThrowsAsync<EntityNotFoundException>(async () => await tehnologyService.GetEntityByIdAsync(1000));
  72. }
  73. }
  74. }