Ejemplo n.º 1
0
		public void WhenStaleObjectStateThenMessageContainsEntity()
		{
			using (var scenario = new ParentWithTwoChildrenScenario(Sfi))
			{
				using (var client1 = OpenSession())
				using (var tx1 = client1.BeginTransaction())
				{
					var parentFromClient1 = client1.Get<Parent>(scenario.ParentId);
					NHibernateUtil.Initialize(parentFromClient1.Children);
					var firstChildId = parentFromClient1.Children[0].Id;
					
					DeleteChildUsingAnotherSession(firstChildId);

					parentFromClient1.Children[0].Description = "Modified info";
					var expectedException = tx1.Executing(x => x.Commit()).Throws<StaleObjectStateException>().Exception;
					expectedException.EntityName.Should().Be(typeof(Child).FullName);
					expectedException.Identifier.Should().Be(firstChildId);
				}
			}
		}
Ejemplo n.º 2
0
        public async Task WhenStaleObjectStateThenMessageContainsEntityAsync()
        {
            using (var scenario = new ParentWithTwoChildrenScenario(Sfi))
            {
                using (var client1 = OpenSession())
                {
                    var parentFromClient1 = await(client1.GetAsync <Parent>(scenario.ParentId));
                    await(NHibernateUtil.InitializeAsync(parentFromClient1.Children));
                    var firstChildId = parentFromClient1.Children[0].Id;

                    await(DeleteChildUsingAnotherSessionAsync(firstChildId));

                    using (var tx1 = client1.BeginTransaction())
                    {
                        parentFromClient1.Children[0].Description = "Modified info";
                        var expectedException = Assert.ThrowsAsync <StaleObjectStateException>(() => tx1.CommitAsync());
                        Assert.That(expectedException.EntityName, Is.EqualTo(typeof(Child).FullName));
                        Assert.That(expectedException.Identifier, Is.EqualTo(firstChildId));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void WhenStaleObjectStateThenMessageContainsEntity()
        {
            using (var scenario = new ParentWithTwoChildrenScenario(Sfi))
            {
                using (var client1 = OpenSession())
                {
                    var parentFromClient1 = client1.Get <Parent>(scenario.ParentId);
                    NHibernateUtil.Initialize(parentFromClient1.Children);
                    var firstChildId = parentFromClient1.Children[0].Id;

                    DeleteChildUsingAnotherSession(firstChildId);

                    using (var tx1 = client1.BeginTransaction())
                    {
                        parentFromClient1.Children[0].Description = "Modified info";
                        var expectedException = tx1.Executing(x => x.Commit()).Throws <StaleObjectStateException>().Exception;
                        expectedException.EntityName.Should().Be(typeof(Child).FullName);
                        expectedException.Identifier.Should().Be(firstChildId);
                    }
                }
            }
        }
Ejemplo n.º 4
0
		public void WhenStaleObjectStateThenMessageContainsEntity()
		{
			using (var scenario = new ParentWithTwoChildrenScenario(Sfi))
			{
				using (var client1 = OpenSession())
				{
					var parentFromClient1 = client1.Get<Parent>(scenario.ParentId);
					NHibernateUtil.Initialize(parentFromClient1.Children);
					var firstChildId = parentFromClient1.Children[0].Id;

					DeleteChildUsingAnotherSession(firstChildId);

					using (var tx1 = client1.BeginTransaction())
					{
						parentFromClient1.Children[0].Description = "Modified info";
						var expectedException = Assert.Throws<StaleObjectStateException>(() => tx1.Commit());
						Assert.That(expectedException.EntityName, Is.EqualTo(typeof (Child).FullName));
						Assert.That(expectedException.Identifier, Is.EqualTo(firstChildId));
					}
				}
			}
		}