コード例 #1
0
		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;
		}
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
		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();
				}
			}
		}
コード例 #5
0
        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();
                }
            }
        }
コード例 #6
0
        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());
                }
            }
        }
コード例 #7
0
        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();
                }
            }
        }
コード例 #8
0
        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());
                }
            }
        }
コード例 #9
0
        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();
                }
            }
        }
コード例 #10
0
		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();
				}
			}
		}