public void ShouldRunPostSaveHooks_WhenExceptionOccured_OnSave() { var dbContext = new DbHookContextStub(); var hook1 = Substitute.For <IDbHook>(); var hook2 = Substitute.For <IDbHook>(); dbContext.AddPostSaveHook(hook1); dbContext.AddPostSaveHook(hook2); var sameKey = Guid.NewGuid(); dbContext.Foos.Add(new FooEntityStub() { Id = sameKey }); dbContext.Foos.Add(new FooEntityStub() { Id = sameKey }); try { dbContext.SaveChanges(); } catch (DbUpdateException) { } hook1.Received(2).HookEntry(Arg.Any <IDbEntityEntry>()); hook2.Received(2).HookEntry(Arg.Any <IDbEntityEntry>()); }
public void PostSaveHookShouldReflectPreSaveEntityState() { var dbContext = new DbHookContextStub(); var hook1 = Substitute.For <IDbHook>(); dbContext.AddPostSaveHook(hook1); var foo = new FooEntityStub(); dbContext.Foos.Add(foo); dbContext.SaveChanges(); hook1.Received(1).HookEntry(Arg.Is <IDbEntityEntry>(entry => entry.State == EntityState.Added)); }
public void ShouldRunPostSaveHooks_OnSave() { var dbContext = new DbHookContextStub(); var hook1 = Substitute.For <IDbHook>(); var hook2 = Substitute.For <IDbHook>(); dbContext.AddPostSaveHook(hook1); dbContext.AddPostSaveHook(hook2); var foo = new FooEntityStub(); dbContext.Foos.Add(foo); dbContext.SaveChanges(); hook1.Received(1).HookEntry(Arg.Any <IDbEntityEntry>()); hook2.Received(1).HookEntry(Arg.Any <IDbEntityEntry>()); }