Example #1
0
        public async Task Get_ShouldReturnAllQuestions()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            await questionController.Add(_questionModel);

            await questionController.Add(_questionModel2);

            var okResult = await questionController.Get();

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

            Assert.IsInstanceOfType(okResult, typeof(OkObjectResult));
            Assert.AreEqual(2, questions.Count);
        }
Example #2
0
        public async Task Add_ShouldReturnBadRequestIfQuestionModelIsNotSend()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var badRequestResult = await questionController.Add(null);

            Assert.IsInstanceOfType(badRequestResult, typeof(BadRequestResult));
        }
Example #3
0
        public async Task Add_ShouldAddQuestion()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var okResult = await questionController.Add(_questionModel);

            Assert.IsInstanceOfType(okResult, typeof(CreatedAtRouteResult));
        }
Example #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));
        }
Example #5
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));
        }
Example #6
0
        public async Task GetOne_ShouldReturnOneQuestion()
        {
            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.GetOne(savedQuestion.Id);

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

            Assert.IsInstanceOfType(okResult, typeof(OkObjectResult));
        }
Example #7
0
        public async Task Remove_ShouldRemoveQuestion()
        {
            var questionRepository = new QuestionRepositoryBuilder().Build();
            var questionController = new QuestionsControllerBuilder().WithRepository(questionRepository)
                                     .Build();

            var savedQuestion = (await questionController.Add(_questionModel)).Cast <CreatedAtRouteResult, Question>();
            var allQuestions  = (await questionController.Get()).Cast <OkObjectResult, List <QuestionModel> >();

            Assert.AreEqual(1, allQuestions.Count);

            var okResult = await questionController.Remove(savedQuestion.Id);

            allQuestions = (await questionController.Get()).Cast <OkObjectResult, List <QuestionModel> >();

            Assert.IsInstanceOfType(okResult, typeof(OkResult));
            Assert.AreEqual(0, allQuestions.Count);
        }