Esempio n. 1
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        //create a new instance of clsProduct
        clsProduct AProduct = new clsProduct();
        //capture the name
        string Name = txtName.Text;
        //capture the price
        string Price = txtName.Text;
        //capture the description
        string Description = txtDescription.Text;
        //variable to the store any error messages
        string Error = "";

        //validate the data
        Error = AProduct.Valid(Name, Price, Description);
        if (Error == "")
        {
            //capture the Name
            AProduct.Name = Name;
            //capture the price
            AProduct.Price = Price;
            //capture the description
            AProduct.Description = Description;
            //store the product name in the session object
            Session["AProduct"] = AProduct;
            //redirect to the viewer page
            Response.Redirect("ProductViewer.aspx");
        }
        else
        {
            //display the error message
            lblError.Text = Error;
        }
    }
Esempio n. 2
0
    protected void OK_Click(object sender, EventArgs e)
    {
        clsProduct AProduct           = new clsProduct();
        String     ProductName        = txtProductName.Text;
        String     ProductDescription = txtProductDescription.Text;
        String     UnitPrice          = txtUnitPrice.Text;
        String     StockAmount        = txtStockAmount.Text;
        String     DiscountPercentage = txtDiscountPercentage.Text;
        String     Error = "";

        Error = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);

        if (Error == "")
        {
            if (Convert.ToInt32(StockAmount) == 0)
            {
                AProduct.InStock = false;
            }
            else
            {
                AProduct.InStock = true;
            }

            if (Convert.ToInt32(DiscountPercentage) == 0)
            {
                AProduct.DiscountActive = false;
            }
            else
            {
                AProduct.DiscountActive = true;
            }

            AProduct.ProductNo          = ProductNo;
            AProduct.ProductName        = ProductName;
            AProduct.ProductDescription = ProductDescription;
            AProduct.UnitPrice          = Convert.ToDouble(UnitPrice);
            AProduct.StockAmount        = Convert.ToInt32(StockAmount);
            AProduct.DiscountPercentage = Convert.ToInt32(DiscountPercentage);
            AProduct.Active             = Active.Checked;
            clsProductCollection Products = new clsProductCollection();

            if (ProductNo == -1)
            {
                Products.ThisProduct = AProduct;
                Products.Add();
            }
            else
            {
                Products.ThisProduct.Find(ProductNo);
                Products.ThisProduct = AProduct;
                Products.Update();
            }
            Response.Redirect("ProductList.aspx");
        }
        else
        {
            lblError.Text = Error;
        }
    }
Esempio n. 3
0
        public void ValidMethodOk2()
        {
            clsProduct AProduct = new clsProduct();
            String     Error    = "";

            Error = AProduct.Valid(ProductName, Description, Price);
            Assert.AreEqual(Error, "");
        }
Esempio n. 4
0
        public void PlatformMinLessOne()
        {
            clsProduct AProduct = new clsProduct();
            string     Error    = "";
            string     Platform = ""; //should trigger an error

            Error = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 5
0
        public void GenreMaxPlusOne()
        {
            clsProduct AProduct = new clsProduct();
            string     Error    = "";
            string     Genre    = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; //should fail 51 characters long

            Error = AProduct.Valid(Genre, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 6
0
        public void GenreMinPlusOne()
        {
            clsProduct AProduct = new clsProduct();
            string     Error    = "";
            string     Genre    = "aa"; //should pass

            Error = AProduct.Valid(Genre, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }
Esempio n. 7
0
        public void Unit_PriceExtremeMax()
        {
            clsProduct AProduct   = new clsProduct();
            string     Error      = "";
            string     Unit_Price = "2000.00";

            Error = AProduct.Valid(Title, Unit_Price, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 8
0
        public void Unit_PriceMidValue()
        {
            clsProduct AProduct   = new clsProduct();
            string     Error      = "";
            string     Unit_Price = "500.00"; //should pass

            Error = AProduct.Valid(Title, Unit_Price, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }
Esempio n. 9
0
        public void Unit_PriceMaxPlusOne()
        {
            clsProduct AProduct   = new clsProduct();
            string     Error      = "";
            string     Unit_Price = "1000.00"; //should fail 7 characters long

            Error = AProduct.Valid(Title, Unit_Price, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 10
0
        public void Unit_PriceMax()
        {
            clsProduct AProduct   = new clsProduct();
            string     Error      = "";
            string     Unit_Price = "999.99"; //should pass 6 characters long

            Error = AProduct.Valid(Title, Unit_Price, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }
Esempio n. 11
0
        public void PlatformMidValue()
        {
            clsProduct AProduct = new clsProduct();
            string     Error    = "";
            string     Platform = "aaaaaaaaaaaaaaaaaaaaaaaaa"; //should pass 25 characters long

            Error = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }
Esempio n. 12
0
        public void TypeMaxLessOne()
        {
            clsProduct AProduct = new clsProduct();
            String     Error    = "";
            String     Type     = "PPPPPPPPPPPPPPPPPPP";

            Error = AProduct.Valid(Product_ID, Name, Type, Colour, Cost, Stock_Count, Next_Delivery);
            Assert.AreEqual(Error, "");
        }
        public void StockAmountMax()
        {
            clsProduct AProduct    = new clsProduct();
            String     Error       = "";
            string     StockAmount = Int16.MaxValue.ToString();

            Error = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);
            Assert.AreEqual(Error, "");
        }
Esempio n. 14
0
        public void ReleaseDateInvalidData()
        {
            clsProduct AProduct     = new clsProduct();
            string     Error        = "";
            string     Release_Date = "this is not a date!";

            Error = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 15
0
        public void Next_DeliveryInvalidData()
        {
            clsProduct AProduct      = new clsProduct();
            String     Error         = "";
            String     Next_Delivery = "This is not a date";

            Error = AProduct.Valid(Product_ID, Name, Type, Colour, Cost, Stock_Count, Next_Delivery);
            Assert.AreNotEqual(Error, "");
        }
        public void DiscountPercentageMinPlusOne()
        {
            clsProduct AProduct           = new clsProduct();
            String     Error              = "";
            string     DiscountPercentage = "1";

            Error = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);
            Assert.AreEqual(Error, "");
        }
Esempio n. 17
0
        public void CostMinLessOne()
        {
            clsProduct AProduct = new clsProduct();
            String     Error    = "";
            int        Cost     = -1;

            Error = AProduct.Valid(Product_ID, Name, Type, Colour, Cost, Stock_Count, Next_Delivery);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 18
0
        public void Stock_CountMid()
        {
            clsProduct AProduct    = new clsProduct();
            String     Error       = "";
            int        Stock_Count = (300);

            Error = AProduct.Valid(Product_ID, Name, Type, Colour, Cost, Stock_Count, Next_Delivery);
            Assert.AreEqual(Error, "");
        }
Esempio n. 19
0
        public void ColourExtremeMax()
        {
            clsProduct AProduct = new clsProduct();
            String     Error    = "";
            String     Colour   = "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP";

            Error = AProduct.Valid(Product_ID, Name, Type, Colour, Cost, Stock_Count, Next_Delivery);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 20
0
        public void NameMin()
        {
            clsProduct AProduct = new clsProduct();
            String     Error    = "";
            String     Name     = "A";

            Error = AProduct.Valid(Product_ID, Name, Type, Colour, Cost, Stock_Count, Next_Delivery);
            Assert.AreEqual(Error, "");
        }
        public void StockAmountMinLessOne()
        {
            clsProduct AProduct    = new clsProduct();
            String     Error       = "";
            string     StockAmount = "-1";

            Error = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 22
0
        public void DescriptionMin()
        {
            clsProduct AProduct    = new clsProduct();
            string     Error       = "";
            string     Description = "a"; //should pass

            Error = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }
        public void UnitPriceMaxMinusOne()
        {
            clsProduct AProduct  = new clsProduct();
            String     Error     = "";
            string     UnitPrice = "";

            UnitPrice = (Int16.MaxValue - 1).ToString();
            Error     = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);
            Assert.AreEqual(Error, "");
        }
        public void ProductDescriptionMid()
        {
            clsProduct AProduct           = new clsProduct();
            String     Error              = "";
            string     ProductDescription = "";

            ProductDescription = ProductDescription.PadRight(50, 'a');
            Error = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);
            Assert.AreEqual(Error, "");
        }
        public void ProductNameMaxPlusOne()
        {
            clsProduct AProduct    = new clsProduct();
            String     Error       = "";
            string     ProductName = "";

            ProductName = ProductName.PadRight(101, 'a');
            Error       = AProduct.Valid(ProductName, ProductDescription, UnitPrice, StockAmount, DiscountPercentage);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 26
0
        public void DescriptionMaxPlusOne()
        {
            clsProduct AProduct    = new clsProduct();
            string     Error       = "";
            string     Description = "";                  //should fail 501 characters long

            Description = Description.PadRight(501, 'a'); //should fail 501 characters long
            Error       = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 27
0
        public void PlatformExtremeMax()
        {
            clsProduct AProduct = new clsProduct();
            string     Error    = "";
            string     Platform = "";

            Platform = Platform.PadRight(500, 'a'); //should fail 500 characters long
            Error    = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreNotEqual(Error, "");
        }
Esempio n. 28
0
        public void DescriptionMidValue()
        {
            clsProduct AProduct    = new clsProduct();
            string     Error       = "";
            string     Description = ""; //should pass 250 characters long

            Description = Description.PadRight(250, 'a');
            Error       = AProduct.Valid(Title, Description, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }
        public void ValidMethodOK()
        {
            clsProduct aProduct = new clsProduct();
            String     Error    = "";

            Error = aProduct.Valid(ProductName,
                                   ProductDescription,
                                   UnitPrice,
                                   StockAmount,
                                   DiscountPercentage);
        }
Esempio n. 30
0
        public void Release_DateMid()
        {
            clsProduct AProduct = new clsProduct();
            String     Error    = "";
            DateTime   TestDate;

            TestDate = DateTime.Now.Date;
            string Release_Date = TestDate.ToString();

            Error = AProduct.Valid(Title, Unit_Price, Unit_Price, Release_Date, Platform, Genre);
            Assert.AreEqual(Error, "");
        }