Example #1
0
        public void ValidMethodOK()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreEqual(Error, "");
        }
Example #2
0
        public void SizeInvalidData()
        {
            //create instance of the class
            clsTrainers ATrainer = new clsTrainers();
            //string to store error message
            String Error = "";
            //set the date added to non date value
            String Size = "Value entered is not a number!";

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Example #3
0
        public void ColourMinPlusOne()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";
            //create some test data to pass to the method
            string Colour = "aa"; //this should be okay

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreEqual(Error, "");
        }
Example #4
0
        public void DateAddedInvalidData()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";
            //set the dateAdded to a non date value
            string DateAdded = "This is not a date";

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Example #5
0
        public void ColourMaxExtreme()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";
            //create some test data to pass to the method
            string Colour = "";

            Colour = Colour.PadRight(100, 'N'); //this should fail
            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Example #6
0
        public void PriceMin()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";
            //create some test data to pass to the method
            Decimal TestPrice = 0.01M; //this should pass
            //convert the size variable to a string variable
            string Price = TestPrice.ToString();

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreEqual(Error, "");
        }
Example #7
0
        public void SizeMinLessOne()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";
            //create some test data to pass to the method
            Int32 TestSize = 0; //this should trigger an error
            //convert the size variable to a string variable
            string Size = TestSize.ToString();

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
Example #8
0
        public void DateAddedMin()
        {
            //create an instance of the class we want to create
            clsTrainers ATrainer = new clsTrainers();
            //string variable to store any error message
            String Error = "";
            //create some test data to pass to the method
            DateTime TestData;

            //set the date to todays date
            TestData = DateTime.Now.Date;
            //convert the date variable to a string variable
            string DateAdded = TestData.ToString();

            //invoke the method
            Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
            //test to see that the result is correct
            Assert.AreEqual(Error, "");
        }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        //create a new instance of clsTrainers
        clsTrainers ATrainer = new clsTrainers();
        //capture the properties
        string Brand     = txtBrand.Text;
        string Name      = txtName.Text;
        string Colour    = ddlColour.Text;
        string Size      = txtSize.Text;
        string Price     = txtPrice.Text;
        string DateAdded = txtDateAdded.Text;
        //variable to store any error messages
        string Error = "";

        //validate the data
        Error = ATrainer.Valid(Brand, Name, Colour, Size, Price, DateAdded);
        if (Error == "")
        {
            //capture the properties
            ATrainer.Brand     = Brand;
            ATrainer.Name      = Name;
            ATrainer.Colour    = Colour;
            ATrainer.Size      = Convert.ToInt32(Size);
            ATrainer.Price     = Convert.ToDecimal(Price);
            ATrainer.DateAdded = Convert.ToDateTime(DateAdded);
            //store the trainers in the session object
            Session["ATrainer"] = ATrainer;
            //redirect to the viewer page
            Response.Redirect("TrainerViewer.aspx");
        }
        else
        {
            //display an error message
            lblError.Text = Error;
        }
    }