public void Put_Method_Updates_A_Post() { // Arrange var testPostId = 99; var posts = CreateTestPosts(5); posts[0].Id = testPostId; // Make sure we know the Id of one of the posts var repo = new InMemoryPostRepository(posts); var controller = new PostController(repo); var postToUpdate = new Post() { Id = testPostId, Caption = "Updated!", Title = "Updated!", UserProfileId = 99, DateCreated = DateTime.Today, ImageUrl = "http://some.image.url", }; // Act controller.Put(testPostId, postToUpdate); // Assert var postFromDb = repo.InternalData.FirstOrDefault(p => p.Id == testPostId); Assert.NotNull(postFromDb); Assert.Equal(postToUpdate.Caption, postFromDb.Caption); Assert.Equal(postToUpdate.Title, postFromDb.Title); Assert.Equal(postToUpdate.UserProfileId, postFromDb.UserProfileId); Assert.Equal(postToUpdate.DateCreated, postFromDb.DateCreated); Assert.Equal(postToUpdate.ImageUrl, postFromDb.ImageUrl); }
public void Put_Method_Returns_BadRequest_When_Ids_Do_Not_Match() { // Arrange var testPostId = 99; var posts = CreateTestPosts(5); posts[0].Id = testPostId; // Make sure we know the Id of one of the posts var repo = new InMemoryPostRepository(posts); var controller = new PostController(repo); var postToUpdate = new Post() { Id = testPostId, Caption = "Updated!", Title = "Updated!", UserProfileId = 99, DateCreated = DateTime.Today, ImageUrl = "http://some.image.url", }; var someOtherPostId = testPostId + 1; // make sure they aren't the same // Act var result = controller.Put(someOtherPostId, postToUpdate); // Assert Assert.IsType <BadRequestResult>(result); }