public void GetTodoById_Positive() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.GetTodoById(1); //Assert Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public void GetTodoById_Invalid_Id() { // Arrange todoController = new TodoController(todoMockDal); todoController.Request = new HttpRequestMessage(); todoController.Request.SetConfiguration(new HttpConfiguration()); //Act var result = todoController.GetTodoById(0); //Assert //Assert.IsInstanceOf<BadRequestResult>(result); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); }
public async Task GetTodoById_Should_ReturnNotFound() { // Arrange var adapterMock = new Mock <ITodoAdapter>(); var loggerMock = new Mock <ILogger <TodoController> >(); var testTodoId = 123; var controller = new TodoController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.GetTodoById(testTodoId); // Assert var actionResult = Assert.IsAssignableFrom <ActionResult <TodoViewModel> >(result); Assert.IsAssignableFrom <NotFoundObjectResult>(actionResult.Result); }
public async Task GetTodoById_Should_ReturnTodoWithId() { // Arrange var adapterMock = new Mock <ITodoAdapter>(); var loggerMock = new Mock <ILogger <TodoController> >(); var testTodoId = 1; adapterMock.Setup(x => x.GetTodo(testTodoId)).Returns(Task.FromResult(GetTestTodos().FirstOrDefault(s => s.TodoId == testTodoId))); var controller = new TodoController(adapterMock.Object, loggerMock.Object); // Act var result = await controller.GetTodoById(testTodoId); // Assert Assert.IsAssignableFrom <ActionResult <TodoViewModel> >(result); Assert.Equal(result.Value.TodoId, testTodoId); }