public static OrderDetail GetOrderDetail1(Product product) {
     //show that you can get coverage on property initializers.
     OrderDetail retVal = new OrderDetail();
     retVal.Product = product;
     retVal.Quantity = 4;
     retVal.UnitPrice = 12;
     return retVal;
 }
        public static Product GetProduct2() {
            //show that you can get coverage on property initializers.
            Product retVal = new Product();
            retVal.Cost = 3;
            retVal.Name = "Sample Product 2";
            retVal.Price = 13.75m;

            return retVal;
        }
        public static Product GetProduct1() {
            //show that you can get coverage on property initializers.
            Product retVal = new Product();
            retVal.Cost = 7;
            retVal.Name = "Sample Product 1";
            retVal.Price = 11.50m;
            retVal.ProductId = 1;

            return retVal;
        }
Ejemplo n.º 4
0
        // creates query parameter list from Product object

        private object[] Take(Product product)
        {
            return new object[]  
            {
                "@ProductId", product.ProductId,
                "@ProductName", product.ProductName,
                "@Weight", product.Weight,
                "@UnitPrice", product.UnitPrice,
                "@UnitsInStock", product.UnitsInStock
            };
        }
Ejemplo n.º 5
0
 public void UpdateProduct(Product product)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         Db.ExecuteNonQuery("usp_Product_UpdateProduct", CommandType.StoredProcedure,
             new DbParameter[] {
                        Db.CreateParameter("ProductId", product.ProductId),
                        Db.CreateParameter("ProductName", product.ProductName),
                        Db.CreateParameter("Description", product.Description),
                        Db.CreateParameter("Quantity", product.Quantity),
                        Db.CreateParameter("UntiPrice", product.UnitPrice),
                        Db.CreateParameter("TaxId", product.TaxId)
          });
         scope.Complete();
     }
 }
Ejemplo n.º 6
0
 public int AddProduct(Product product)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         DbParameter parameter = null;
         parameter = Db.CreateParameter("ProductId", DbType.Int32, 8);
         parameter.Direction = ParameterDirection.Output;
         Db.ExecuteNonQuery("usp_Product_InsertProductDetails", CommandType.StoredProcedure,
             new DbParameter[] {
                        parameter,
                        Db.CreateParameter("ProductName", product.ProductName),
                        Db.CreateParameter("Description", product.Description),
                        Db.CreateParameter("UnitPrice", product.UnitPrice),
                        Db.CreateParameter("Quantity", product.Quantity),
                        Db.CreateParameter("TaxId", product.TaxId),
                        Db.CreateParameter("Status", product.Status)
          });
         scope.Complete();
         return (int)parameter.Value;
     }
 }
Ejemplo n.º 7
0
        public void InitializeMocks()
        {
            mockService = new Mock<IService>();

            // setup for getting a list of categories

            var categories = new List<Category> { new Category { CategoryId = 1, CategoryName = "test-category" } };
            mockService.Setup(s => s.GetCategories()).Returns(categories);

            // setup for getting a list of products

            var products = new List<Product> { new Product { ProductId = 1, ProductName = "test-product" } };
            mockService.Setup(s => s.GetProductsByCategory(It.IsAny<int>(),"unitprice asc")).Returns(products);

            // setup for getting a product

            var product = new Product { ProductId = 1, ProductName = "test-product", Category = new Category { CategoryName = "test-category" } };
            mockService.Setup(s => s.GetProduct(1)).Returns(product);

            // setup for searching for products

            mockService.Setup(s => s.SearchProducts("", 0, 5000, "unitprice asc")).Returns(products);
        }
Ejemplo n.º 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Product product = new Product();
                product.ProductName = txtProductName.Text.Trim();
                product.Description = txtProdDesc.Text.Trim();
                product.UnitPrice = Convert.ToDecimal(txtUnitPrice.Text);
                product.Quantity = Convert.ToInt32(txtQuantity.Text);
                product.TaxId = Convert.ToInt32(cmbTaxRate.SelectedValue);
                product.Status = true;

                if (productID == 0)
                {
                    int productId = productService.AddProduct(product);
                    ResetControls();
                    CustomMessageBox.Show(string.Format(Constants.SUCCESSFULL_ADD_MESSAGE, Constants.CONSTANT_PRODUCT, txtProductName.Text),
                                                              Constants.CONSTANT_INFORMATION,
                                                              Sleek_Bill.Controls.CustomMessageBox.eDialogButtons.OK,
                                                              CustomImages.GetDialogImage(Sleek_Bill.Controls.CustomImages.eCustomDialogImages.Success));
                }
                else
                {
                    product.ProductId = productID;
                    productService.UpdateProduct(product);
                    CustomMessageBox.Show(string.Format(Constants.SUCCESSFULL_SAVE_MESSAGE, txtProductName.Text),
                                                                  Constants.CONSTANT_INFORMATION,
                                                                  Sleek_Bill.Controls.CustomMessageBox.eDialogButtons.OK,
                                                                  CustomImages.GetDialogImage(Sleek_Bill.Controls.CustomImages.eCustomDialogImages.Success));
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error :" + ex.Message);
            }
        }
        public void CastToGuid()
        {
            int prdId = 0;

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    // Create an employee with a guid in the LastName column
                    Product prd = new Product();
                    prd.es.Connection.Name = "ForeignKeyTest";

                    prd.ProductName = "551cfc32-c6d2-4756-8c59-efb460a0d1d9";
                    prd.UnitPrice = 35.23M;
                    prd.Discontinued = false;
                    prd.Save();

                    prdId = prd.ProductID.Value;

                    prd = new Product();
                    prd.es.Connection.Name = "ForeignKeyTest";

                    prd.Query.Select((esGuid)prd.Query.ProductName.As("CastColumn"));
                    prd.Query.Where(prd.Query.ProductID == prdId);

                    switch (prd.es.Connection.ProviderSignature.DataProviderName)
                    {
                        //case "EntitySpaces.VistaDBProvider":
                        case "EntitySpaces.MSAccessProvider":
                        case "EntitySpaces.MySqlClientProvider":
                        case "EntitySpaces.OracleClientProvider":
                        case "EntitySpaces.NpgsqlProvider":
                        case "EntitySpaces.SQLiteProvider":
                        //case "EntitySpaces.SqlServerCeProvider":
                            Assert.Ignore("Not supported.");
                            break;
                        default:
                            Assert.IsTrue(prd.Query.Load());

                            Guid value = new Guid("551cfc32-c6d2-4756-8c59-efb460a0d1d9");
                            object obj = prd.GetColumn("CastColumn");
                            Assert.AreEqual("System.Guid", obj.GetType().ToString());
                            Assert.AreEqual(value, obj);
                            break;
                    }
                }
            }
            finally
            {
                Product prd = new Product();
                prd.es.Connection.Name = "ForeignKeyTest";

                prd.Query.Where(prd.Query.ProductID == prdId); ;
                if (prd.Query.Load())
                {
                    prd.MarkAsDeleted();
                    prd.Save();
                }
            } 
        }
 /// <summary>
 /// Clear the product.
 /// </summary>
 public void ClearProduct() {
     _product = null;
 }
Ejemplo n.º 11
0
 public void UpdateProduct(Product product)
 {
     this.productDBObj.UpdateProduct(product);
 }
Ejemplo n.º 12
0
 public int AddProduct(Product product)
 {
     return this.productDBObj.AddProduct(product);
 }
        public void TestCollectionDeleteAll()
        {
            int prdId = -1;
            Product prd = new Product();
            prd.es.Connection.Name = "ForeignKeyTest";

            try
            {
                using (esTransactionScope scope = new esTransactionScope())
                {
                    prd.ProductName = "UnitTest";
                    prd.UnitPrice = 1;
                    prd.Discontinued = false;
                    for (int i = 0; i < 3; i++)
                    {
                        OrderItem oi = prd.OrderItemCollectionByProductID.AddNew();
                        oi.OrderID = i + 1;
                        oi.UnitPrice = prd.UnitPrice;
                        oi.Quantity = Convert.ToInt16(i);
                        oi.Discount = 0;
                    }
                    prd.Save();
                    prdId = prd.ProductID.Value;

                    // Test
                    ProductCollection collection = new ProductCollection();
                    collection.es.Connection.Name = "ForeignKeyTest";

                    Assert.IsTrue(collection.LoadAll());
                    Product entity = collection.FindByPrimaryKey(prdId);
                    Assert.AreEqual(3, entity.OrderItemCollectionByProductID.Count);
                    entity.OrderItemCollectionByProductID.MarkAllAsDeleted();
                    entity.MarkAsDeleted();
                    collection.Save();

                    prd = new Product();
                    prd.es.Connection.Name = "ForeignKeyTest";
                    Assert.IsFalse(prd.LoadByPrimaryKey(prdId));

                    OrderItemCollection oic = new OrderItemCollection();
                    oic.es.Connection.Name = "ForeignKeyTest";
                    oic.Query.Where(oic.Query.ProductID == prdId);
                    Assert.IsFalse(oic.Query.Load());
                }
            }
            finally
            {
                prd = new Product();
                prd.es.Connection.Name = "ForeignKeyTest";

                if (prd.LoadByPrimaryKey(prdId))
                {
                    prd.OrderItemCollectionByProductID.MarkAllAsDeleted();
                    prd.MarkAsDeleted();
                    prd.Save();
                }
            }
        }
 private void _List_AddingNew(object sender, AddingNewEventArgs e)
 {
     e.NewObject = new Product();
     Product product = (Product)e.NewObject;
     product.Savable += Product_Savable;
 }