コード例 #1
0
        public async Task On_Update_Should_Throw_FailedToUpdateTodoException_When_Exception_Received()
        {
            // Given:
            var todoItem = new Todo()
            {
                Id        = 0,
                Name      = "Water plants",
                Completed = false
            };

            // And:
            var commandRepository = new Mock <ITodoCommandRepository>();

            commandRepository
            .Setup(r => r.UpdateTodoAsync(It.IsAny <Todo>()))
            .ThrowsAsync(new NullReferenceException("Problem with database!"));

            // And:
            var sut = new DefaultTodoService(commandRepository.Object, null);

            // When:
            var func = new Func <Task>(async() => { await sut.UpdateTodoAsync(todoItem); });

            // Then:
            var exception = await Assert.ThrowsAsync <FailedToUpdateTodoException>(func);

            Assert.Equal("Problem with database!", exception.Message);
        }
コード例 #2
0
        public async Task On_Update_Should_Proceed_When_No_Exception()
        {
            // Given:
            var todoItem = new Todo()
            {
                Id        = 0,
                Name      = "Water plants",
                Completed = false
            };

            // And:
            var commandRepository = new Mock <ITodoCommandRepository>();

            commandRepository
            .Setup(r => r.UpdateTodoAsync(It.IsAny <Todo>()))
            .ReturnsAsync(todoItem);

            // And:
            var sut = new DefaultTodoService(commandRepository.Object, null);

            // When:
            var result = await sut.UpdateTodoAsync(todoItem);

            // Then:
            Assert.NotNull(result);
        }
コード例 #3
0
        public async Task On_Update_Should_Throw_TodoNotFoundException_When_TodoNotFoundException_Received()
        {
            // Given:
            var todoItem = new Todo()
            {
                Id        = 0,
                Name      = "Water plants",
                Completed = false
            };

            // And:
            var commandRepository = new Mock <ITodoCommandRepository>();

            commandRepository
            .Setup(r => r.UpdateTodoAsync(It.IsAny <Todo>()))
            .ThrowsAsync(new TodoNotFoundException(todoItem.Id.ToString()));

            // And:
            var sut = new DefaultTodoService(commandRepository.Object, null);

            // When:
            var func = new Func <Task>(async() => { await sut.UpdateTodoAsync(todoItem); });

            // Then:
            var exception = await Assert.ThrowsAsync <TodoNotFoundException>(func);

            Assert.Equal("0", exception.Message);
        }