public void AddAnswer_failed_if_answer_is_null()
        {
            //arrange
            Mock <IUnitOfWork> uow     = new Mock <IUnitOfWork>();
            TestManager        manager = new TestManager(uow.Object);
            //act
            var result = manager.AddAnswer(null, new Question {
            }).Result;

            //assert
            Assert.False(result.Succeeded);
        }
        public void AddAnswer_failed_if_no_changes_occured()
        {
            //arrange
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();

            uow.Setup(u => u.SaveChanges()).ReturnsAsync(0);

            TestManager manager = new TestManager(uow.Object);
            //act
            var result = manager.AddAnswer(new Answer {
            }, _addQuestions[0]).Result;

            //assert
            Assert.False(result.Succeeded);
        }
        public void AddAnswer_failed_if_question_contains_answer()
        {
            //arrange
            Mock <IUnitOfWork> uow     = new Mock <IUnitOfWork>();
            TestManager        manager = new TestManager(uow.Object);
            var testAnswer             = new Answer();
            var questionToTest         = new Question {
                Answers = new List <Answer> {
                    testAnswer
                }
            };
            //act
            var result = manager.AddAnswer(testAnswer, questionToTest).Result;

            //assert
            Assert.False(result.Succeeded);
        }
        public void AddAnswer_succeded_if_answer_and_question_valid()
        {
            //arrange
            Mock <IUnitOfWork>       uow  = new Mock <IUnitOfWork>();
            Mock <IAnswerRepository> repo = new Mock <IAnswerRepository>();

            repo.Setup(r => r.Add(It.IsNotNull <Answer>()))
            .Callback <Answer>(a => _addQuestions[0].Answers.Add(a))
            .Verifiable();

            uow.Setup(u => u.SaveChanges()).ReturnsAsync(1).Verifiable();

            TestManager manager         = new TestManager(uow.Object);
            var         answersToModify = _addQuestions[0].Answers;
            var         expectedCount   = answersToModify.Count + 1;
            //act
            var result = manager.AddAnswer(new Answer(), _addQuestions[0]).Result;

            //assert
            Assert.True(result.Succeeded);
            Assert.Equal(expectedCount, answersToModify.Count);
        }