public async Task CreateAnswerErrorTest()
        {
            // Arrange
            var repo      = new Mock <IRepositoryEnq>();
            var answer    = QuestionData.TestAnswerMinProps;
            var errAnswer = QuestionData.InvalidTestAnswer;
            var context   = GetMockContext();

            repo.Setup(r => r.ExistsAsync <Question>(q => q.Id == answer.Id))
            .ReturnsAsync(false);

            var controller
                = new WriteApiController(repo.Object, context.Object);

            // Act
            var notFoundResult = await controller.CreateAnswer(answer);

            var badReqResult = await controller.CreateAnswer(errAnswer);

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult);
            Assert.IsType <BadRequestResult>(badReqResult);

            repo.Verify(r => r.ExistsAsync <Question>
                            (It.IsAny <Expression <Func <Question, bool> > >()), Times.Once);
            VerifyMockContext(context, 0);
            repo.VerifyNoOtherCalls();
        }
        public async Task CreateAnswerTest()
        {
            // Arrange
            var repo    = new Mock <IRepositoryEnq>();
            var answer  = QuestionData.TestAnswerMinProps;
            var context = GetMockContext();

            repo.Setup(r => r.ExistsAsync <Question>
                           (It.IsAny <Expression <Func <Question, bool> > >()))
            .ReturnsAsync(true);

            var controller
                = new WriteApiController(repo.Object, context.Object);

            // Act
            var result = await controller.CreateAnswer(answer);

            // Assert
            Assert.IsType <OkObjectResult>(result);

            repo.Verify(r => r.Create(answer), Times.Once);
            repo.Verify(r => r.SaveAsync(), Times.Once);
            repo.Verify(r => r.ExistsAsync <Question>
                            (It.IsAny <Expression <Func <Question, bool> > >()), Times.Once);
            VerifyMockContext(context, 1);
            repo.VerifyNoOtherCalls();
        }
        public async Task CreateQuestionErrorTest()
        {
            // Arrange
            var repo     = new Mock <IRepositoryEnq>();
            var question = QuestionData.CreateTestInvalidQuestion;
            var context  = GetMockContext();

            var controller
                = new WriteApiController(repo.Object, context.Object);

            // Act
            var result = await controller.CreateQuestion(question);

            // Assert
            Assert.IsType <BadRequestResult>(result);
            VerifyMockContext(context, 0);
            repo.VerifyNoOtherCalls();
        }
        public async Task CreateQuestionTest()
        {
            // Arrange
            var repo    = new Mock <IRepositoryEnq>();
            var context = GetMockContext();

            var question = QuestionData.TestQuestionMinProps;
            var controller
                = new WriteApiController(repo.Object, context.Object);

            // Act
            var result = await controller.CreateQuestion(question);

            // Assert
            Assert.IsType <OkObjectResult>(result);

            repo.Verify(r => r.Create(question), Times.Once);
            repo.Verify(r => r.SaveAsync(), Times.Once);
            VerifyMockContext(context, 1);
            repo.VerifyNoOtherCalls();
        }