private object PersistANewSomething() { object savedId; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { var e = new SimpleVersioned {Something = "something"}; savedId = s.Save(e); tx.Commit(); } } return savedId; }
private object PersistANewSomething() { object savedId; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { var e = new SimpleVersioned { Something = "something" }; savedId = s.Save(e); tx.Commit(); } } return(savedId); }
private async System.Threading.Tasks.Task <object> PersistANewSomethingAsync(CancellationToken cancellationToken = default(CancellationToken)) { object savedId; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { var e = new SimpleVersioned { Something = "something" }; savedId = await(s.SaveAsync(e, cancellationToken)); await(tx.CommitAsync(cancellationToken)); } } return(savedId); }
public void ShouldRetrieveVersionAfterFlush() { // Note : if you are using identity-style strategy the value of version // is available inmediately after save. var e = new SimpleVersioned {Something = "something"}; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { Assert.That(e.LastModified, Is.Null); s.Save(e); s.Flush(); Assert.That(e.LastModified, Is.Not.Null); s.Delete(e); tx.Commit(); } } }
public void ShouldRetrieveVersionAfterFlush() { // Note : if you are using identity-style strategy the value of version // is available inmediately after save. var e = new SimpleVersioned { Something = "something" }; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { Assert.That(e.LastModified, Is.Null); s.Save(e); s.Flush(); Assert.That(e.LastModified, Is.Not.Null); s.Delete(e); tx.Commit(); } } }
public async System.Threading.Tasks.Task ShouldRetrieveVersionAfterFlushAsync() { // Note : if you are using identity-style strategy the value of version // is available inmediately after save. var e = new SimpleVersioned { Something = "something" }; using (ISession s = OpenSession()) { using (ITransaction tx = s.BeginTransaction()) { Assert.That(e.LastModified, Is.Null); await(s.SaveAsync(e)); await(s.FlushAsync()); Assert.That(e.LastModified, Is.Not.Null); await(s.DeleteAsync(e)); await(tx.CommitAsync()); } } }
public void ShouldCheckStaleState() { var versioned = new SimpleVersioned { Something = "original string" }; try { using (var session = OpenSession()) { session.Save(versioned); session.Flush(); using (var concurrentSession = OpenSession()) { var sameVersioned = concurrentSession.Get <SimpleVersioned>(versioned.Id); sameVersioned.Something = "another string"; concurrentSession.Flush(); } versioned.Something = "new string"; var expectedException = Sfi.Settings.IsBatchVersionedDataEnabled ? Throws.InstanceOf <StaleStateException>() : Throws.InstanceOf <StaleObjectStateException>(); Assert.That(() => session.Flush(), expectedException); } } finally { using (ISession session = OpenSession()) { session.Delete("from SimpleVersioned"); session.Flush(); } } }
public async System.Threading.Tasks.Task ShouldCheckStaleStateAsync() { var versioned = new SimpleVersioned { Something = "original string" }; try { using (var session = OpenSession()) { await(session.SaveAsync(versioned)); await(session.FlushAsync()); using (var concurrentSession = OpenSession()) { var sameVersioned = await(concurrentSession.GetAsync <SimpleVersioned>(versioned.Id)); sameVersioned.Something = "another string"; await(concurrentSession.FlushAsync()); } versioned.Something = "new string"; var expectedException = Sfi.Settings.IsBatchVersionedDataEnabled ? Throws.InstanceOf <StaleStateException>() : Throws.InstanceOf <StaleObjectStateException>(); Assert.That(() => session.FlushAsync(), expectedException); } } finally { using (ISession session = OpenSession()) { await(session.DeleteAsync("from SimpleVersioned")); await(session.FlushAsync()); } } }
public void ShouldCheckStaleState() { var versioned = new SimpleVersioned { Something = "original string" }; try { using (ISession session = OpenSession()) { session.Save(versioned); session.Flush(); using (ISession concurrentSession = OpenSession()) { var sameVersioned = concurrentSession.Get <SimpleVersioned>(versioned.Id); sameVersioned.Something = "another string"; concurrentSession.Flush(); } versioned.Something = "new string"; session.Flush(); } Assert.Fail("Expected exception was not thrown"); } catch (StaleObjectStateException) { // as expected } finally { using (ISession session = OpenSession()) { session.Delete("from SimpleVersioned"); session.Flush(); } } }
public void ShouldCheckStaleState() { var versioned = new SimpleVersioned {Something = "original string"}; try { using (ISession session = OpenSession()) { session.Save(versioned); session.Flush(); using (ISession concurrentSession = OpenSession()) { var sameVersioned = concurrentSession.Get<SimpleVersioned>(versioned.Id); sameVersioned.Something = "another string"; concurrentSession.Flush(); } versioned.Something = "new string"; session.Flush(); } Assert.Fail("Expected exception was not thrown"); } catch (StaleObjectStateException) { // as expected } finally { using (ISession session = OpenSession()) { session.Delete("from SimpleVersioned"); session.Flush(); } } }