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

CommentServiceTests.cs 2.1KB

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