protected override void OnSetUp()
		{
			using (var session = OpenSession())
			using (var transaction = session.BeginTransaction())
			{
				var e1 = new BatcherLovingEntity { Name = "Bob" };
				session.Save(e1);

				var e2 = new BatcherLovingEntity { Name = "Sally" };
				session.Save(e2);

				session.Flush();
				transaction.Commit();
			}
		}
Пример #2
0
        protected override void OnSetUp()
        {
            using (var session = OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    var e1 = new BatcherLovingEntity {
                        Name = "Bob"
                    };
                    session.Save(e1);

                    var e2 = new BatcherLovingEntity {
                        Name = "Sally"
                    };
                    session.Save(e2);

                    session.Flush();
                    transaction.Commit();
                }
        }
Пример #3
0
        public void Test_Batcher_Is_Reusable_After_Failed_Operation()
        {
            using (var session = OpenSession())
            {
                try
                {
                    using (session.BeginTransaction())
                    {
                        var valid = new BatcherLovingEntity {
                            Name = "Bill"
                        };
                        session.Save(valid);

                        Assert.That(() => session.Query <BatcherLovingEntity>().Count(x => x.Name == "Bob"), Is.EqualTo(1));
                        var bob = new BatcherLovingEntity {
                            Name = "Bob"
                        };
                        session.Save(bob);

                        // Should fail on unique constraint violation
                        // Expected behavior
                        session.Flush();
                    }
                }
                catch (Exception)
                {
                    // Opening next transaction in the same session after rollback
                    // to log the problem, for instance.
                    // Executing in the same session with the same instance of IBatcher
                    using (session.BeginTransaction())
                    {
                        // Inserting any valid entity will fail on expected rows count assert in batcher
                        var e1 = new BatcherLovingEntity {
                            Name = "Robert (because Bob already exists)"
                        };
                        session.Save(e1);
                        // Batch update returned unexpected row count from update; actual row count: 1; expected: 2
                        session.Flush();
                    }
                }
            }
        }
		public void Test_Batcher_Is_Reusable_After_Failed_Operation()
		{
			using (var session = OpenSession())
			{
				try
				{
					using (session.BeginTransaction())
					{
						var valid = new BatcherLovingEntity { Name = "Bill" };
						session.Save(valid);

						Assert.That(() => session.Query<BatcherLovingEntity>().Count(x => x.Name == "Bob"), Is.EqualTo(1));
						var bob = new BatcherLovingEntity { Name = "Bob" };
						session.Save(bob);

						// Should fail on unique constraint violation
						// Expected behavior
						session.Flush();
					}
				}
				catch (Exception)
				{
					// Opening next transaction in the same session after rollback
					// to log the problem, for instance.
					// Executing in the same session with the same instance of IBatcher
					using (session.BeginTransaction())
					{
						// Inserting any valid entity will fail on expected rows count assert in batcher
						var e1 = new BatcherLovingEntity { Name = "Robert (because Bob already exists)" };
						session.Save(e1);
						// Batch update returned unexpected row count from update; actual row count: 1; expected: 2
						session.Flush();
					}
				}
			}
		}