Esempio n. 1
0
        public void CRUDProductTest()
        {
            int pid     = 9876;
            var product = new product()
            {
                product_id  = pid,
                product1    = "TestProduct",
                price       = 123,
                quantity    = 321,
                catagory    = "Test Catagory",
                subcatagory = "Test SubCatagory",
                note        = "Note"
            };

            var addedProduct = this.invoiceDbEntities.products.Add(product);

            pid = addedProduct.product_id;
            this.invoiceDbEntities.SaveChanges();

            var products    = ProductApi.GetProductList(null);
            var testProduct = products.FirstOrDefault(x => x.product_id == addedProduct.product_id);

            Assert.IsNotNull(testProduct, "Test product not found.");
            Assert.AreEqual(testProduct.price, product.price, "Products are different.");

            testProduct = this.invoiceDbEntities.products.Remove(product);
            this.invoiceDbEntities.SaveChanges();

            products = ProductApi.GetProductList(null);
            Assert.IsNull(products.FirstOrDefault(x => x.product_id == addedProduct.product_id), "Test product is not removed.");
        }
Esempio n. 2
0
        public void GetProductListWebApi()
        {
            var category = (string)this.CatagoryBox.SelectedItem;
            var products = ProductApi.GetProductList(category);

            foreach (var product in products.OrderBy(x => x.product_id))
            {
                // product_id as No, Product, Price, Quantity, Catagory, SubCatagory, Not
                DataGridViewRow row = (DataGridViewRow)ProductDataView.Rows[0].Clone();
                row.Cells[0].Value = product.product_id.ToString();
                row.Cells[1].Value = product.product1.ToString();
                row.Cells[2].Value = product.price.ToString();
                row.Cells[3].Value = product.quantity.ToString();
                row.Cells[4].Value = product.catagory.ToString().Trim();
                SelectedCatagory(row, product.catagory.ToString().Trim());
                row.Cells[5].Value = (string)product.subcatagory;
                row.Cells[6].Value = (string)product.note;
                this.ProductDataView.Rows.Add(row);
            }
        }