public void OptimisticConcurrencyControl() { // Arrange var ann = new ConcurrentPickupAddressModifier( Container.GetNestedContainer(), "Ann"); var bob = new ConcurrentPickupAddressModifier( Container.GetNestedContainer(), "Bob"); Assert.That(ann.IsOnSeparateNHibernateSessionFrom(bob)); var id = ann.Save(NewReverseAuction()); bob.LoadExistingReverseAuction(id); // Act ann.AlterPickupButDoNotFlush("Abu Dahbi"); bob.AlterPickupButDoNotFlush("Timbuktu"); ann.FlushNHibernateSession(); // Notice that Ann just saved version 2, but Bob has version 1! // Assert Assert.Throws <StaleObjectStateException>(() => { bob.FlushNHibernateSession(); }); }
public bool IsOnSeparateNHibernateSessionFrom(ConcurrentPickupAddressModifier other) { return(!object.ReferenceEquals(_session, other._session) && !object.ReferenceEquals(_repository, other._repository)); }