Exemplo n.º 1
0
        public void DeleteMethodOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create the item of test data
            clsCourses TestItem = new clsCourses();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.Available = true;
            TestItem.IDno      = 1;
            TestItem.Title     = "Web Development";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "R Sunderland";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 180;
            //set ThisCourse to the test data
            AllCourses.ThisCourse = TestItem;
            //add the record
            PrimaryKey = AllCourses.Add();
            //set the primary key of the test data
            TestItem.IDno = PrimaryKey;
            //find the record
            AllCourses.ThisCourse.Find(PrimaryKey);
            //delete the record
            AllCourses.Delete();
            //now find the record
            Boolean Found = AllCourses.ThisCourse.Find(PrimaryKey);

            //test to see that the record was not found
            Assert.IsFalse(Found);
        }
Exemplo n.º 2
0
        public void ListAndCountOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create some test data to assign to the property
            //in this case the data needs to be a list of objects
            List <clsCourses> TestList = new List <clsCourses>();
            //add an item to the list
            //create the item of test data
            clsCourses TestItem = new clsCourses();

            //set its properties
            TestItem.Available = true;
            TestItem.IDno      = 1;
            TestItem.Title     = "Computing";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "D Lewis";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 200;
            //add the item to the test list
            TestList.Add(TestItem);
            //assign the data to the property
            AllCourses.CourseList = TestList;
            //test to see that the two values are the same
            Assert.AreEqual(AllCourses.Count, TestList.Count);
        }
Exemplo n.º 3
0
        public void ReportByCategoryTestDataFound()
        {
            //create an instance of the filtered data
            clsCourseCollection FilteredCourses = new clsCourseCollection();
            //var to store outcome
            Boolean OK = true;

            //apply a category that doesnt exist
            FilteredCourses.ReportByCategory("Science");
            //check that the correct number of records are found
            if (FilteredCourses.Count == 2)
            {
                //check that the first record is ID 36
                if (FilteredCourses.CourseList[0].IDno != 2)
                {
                    OK = false;
                }
                //check that the first record is ID 37
                if (FilteredCourses.CourseList[1].IDno != 6)
                {
                    OK = false;
                }
            }
            else
            {
                OK = false;
            }
            //test to see that there are no records
            Assert.IsTrue(OK);
        }
Exemplo n.º 4
0
    void DisplayCourses()
    {
        //create and instance of the Courses
        clsCourseCollection Courses = new clsCourseCollection();

        //find the record to update
        Courses.ThisCourse.Find(IDno);
        //display the data for this record
        txtIDno.Text           = Courses.ThisCourse.IDno.ToString();
        txtTitleCourse.Text    = Courses.ThisCourse.Title;
        txtCategoryCourse.Text = Courses.ThisCourse.Category;
        txtTutorCourse.Text    = Courses.ThisCourse.Tutor;
        if (Courses.ThisCourse.LiveDate.Day < 10 & Courses.ThisCourse.LiveDate.Month < 10 & Courses.ThisCourse.LiveDate.Year < 2)
        {
            txtLiveDateCourse.Text = "0" + Courses.ThisCourse.LiveDate.Day + "/0" + Courses.ThisCourse.LiveDate.Month + "/000" + Courses.ThisCourse.LiveDate.Year;
        }
        else if (Courses.ThisCourse.LiveDate.Day < 10 & Courses.ThisCourse.LiveDate.Month < 10)
        {
            txtLiveDateCourse.Text = "0" + Courses.ThisCourse.LiveDate.Day + "/0" + Courses.ThisCourse.LiveDate.Month + "/" + Courses.ThisCourse.LiveDate.Year;
        }
        else if (Courses.ThisCourse.LiveDate.Day < 10)
        {
            txtLiveDateCourse.Text = "0" + Courses.ThisCourse.LiveDate.Day + "/" + Courses.ThisCourse.LiveDate.Month + "/" + Courses.ThisCourse.LiveDate.Year;
        }
        else if (Courses.ThisCourse.LiveDate.Month < 10)
        {
            txtLiveDateCourse.Text = Courses.ThisCourse.LiveDate.Day + "/0" + Courses.ThisCourse.LiveDate.Month + "/" + Courses.ThisCourse.LiveDate.Year;
        }
        else if (Courses.ThisCourse.LiveDate.Year < 2)
        {
            txtLiveDateCourse.Text = Courses.ThisCourse.LiveDate.Day + "/0" + Courses.ThisCourse.LiveDate.Month + "/000" + Courses.ThisCourse.LiveDate.Year;
        }
        Available.Checked   = Courses.ThisCourse.Available;
        txtpriceCourse.Text = Courses.ThisCourse.Price.ToString();
    }
Exemplo n.º 5
0
        public void InstanceOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();

            //test to see that it exists
            Assert.IsNotNull(AllCourses);
        }
Exemplo n.º 6
0
        public void ReportByCategoryNoneFound()
        {
            //create an instance of the filtered data
            clsCourseCollection FilteredCourses = new clsCourseCollection();

            //apply a category that doesnt exist
            FilteredCourses.ReportByCategory("xxx xxx");
            //test to see that there are no records
            Assert.AreEqual(0, FilteredCourses.Count);
        }
Exemplo n.º 7
0
        public void ReportByCategoryMethodOK()
        {
            //create an instance of the class containing unfiltered results
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create an instance of the filtered data
            clsCourseCollection FilteredCourses = new clsCourseCollection();

            //apply a blank string (should return all records);
            FilteredCourses.ReportByCategory("");
            //test to see that the two values are the same
            Assert.AreEqual(AllCourses.Count, FilteredCourses.Count);
        }
Exemplo n.º 8
0
    protected void btnYes_Click(object sender, EventArgs e)
    {
        //create a new instance of the courses
        clsCourseCollection CourseBook = new clsCourseCollection();

        //find the record to delete
        CourseBook.ThisCourse.Find(IDno);
        //delete the record
        CourseBook.Delete();
        //redirect back to the main page
        Response.Redirect("CourseList.aspx");
    }
    protected void btnApply_Click(object sender, EventArgs e)
    {
        //create an instance of the course collection
        clsCourseCollection Courses = new clsCourseCollection();

        Courses.ReportByCategory(txtFilter.Text);
        lstCourseList.DataSource = Courses.CourseList;
        //set the name of the primary key
        lstCourseList.DataValueField = "IDno";
        //set the name of the field to display
        lstCourseList.DataTextField = "Title";
        //bind the data to the list
        lstCourseList.DataBind();
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        //create an instance of the course collection
        clsCourseCollection Courses = new clsCourseCollection();

        Courses.ReportByCategory("");
        //clear any existing filter to tidy up the interface
        txtFilter.Text           = "";
        lstCourseList.DataSource = Courses.CourseList;
        //set the name of the primary key
        lstCourseList.DataValueField = "IDno";
        //set the name of the field to display
        lstCourseList.DataTextField = "Title";
        //bind the data to the list
        lstCourseList.DataBind();
    }
Exemplo n.º 11
0
    Int32 DisplayCourses()
    {
        clsCourseCollection Courses = new clsCourseCollection();
        string CourseNo;
        string Course;
        Int32  Index = 0;

        while (Index < Courses.Count)
        {
            CourseNo = Convert.ToString(Courses.AllCourses[Index].CourseNo);
            Course   = Courses.AllCourses[Index].CourseName;
            ListItem NewCourse = new ListItem(Course, CourseNo);
            ddlStudentCourse.Items.Add(NewCourse);
            Index++;
        }
        return(Courses.Count);
    }
Exemplo n.º 12
0
        public void ThisCoursePropertyOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create some test data to assign to the property
            clsCourses TestCourses = new clsCourses();

            //set the properties of the test object
            TestCourses.Available = true;
            TestCourses.IDno      = 1;
            TestCourses.Title     = "Computing";
            TestCourses.Category  = "Technology";
            TestCourses.Tutor     = "D Lewis";
            TestCourses.LiveDate  = DateTime.Now.Date;
            TestCourses.Price     = 200;
            //assign the data to the property
            AllCourses.ThisCourse = TestCourses;
            //test to see that the two values are the same
            Assert.AreEqual(AllCourses.ThisCourse, TestCourses);
        }
Exemplo n.º 13
0
        public void UpdateMethodOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create the item of test data
            clsCourses TestItem = new clsCourses();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.Available = true;
            TestItem.IDno      = 1;
            TestItem.Title     = "Web Development";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "R Sunderland";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 180;
            //set ThisCourse to the test data
            AllCourses.ThisCourse = TestItem;
            //add the record
            PrimaryKey = AllCourses.Add();
            //set the primary key of the test data
            TestItem.IDno = PrimaryKey;
            //modify the test data
            TestItem.Available = false;
            TestItem.IDno      = 11;
            TestItem.Title     = "Front-end Web Development";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "S Sunderland";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 150;
            //set the record based on the new test data
            AllCourses.ThisCourse = TestItem;
            //update the record
            AllCourses.Update();
            //find the record
            AllCourses.ThisCourse.Find(PrimaryKey);
            //test to see ThisCourse matches the test data
            Assert.AreEqual(AllCourses.ThisCourse, TestItem);
        }
Exemplo n.º 14
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;
        }
    }