Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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;
        }
    }
Esempio n. 4
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);
            //
        }