public async Task PutPublisher_ExistingIdCorrectPublisherWithWebsiteChanged_NoContentResult() { // Arrange const int publisherId = 3; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Publisher publisherToUpdate = GetFakeList().Where(d => d.ID == publisherId).FirstOrDefault(), // Should use ICopyable interface here expectedPublisher = GetFakeList().Where(d => d.ID == publisherId).FirstOrDefault(); // Act using (var context = new GameReviewsContext(options)) { publisherToUpdate.Website = "newWebsite"; expectedPublisher.Website = "newWebsite"; PublishersController publishersController = new PublishersController(context); var result = (await publishersController.PutPublisher(publisherId, publisherToUpdate)); Publisher actualPublisher = await context.Publishers.Where(d => d.ID == publisherId).FirstOrDefaultAsync(); // Assert Assert.True(AreEqual(expectedPublisher, actualPublisher)); Assert.IsType <NoContentResult>(result); } }
public async Task PutPublisher_ExistingIdCorrectPublisherWithIdChangedNegative_BadRequestResult() { // Arrange const int publisherId = 3, idChanged = -1; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Publisher publisherToUpdate = GetFakeList().Where(d => d.ID == publisherId).FirstOrDefault(); // Act using (var context = new GameReviewsContext(options)) { publisherToUpdate.ID = idChanged; PublishersController publishersController = new PublishersController(context); var result = (await publishersController.PutPublisher(publisherId, publisherToUpdate)); Publisher actualPublisher = await context.Publishers.Where(d => d.ID == publisherId).FirstOrDefaultAsync(); // Assert Assert.IsType <BadRequestResult>(result); } }