Ejemplo n.º 1
0
        public void ChangeSavedEntityInsideTransactionTest01()
        {
            using (var session = Domain.OpenSession()) {
                TestEntityWithUniqueIndex a;
                TestEntityWithUniqueIndex b;
                using (var transaction = session.OpenTransaction()) {
                    _ = new TestEntityWithUniqueIndex {
                        Index = 1,
                        Value = 1,
                    };
                    _ = new TestEntityWithUniqueIndex {
                        Index = 2,
                        Value = 2
                    };
                    transaction.Complete();
                }

                a = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 1);
                b = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 2);

                try {
                    using (var trasaction = session.OpenTransaction()) {
                        a.Value = 2; //unique constraint violation
                        trasaction.Complete();
                    }
                }
                catch (Exception) {}

                Assert.That(a.Index, Is.EqualTo(1));
                Assert.That(a.Value, Is.EqualTo(1));
                Assert.That(b.Index, Is.EqualTo(2));
                Assert.That(b.Value, Is.EqualTo(2));
                Assert.That(session.EntityChangeRegistry.Count, Is.EqualTo(0));
            }
        }
Ejemplo n.º 2
0
        public void DeleteInsideTransaction()
        {
            using (var session = Domain.OpenSession()) {
                TestEntityWithUniqueIndex a;
                TestEntityWithUniqueIndex b;
                TestEntityWithUniqueIndex c;
                using (var transaction = session.OpenTransaction()) {
                    _ = new TestEntityWithUniqueIndex {
                        Index = 7,
                        Value = 7,
                    };
                    _ = new TestEntityWithUniqueIndex {
                        Index = 8,
                        Value = 8
                    };
                    _ = new TestEntityWithUniqueIndex {
                        Index = 9,
                        Value = 9
                    };
                    transaction.Complete();
                }

                a = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 7);
                b = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 8);
                c = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 9);

                try {
                    using (var transaction = session.OpenTransaction()) {
                        a.Value = 8;
                        c.Remove();

                        transaction.Complete();
                    }
                }
                catch (Exception) {}

                Assert.That(a.Index, Is.EqualTo(7));
                Assert.That(a.Value, Is.EqualTo(7));
                Assert.That(b.Index, Is.EqualTo(8));
                Assert.That(b.Value, Is.EqualTo(8));
                Assert.That(c.IsRemoved, Is.False);
                Assert.That(c.Index, Is.EqualTo(9));
                Assert.That(c.Value, Is.EqualTo(9));
                Assert.That(session.EntityChangeRegistry.Count, Is.EqualTo(0));
            }
        }
Ejemplo n.º 3
0
        public void ChangeEntityOutsideTransaction()
        {
            using (var session = Domain.OpenSession()) {
                TestEntityWithUniqueIndex a;
                TestEntityWithUniqueIndex b;
                using (var transaction = session.OpenTransaction()) {
                    _ = new TestEntityWithUniqueIndex {
                        Index = 3,
                        Value = 3,
                    };
                    _ = new TestEntityWithUniqueIndex {
                        Index = 4,
                        Value = 4
                    };
                    transaction.Complete();
                }

                a = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 3);
                b = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 4);
                _ = Assert.Throws <InvalidOperationException>(() => a.Value = 5);
            }
        }
Ejemplo n.º 4
0
        public void DeleteOutsideTransactionTest()
        {
            using (var session = Domain.OpenSession()) {
                TestEntityWithUniqueIndex a;
                TestEntityWithUniqueIndex b;
                using (var transaction = session.OpenTransaction()) {
                    _ = new TestEntityWithUniqueIndex {
                        Index = 5,
                        Value = 5,
                    };
                    _ = new TestEntityWithUniqueIndex {
                        Index = 6,
                        Value = 6
                    };
                    transaction.Complete();
                }

                a = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 5);
                b = session.Query.All <TestEntityWithUniqueIndex>().First(el => el.Index == 6);

                _ = Assert.Throws <InvalidOperationException>(() => a.Remove());
            }
        }