public void ShouldDeleteACategoryWithTimestampData() { var category = CreateCategoryInstance("Foo"); _db.Categories.Add(category); _db.SaveChanges(); var db2 = new SpyStoreContext(); var catToDelete = new Category { Id = category.Id, TimeStamp = category.TimeStamp}; db2.Entry(catToDelete).State = EntityState.Deleted; var affected = db2.SaveChanges(); Assert.Equal(1,affected); }
public void ShouldNotDeleteACategoryWithoutTimestampData() { var category = CreateCategoryInstance("Foo"); _db.Categories.Add(category); _db.SaveChanges(); var db2 = new SpyStoreContext(); var catToDelete = new Category { Id = category.Id}; db2.Categories.Remove(catToDelete); var ex = Assert.Throws<DbUpdateConcurrencyException>(() =>db2.SaveChanges()); Assert.Equal(1,ex.Entries.Count); Assert.Equal(2,((Category)ex.Entries[0].Entity).Id); }