コード例 #1
0
        public async Task AddReply_ShouldReturnNotFoundIfQuestionNotExists()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var okResult = await questionController.AddReply(_replyModel, 1);

            Assert.IsInstanceOfType(okResult, typeof(NotFoundResult));
        }
コード例 #2
0
        public async Task AddReply_ShouldReturnBadRequestIfReplyModelIsNotSend()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var badRequestResult = await questionController.AddReply(null, 1);

            Assert.IsInstanceOfType(badRequestResult, typeof(BadRequestResult));
        }
コード例 #3
0
        public async Task AddReply_ShouldAddReplyToQuestion()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var savedQuestion = (await questionController.Add(_questionModel)).Cast <CreatedAtRouteResult, Question>();

            var okResult = await questionController.AddReply(_replyModel, savedQuestion.Id);

            Assert.IsInstanceOfType(okResult, typeof(CreatedAtRouteResult));
        }
コード例 #4
0
        public async Task GetUnanswered_ShouldReturnUnanswered()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var savedQuestion = (await questionController.Add(_questionModel)).Cast <CreatedAtRouteResult, Question>();
            await questionController.Add(_questionModel2);

            await questionController.AddReply(_replyModel, savedQuestion.Id);

            var okResult = await questionController.GetUnanswered();

            var questions = okResult.Cast <OkObjectResult, List <QuestionModel> >();

            Assert.IsInstanceOfType(okResult, typeof(OkObjectResult));
            Assert.AreEqual(1, questions.Count);
            Assert.IsFalse(questions.TrueForAll(q => q.Replies.Count > 0));
        }