public void D0_SelectPensByLocalProperty()
        {
            //reported by Andrus.
            //http://groups.google.com/group/dblinq/browse_thread/thread/c25527cbed93d265

            Northwind db = CreateDB();

            Product localProduct = new Product { ProductName = "Chai" };
            var q = from p in db.Products where p.ProductName == localProduct.ProductName select p;

            List<Product> products = q.ToList();
            int productCount = products.Count;
            Assert.AreEqual(productCount, 1, "Expected one pen, got count=" + productCount);
        }
Example #2
0
 private void detach_Products(Product entity)
 {
     this.SendPropertyChanging();
     entity.Supplier = null;
 }
Example #3
0
 private void attach_Products(Product entity)
 {
     this.SendPropertyChanging();
     entity.Supplier = this;
 }
Example #4
0
 private void attach_Products(Product entity)
 {
     this.SendPropertyChanging();
     entity.Category = this;
 }
 private void ResetProducts() {
     ClearDBCache();
     Northwind dbClean = new Northwind(connString);
     Product[] prod = new Product[4];
     decimal[] price = new decimal[4] { 18.00M, 19.00M, 10.00M, 22.00M };
     for (int i = 0; i < 4; i++) {
         prod[i] = dbClean.Products.First(p => p.ProductID == i + 1);
         prod[i].UnitPrice = price[i];
     }
     prod[0].UnitsInStock = 39;
     prod[0].UnitsOnOrder = 0;
     dbClean.SubmitChanges();
 }
		public void Products_Attach(Product entity)
		{
			entity.Category = this;
		}
Example #7
0
partial         void UpdateProduct(Product instance);
Example #8
0
partial         void DeleteProduct(Product instance);
Example #9
0
        public void G5_SetFieldToNull()
        {
            string productName = "temp_G5_" + Environment.TickCount;
            Northwind db = CreateDB();
#if ORACLE
            //todo fix Oracle
            Product p1 = new Product { ProductName = productName, Discontinued = false, UnitPrice = 11 };
#elif INGRES && !MONO_STRICT
            Product p1 = new Product { ProductName = productName, Discontinued = "N", UnitPrice = 11m };
#else
            Product p1 = new Product { ProductName = productName, Discontinued = false, UnitPrice = 11m };
#endif
            db.Products.InsertOnSubmit(p1);
            db.SubmitChanges();

            p1.UnitPrice = null;
            db.SubmitChanges();

            Northwind db3 = CreateDB();
            Product p3 = db3.Products.Single(p => p.ProductName == productName);
            Assert.IsNull(p3.UnitPrice);
        }
Example #10
0
        public void G4_DuplicateSubmitTest()
        {
            Northwind db = CreateDB();
            int productCount1 = db.Products.Count();
#if INGRES && !MONO_STRICT
            Product p_temp = new Product { ProductName = "temp_g4", Discontinued = "N" };
#else
            Product p_temp = new Product { ProductName = "temp_g4", Discontinued = false };
#endif
            db.Products.InsertOnSubmit(p_temp);
            db.SubmitChanges();
            db.SubmitChanges();
            int productCount2 = db.Products.Count();
            Assert.IsTrue(productCount2 == productCount1 + 1, "Expected product count to grow by one");
        }
Example #11
0
        private int insertProduct_priv()
        {
            Northwind db = CreateDB();

            Product newProd = new Product();
            newProd.CategoryID = db.Categories.First().CategoryID;
            newProd.ProductName = "Temp." + Environment.TickCount;
            newProd.QuantityPerUnit = "33 1/2";
            db.Products.InsertOnSubmit(newProd);
            db.SubmitChanges();
            Assert.Greater(newProd.ProductID, 0, "After insertion, ProductID should be non-zero");
            //Assert.IsFalse(newProd.IsModified, "After insertion, Product.IsModified should be false");
            return (int)newProd.ProductID; //this test cab be used from delete tests
        }
 private bool isValidProduct(Product p)
 {
     return (p.ProductName.LastIndexOf("C") == 0);
 }
		public void Products_Detach(Product entity)
		{
			entity.Supplier = null;
		}
		public void Products_Attach(Product entity)
		{
			entity.Supplier = this;
		}
		public void Products_Detach(Product entity)
		{
			entity.Category = null;
		}
Example #16
0
 private void detach_Products(Product entity)
 {
     this.SendPropertyChanging();
     entity.Category = null;
 }
        public static Product NewProduct(string productName)
        {
            var p = new Product
            {
                ProductName = productName,
                SupplierID = 1,
                CategoryID = 1,
                QuantityPerUnit = "11",
#if ORACLE || FIREBIRD
                UnitPrice = 11, //type "int?"
#else
                UnitPrice = 11m,
#endif
                UnitsInStock = 23,
                UnitsOnOrder = 0,
            };
            return p;
        }
Example #18
0
        public void InsertAndDeleteWithDependencies()
        {
            const string newCategoryName  = "temp Category";
            const string newProduct1 = "temp First Test Product";
            const string newProduct2 = "temp Second Test Product";

            var db = CreateDB();

            var product = new Product
            {
#if INGRES
                Discontinued = "Y",
#else
                Discontinued = true,
#endif
                ProductName = newProduct1,
            };

            var category = new Category
            {
                CategoryName = newCategoryName,
                Description  = "Insert Description Here",
            };
            category.Products.Add(product);

            Assert.AreEqual(0, category.CategoryID);
            Assert.AreEqual(0, product.CategoryID.Value);

            db.Categories.InsertOnSubmit(category);
            db.SubmitChanges();

            Assert.AreEqual(1, db.Categories.Where(c => c.CategoryName == newCategoryName).Count());
            Assert.AreNotEqual(0, category.CategoryID);
            Assert.AreEqual(1, db.Products.Where(p => p.ProductName == newProduct1).Count());
            Assert.AreEqual(category.CategoryID, product.CategoryID.Value);

            var p2 = new Product
            {
#if INGRES
                Discontinued = "Y",
#else
                Discontinued = true,
#endif
                ProductName = newProduct2
            };
            category.Products.Add(p2);
            db.SubmitChanges();

            Assert.AreEqual(1, db.Products.Where(p => p.ProductName == newProduct2).Count());

            db.Products.DeleteOnSubmit(product);
            db.Products.DeleteOnSubmit(p2);
            db.Categories.DeleteOnSubmit(category);
            db.SubmitChanges();

            Assert.AreEqual(0, db.Categories.Where(c => c.CategoryName == newCategoryName).Count());
            Assert.AreEqual(0, db.Products.Where(p => p.ProductName == newProduct1).Count());
            Assert.AreEqual(0, db.Products.Where(p => p.ProductName == newProduct2).Count());
        }
Example #19
0
partial         void InsertProduct(Product instance);
Example #20
0
        public void LinqToSqlInsert02() {

            Northwind db2 = new Northwind(connString);

            DataLoadOptions ds = new DataLoadOptions();

            ds.LoadWith<nwind.Category>(p => p.Products);
            db2.LoadOptions = ds;

            var q = (
                from c in db2.Categories
                where c.CategoryName == "Widgets"
                select c);


            Console.WriteLine("*** BEFORE ***");
            ObjectDumper.Write(q, 1);


            Console.WriteLine();
            Console.WriteLine("*** INSERT ***");
            var newCategory = new Category { CategoryName = "Widgets",
                                             Description = "Widgets are the customer-facing analogues " +
                                                           "to sprockets and cogs."
                                           };
            var newProduct = new Product { ProductName = "Blue Widget",
                                           UnitPrice = 34.56M,
                                           Category = newCategory
                                         };
            db2.Categories.InsertOnSubmit(newCategory);
            db2.SubmitChanges();


            Console.WriteLine();
            Console.WriteLine("*** AFTER ***");
            ObjectDumper.Write(q, 1);

            Cleanup65();  // Restore previous database state
        }
        public void LinqToSqlInsert02()
        {
            Northwind db = CreateDB();

            var ds = new DataLoadOptions();

            ds.LoadWith<Category>(c => c.Products);
            db.LoadOptions = ds;

            var q = from c in db.Categories
                    where c.CategoryName == "Temp Widgets"
                    select c;

            var newCategory = new Category
                                {
                                    CategoryName = "Temp Widgets",
                                    Description = "Widgets are the customer-facing analogues to sprockets and cogs."
                                };

            var newProduct = new Product
            {
                ProductName = "temp Blue Widget",
                UnitPrice = 34.56m,
                Category = newCategory
            };
            db.Categories.InsertOnSubmit(newCategory);
            db.SubmitChanges();

            var reloadedProduct = db.Products.First(p => p.ProductID == newProduct.ProductID);

            Assert.AreEqual(reloadedProduct.ProductName, newProduct.ProductName);
            Assert.AreEqual(reloadedProduct.UnitPrice, newProduct.UnitPrice);
            Assert.AreEqual(reloadedProduct.Category.CategoryID, newProduct.CategoryID);

            var reloadedCategory = reloadedProduct.Category;

            Assert.AreEqual(reloadedCategory.CategoryName, newCategory.CategoryName);
            Assert.AreEqual(reloadedCategory.Description, reloadedCategory.Description);

            db.Products.DeleteOnSubmit(newProduct);
            db.Categories.DeleteOnSubmit(newCategory);
            db.SubmitChanges();
        }
Example #22
0
 private bool isValidProduct(Product p) {
     return p.ProductName.LastIndexOf('C') == 0;
 }