Beispiel #1
0
        public void AnsweringQuestion_Successful()
        {
            var mockAnswerRepository = new Mock <IAnswerRepository>();

            mockAnswerRepository.Setup(u => u.Create(It.IsAny <AnswerTO>()))
            .Returns(MockAnswer);
            var mockQuestionRepository = new Mock <IQuestionRepository>();

            mockQuestionRepository.Setup(u => u.GetById(It.IsAny <int>()))
            .Returns(MockQuestion);

            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var answer2 = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = question,
            };

            var askUC       = new AskUC(mockAnswerRepository.Object, mockQuestionRepository.Object);
            var addedAnswer = askUC.AnsweringQuestion(1, answer2);

            Assert.IsNotNull(addedAnswer);
            mockAnswerRepository.Verify((m => m.Create(It.IsAny <AnswerTO>())), Times.Once());
        }
Beispiel #2
0
        public void AnsweringQuestion_NulAnswerSubmitted_ThrowException()
        {
            var mockAnswerRepository   = new Mock <IAnswerRepository>();
            var mockQuestionRepository = new Mock <IQuestionRepository>();
            var askUC = new AskUC(mockAnswerRepository.Object, mockQuestionRepository.Object);

            Assert.ThrowsException <NullReferenceException>(() => askUC.AnsweringQuestion(1, null));
        }