public void HookedDbContext_ShouldNotPostHook_IfExceptionIsHit() { var runCheckingHook = new RunCheckedPreInsertHook(); var hooks = new IHook[] { runCheckingHook, new TimestampPostInsertHook() }; var context = new LocalContext(hooks); var valEntity = new ValidatedEntity(); valEntity.CreatedAt = DateTime.Now; context.ValidatedEntities.Add(valEntity); Assert.Throws <DbEntityValidationException>(() => context.SaveChanges()); Assert.IsFalse(runCheckingHook.HasRun); Assert.IsFalse(valEntity.ModifiedAt.HasValue); }
public void HookedDbContext_ShouldPostHook_IfNoExceptionIsHit() { var runCheckingHook = new RunCheckedPreInsertHook(); var hooks = new IHook[] { runCheckingHook, new TimestampPostInsertHook() }; var context = new LocalContext(hooks); var tsEntity = new TimestampedSoftDeletedEntity(); tsEntity.CreatedAt = DateTime.Now; context.Entities.Add(tsEntity); context.SaveChanges(); Assert.IsTrue(runCheckingHook.HasRun); Assert.AreEqual(DateTime.Today, tsEntity.ModifiedAt.Value.Date); }