public void IdentityInsert()
        {
            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    using (DbReposetoryIdentityInsertScope.CreateOrObtain())
                    {
                        var image     = new Image();
                        image.ImageId = 10;
                        _images.Add(image);
                        var book    = new Book();
                        book.BookId = 0;
                        _books.Add(book);
                        image.IdBook = book.BookId;

                        Assert.That(book.BookId, Is.EqualTo(0));
                        Assert.That(image.ImageId, Is.EqualTo(10));

                        Assert.AreNotEqual(_books.Count, 0);
                        Assert.AreNotEqual(_images.Count, 0);
                        transaction.Complete();
                    }
                }
            }, Throws.Nothing);
        }
        public void ParentWithNullableChildIsNullWithPkInsert()
        {
            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    var completedFlag = false;
                    using (var scope = DbReposetoryIdentityInsertScope.CreateOrObtain())
                    {
                        var book  = new Book();
                        var image = new ImageNullable();

                        Assert.That(() => _books.Add(book), Throws.Nothing);
                        image.IdBook = null;
                        Assert.That(() => _imagesNullable.Add(image), Throws.Nothing);
                        scope.OnIdentityInsertCompleted += (sender, args) =>
                        {
                            Assert.That(completedFlag, Is.False);
                            completedFlag = true;
                        };
                        Assert.That(completedFlag, Is.False);
                        transaction.Complete();
                    }
                    Assert.That(completedFlag, Is.True);
                }
            }, Throws.Nothing);
        }
        public void AddChildWithoutParent()
        {
            var image = new Image();

            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    Assert.That(() => _images.Add(image), Throws.Nothing);
                    transaction.Complete();
                }
            }, Throws.Exception.TypeOf <ForginKeyConstraintException>());
        }
        public void ParentWithNullableChildIsNull()
        {
            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    var book  = new Book();
                    var image = new ImageNullable();

                    Assert.That(() => _books.Add(book), Throws.Nothing);
                    image.IdBook = null;
                    Assert.That(() => _imagesNullable.Add(image), Throws.Nothing);
                    transaction.Complete();
                }
            }, Throws.Nothing);
        }
        public void ParentWithChild()
        {
            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    var book = new Book();
                    _books.Add(book);

                    var image    = new Image();
                    image.IdBook = book.BookId;

                    _books.Remove(book);
                    Assert.That(() => _images.Add(image), Throws.Nothing);
                    transaction.Complete();
                }
            }, Throws.Exception.TypeOf <ForginKeyConstraintException>());
        }
        public void ParentWithNullableChildWithPkInsert()
        {
            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    using (DbReposetoryIdentityInsertScope.CreateOrObtain())
                    {
                        var book  = new Book();
                        var image = new ImageNullable();

                        Assert.That(() => _books.Add(book), Throws.Nothing);
                        image.IdBook = book.BookId;
                        Assert.That(() => _imagesNullable.Add(image), Throws.Nothing);
                        transaction.Complete();
                    }
                }
            }, Throws.Nothing);
        }
Пример #7
0
        public void InsertIOReaddTriggerOrder()
        {
            var     orderFlag = false;
            var     inserted  = false;
            DbScope repro;

            using (repro = MockRepro())
            {
                repro.users.Triggers.WithReplication.For.Insert += (sender, token) =>
                {
                    if (!inserted)
                    {
                        Assert.That(orderFlag, Is.False);
                    }
                    orderFlag = true;
                };

                repro.users.Triggers.WithReplication.After.Insert += (sender, token) =>
                {
                    Assert.That(orderFlag, Is.True);
                };

                repro.users.Triggers.WithReplication.InsteadOf.Insert += (sender, token) =>
                {
                    Assert.That(orderFlag, Is.True);
                    inserted = true;
                    using (var tr = new TransactionScope())
                    {
                        using (DbReposetoryIdentityInsertScope.CreateOrObtain())
                        {
                            token.Table.Add(token.Item);
                        }
                        tr.Complete();
                    }
                };
            }

            Assert.That(orderFlag, Is.False);
            repro.users.Add(new Users());
            Assert.That(orderFlag, Is.True);
            Assert.That(repro.users.Count, Is.EqualTo(1));
        }
        public void AddMultibeItems()
        {
            Assert.That(() =>
            {
                using (var transaction = new TransactionScope())
                {
                    var image = new Image();
                    _images.Add(image);
                    var book = new Book();
                    _books.Add(book);
                    image.IdBook = book.BookId;

                    Assert.AreNotEqual(book.BookId, 0);
                    Assert.AreNotEqual(image.ImageId, 0);

                    Assert.AreNotEqual(_books.Count, 0);
                    Assert.AreNotEqual(_images.Count, 0);
                    transaction.Complete();
                }
            }, Throws.Nothing);
        }