public void CategoryMaxPlusOne()
        {
            //create an instance of the class we want to create
            clsCourses aCourse = new clsCourses();
            //string variable to store any error message
            String Error = "";
            //create some test data to pass to the method
            string Category = "aaaaaaaaaaaaaaaaaaaaa";//this should fail

            //invoke the method
            Error = aCourse.Valid(Title, Category, Tutor, LiveDate, Price);
            //test to see that the result is correct
            Assert.AreNotEqual(Error, "");
        }
        public void PriceMin()
        {
            //create an instance of the class we want to create
            clsCourses aCourse = new clsCourses();
            //string variable to store any error message
            String Error = "";
            //create a variable to store the test date data
            Decimal TestPrice;

            //set TestPrice to a value
            TestPrice = 00.00m;
            //convert the decimal variable to a string variable
            string Price = TestPrice.ToString();

            //invoke the method
            Error = aCourse.Valid(Title, Category, Tutor, LiveDate, Price);
            //test to see that the result is correct
            Assert.AreEqual(Error, "");
        }
        public void LiveDateMin()
        {
            //create an instance of the class we want to create
            clsCourses aCourse = new clsCourses();
            //string variable to store any error message
            String Error = "";
            //create a variable to store the test date data
            DateTime TestDate;

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

            //invoke the method
            Error = aCourse.Valid(Title, Category, Tutor, LiveDate, Price);
            //test to see that the result is correct
            Assert.AreEqual(Error, "");
        }
Пример #4
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        //create a new instance of clsCourses
        clsCourses aCourse = new clsCourses();
        //capture the CourseTitle
        string Title = txtTitleCourse.Text;
        //capture the  courseCategory
        string Category = txtCategoryCourse.Text;
        //capture the  courseTutor
        string Tutor = txtTutorCourse.Text;
        //capture the courseLiveDate
        string LiveDate = txtLiveDateCourse.Text;
        //capture the coursePrice
        string Price = txtpriceCourse.Text;
        //variable to store any error messages
        string Error = "";

        //validate the data
        Error = aCourse.Valid(Title, Category, Tutor, LiveDate, Price);
        if (Error == "")
        {
            //capture the IDno
            aCourse.IDno = IDno;
            //capture the Title
            aCourse.Title = Title;
            //capture the Category
            aCourse.Category = Category;
            //capture the Tutor
            aCourse.Tutor = Tutor;
            //capture the LiveDate
            aCourse.LiveDate = Convert.ToDateTime(LiveDate);
            //capture the Price
            aCourse.Price = Convert.ToDecimal(Price);
            //capture Available
            aCourse.Available = Available.Checked;
            //create a new instance of the address collection
            clsCourseCollection courseList = new clsCourseCollection();

            //if this is a new record i.e IDno = -1 then add the data
            if (IDno == -1)
            {
                //set the ThisCourse property
                courseList.ThisCourse = aCourse;
                //add the new record
                courseList.Add();
            }
            //otherwise it must be an update
            else
            {
                //find the record to update
                courseList.ThisCourse.Find(IDno);
                //set the ThisCourse property
                courseList.ThisCourse = aCourse;
                //update the record
                courseList.Update();
            }
            //redirect back to the listpage
            Response.Redirect("CourseList.aspx");
        }
        else
        {
            //display the error message
            lblError.Text = Error;
        }
    }