public async Task Should_Update_With_ID_And_Name_Then_Return_Person() { // Arrange Person expected = new Person { Id = testId, Name = testUpdatedName }; var mockRepository = new Mock <IPersonRepository>(); mockRepository.Setup(o => o.UpdatePerson(It.Is <Person>(x => x.Id == testId && x.Name == testUpdatedName))) .ReturnsAsync(expected); // Act var controller = new PersonsController(mockRepository.Object); IHttpActionResult actionResult = await controller.PutPerson(testId, new PersonDTO { Name = testUpdatedName }); var contentResult = actionResult as OkNegotiatedContentResult <Person>; // Assert Assert.NotNull(contentResult); Assert.NotNull(contentResult.Content); Assert.Equal(testUpdatedName, contentResult.Content.Name); Assert.Equal(testId, contentResult.Content.Id); }
public async Task Should_Return_BadRequestWithMessage_When_Update_With_NonExist_ID() { // Arrange Person expected = new Person { Id = testId, Name = testUpdatedName }; var mockRepository = new Mock <IPersonRepository>(); mockRepository.Setup(o => o.UpdatePerson(It.Is <Person>(x => x.Id == testId && x.Name == testUpdatedName))) .Returns(Task.FromResult <Person>(null)); // Act var controller = new PersonsController(mockRepository.Object); IHttpActionResult actionResult = await controller.PutPerson(testId, new PersonDTO { Name = testUpdatedName }); // Assert var customActionResult = actionResult as CustomJSONActionResult; Assert.NotNull(customActionResult); Assert.Equal(HttpStatusCode.BadRequest, customActionResult.StatusCode); }