Example #1
0
        public void TestInsertOrRollBackBreaksUniqueConstraint()
        {
            Assert.Empty(_db.Products);

            var product1 = new Product {
                Name = "Laptop", Price = 1500M
            };
            var product2 = new Product {
                Name = "Laptop", Price = 2000M
            };
            var product3 = new Product {
                Name = "Computer", Price = 2300M
            };

            _db.BeginTransaction();
            {
                Assert.Equal(1, _db.Products.Insert(product1, Conflict.Rollback));
                Assert.Throws <UniqueConstraintException>(() => _db.Products.Insert(product2, Conflict.Rollback));
                Assert.Equal(1, _db.Products.Insert(product3, Conflict.Rollback));
            }
            Assert.Throws <SQLiteException>(() => _db.EndTransaction());

            Assert.Collection(_db.Products, p =>
            {
                Assert.Equal(1, p.Id);
                Assert.Equal(product3.Name, p.Name);
                Assert.Equal(product3.Price, p.Price);
            });
        }