public async Task Should_update_reply_and_add_event() { var options = Shared.CreateContextOptions(); var siteId = Guid.NewGuid(); var categoryId = Guid.NewGuid(); var forumId = Guid.NewGuid(); var topicId = Guid.NewGuid(); var category = new Category(categoryId, siteId, "Category", 1, Guid.NewGuid()); var forum = new Forum(forumId, categoryId, "Forum", "my-forum", "My Forum", 1); var topic = Post.CreateTopic(topicId, forumId, Guid.NewGuid(), "Title", "slug", "Content", StatusType.Published); var reply = Post.CreateReply(Guid.NewGuid(), topicId, forumId, Guid.NewGuid(), "Content", StatusType.Published); using (var dbContext = new AtlasDbContext(options)) { dbContext.Categories.Add(category); dbContext.Forums.Add(forum); dbContext.Posts.Add(topic); dbContext.Posts.Add(reply); await dbContext.SaveChangesAsync(); } using (var dbContext = new AtlasDbContext(options)) { var command = Fixture.Build <UpdateReply>() .With(x => x.Id, reply.Id) .With(x => x.SiteId, siteId) .With(x => x.ForumId, forumId) .With(x => x.TopicId, topicId) .Create(); var cacheManager = new Mock <ICacheManager>(); var createValidator = new Mock <IValidator <CreateReply> >(); var updateValidator = new Mock <IValidator <UpdateReply> >(); updateValidator .Setup(x => x.ValidateAsync(command, new CancellationToken())) .ReturnsAsync(new ValidationResult()); var sut = new ReplyService(dbContext, cacheManager.Object, createValidator.Object, updateValidator.Object); await sut.UpdateAsync(command); var updatedReply = await dbContext.Posts.FirstOrDefaultAsync(x => x.Id == command.Id); var @event = await dbContext.Events.FirstOrDefaultAsync(x => x.TargetId == command.Id); updateValidator.Verify(x => x.ValidateAsync(command, new CancellationToken())); Assert.AreEqual(command.Content, updatedReply.Content); Assert.NotNull(@event); } }