public async Task GetAllTodos_ListOfTodos_Ok() { // Arrange var service = new MockTodoService { MGetAllTodosOrderedByDueAsync = (year, month, day, userId) => new[] { MockTodoDto.Get(0), MockTodoDto.Get(1) } }; var controller = new TodoController(service); MockClaims.AddUserIdClaim(controller, MockApplicationUsers.Get(5).Id); // Act var result = await controller.GetAllTodos() as OkObjectResult; var list = result?.Value as TodoDto[]; // Assert Assert.NotNull(result); Assert.Equal(200, result.StatusCode); Assert.NotNull(list); Assert.Equal(2, list.Count()); Assert.Equal(MockTodoDto.Get(0).Id, list[0].Id); Assert.Equal(MockTodoDto.Get(0).Due, list[0].Due); Assert.Equal(MockTodoDto.Get(0).Description, list[0].Description); Assert.Equal(MockTodoDto.Get(1).Id, list[1].Id); Assert.Equal(MockTodoDto.Get(1).Due, list[1].Due); Assert.Equal(MockTodoDto.Get(1).Description, list[1].Description); }
public async Task GetAllTodos_Should_ReturnAllTodos() { // Arrange var adapterMock = new Mock <ITodoAdapter>(); var loggerMock = new Mock <ILogger <TodoController> >(); adapterMock.Setup(x => x.GetTodos()).Returns(Task.FromResult(GetTestTodos())); var controller = new TodoController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.GetAllTodos(); // Assert Assert.IsAssignableFrom <IEnumerable <TodoViewModel> >(result); Assert.Equal(2, result.Count()); }