コード例 #1
0
        public async Task DeleteAllTodos_Should_ReturnOk()
        {
            // Arrange
            var adapterMock = new Mock <ITodoAdapter>();
            var loggerMock  = new Mock <ILogger <TodoController> >();

            var testTodos = GetTestTodos();
            int countTodosBeforeDelete = testTodos.Count;

            adapterMock.Setup(x => x.DeleteAllTodos())
            .Callback(() => testTodos.Clear());

            var controller = new TodoController(adapterMock.Object, loggerMock.Object);

            // Act
            var result = await controller.DeleteAllTodos();

            // Assert
            var actionResult = Assert.IsAssignableFrom <IActionResult>(result);

            Assert.IsAssignableFrom <OkResult>(actionResult);
            Assert.Equal(2, countTodosBeforeDelete);
            Assert.Empty(testTodos);
        }