Exemple #1
0
        public async void Publish_Answer_Fail_When_Question_Not_Exists()
        {
            _questionsRepository.Setup(r => r.QuestionExists(1)).Returns(Task.FromResult(false));

            var command = new PublishAnswerCommand {
                QuestionId = 1, UserId = 1, Answer = "answer"
            };
            var commandHandler = new Application.Answers.Commands.PublishAnswerCommandHandler(
                _questionsRepository.Object,
                _answersRepository.Object,
                _questionsFollowingRepository.Object,
                _unitOfWork.Object);

            var result = await commandHandler.Handle(command, CancellationToken.None);

            Assert.Equal("Question does not exist.", result.Message);
        }
Exemple #2
0
        public async void Publish_Answer_Success_When_Question_Exists_And_Has_No_Followers()
        {
            _questionsRepository.Setup(r => r.QuestionExists(1)).Returns(Task.FromResult(true));
            _answersRepository.Setup(x => x.AddAsync(It.IsAny <Answer>())).Returns(Task.CompletedTask);
            _questionsFollowingRepository.Setup(x => x.QuestionsHasFollowers(1)).Returns(Task.FromResult(false));
            _unitOfWork.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1));

            var command = new PublishAnswerCommand {
                QuestionId = 1, UserId = 1, Answer = "answer"
            };
            var commandHandler = new Application.Answers.Commands.PublishAnswerCommandHandler(
                _questionsRepository.Object,
                _answersRepository.Object,
                _questionsFollowingRepository.Object,
                _unitOfWork.Object);

            var result = await commandHandler.Handle(command, CancellationToken.None);

            Assert.Equal("Answer published successfully", result.Message);
            Assert.False(result.HasFollowers);
        }