public void TodoController_Put_return_Internal_error() { _tasksService.Setup(x => x.IsValidTaskForUpdate(It.IsAny <Task>())).Throws(new Exception()); var response = _todoController.Put(new TaskModel()); Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode); }
public void Update_Success() { var todo = new TodoItem() { Id = 1, Description = "" }; _todosRepository.Setup(x => x.Get(1)).Returns(todo); _todosRepository.Setup(x => x.Update(todo)); var result = _todoController.Put(1, todo); Assert.IsInstanceOfType(result, typeof(NoContentResult)); }
public void PutTest() { var userId = 1; var taskId = 1; var description = "AAA"; var check = false; var todo = GetAllTodo.First(t => t.Id == taskId && t.UserId == userId); var todoVM = new TodoViewModel { Id = 1, Description = "AAA", Check = false }; // Arrange var mockServ = new Mock <ITodoService>(); mockServ.Setup(s => s.UpdateTodo(taskId, description, check, userId)).Returns(todo); var controller = new TodoController(mockServ.Object); controller.ControllerContext = FakeContext; // Act var actualResp = controller.Put(taskId, todoVM) as OkObjectResult; var actual = actualResp.Value as Todo; // Assert Assert.AreEqual(actual.Id, todo.Id); Assert.AreEqual(actual.Checked, todo.Checked); Assert.AreEqual(actual.UserId, todo.UserId); Assert.AreEqual(actual.Description, todo.Description); }
public void PutShouldReturnNotFound() { var mockCurrentUser = new Mock <ICurrentUser>(); var mockTodoRepository = new Mock <ITodoRepository>(); var controller = new TodoController(mockCurrentUser.Object, mockTodoRepository.Object); var response = controller.Put(new Todo()); Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public void PutShouldReturnOk() { var mockCurrentUser = new Mock <ICurrentUser>(); var mockTodoRepository = new Mock <ITodoRepository>(); mockTodoRepository .Setup(_ => _.GetById(It.IsAny <int>())) .Returns(new Todo()); var controller = new TodoController(mockCurrentUser.Object, mockTodoRepository.Object); var response = controller.Put(new Todo()); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void ModifyNote_Negative() { var datarepo = new Mock <IDataRepo>(); Note note = new Note { NoteId = 4, Title = "Testing Post" }; int id = (int)note.NoteId; datarepo.Setup(d => d.ModifyNote(id, note)).Returns(false); TodoController todoController = new TodoController(datarepo.Object); var actionResult = todoController.Put(id, note); var nfObjectResult = actionResult as NotFoundObjectResult; Assert.NotNull(nfObjectResult); }
public void UserFailTest() { // Arrange var mockServ = new Mock <ITodoService>(); var controller = new TodoController(mockServ.Object); // Act var actualGetResp = controller.Get(null) as BadRequestResult; var actualPostResp = controller.Post(null) as BadRequestResult; var actualPutResp = controller.Put(0, null) as BadRequestResult; var actualDeleteResp = controller.Delete(0) as BadRequestResult; // Assert Assert.IsNotNull(actualGetResp); Assert.IsNotNull(actualPostResp); Assert.IsNotNull(actualPutResp); Assert.IsNotNull(actualDeleteResp); }
public void Put_Updates_Todo() { var originalTodo = new Todo(1, "First item"); var expectedTodos = new List <Todo>() { originalTodo }; var updatedTodo = new Todo(1, "Updated item"); todoRepo.When(t => todoRepo.Update(updatedTodo)) .Do(Callback.First(t => expectedTodos.Remove(originalTodo)) .Then(t => expectedTodos.Add(updatedTodo))); todoRepo.GetAll().Returns(expectedTodos); var result = underTest.Put(updatedTodo); // Assert.Equal(expectedTodos, result.ToList()); Assert.All(result, item => Assert.Contains("Updated item", item.Name)); }
public async Task Can_400_When_Putting_An_Invalid_Todo(string task) { var fixture = new TodoDataFixture(); var subject = new TodoController(fixture.Repository); var request = new TodoRequestApiModel { Task = task }; var result = (await subject.Put("test-id", request)).Result as BadRequestObjectResult; Assert.NotNull(result); Assert.Equal(400, result.StatusCode); Assert.Equal( "failed_validation", ((ApiErrorModel)result.Value).Code ); Assert.Equal( new[] { "Test Value" }, fixture.Repository.Values.Values.Select(x => x.Task).ToArray() ); }
public void ModifyNote_Positive() { var datarepo = new Mock <IDataRepo>(); Note note = new Note { NoteId = 4, Title = "Testing Post" }; int id = (int)note.NoteId; datarepo.Setup(d => d.ModifyNote(id, note)).Returns(true); TodoController todoController = new TodoController(datarepo.Object); var actionResult = todoController.Put(id, note); var crObjectResult = actionResult as CreatedResult; Assert.NotNull(crObjectResult); var model = crObjectResult.Value as Note; Assert.Equal(id, model.NoteId); }
public async Task Can_404_When_Putting_A_Missing_Todo() { var fixture = new TodoDataFixture(); var subject = new TodoController(fixture.Repository); var request = new TodoRequestApiModel { Task = "Updated value" }; var result = (await subject.Put("BADID", request)).Result as NotFoundObjectResult; Assert.NotNull(result); Assert.Equal(404, result.StatusCode); Assert.IsAssignableFrom <ApiErrorModel>(result.Value); Assert.Equal( "not_found", ((ApiErrorModel)result.Value).Code ); Assert.Equal( new[] { "Test Value" }, fixture.Repository.Values.Values.Select(x => x.Task).ToArray() ); }
public async Task Can_Put_A_Todo() { var fixture = new TodoDataFixture(); var subject = new TodoController(fixture.Repository); var request = new TodoRequestApiModel { Task = "Updated Value" }; var result = (await subject.Put("test-id", request)).Result as OkObjectResult; Assert.NotNull(result); Assert.Equal(200, result.StatusCode); Assert.Equal( TodoDataFixture.UpdatedTodoApiModel, (TodoApiModel)result.Value, new TodoApiModelComparer() ); Assert.Equal( new[] { "Updated Value" }, fixture.Repository.Values.Values.Select(x => x.Task).ToArray() ); }
public void PutFailTest() { var taskId = 1; var todoVM = new TodoViewModel { Id = 1, Description = "AAA", Check = false }; // Arrange var mockServ = new Mock <ITodoService>(); var controller = new TodoController(mockServ.Object); controller.ControllerContext = FakeContext; // Act var actualResp = controller.Put(taskId, todoVM) as BadRequestResult; // Assert Assert.IsNotNull(actualResp); }