Example #1
0
    void Update()
    {
        //create an instance of the cars
        clsCarCollection CarBook = new clsCarCollection();
        //validate the data on the web form
        String Error = CarBook.ThisCar.Valid(txtCarName.Text, txtCarModel.Text, txtCarReg.Text, txtColour.Text, txtEngineSize.Text, txtPrice.Text);

        //if data is ok add to object
        if (Error == "")
        {
            CarBook.ThisCar.Find(CarID);
            //get the data entrted by user
            CarBook.ThisCar.RegPlate   = txtCarReg.Text;
            CarBook.ThisCar.CarName    = txtCarName.Text;
            CarBook.ThisCar.CarModel   = txtCarModel.Text;
            CarBook.ThisCar.CarColour  = txtColour.Text;
            CarBook.ThisCar.EngineSize = txtEngineSize.Text;
            CarBook.ThisCar.Price      = Convert.ToInt32(txtPrice.Text);
            //add the records
            CarBook.Update();
            //all done so redirect back to the main page
            Response.Redirect("CarList.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "There were problems with the enterd data" + Error;
        }
    }
        public void UpdateMethodOk()
        {
            //create an instance of the class we want to create
            clsCarCollection AllMainteance = new clsCarCollection();
            //create the item of test data
            clsMaintenance TestItem = new clsMaintenance();
            //var to store the primary key
            int PrimaryKey = 0;

            //set its properties
            TestItem.Active        = true;
            TestItem.MaintenanceID = 1;
            TestItem.Cost          = 1;
            TestItem.Date          = DateTime.Now.Date;
            TestItem.Description   = "something";
            TestItem.Repair        = true;
            //add the item
            //set ThisCar to the test data
            AllMainteance.ThisMaitenance = TestItem;
            //add record
            PrimaryKey = AllMainteance.Add();
            //set the pirmary key
            TestItem.MaintenanceID = PrimaryKey;
            //modify the test data
            TestItem.Active        = true;
            TestItem.MaintenanceID = 1;
            TestItem.Cost          = 1;
            TestItem.Date          = DateTime.Now.Date;
            TestItem.Description   = "something";
            TestItem.Repair        = true;
            //set the reocrd
            AllMainteance.ThisMaitenance = TestItem;
            //find the record
            AllMainteance.Update();
            //find the reocrd
            AllMainteance.ThisMaitenance.Find(PrimaryKey);
            //test to see thismainatenace the test data
            Assert.AreEqual(AllMainteance.ThisMaitenance, TestItem);
        }
Example #3
0
        public void UpdateMethodOk()
        {
            //create an instance of the class we want to create
            clsCarCollection AllCars = new clsCarCollection();
            //create the item of test data
            clsCar TestItem = new clsCar();
            //var to store the prim key
            Int32 PrimaryKey = 0;

            //set its proprties
            TestItem.RegPlate   = "dy20abc";
            TestItem.CarName    = "Audi";
            TestItem.CarModel   = "S5";
            TestItem.CarColour  = "Blue";
            TestItem.EngineSize = "2949cc";
            TestItem.Price      = 150;
            //set this cars to the test data
            AllCars.ThisCar = TestItem;
            //+ the record
            PrimaryKey = AllCars.Add();
            //modify the test data
            TestItem.RegPlate   = "kl98ght";
            TestItem.CarName    = "Audj";
            TestItem.CarModel   = "q5";
            TestItem.CarColour  = "Black";
            TestItem.EngineSize = "3000cc";
            TestItem.Price      = 150;
            //set the record based on the new test data
            AllCars.ThisCar = TestItem;
            //update the record
            AllCars.Update();
            //find the record
            AllCars.ThisCar.Find(PrimaryKey);
            //test to see that the 2 values are the same
            Assert.AreEqual(AllCars.ThisCar, TestItem);
        }