public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit() { var testContent = "TestContent"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var replyRepository = new EfDeletableEntityRepository <Reply>(context); var repliesService = new RepliesService(replyRepository); var inputModel = new CreateReplyInputModel() { Content = testContent, }; await repliesService.CreateAsync(inputModel); var reply = replyRepository.All().FirstOrDefault(c => c.Content == testContent); // Act var expectedReplyContent = "Edited_TestContent"; await repliesService.EditAsync(reply.Id, expectedReplyContent); var actualReplyContent = reply.Content; // Assert reply = await replyRepository.GetByIdWithDeletedAsync(reply.Id); Assert.Equal(expectedReplyContent, actualReplyContent); }
public async Task CreateMethodShouldAddReplyInDatabase(string description, int?parentId, int postId) { var guid = Guid.NewGuid().ToString(); var options = new DbContextOptionsBuilder <ForumDbContext>() .UseInMemoryDatabase(guid) .Options; var db = new ForumDbContext(options); var usersServiceMock = new Mock <IUsersService>(); var dateTimeProviderMock = new Mock <IDateTimeProvider>(); var repliesService = new RepliesService(db, null, usersServiceMock.Object, dateTimeProviderMock.Object); await repliesService.CreateAsync(description, parentId, postId, guid); db.Replies.Should().HaveCount(1); }
public async Task CreateAsync_ShouldSuccessfullyCreate() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var replyRepository = new EfDeletableEntityRepository <Reply>(context); var repliesService = new RepliesService(replyRepository); var inputModel = new CreateReplyInputModel() { Content = "TestContent", }; // Act var expectedRepliesCount = 1; await repliesService.CreateAsync(inputModel); var actualRepliesCount = replyRepository.All().Count(); // Assert Assert.Equal(expectedRepliesCount, actualRepliesCount); }
public async Task CreateMethodShouldAddRightReplyInDatabase(string description, int?parentId, int postId) { var guid = Guid.NewGuid().ToString(); var options = new DbContextOptionsBuilder <ForumDbContext>() .UseInMemoryDatabase(guid) .Options; var db = new ForumDbContext(options); var usersServiceMock = new Mock <IUsersService>(); var dateTimeProviderMock = new Mock <IDateTimeProvider>(); dateTimeProviderMock.Setup(dtp => dtp.Now()).Returns(new DateTime(2020, 3, 27)); var repliesService = new RepliesService(db, null, usersServiceMock.Object, dateTimeProviderMock.Object); await repliesService.CreateAsync(description, parentId, postId, guid); var expected = new Reply { Id = 1, Description = description, ParentId = parentId, PostId = postId, AuthorId = guid, CreatedOn = dateTimeProviderMock.Object.Now(), }; var actual = await db.Replies.FirstOrDefaultAsync(); expected.Id.Should().Be(actual.Id); expected.Description.Should().Be(actual.Description); expected.ParentId.Should().Be(actual.ParentId); expected.PostId.Should().Be(actual.PostId); expected.AuthorId.Should().Be(actual.AuthorId); expected.CreatedOn.Should().BeSameDateAs(actual.CreatedOn); }