예제 #1
0
        public void DeleteMethodOK()
        {
            //create an instance of the calss we want to create
            ClsCarCollection AllCars = new ClsCarCollection();
            //create the item of test data
            ClsCar TestItem   = new ClsCar();
            int    PrimaryKey = 0;

            //set its propertiers
            TestItem.NumberPlate = "1234 ABCD";
            TestItem.Make        = "Nissan";
            TestItem.Model       = "Micra";
            TestItem.Colour      = "Blue";
            TestItem.Description = "4 wheeler";
            TestItem.Sold        = true;
            TestItem.Price       = 100.00;
            TestItem.OfficeCode  = 1;
            //set ThisAddress to the test data
            AllCars.ThisCar = TestItem;
            //add the record
            PrimaryKey = AllCars.Add();
            //set the primary key of the test data
            TestItem.CarID = PrimaryKey;
            //find the record
            AllCars.ThisCar.Find(PrimaryKey);
            //delete the record
            AllCars.Delete();
            //now find the record
            Boolean Found = AllCars.ThisCar.Find(PrimaryKey);

            //test to see that the record was not found
            Assert.IsFalse(Found);
        }
예제 #2
0
        public void ListAndCountOK()

        {
            ClsCarCollection AllCars = new ClsCarCollection();
            //create some test data to asign to the property
            //in this cas the data needs to be a list of objects
            List <ClsCar> TestList = new List <ClsCar>();
            //add an item to the list
            //create the item of test data
            ClsCar TestItem = new ClsCar();

            //set its properties
            TestItem.CarID       = 0;
            TestItem.NumberPlate = "1234 ABCD";
            TestItem.Make        = "Nissan";
            TestItem.Model       = "Micra";
            TestItem.Colour      = "Blue";
            TestItem.Description = "4 wheeler";
            TestItem.Sold        = true;
            TestItem.Price       = 100.00;
            TestItem.OfficeCode  = 1;
            //add the item to the list
            TestList.Add(TestItem);
            //assign the data to the property
            AllCars.CarList = TestList;
            //test to see that the two values are the same
            Assert.AreEqual(AllCars.Count, TestList.Count);
        }
예제 #3
0
        public void ReportByMakeTestDataFound()
        {
            //create an instacne of the filterd data
            ClsCarCollection FilteredCars = new ClsCarCollection();
            //var to store the outcome
            Boolean OK = true;

            //apply a make that doesn't exist
            FilteredCars.ReportByMake("XXXX");
            //check that the correct number of records are found
            if (FilteredCars.Count == 2)
            {
                //check if the first record is carid 6
                if (FilteredCars.CarList[0].CarID != 6)
                {
                    OK = false;
                }
                //check thet the first record is ID 8
                if (FilteredCars.CarList[1].CarID != 8)
                {
                    OK = false;
                }
            }
            else
            {
                OK = false;
            }
            //test to see that there are no records
            Assert.IsTrue(OK);
        }
예제 #4
0
        public void ReportByMakeNoneFound()
        {
            //create an instacne of the filtered data
            ClsCarCollection FilteredCars = new ClsCarCollection();

            //apply a make that does not exsist
            FilteredCars.ReportByMake("XXXXXX");
            //test to see that there are no records
            Assert.AreEqual(0, FilteredCars.Count);
        }
예제 #5
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        ClsCar ACar        = new ClsCar();
        String NumberPlate = txtNumberPlate.Text;
        String Make        = txtMake.Text;
        String Model       = txtModel.Text;
        String Colour      = txtColour.Text;
        String Description = txtDescription.Text;
        String Price       = txtPrice.Text;
        String OfficeCode  = txtOfficeCode.Text;

        String Error = "";

        Error = ACar.Valid(NumberPlate, Make, Model, Description, Colour, Price);
        if (Error == "")
        {
            ACar.NumberPlate = NumberPlate;
            ACar.Make        = Make;
            ACar.Model       = Model;
            ACar.Colour      = Colour;
            ACar.Description = Description;
            ACar.Price       = Convert.ToInt32(Price);
            ACar.OfficeCode  = Convert.ToInt32(OfficeCode);

            ClsCarCollection CarList = new ClsCarCollection();

            //if this is a new record i.e. NumberPlate != -1 then add the data
            if (CarID == -1)
            {
                //set the ThisCar Property
                CarList.ThisCar = ACar;
                //add the new record
                CarList.Add();
            }
            //otherwise it must be an update
            else
            {
                //find the record to update
                CarList.ThisCar.Find(CarID);
                //set the ThisCar property
                CarList.ThisCar = ACar;
                //update the record
                CarList.Update();
            }
            //redirect back to thte list page
            Response.Redirect("CarList.aspx");
        }
        else
        {
            //display the error message
            lblError.Text = Error;
        }
    }
예제 #6
0
        public void ReportByMakeMethodOK()
        {
            //creat an instance of the class containing the unfiltered results
            ClsCarCollection AllCars = new ClsCarCollection();
            //create an instacne of the filtered data
            ClsCarCollection FilteredCars = new ClsCarCollection();

            //apply a blank string (should return all the records)
            FilteredCars.ReportByMake("");
            //test to see that the 2 values are the same
            Assert.AreEqual(AllCars.Count, FilteredCars.Count);
        }
예제 #7
0
    protected void BtnYes_Click(object sender, EventArgs e)
    {
        //create an instance of the car collection
        ClsCarCollection AllCars = new ClsCarCollection();

        //find the record to delete
        AllCars.ThisCar.Find(CarID);
        //delete the record
        AllCars.Delete();
        //redirect back to main page
        Response.Redirect("CarList.aspx");
    }
예제 #8
0
    protected void btnApply_Click(object sender, EventArgs e)
    {
        //create an instacne of the car collection
        ClsCarCollection AllCars = new ClsCarCollection();

        AllCars.ReportByMake(txtFilter.Text);
        lstCarList.DataSource = AllCars.CarList;
        //set the name of th epriamry key
        lstCarList.DataValueField = "CarID";
        //set the name of the field to display
        lstCarList.DataTextField = "Make";
        //bind the data to the list
        lstCarList.DataBind();
    }
예제 #9
0
    protected void btnClear_Click(object sender, EventArgs e)
    {
        //create an instanc eof the car collection
        ClsCarCollection AllCars = new ClsCarCollection();

        AllCars.ReportByMake("");
        //clear an y exsitin gfilter to tidy up the interface
        txtFilter.Text        = "";
        lstCarList.DataSource = AllCars.CarList;
        //set the name of th epriamry key
        lstCarList.DataValueField = "CarID";
        //set the name of the field to display
        lstCarList.DataTextField = "Make";
        //bind the data to the list
        lstCarList.DataBind();
    }
예제 #10
0
    void DisplayCar()
    {
        //create an instanc of the collection
        ClsCarCollection AllCars = new ClsCarCollection();

        //find the record to update
        AllCars.ThisCar.Find(CarID);
        //display the data for this record
        txtCarID.Text       = AllCars.ThisCar.CarID.ToString();
        txtNumberPlate.Text = AllCars.ThisCar.NumberPlate;
        txtMake.Text        = AllCars.ThisCar.Make;
        txtModel.Text       = AllCars.ThisCar.Model;
        txtColour.Text      = AllCars.ThisCar.Colour;
        txtDescription.Text = AllCars.ThisCar.Description;
        txtPrice.Text       = AllCars.ThisCar.Price.ToString();
        txtOfficeCode.Text  = AllCars.ThisCar.OfficeCode.ToString();
    }
예제 #11
0
        public void ThisCarPropertyOK()
        {
            ClsCarCollection AllCars = new ClsCarCollection();
            //create some test data to assign to the property
            ClsCar TestCar = new ClsCar();

            //set its properties
            TestCar.CarID       = 0;
            TestCar.NumberPlate = "1234 ABCD";
            TestCar.Make        = "Nissan";
            TestCar.Model       = "Micra";
            TestCar.Colour      = "Blue";
            TestCar.Description = "4 wheeler";
            TestCar.Sold        = true;
            TestCar.Price       = 100.00;
            TestCar.OfficeCode  = 1;
            //assign the data to the property
            AllCars.ThisCar = TestCar;
            Assert.AreEqual(AllCars.ThisCar, TestCar);
        }
예제 #12
0
        public void UpdateMethodOK()
        {
            //create an instance of the calss we want to create
            ClsCarCollection AllCars = new ClsCarCollection();
            //create the item of test data
            ClsCar TestItem   = new ClsCar();
            int    PrimaryKey = 0;

            //set its propertiers
            TestItem.NumberPlate = "1234 ABCD";
            TestItem.Make        = "Nissan";
            TestItem.Model       = "Micra";
            TestItem.Colour      = "Blue";
            TestItem.Description = "4 wheeler";
            TestItem.Sold        = true;
            TestItem.Price       = 100.00;
            TestItem.OfficeCode  = 1;
            //set ThisAddress to the test data
            AllCars.ThisCar = TestItem;
            //add the record
            PrimaryKey = AllCars.Add();
            //set the primary key of the test data
            TestItem.CarID = PrimaryKey;
            //modify the test data
            TestItem.NumberPlate = "4567 HGTY";
            TestItem.Make        = "BMW";
            TestItem.Model       = "A5";
            TestItem.Colour      = "Green";
            TestItem.Description = "2 wheeler";
            TestItem.Sold        = false;
            TestItem.Price       = 200.00;
            TestItem.OfficeCode  = 2;
            //set the record based on the new data
            AllCars.ThisCar = TestItem;
            //update the record
            AllCars.Update();
            //find the record
            AllCars.ThisCar.Find(PrimaryKey);
            //test to see ThisCar matches the test data
            Assert.AreEqual(AllCars.ThisCar, TestItem);
        }
예제 #13
0
        public void InstanceOK()
        {
            ClsCarCollection AllCars = new ClsCarCollection();

            Assert.IsNotNull(AllCars);
        }