public void should_add_reply() { // Arrange var user = _app.MockUser(); var topic = _app.NewTopic().WithAuthor(user).Create(); // Act var replyController = _app.CreateController <ReplyController>(); replyController.Reply(topic.Id, new ReplyCreationModel { Content = "my reply" }); // Assert var replies = _app.GetService <IRepository <Reply> >() .All() .Where(c => c.TopicId == topic.Id) .ToList(); replies.Count.ShouldEqual(1); replies[0].TopicId.ShouldEqual(topic.Id); replies[0].CreatedBy.ShouldEqual(user.Id); replies[0].Content.ShouldEqual("my reply"); var dbContext = _app.GetService <ApplicationDbContext>(); dbContext.Entry(topic).Reload(); topic.ReplyCount.ShouldEqual(1); topic.LastRepliedByUser.ShouldNotBeNull(); topic.LastRepliedAuthor.ShouldNotBeNull(); topic.LastRepliedAt.ShouldNotBeNull(); var span = DateTime.UtcNow - topic.LastRepliedAt.Value; Assert.True(span.TotalSeconds > 0); Assert.True(span.TotalSeconds < 10); var replyCreatedLog = _app.GetLogs().FirstOrDefault(log => log.Message.Contains("添加回复成功")); Assert.NotNull(replyCreatedLog); Assert.Contains($"UserId = {user.Id}", replyCreatedLog.Message); Assert.Contains($"TopicId = {topic.Id}", replyCreatedLog.Message); Assert.Contains($"ReplyId = {replies[0].Id}", replyCreatedLog.Message); }
public void should_reply_a_topic_by_an_authorized_user() { var topic = _app.NewTopic().Create(); _app.ShouldPost($"/topics/{topic.Id}/replies", new { Content = "reply content" }, SigninRequired); }
public void should_serve_topic_list_on_page() { _app.NewTopic("dummy topic 1").WithReply().Create(); _app.NewTopic("dummy topic 2", type: TopicType.Question).WithReply().Create(); _app.NewTopic("dummy topic 3", type: TopicType.Job).WithReply().Create(); var topicController = _app.CreateController <TopicController>(); var topicListResult = topicController.List() as ViewResult; var listViewModel = topicListResult.ViewData.Model as Paged <Topic>; Assert.NotNull(listViewModel); var showedTopics = listViewModel.Items; showedTopics.ShouldContain(t => t.Title == "dummy topic 1" && t.Type == TopicType.Discussion); showedTopics.ShouldContain(t => t.Title == "dummy topic 2" && t.Type == TopicType.Question); showedTopics.ShouldContain(t => t.Title == "dummy topic 3" && t.Type == TopicType.Job); showedTopics.All(t => t.Author != null).ShouldEqual(true); showedTopics.All(t => t.LastRepliedUser != null).ShouldEqual(true); }