public void CanRetryDeleteUsingNewSession() { //setup - trigger a failure when deleting... Guid customerOneId = DbFixture.InsertCustomer(); var c = Nh.CurrentSession.Get <Customer>(customerOneId); Nh.CurrentSession.Delete(c); //cause transaction to fail Nh.CurrentSession.Save(Om.CreateInvalidCustomer()); CommitSessionExpectingException(); //run test... using (ISession newSession = Nh.CreateSession()) { newSession.Delete(c); newSession.Flush(); } Assert.That(DbFixture.CustomerExists(c), Is.False); }
public void UpdateWillNotIncrementVersionProperty() { Guid id = DbFixture.InsertCustomer(); var c = Nh.CurrentSession.Get <Customer>(id); int versionPropertyBeforeUpdate = c.ConcurrencyId; Nh.CurrentSession.Update(c); Assert.That(c.ConcurrencyId, Is.EqualTo(versionPropertyBeforeUpdate), "version property not incremented"); }
public void ExceptionFlushingAnExistingObjectWillStopIncrementOfVersion() { Guid id = DbFixture.InsertCustomer(); var c = Nh.CurrentSession.Get <Customer>(id); c.ShortCode = "CCCCCCCCC"; //update will fail when saved to the db int versionPropertyBeforeFlush = c.ConcurrencyId; CommitSessionExpectingException(); Assert.That(c.ConcurrencyId, Is.EqualTo(versionPropertyBeforeFlush), "ConcurrencyId has NOT been incremented"); }
public void FlushWillIncrementVersionPropertyOnExistingObject() { Guid id = DbFixture.InsertCustomer(); var c = Nh.CurrentSession.Get <Customer>(id); c.Name = "George, Katie"; int versionPropertyBeforeFlush = c.ConcurrencyId; Nh.CurrentSession.Flush(); Assert.That(c.ConcurrencyId, Is.EqualTo(versionPropertyBeforeFlush + 1), "version property incremented"); }
public void CanGetObjectFromFirstLevelCacheByIdentifier() { Guid customerId = DbFixture.InsertCustomer(); EntityKey key = EntityKeyFor <Customer>(customerId); Nh.CurrentSession.Get <Customer>(customerId); Assert.That(Nh.CurrentSession.GetSessionImplementation().GetEntityUsingInterceptor(key), Is.Not.Null, "entity found"); Nh.CurrentSession.Clear(); Assert.That(Nh.CurrentSession.GetSessionImplementation().GetEntityUsingInterceptor(key), Is.Null, "entity not found"); }
public void CanEvictObjectsContainedWithinAnotherSession() { Guid customerId = DbFixture.InsertCustomer(); var customer = Nh.CurrentSession.Get <Customer>(customerId); using (ISession newSession = Nh.CreateSession()) { newSession.Get <Customer>(customerId); //not testing yet just clarifying assumptions Assert.That(Nh.CurrentSession.Contains(customer), Is.True, "entity in session"); EvictObjectsInCurrentSessionFoundWithin(newSession); } Assert.That(Nh.CurrentSession.Contains(customer), Is.False, "entity has been evicted from session"); }
public void CanRetryUpdateWhenUsingAnotherSession() { //setup - trigger an exception when updating... Guid id = DbFixture.InsertCustomer(); var c = Nh.CurrentSession.Get <Customer>(id); c.ShortCode = "12345678"; //update will fail when saved to the db int versionPropertyBeforeFlush = c.ConcurrencyId; CommitSessionExpectingException(); //run test... c.ShortCode = "ABCDE"; //correct problem that was causing save to fail PersistUsingNewSession(c); Assert.That(c.ConcurrencyId, Is.EqualTo(versionPropertyBeforeFlush + 1), "customer has been updated"); }