public void Insert(string ProductName,int? SupplierID,int? CategoryID,string QuantityPerUnit,decimal? UnitPrice,short? UnitsInStock,short? UnitsOnOrder,short? ReorderLevel,bool Discontinued)
	    {
		    Product item = new Product();
		    
            item.ProductName = ProductName;
            
            item.SupplierID = SupplierID;
            
            item.CategoryID = CategoryID;
            
            item.QuantityPerUnit = QuantityPerUnit;
            
            item.UnitPrice = UnitPrice;
            
            item.UnitsInStock = UnitsInStock;
            
            item.UnitsOnOrder = UnitsOnOrder;
            
            item.ReorderLevel = ReorderLevel;
            
            item.Discontinued = Discontinued;
            
	    
		    item.Save(UserName);
	    }
Example #2
0
        public void ActiveRecord_IsLoaded_ShouldBe_False_When_Record_Not_Present_Using_PK_Constructor()
        {
            Product p = new Product(1);
            Assert.IsTrue(p.IsLoaded);

            p = new Product(1111111);
            Assert.IsFalse(p.IsLoaded);
        }
Example #3
0
        public void ETL_CloneInstance()
        {
            Product product1 = new Product(1);
            Product product2 = product1.Clone();

            product2.ProductName = "Unit Test";
            Assert.IsTrue(product2.ProductName != product1.ProductName);
        }
        public void NoTransactionScope_CanRetrieveMultipleProducts()
        {
            Product p1 = new Product(1);
            Product p2 = new Product(2);

            Assert.AreEqual(1, p1.ProductID);
            Assert.AreEqual(2, p2.ProductID);
        }
Example #5
0
        public void Update_SimpleTyped()
        {
            int records = DB.Update<Product>().Set("UnitPrice").EqualTo(100).Where("productid").IsEqualTo(1).Execute();
            Assert.IsTrue(records == 1);

            //pull it back out
            Product p = new Product(1);
            Assert.IsTrue(p.UnitPrice == 100);

            //reset it to 50
            p.UnitPrice = 50;
            p.Save("unit test");
        }
        public void DirtyColumnsExist()
        {
            Product p = new Product(1);

            //make sure no dirties
            Assert.IsTrue(p.DirtyColumns.Count == 0);

            //set the product name to something different
            p.ProductName = DateTime.Now.ToString();

            //see if the dirty col is set right
            Assert.IsTrue(p.DirtyColumns.Count == 1 && p.DirtyColumns[0].ColumnName == "ProductName");
            //p.Save("bbep");
        }
        public void Transaction_RollbackProduct()
        {
            //use the product object to test the transaction scope
            using(TransactionScope scope = new TransactionScope())
            {
                UpdateProduct(1, "20 pounds");
                UpdateProduct(2, "20 pounds");
                UpdateProduct(3, "20 pounds");
            }

            //the saves shouldn't be committed, hopefully!
            Product pVal = new Product(1);
            Assert.IsTrue(pVal.QuantityPerUnit != "20 pounds");
        }
Example #8
0
        public void Update_Expression()
        {
            Product p = new Product(1);
            p.UnitPrice = 50;
            p.Save("unit test");

            int records = new Update(Product.Schema)
                .SetExpression("UnitPrice").EqualTo("UnitPrice * 3")
                .Where("productid").IsEqualTo(1)
                .Execute();
            Assert.IsTrue(records == 1);

            //pull it back out
            p = new Product(1);
            Assert.IsTrue(p.UnitPrice == 150);

            //reset it to 50
            p.UnitPrice = 50;
            p.Save("unit test");
        }
        public void RetrieveMultipleProducts_FailsWithoutSharedConnection()
        {
            string errorMessage = String.Empty;
            try
            {
                using(TransactionScope ts = new TransactionScope())
                {
                    Product p1 = new Product(1);
                    Product p2 = new Product(2);

                    Assert.AreEqual(1, p1.ProductID);
                    Assert.AreEqual(2, p2.ProductID);
                }
            }
            catch(SqlException e)
            {
                errorMessage = e.Message;
            }

            Assert.IsTrue(_dtcErrorMessage.IsMatch(errorMessage), errorMessage);
        }
        public void CanNestSharedConnections()
        {
            SortedList originalNames = new SortedList();
            for(int i = 1; i <= 4; i++)
                originalNames[i] = new Product(i).ProductName;

            using(TransactionScope outerTransactionScope = new TransactionScope())
            {
                using(SharedDbConnectionScope outerConnectionScope = new SharedDbConnectionScope())
                {
                    Product p1 = UpdateProduct(1, "new name of product 1: " + _rand.Next(MaxRandomNumber));
                    Product p2 = UpdateProduct(2, "new name of product 2: " + _rand.Next(MaxRandomNumber));

                    using(TransactionScope innerTransactionScope = new TransactionScope())
                    {
                        using(SharedDbConnectionScope innerConnectionScope = new SharedDbConnectionScope())
                        {
                            Assert.AreSame(outerConnectionScope.CurrentConnection, innerConnectionScope.CurrentConnection);

                            SaveProduct(3, "new name of product 3: " + +_rand.Next(MaxRandomNumber));
                            SaveProduct(4, "new name of product 4: " + +_rand.Next(MaxRandomNumber));

                            innerTransactionScope.Complete();
                        }
                    }

                    // ensure the connection hasn't been disposed by the inner scope
                    Assert.IsTrue(outerConnectionScope.CurrentConnection.State == ConnectionState.Open);

                    p1.Save();
                    p2.Save();
                }
            }

            for(int i = 1; i <= 4; i++)
                Assert.AreEqual(originalNames[i], new Product(i).ProductName, "Product {0} is incorrect", i);
        }
        public void CanRetrieveMultipleEntities_SucceedsWithSharedConnectionScope()
        {
            using(TransactionScope ts = new TransactionScope())
            {
                using(SharedDbConnectionScope connScope = new SharedDbConnectionScope())
                {
                    Product p1 = new Product(1);
                    Product p2 = new Product(2);

                    Order o1 = new Order(10248);
                    Order o2 = new Order(10249);

                    Assert.AreEqual(1L, p1.ProductID);
                    Assert.AreEqual(2L, p2.ProductID);
                    Assert.AreEqual(10248L, o1.OrderID);
                    Assert.AreEqual(10249L, o2.OrderID);
                }
            }
        }
 /// <summary>
 /// Updates the product.
 /// </summary>
 /// <param name="productId">The product id.</param>
 /// <param name="quantityPerUnit">The quantity per unit.</param>
 private static void UpdateProduct(int productId, string quantityPerUnit)
 {
     Product p1 = new Product(productId);
     p1.QuantityPerUnit = quantityPerUnit;
     p1.UnitPrice = 50;
     p1.Save("Unit Test");
 }
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Category = null;
		}
 public void NoTransactionScope_CanRetrieveSingleProduct()
 {
     Product p1 = new Product(1);
     Assert.AreEqual(1, p1.ProductID);
 }
		private void attach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Category = this;
		}
		private void attach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Supplier = this;
		}
 /// <summary>
 /// Determines whether [is units equal minus9] [the specified p].
 /// </summary>
 /// <param name="p">The p.</param>
 /// <returns>
 /// 	<c>true</c> if [is units equal minus9] [the specified p]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsUnitsEqualMinus9(Product p)
 {
     return p.UnitsOnOrder == -9;
 }
 public void Object_DefaultSettings()
 {
     Product p = new Product(true);
     Assert.IsNotNull(p.DateCreated, "Should not be NULL");
     Assert.AreEqual(DateTime.Now.ToString(), p.DateCreated.ToString(), "Should not be NULL");
 }
        public void Transaction_CommitProduct()
        {
            using(TransactionScope scope = new TransactionScope())
            {
                //try
                //{
                UpdateProduct(1, "10 boxes x 30 bags");
                UpdateProduct(2, "24 - 42 oz bottles");
                UpdateProduct(3, "12 - 5500 ml bottles");
                scope.Complete();
                //}
                //catch(System.Data.SqlClient.SqlException x)
                //{
                //    //trap/trace/log as needed
                //    throw x;
                //}
            }

            //the saves shouldn't be committed, hopefully!
            Product pVal = new Product(1);
            Assert.AreEqual("10 boxes x 30 bags", pVal.QuantityPerUnit);

            //set them back
            UpdateProduct(1, "10 boxes x 20 bags");
            UpdateProduct(2, "24 - 12 oz bottles");
            UpdateProduct(3, "12 - 550 ml bottles");
        }
        public void CanRetrieveMultipleEntities_FailsWithoutSharedConnectionScope()
        {
            string errorMessage = String.Empty;
            try
            {
                using(TransactionScope ts = new TransactionScope())
                {
                    Product p1 = new Product(1);
                    Product p2 = new Product(2);

                    Order o1 = new Order(1);
                    Order o2 = new Order(2);

                    Assert.AreEqual(1, p1.ProductID);
                    Assert.AreEqual(2, p2.ProductID);
                    Assert.AreEqual(1, o1.OrderID);
                    Assert.AreEqual(2, o2.OrderID);
                }
            }
            catch(Exception e)
            {
                errorMessage = e.Message;
            }

            Assert.IsTrue(_dtcErrorMessage.IsMatch(errorMessage) || errorMessageTransAbort.IsMatch(errorMessage), errorMessage);
        }
        public void UpdateSingleProductRetrieveMultipleProducts_FailsWithoutSharedConnection()
        {
            string errorMessage = String.Empty;

            try
            {
                using(TransactionScope ts = new TransactionScope())
                {
                    SaveProduct(1, "new name of product");

                    Product p2 = new Product(2);
                    Product p3 = new Product(3);
                }
            }
            catch(Exception e)
            {
                errorMessage = e.Message;
            }
            Assert.IsTrue(_dtcErrorMessage.IsMatch(errorMessage) || errorMessageTransAbort.IsMatch(errorMessage), errorMessage);
        }
        // Retire this test for now - it's causing too many problems even with waiting for the threads to complete
        // - transactions are not failing gracefully ... BMc
        //[Test, MTAThreadAttribute()]
        public void MultiThreadedTest()
        {
            // TODO: this should be improved to wait for threads to complete and consolidate any error messages.
            // Right now, if there is a problem, this test will succeed and (a) other tests will fail (b) the VsTestHost.exe
            // will fail with an unhandled exception.

            // Threading wait added Jun 2011 BMc
            // thanks to: http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-threadpool

            string p1OriginalProductName = new Product(1).ProductName;
            string p2OriginalProductName = new Product(2).ProductName;

            const int iterations = 50;
            resetEvents = new ManualResetEvent[iterations];

            for (int i = 0; i < iterations; i++) {
                resetEvents[i] = new ManualResetEvent(false);
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadingTarget), (object)i);
            }
            WaitHandle.WaitAll(resetEvents);

            SaveProduct(1, p1OriginalProductName);
            SaveProduct(2, p2OriginalProductName);
        }
        /// <summary>
        /// Asserts the validation.
        /// </summary>
        /// <param name="unitPrice">The unit price.</param>
        /// <param name="expected">if set to <c>true</c> [expected].</param>
        private static void AssertValidation(decimal unitPrice, bool expected)
        {
            Product p = new Product();
            p.ProductName = "Test";
            p.QuantityPerUnit = "test amount";
            p.ReorderLevel = null;
            p.SupplierID = 1;
            p.UnitsInStock = 0;
            p.UnitsOnOrder = 0;
            p.CategoryID = 1;
            p.Discontinued = false;

            p.UnitPrice = unitPrice;
            Assert.AreEqual(expected, p.Validate());
        }
        //[Ignore] // fails with sqlite
        public void UpdateSingleProductRetrieveMultipleProducts_SucceedsWithSharedConnection()
        {
            string p1OriginalProductName = new Product(1).ProductName;

            using(TransactionScope ts = new TransactionScope())
            {
                using(SharedDbConnectionScope connScope = new SharedDbConnectionScope())
                {
                    SaveProduct(1, "new name of product");

                    Product p2 = new Product(2);
                    Product p3 = new Product(3);
                }
            }

            Assert.AreEqual(p1OriginalProductName, new Product(1).ProductName, "Transaction NOT rolled back");
        }
        public void Object_CRUD()
        {
            //Add a product
            Product p = new Product();
            p.ProductName = "Test";
            p.QuantityPerUnit = "test amount";
            p.ReorderLevel = null;
            p.SupplierID = 1;
            p.UnitPrice = 100;
            p.UnitsInStock = 0;
            p.UnitsOnOrder = 0;
            p.CategoryID = 1;
            p.Discontinued = false;

            Assert.AreEqual(0, p.ProductID);

            p.Save("Unit Test");

            Assert.IsTrue(p.ProductID > 0);
        }
        public void MultiThreadRepeat()
        {
            lock(thisLock)
            {
                var qcc = new QueryCommandCollection();
                int threadId = Thread.CurrentThread.ManagedThreadId;
                Debug.WriteLine("MultiThreadRepeat: thread id = " + threadId);
                int count = 0;
                for(int n = 0; n < 10; n++)
                {
                    Query qry1 = new Query(Product.Schema);
                    qry1.QueryType = QueryType.Update;
                    qry1.AddWhere(Product.Columns.ProductID, n);
                    qry1.AddUpdateSetting("ProductName", threadId + ": unit test ");
                    QueryCommand cmd = qry1.BuildUpdateCommand();
                    qcc.Add(cmd);
                    count++;
                }
                DataService.ExecuteTransaction(qcc);
                var p1 = new Product(1);
                Assert.AreEqual(p1.ProductName, threadId + ": unit test ", StringComparison.InvariantCultureIgnoreCase);
            }

        }
 /// <summary>
 /// Creates the product.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <returns></returns>
 private static Product CreateProduct(int index)
 {
     Product product = new Product();
     product.CategoryID = 1;
     product.Discontinued = false;
     product.ProductName = string.Format("Unit Test Product {0}", index);
     product.QuantityPerUnit = "Qty";
     product.ReorderLevel = 3;
     product.SupplierID = 1;
     product.UnitPrice = 99;
     product.UnitsInStock = 20;
     product.UnitsOnOrder = 9;
     return product;
 }
 /// <summary>
 /// Updates the product.
 /// </summary>
 /// <param name="productId">The product id.</param>
 /// <param name="productName">Name of the product.</param>
 /// <returns></returns>
 private static Product UpdateProduct(int productId, string productName)
 {
     Product p1 = new Product(productId);
     p1.ProductName = productName;
     p1.UnitPrice = 50;
     return p1;
 }
        public void UpdateSingleProduct_CommitChangeToDatabase()
        {
            string newProductName = "new name of product 20: " + _rand.Next(MaxRandomNumber);

            using(TransactionScope ts = new TransactionScope())
            {
                using(SharedDbConnectionScope connScope = new SharedDbConnectionScope())
                {
                    SaveProduct(20, newProductName);

                    Product p2 = new Product(2);
                    Product p3 = new Product(3);

                    ts.Complete();
                }
            }

            Assert.AreEqual(newProductName, new Product(20).ProductName, "Transaction Not Committed");
        }
 partial void DeleteProduct(Product instance);