public void UpdateAsyncSuccessTest()
        {
            // Arrange
            IQbQuestionRepository repository = Substitute.For <IQbQuestionRepository>();
            IUnitOfWork           unitOfWork = Substitute.For <IUnitOfWork>();
            QbQuestion            question   = new QbQuestion();

            repository.FindByIdAsync(Arg.Any <int>()).Returns(question);
            repository.Update(Arg.Any <QbQuestion>()).Returns(true);
            unitOfWork.CompleteAsync().Returns(Task.CompletedTask);
            QbQuestionService service = new QbQuestionService(repository, unitOfWork);

            // Act
            Task <QbQuestionResponse> result = service.UpdateAsync(1, question);

            // Assert
            result.Result.Success.Should().Be(true);
        }
        public void DeleteAsyncFailureOnFindTest()
        {
            // Arrange
            IQbQuestionRepository repository = Substitute.For <IQbQuestionRepository>();
            IUnitOfWork           unitOfWork = Substitute.For <IUnitOfWork>();
            QbQuestion            question   = null;

            repository.FindByIdAsync(Arg.Any <int>()).Returns(question);
            QbQuestionService service = new QbQuestionService(repository, unitOfWork);

            // Act
            Task <QbQuestionResponse> result = service.DeleteAsync(1);

            // Assert
            string errorMessage = "Question not found.";

            result.Result.Success.Should().Be(false);
            result.Result.Message.Should().Be(errorMessage);
        }
        public void DeleteAsyncFailureOnRemoveTest()
        {
            // Arrange
            IQbQuestionRepository repository = Substitute.For <IQbQuestionRepository>();
            IUnitOfWork           unitOfWork = Substitute.For <IUnitOfWork>();
            QbQuestion            question   = new QbQuestion();

            repository.FindByIdAsync(Arg.Any <int>()).Returns(question);
            repository.Remove(Arg.Any <QbQuestion>()).Throws(new Exception("Exception occurred on Remove"));
            QbQuestionService service = new QbQuestionService(repository, unitOfWork);

            // Act
            Task <QbQuestionResponse> result = service.DeleteAsync(1);

            // Assert
            string errorMessage = "An error occurred when deleting the question: Exception occurred on Remove";

            result.Result.Success.Should().Be(false);
            result.Result.Message.Should().Be(errorMessage);
        }
Пример #4
0
 public async Task <QbQuestion> GetAsync(int id)
 {
     return(await _qbQuestionRepository.FindByIdAsync(id));
 }