Example #1
0
        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_serve_topic_list_on_page()
        {
            var topicItems = new[]
            {
                new Topic {
                    Title = "dummy topic 1", Type = TopicType.Discussion
                },
                new Topic {
                    Title = "dummy topic 2", Type = TopicType.Discussion
                },
                new Topic {
                    Title = "dummy topic 3", Type = TopicType.Discussion
                },
            };
            var repo = _myApp.GetService <IRepository <Topic> >();

            foreach (var item in topicItems)
            {
                repo.Save(item);
            }

            var topicController = _myApp.CreateController <TopicController>();

            var topicListResult = topicController.List() as ViewResult;
            var listViewModel   = topicListResult.ViewData.Model as TopicListViewModel;

            listViewModel.ShouldNotBeNull();
            var topicList = listViewModel.Topics;

            topicList.ShouldContain(t => t.Title == "dummy topic 1");
            topicList.ShouldContain(t => t.Title == "dummy topic 2");
            topicList.ShouldContain(t => t.Title == "dummy topic 3");
        }
        public void should_serve_error_page_as_view_result()
        {
            var homeController = _myApp.CreateController <HomeController>();

            var errorResult = homeController.Error();

            Assert.NotNull(errorResult);
            Assert.IsType <ViewResult>(errorResult);

            homeController.Response.StatusCode.ShouldEqual((int)HttpStatusCode.InternalServerError);
        }
        public void should_serve_signin_page_as_view_result()
        {
            var accountCtrl = _myApp.CreateController <AccountController>();

            IActionResult signinPageResult = accountCtrl.Signin(null);

            var viewResult = signinPageResult as ViewResult;

            Assert.NotNull(viewResult);
        }