您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CommentServiceTests.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. namespace Diligent.WebAPI.Tests.Services
  8. {
  9. public class CommentServiceTests
  10. {
  11. private readonly IMapper _mapper;
  12. private readonly List<Comment> _comments;
  13. private readonly List<Applicant> _applicants;
  14. private readonly List<User> _users;
  15. public CommentServiceTests()
  16. {
  17. _applicants = MockData.GetListOfApplicants();
  18. _comments = MockData.GetListOfComments();
  19. _users = MockData.GetListOfUsers();
  20. // configure mapper
  21. var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
  22. new List<Profile>
  23. {
  24. new CommentMappingProfile()
  25. }));
  26. _mapper = new Mapper(configuration);
  27. }
  28. [Fact]
  29. public async Task CreateComment_ShouldUpdatedListOfComments_Always()
  30. {
  31. var databaseContext = await Helpers<Comment>.GetDatabaseContext(_comments);
  32. CommentService applicantService = new(databaseContext, _mapper);
  33. var commentCreateDto = new CommentCreateDto
  34. {
  35. ApplicantId = _applicants[0].ApplicantId,
  36. Content = "dsadasd",
  37. UserId = _users[0].Id
  38. };
  39. await applicantService.CreateComment(commentCreateDto);
  40. var comments = await databaseContext.Comments.ToListAsync();
  41. Assert.Equal(2, comments.Count);
  42. }
  43. }
  44. }