Exemplo n.º 1
0
        public void ListAndCountOK()
        {
            //create an instance of the class we want to create
            clsTrainerCollection AllTrainers = new clsTrainerCollection();
            //create some test data to assign to the property
            //in this case the data needs to be a list of objects
            List <clsTrainer> TestList = new List <clsTrainer>();
            //add an item to the list
            //create the item of test data
            clsTrainer TestItem = new clsTrainer();

            //set its properites
            TestItem.FullName     = "Ross O'Donegan";
            TestItem.Gender       = "Male";
            TestItem.EmailAddress = "*****@*****.**";
            TestItem.DateOfBirth  = DateTime.Parse("20/05/1999");
            TestItem.TrainerID    = 20;
            TestItem.Retrained    = false;
            //add the item to the test list
            TestList.Add(TestItem);
            //asign the data to the property
            AllTrainers.TrainerList = TestList;
            //test to see that the wo values are the same
            Assert.AreEqual(AllTrainers.Count, TestList.Count);
        }
Exemplo n.º 2
0
        public void AddMethodOK()
        {
            //create an instance of the class we want to create
            clsTrainerCollection AllTrainers = new clsTrainerCollection();
            //create the item of test data
            clsTrainer TestItem = new clsTrainer();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.TrainerID    = 44;
            TestItem.FullName     = "Ross O'Donegan";
            TestItem.EmailAddress = "*****@*****.**";
            TestItem.Gender       = "Male";
            TestItem.Retrained    = true;
            TestItem.DateOfBirth  = DateTime.Parse("17/05/2000");
            //set ThisAddress to the test data
            AllTrainers.ThisTrainer = TestItem;
            //add the record
            PrimaryKey = AllTrainers.Add();
            //set the primary key to the test data
            TestItem.TrainerID = PrimaryKey;
            //find the record
            AllTrainers.ThisTrainer.Find(PrimaryKey);
            //test to see that the two values are the same
            Assert.AreEqual(AllTrainers.ThisTrainer, TestItem);
        }
Exemplo n.º 3
0
        public void ReportByGenderFound()
        {
            //create an instance of the filtered data
            clsTrainerCollection FilteredTrainers = new clsTrainerCollection();
            //var to store the outcome
            Boolean OK = true;

            //apply a gender that doesn't exist (but is in the database)
            FilteredTrainers.ReportByGender("TEST");
            //check that the correct number of records are found
            if (FilteredTrainers.Count == 2)
            {
                //check that the first record ID is 58
                if (FilteredTrainers.TrainerList[0].TrainerID != 58)
                {
                    OK = false;
                }
                //check that the second record ID is 59
                if (FilteredTrainers.TrainerList[1].TrainerID != 59)
                {
                    OK = false;
                }
            }
            else
            {
                OK = false;
            }
            //test to to see the correct amount of records were shown
            Assert.IsTrue(OK);
        }
Exemplo n.º 4
0
        public void DeleteMethodOK()
        {
            //create an instance of the class we want to create
            clsTrainerCollection AllTrainers = new clsTrainerCollection();
            //create an item of test data
            clsTrainer TestItem = new clsTrainer();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.TrainerID    = 44;
            TestItem.FullName     = "Ross O'Donegan";
            TestItem.EmailAddress = "*****@*****.**";
            TestItem.Gender       = "Male";
            TestItem.Retrained    = true;
            TestItem.DateOfBirth  = DateTime.Parse("17/05/2000");
            //set ThisTrainer to the test data
            AllTrainers.ThisTrainer = TestItem;
            //add the record
            PrimaryKey = AllTrainers.Add();
            //set the primary key of the test data
            TestItem.TrainerID = PrimaryKey;
            //find the record
            AllTrainers.ThisTrainer.Find(PrimaryKey);
            //delete the record
            AllTrainers.Delete();
            //now find the record
            Boolean Found = AllTrainers.ThisTrainer.Find(PrimaryKey);

            //test to see that the record was not found
            Assert.IsFalse(Found);
        }
Exemplo n.º 5
0
        public void InstanceOK()
        {
            //create an instance of the class we want to create
            clsTrainerCollection AllTrainers = new clsTrainerCollection();

            //test to see that it exists
            Assert.IsNotNull(AllTrainers);
        }
Exemplo n.º 6
0
        public void ReportByGenderNoneFound()
        {
            //create an instance of the filtered data
            clsTrainerCollection FilteredTrainers = new clsTrainerCollection();

            //apply a gender that doesnt exist
            FilteredTrainers.ReportByGender("Hello");
            //test to see that that there are no records
            Assert.AreEqual(0, FilteredTrainers.Count);
        }
Exemplo n.º 7
0
        public void ReportByGenderMethodOK()
        {
            //create an instance of the class containing unflitered results
            clsTrainerCollection AllTrainers = new clsTrainerCollection();
            //create  an instance of the filtered data
            clsTrainerCollection FilteredTrainers = new clsTrainerCollection();

            //apply a blank string (should return all records)
            FilteredTrainers.ReportByGender("");
            Assert.AreEqual(AllTrainers.Count, FilteredTrainers.Count);
        }
Exemplo n.º 8
0
    protected void btnView_Click(object sender, EventArgs e)
    {
        //create a new instance of clsTrainer
        clsTrainer ATrainer = new clsTrainer();

        //capture all data for validation
        string fullName    = txtFullname.Text;
        string gender      = txtGender.Text;
        string dateOfBirth = txtDateOfBirth.Text;
        string email       = txtEmail.Text;
        //variable to store error messages
        string Error = "";

        Error = ATrainer.Valid(fullName, gender, dateOfBirth, email);
        if (Error == "")
        {
            //capture all the data
            ATrainer.EmailAddress = email;
            ATrainer.TrainerID    = TrainerID;
            ATrainer.FullName     = fullName;
            ATrainer.DateOfBirth  = Convert.ToDateTime(dateOfBirth);
            ATrainer.Gender       = gender;
            ATrainer.Retrained    = chkRetrained.Checked;

            //create a new instance of the trainer collection
            clsTrainerCollection AllTrainers = new clsTrainerCollection();

            //if this is a new record i.e. Trainer ID = -1 then add the data
            if (TrainerID == -1)
            {
                //set the ThisTrainer property
                AllTrainers.ThisTrainer = ATrainer;
                //add the new record
                AllTrainers.Add();
            }
            else //otherwise it must be an update
            {
                //find the record to update
                AllTrainers.ThisTrainer.Find(TrainerID);
                //set the ThisTrainer property
                AllTrainers.ThisTrainer = ATrainer;
                //update the record
                AllTrainers.Update();
            }

            //redirect back to the listpage
            Response.Redirect("DefaultTrainer.aspx");
        }
        else
        {
            lblError.Text = Error;
        }
    }
    protected void btnYes_Click(object sender, EventArgs e)
    {
        //create a new instance of the Trainer collection
        clsTrainerCollection AllTrainers = new clsTrainerCollection();

        //find the record to delete
        AllTrainers.ThisTrainer.Find(TrainerID);
        //delete the record
        AllTrainers.Delete();
        //redirect back to the main page
        Response.Redirect("DefaultTrainer.aspx");
    }
    protected void btnApply_Click(object sender, EventArgs e)
    {
        //create an instance of the trainer collection
        clsTrainerCollection Trainers = new clsTrainerCollection();

        Trainers.ReportByGender(txtFilter.Text);
        lstTrainerList.DataSource = Trainers.TrainerList;
        //set the name of the primary key
        lstTrainerList.DataValueField = "TrainerID";
        //set the name of the field to display
        lstTrainerList.DataTextField = "FullName";
        //bind the data to the list
        lstTrainerList.DataBind();
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        //create an instance of the trainer collection
        clsTrainerCollection Trainers = new clsTrainerCollection();

        Trainers.ReportByGender("");
        //clear any existing filter to tidy up the interface
        lstTrainerList.DataSource     = Trainers.TrainerList;
        txtFilter.Text                = "";
        lstTrainerList.DataValueField = "TrainerID";
        //set the name of the field to display
        lstTrainerList.DataTextField = "FullName";
        //bind the data to the list
        lstTrainerList.DataBind();
    }
Exemplo n.º 12
0
    void DisplayTrainer()
    {
        //create an instance of the trainer collection
        clsTrainerCollection Trainers = new clsTrainerCollection();

        //find the record to update
        Trainers.ThisTrainer.Find(TrainerID);
        //dispaly the data for this record
        txtTrainerID.Text    = Trainers.ThisTrainer.TrainerID.ToString();
        txtFullname.Text     = Trainers.ThisTrainer.FullName;
        txtEmail.Text        = Trainers.ThisTrainer.EmailAddress;
        txtGender.Text       = Trainers.ThisTrainer.Gender;
        txtDateOfBirth.Text  = Trainers.ThisTrainer.DateOfBirth.ToString();
        chkRetrained.Checked = Trainers.ThisTrainer.Retrained;
    }
Exemplo n.º 13
0
        public void ThisTrainerPropertyOK()
        {
            //create an instance of the class we want to create
            clsTrainerCollection TestList = new clsTrainerCollection();
            //create some test data to assign to the property
            clsTrainer TestItem = new clsTrainer();

            //set the properties of the test object
            TestItem.FullName     = "Ross O'Donegan";
            TestItem.Gender       = "Male";
            TestItem.EmailAddress = "*****@*****.**";
            TestItem.DateOfBirth  = DateTime.Parse("20/05/1999");
            TestItem.TrainerID    = 20;
            TestItem.Retrained    = false;
            //asign the data to the property
            TestList.ThisTrainer = TestItem;
            //test to see that the two values are the same
            Assert.AreEqual(TestList.ThisTrainer, TestItem);
        }
Exemplo n.º 14
0
        public void UpdateMethodOK()
        {
            //create an instance of the class we want to create
            clsTrainerCollection AllTrainers = new clsTrainerCollection();
            //create an item of test data
            clsTrainer TestItem = new clsTrainer();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.FullName     = "Ross O'DoneganUPDATE";
            TestItem.EmailAddress = "*****@*****.**";
            TestItem.Gender       = "Male";
            TestItem.Retrained    = true;
            TestItem.DateOfBirth  = DateTime.Parse("17/05/2000");
            //set ThisTrainer to the test data
            AllTrainers.ThisTrainer = TestItem;
            //set the primary key of the test data
            PrimaryKey = AllTrainers.Add();
            //set the primary key of the test data
            TestItem.TrainerID = PrimaryKey;
            //modify the test data
            TestItem.FullName     = "2Ross O'DoneganUPDATE";
            TestItem.EmailAddress = "*****@*****.**";
            TestItem.Gender       = "Female";
            TestItem.Retrained    = true;
            TestItem.DateOfBirth  = DateTime.Parse("27/05/2000");
            //set the record based on the new test data
            AllTrainers.ThisTrainer = TestItem;
            //update the record
            AllTrainers.Update();
            //fimd the record
            AllTrainers.ThisTrainer.Find(PrimaryKey);
            //test to see ThisTrainer matches the test data
            Assert.AreEqual(AllTrainers.ThisTrainer, TestItem);
            //
        }
    //this function handles the load event for the page
    protected void Page_Load(object sender, EventArgs e)
    {
        //if this is the first time the page is displayed
        if (IsPostBack == false)
        {
            //update the list box
            DisplayTrainers();
        }

        void DisplayTrainers()
        {
            //create an instance of the trainer collection
            clsTrainerCollection AllTrainers = new clsTrainerCollection();

            //set the data source of the list of trainers in the collection
            lstTrainerList.DataSource = AllTrainers.TrainerList;
            //set the name of the primary key
            lstTrainerList.DataValueField = "TrainerID";
            //set the data to display
            lstTrainerList.DataTextField = "FullName";
            //bind the data to the list
            lstTrainerList.DataBind();
        }
    }