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 GetTodo_Existing_OkWithDto() { // Arrange var service = new MockTodoService { MGetTodoByIdAsync = (todoId, userId) => MockTodoDto.Get(0) }; var controller = new TodoController(service); MockClaims.AddUserIdClaim(controller, MockApplicationUsers.Get(5).Id); const int tId = 10101; // Act var result = await controller.GetTodo(tId) as OkObjectResult; var dto = result?.Value as TodoDto; // Assert Assert.NotNull(result); Assert.Equal(200, result.StatusCode); Assert.NotNull(dto); Assert.Equal(MockTodoDto.Get(0).Id, dto.Id); Assert.Equal(MockTodoDto.Get(0).Due, dto.Due); Assert.Equal(MockTodoDto.Get(0).Description, dto.Description); }
public void TodoDto_Setter_Modifies() { // Arrange var dto = MockTodoDto.Get(1); // Act dto.Id = 55; dto.Due = new DateTime(2020, 12, 24, 16, 0, 0); dto.Description = "Start cooking"; // Assert Assert.Equal(55, dto.Id); Assert.Equal(new DateTime(2020, 12, 24, 16, 0, 0), dto.Due); Assert.Equal("Start cooking", dto.Description); }