public async void UpdateAsync_ChangesFields() { //Arrange var contextOptions = InMemoryUtils.ProduceFreshDbContextOptions(); var oldModel = ResourceUtils.TestSet.First(); using (var context = new ApplicationDbContext(contextOptions)) { context.Resources.Add(oldModel); context.SaveChanges(); } var newModel = ResourceUtils.TestSet.Last(); //Act using (var context = new ApplicationDbContext(contextOptions)) { IBasicRepositoryAsync <Resource, int> repo = new ResourcesRepository(context); newModel.Id = oldModel.Id; await repo.UpdateAsync(newModel); } //Assert using (var context = new ApplicationDbContext(contextOptions)) { Assert.Equal(newModel.Title, context.Resources.First().Title); Assert.NotEqual(oldModel.Title, context.Resources.First().Title); } }
public async void UpdateAsync_ThrowsNotFound_OnNonExistent() { //Arrange var contextOptions = InMemoryUtils.ProduceFreshDbContextOptions(); var oldModel = ResourceUtils.TestSet.First(); using (var context = new ApplicationDbContext(contextOptions)) { context.Resources.Add(oldModel); context.SaveChanges(); } var newModel = ResourceUtils.TestSet.Last(); using (var context = new ApplicationDbContext(contextOptions)) { IBasicRepositoryAsync <Resource, int> repo = new ResourcesRepository(context); newModel.Id = ResourceUtils.NonExistentId; //Assert-Act await Assert.ThrowsAsync <CurrentEntryNotFoundException>(() => repo.UpdateAsync(newModel)); Assert.Equal(oldModel.Title, context.Resources.First().Title); } }