You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommentServiceTests.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using AutoMapper;
  2. using Diligent.WebAPI.Business.MappingProfiles;
  3. using Diligent.WebAPI.Business.Services;
  4. using Diligent.WebAPI.Contracts.DTOs.Comment;
  5. using Diligent.WebAPI.Data.Entities;
  6. using Microsoft.EntityFrameworkCore;
  7. using Microsoft.Extensions.Logging;
  8. namespace Diligent.WebAPI.Tests.Services
  9. {
  10. public class CommentServiceTests
  11. {
  12. private readonly IMapper _mapper;
  13. private readonly List<Comment> _comments;
  14. private readonly List<Applicant> _applicants;
  15. private ILogger<CommentService> _logger = Substitute.For<ILogger<CommentService>>();
  16. private readonly List<User> _users;
  17. public CommentServiceTests()
  18. {
  19. _applicants = MockData.GetListOfApplicants();
  20. _comments = MockData.GetListOfComments();
  21. _users = MockData.GetListOfUsers();
  22. // configure mapper
  23. var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
  24. new List<Profile>
  25. {
  26. new CommentMappingProfile()
  27. }));
  28. _mapper = new Mapper(configuration);
  29. }
  30. [Fact]
  31. public async Task CreateComment_ShouldUpdatedListOfComments_Always()
  32. {
  33. var databaseContext = await Helpers<Comment>.GetDatabaseContext(_comments);
  34. CommentService applicantService = new(databaseContext, _mapper, _logger);
  35. var commentCreateDto = new CommentCreateDto
  36. {
  37. ApplicantId = _applicants[0].ApplicantId,
  38. Content = "dsadasd",
  39. UserId = _users[0].Id
  40. };
  41. await applicantService.CreateComment(commentCreateDto);
  42. var comments = await databaseContext.Comments.ToListAsync();
  43. Assert.Equal(2, comments.Count);
  44. }
  45. }
  46. }