Ejemplo n.º 1
0
        public void TestUpdate_NoCommit()
        {
            Product p = null;
            Product retreivedProduct = null;

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                p             = context.QueryItems <Product>("select * from Product where Id = @id", new { id = productId }).First();
                p.Name        = "Waffle Maker";
                p.CategoryId  = 3;
                p.Description = "Makes waffles";
                p.Price       = 29.99m;

                context.Update <Product>(p);
            }

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                retreivedProduct = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = p.Id }).FirstOrDefault();
            }

            Assert.IsTrue(retreivedProduct != null &&
                          retreivedProduct.Id == p.Id &&
                          retreivedProduct.CategoryId != 3 &&
                          retreivedProduct.Name != "Waffle Maker" &&
                          retreivedProduct.Description != "Makes waffles" &&
                          retreivedProduct.Price != 29.99m, "Update should have failed but succeeded");
        }
Ejemplo n.º 2
0
        public void TestNestedConnections_Commit()
        {
            Product p = null;
            Product retreivedProduct = null;

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                using (ADOCRUDContext context2 = new ADOCRUDContext(connectionString))
                {
                    p = context2.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault();
                }

                p.Name = "Bowling ball";

                context.Update <Product>(p);
                context.Commit();

                retreivedProduct = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = productId }).FirstOrDefault();
            }

            Assert.IsTrue(retreivedProduct != null && retreivedProduct.Name == "Bowling ball", "An error occurred with nested connections");
        }
Ejemplo n.º 3
0
        public void TestUpdate_Commit()
        {
            using (ADOCRUDContext context = new ADOCRUDContext(ConfigurationManager.ConnectionStrings["UnitTestDB"].ToString()))
            {
                Product p = context.QueryItems <Product>("select * from Product where Id = @id", new { id = productId }).First();
                p.Name        = "Waffle Maker";
                p.CategoryId  = 3;
                p.Description = "Makes waffles";
                p.Price       = 29.99m;

                context.Update <Product>(p);
                context.Commit();

                Product retreivedProduct = context.QueryItems <Product>("select * from dbo.Product where Id = @id", new { id = p.Id }).FirstOrDefault();

                Assert.IsTrue(retreivedProduct != null &&
                              retreivedProduct.Id == p.Id &&
                              retreivedProduct.CategoryId == 3 &&
                              p.Name == "Waffle Maker" &&
                              p.Description == "Makes waffles" &&
                              p.Price == 29.99m, "An error occurred on update");
            }
        }