public void should_add_reply() { // Arrange _app.MockUser(); var(topic, userId) = CreateTopic(_app); // 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(userId); replies[0].Content.ShouldEqual("my reply"); var dbContext = _app.GetService <ApplicationDbContext>(); dbContext.Entry(topic).Reload(); topic.ReplyCount.ShouldEqual(1); topic.LastRepliedAt.ShouldNotBeNull(); var span = DateTime.UtcNow - topic.LastRepliedAt.Value; Assert.True(span.TotalSeconds > 0); Assert.True(span.TotalSeconds < 10); }
public void should_create_topic() { _myApp.MockUser(); var topicController = _myApp.CreateController <TopicController>(); var model = new TopicCreationModel() { Title = "first topic you created", Content = "**This is the content of this markdown**\r\n* markdown content is greate*", Type = TopicType.Job }; topicController.CreateTopic(model); var repo = _myApp.GetService <IRepository <Topic> >(); var allTopics = repo.All().ToList(); var createdTopic = allTopics.Find(topic => topic.Title == model.Title); createdTopic.ShouldNotBeNull(); createdTopic.Title.ShouldEqual(model.Title); createdTopic.Content.ShouldEqual(model.Content); createdTopic.Type.ShouldEqual(TopicType.Job); createdTopic.CreatedBy.ShouldEqual(_myApp.GetDiscussionUser().Id); var createdAt = DateTime.UtcNow - createdTopic.CreatedAtUtc; Assert.True(createdAt.TotalMilliseconds >= 0); Assert.True(createdAt.TotalMinutes < 2); createdTopic.LastRepliedAt.ShouldBeNull(); createdTopic.ReplyCount.ShouldEqual(0); createdTopic.ViewCount.ShouldEqual(0); }
public async Task should_reply_a_topic_by_an_authorized_user() { _theApp.MockUser(); var(topic, userId) = ReplyControllerSpecs.CreateTopic(_theApp); var response = await RequestToCreateReply(_theApp, topic.Id); response.StatusCode.ShouldEqual(HttpStatusCode.NoContent); }
public async Task should_serve_create_topic_page() { // arrange var request = _theApp.Server.CreateRequest("/topics/create"); _theApp.MockUser(); // act var response = await request.GetAsync(); // assert response.StatusCode.ShouldEqual(HttpStatusCode.OK); response.Content().ShouldContain("创建新话题"); }
public async Task should_signout() { var authService = new Mock <IAuthenticationService>(); authService.Setup(auth => auth.SignOutAsync(It.IsAny <HttpContext>(), It.IsAny <string>(), It.IsAny <AuthenticationProperties>())).Returns(Task.CompletedTask).Verifiable(); ReplacableServiceProvider.Replace(services => { services.AddSingleton(authService.Object); }); _myApp.MockUser(); var accountCtrl = _myApp.CreateController <AccountController>(); var signoutResult = await accountCtrl.DoSignOut(); Assert.NotNull(signoutResult); signoutResult.IsType <RedirectResult>(); authService.Verify(); }