public void should_create_topic()
        {
            _app.MockUser();
            var topicController = _app.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      = _app.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(_app.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);
        }
示例#2
0
        private Topic VerifyTopicCreated(ActionResult actionResult, TopicCreationModel model)
        {
            Assert.IsType <RedirectToActionResult>(actionResult);

            var repo      = _app.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(_app.GetDiscussionUser().Id);

            var createdAt = DateTime.UtcNow - createdTopic.CreatedAtUtc;

            Assert.True(createdAt.TotalMilliseconds >= 0);
            Assert.True(createdAt.TotalMinutes < 2);

            return(createdTopic);
        }