using AutoMapper; using Diligent.WebAPI.Business.MappingProfiles; using Diligent.WebAPI.Business.Services; using Diligent.WebAPI.Business.Settings; using Diligent.WebAPI.Contracts.DTOs.Comment; using Diligent.WebAPI.Data.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Diligent.WebAPI.Tests.Services { public class CommentServiceTests { private readonly IMapper _mapper; private readonly List _comments; private readonly List _applicants; private ILogger _logger = Substitute.For>(); private readonly List _users; public CommentServiceTests() { _applicants = MockData.GetListOfApplicants(); _comments = MockData.GetListOfComments(); _users = MockData.GetListOfUsers(); // configure mapper var configuration = new MapperConfiguration(cfg => cfg.AddProfiles( new List { new CommentMappingProfile() })); _mapper = new Mapper(configuration); } [Fact] public async Task CreateComment_ShouldUpdatedListOfComments_Always() { var databaseContext = await Helpers.GetDatabaseContext(_comments); var frontSettings = Substitute.For>(); var mailer = Substitute.For(); CommentService applicantService = new(frontSettings,databaseContext, _mapper, _logger, mailer); var commentCreateDto = new CommentCreateDto { ApplicantId = _applicants[0].ApplicantId, Content = "dsadasd", UserId = _users[0].Id, UsersToNotify = new List() }; await applicantService.CreateComment(commentCreateDto); var comments = await databaseContext.Comments.ToListAsync(); Assert.Equal(2, comments.Count); } } }