Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using AutoMapper;
  2. using Diligent.WebAPI.Business.MappingProfiles;
  3. using Diligent.WebAPI.Business.Services;
  4. using Diligent.WebAPI.Contracts.DTOs.SelectionLevel;
  5. using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
  6. using Diligent.WebAPI.Contracts.Exceptions;
  7. using Diligent.WebAPI.Data.Entities;
  8. namespace Diligent.WebAPI.Tests.Services
  9. {
  10. public class SelectionProcessServiceTests
  11. {
  12. private readonly IMapper _mapper;
  13. private readonly List<SelectionProcess> _processes;
  14. private readonly SelectionProcess _selectionProcess;
  15. private readonly SelectionProcessCreateDto _selectionProcessCreateDto;
  16. public SelectionProcessServiceTests()
  17. {
  18. _selectionProcessCreateDto = new SelectionProcessCreateDto
  19. {
  20. Id = 1,
  21. ApplicantId = 1,
  22. Date = DateTime.Now,
  23. Link = "link",
  24. Name = "custom name",
  25. SchedulerId = 1,
  26. SelectionLevelId = 4,
  27. Status = "Obrađen"
  28. };
  29. _selectionProcess = new SelectionProcess
  30. {
  31. Id = 1,
  32. ApplicantId = 1,
  33. Date = DateTime.Now,
  34. Link = "link",
  35. Name = "custom name",
  36. SchedulerId = 1,
  37. SelectionLevelId = 4,
  38. Status = "Obrađen"
  39. };
  40. _processes = new List<SelectionProcess>
  41. {
  42. _selectionProcess
  43. };
  44. // configure mapper
  45. var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
  46. new List<Profile>
  47. {
  48. new SelectionProcessMappingProfile(),
  49. }));
  50. _mapper = new Mapper(configuration);
  51. }
  52. [Fact]
  53. public async Task GetAll_ShouldReturnListOfProcesses_Always()
  54. {
  55. var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes);
  56. SelectionProcessService service = new(databaseContext, _mapper);
  57. var result = await service.GetAllAsync();
  58. result.Should().HaveCount(1);
  59. }
  60. [Fact]
  61. public async Task GetById_ShouldReturnProcess_WhenProcessExist()
  62. {
  63. var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes);
  64. SelectionProcessService service = new(databaseContext, _mapper);
  65. var result = await service.GetByIdAsync(1);
  66. result.Should().BeEquivalentTo(_mapper.Map<SelectionProcessResposneDto>(_selectionProcess));
  67. }
  68. [Fact]
  69. public async Task GetById_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist()
  70. {
  71. var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes);
  72. SelectionProcessService service = new(databaseContext, _mapper);
  73. await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.GetByIdAsync(1000));
  74. }
  75. [Fact]
  76. public async Task FinishSelectionProcess_ShouldReturnTrueAndAddNewSelectionProcess_WhenProcessExists()
  77. {
  78. var process = new SelectionProcess
  79. {
  80. Id = 1,
  81. ApplicantId = 1,
  82. Date = DateTime.Now,
  83. Link = "link",
  84. Name = "custom name",
  85. SchedulerId = 1,
  86. SelectionLevelId = 1,
  87. Status = "Zakazan"
  88. };
  89. var processes = new List<SelectionProcess>
  90. {
  91. process
  92. };
  93. var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(processes);
  94. SelectionProcessService service = new(databaseContext, _mapper);
  95. var result = await service.FinishSelectionProcess(_selectionProcessCreateDto);
  96. var newProcesses = await service.GetAllAsync();
  97. result.Should().BeTrue();
  98. newProcesses.Should().HaveCount(processes.Count() + 1);
  99. }
  100. [Fact]
  101. public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessDoesnotExist()
  102. {
  103. var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes);
  104. SelectionProcessService service = new(databaseContext, _mapper);
  105. await Assert.ThrowsAsync<EntityNotFoundException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1000 }));
  106. }
  107. [Fact]
  108. public async Task FinishSelectionProcess_ShouldThrowEntityNotFooundException_WhenProcessIsInLastLevel()
  109. {
  110. var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(_processes);
  111. SelectionProcessService service = new(databaseContext, _mapper);
  112. await Assert.ThrowsAsync<InvalidOperationException>(async () => await service.FinishSelectionProcess(new SelectionProcessCreateDto { Id = 1, SelectionLevelId = 4 }));
  113. }
  114. }
  115. }