Esempio n. 1
0
        public void ListAndCountOk()
        {
            //create an instance of the class we wish to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create some test data to assign to the property
            //in this case the data needs to be a list of objects
            List <clsPhone> TestList = new List <clsPhone>();
            //add an item to the list
            //create the item test data
            clsPhone TestItem = new clsPhone();

            //set its properties
            TestItem.PhoneId       = 1;
            TestItem.Make          = "Apple";
            TestItem.Model         = "Iphone X";
            TestItem.PhoneNo       = "07749493975";
            TestItem.Price         = "500";
            TestItem.ScreenSize    = "7";
            TestItem.CameraQuality = "HD";
            //add the item to the list
            TestList.Add(TestItem);
            //assign the data to the property
            AllPhones.PhoneList = TestList;
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.Count, TestList.Count);
        }
Esempio n. 2
0
        public void AddMethodOK()
        //Add Method
        {
            //create an instance of the class we want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create the item of test data
            clsPhone TestItem = new clsPhone();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.Active      = true;
            TestItem.PhoneID     = 1;
            TestItem.Capacity    = 128;
            TestItem.Price       = 100;
            TestItem.Colour      = "red";
            TestItem.DateAdded   = DateTime.Now.Date;
            TestItem.Description = "This is the latest phone.";
            TestItem.Make        = "Apple";
            TestItem.Model       = "C3500";
            TestItem.StockStatus = true;
            //set ThisPhone to the test data
            AllPhones.ThisPhone = TestItem;
            //add the record
            PrimaryKey = AllPhones.Add();
            //set the primary key of the test data
            TestItem.PhoneID = PrimaryKey;
            //find the record
            AllPhones.ThisPhone.Find(PrimaryKey);
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.ThisPhone, TestItem);
        }
Esempio n. 3
0
        public void ReportByMakeTestDataFound()
        //Report By Make Test Data Found Method
        {
            //create an instance of the filtered data
            clsPhoneCollection FilteredPhones = new clsPhoneCollection();
            //var to store outcome
            Boolean OK = true;

            //apply a make that does exist
            FilteredPhones.ReportByMake("Nokia");
            //check that the correct number of records are found
            if (FilteredPhones.Count == 2)
            {
                //check that the first record id ID 36
                if (FilteredPhones.PhoneList[0].PhoneID != 7)
                {
                    OK = false;
                }

                //check that the first record is ID 37
                if (FilteredPhones.PhoneList[1].PhoneID != 8)
                {
                    OK = false;
                }
            }

            else
            {
                OK = false;
            }


            //test to see that the two values are the same
            Assert.IsTrue(OK);
        }
Esempio n. 4
0
        void Add()
        {
            //create an instance of the Phone book
            clsPhoneCollection PhoneBook = new clsPhoneCollection();
            //validate the data on the web form
            String Error = PhoneBook.ThisPhone.Valid(txtMake.Text, txtModel.Text, txtPhoneNo.Text, txtPrice.Text, txtScreenSize.Text, txtCameraQuality.Text);

            //if the data is okay then add it to the object
            if (Error == "")
            {
                //get the data entered by the user
                PhoneBook.ThisPhone.Make          = txtMake.Text;
                PhoneBook.ThisPhone.Model         = txtModel.Text;
                PhoneBook.ThisPhone.PhoneNo       = txtPhoneNo.Text;
                PhoneBook.ThisPhone.Price         = txtPrice.Text;
                PhoneBook.ThisPhone.ScreenSize    = txtScreenSize.Text;
                PhoneBook.ThisPhone.CameraQuality = txtCameraQuality.Text;
                //add the record
                PhoneBook.Add();
                //all done so redirect to default
                Response.Redirect("Default.aspx");
            }
            else
            {
                //report an error
                lblError.Text = "There were problems with the data entered " + Error;
            }
        }
Esempio n. 5
0
        public void DeleteMethodOk()
        {
            //create an instance of the class we want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create the item of test data
            clsPhone TestItem = new clsPhone();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.PhoneId       = 1;
            TestItem.Make          = "Apple";
            TestItem.Model         = "Iphone X";
            TestItem.PhoneNo       = "07749493975";
            TestItem.Price         = "500";
            TestItem.ScreenSize    = "7";
            TestItem.CameraQuality = "HD";
            //set ThisPhone to the test data
            AllPhones.ThisPhone = TestItem;
            //add the record
            PrimaryKey = AllPhones.Add();
            //set the primary key of the test data
            TestItem.PhoneId = PrimaryKey;
            //find the record
            AllPhones.ThisPhone.Find(PrimaryKey);
            //delete the record
            AllPhones.Delete();
            //now find the record
            Boolean Found = AllPhones.ThisPhone.Find(PrimaryKey);

            //test to see that the record was not found
            Assert.IsFalse(Found);
        }
Esempio n. 6
0
    Int32 DisplayPhone(string MakeFilter)
    {
        Int32              PhoneID;                               //Var to store the primary key
        String             Make;                                  //Var to store the Make
        String             Model;                                 //Var to store the Model
        clsPhoneCollection MakeSearch = new clsPhoneCollection(); //Create an instance of the phone book class

        MakeSearch.ReportByMake(MakeFilter);                      //invoke the phone make filter
        Int32 RecordCount;                                        //Var to store the count of records
        Int32 Index = 0;                                          //Var to store the index for the loop

        RecordCount = MakeSearch.Count;                           //get the count of records
        lstPhones.Items.Clear();                                  //clear the list box
        while (Index < RecordCount)                               //While there are records to process
        {
            PhoneID = MakeSearch.PhoneList[Index].PhoneID;        //get primary key
            Make    = MakeSearch.PhoneList[Index].Make;           //get Make
            Model   = MakeSearch.PhoneList[Index].Model;          //get Model
            //create a new entry for the list box
            ListItem NewEntry = new ListItem(Make + " " + Model, PhoneID.ToString());
            lstPhones.Items.Add(NewEntry);
            Index++;
        }
        return(RecordCount); //return the count of records found
    }
Esempio n. 7
0
        public void AddMethodOk()
        {
            //create an instance of the class we want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create the item of test data
            clsPhone TestItem = new clsPhone();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.PhoneId       = 1;
            TestItem.Make          = "Apple";
            TestItem.Model         = "Iphone X";
            TestItem.PhoneNo       = "07749493975";
            TestItem.Price         = "500";
            TestItem.ScreenSize    = "7";
            TestItem.CameraQuality = "HD";
            //set ThisPhone to the test data
            AllPhones.ThisPhone = TestItem;
            //add the record
            PrimaryKey = AllPhones.Add();
            //set the primary key of the test data
            TestItem.PhoneId = PrimaryKey;
            //find the record
            AllPhones.ThisPhone.Find(PrimaryKey);
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.ThisPhone, TestItem);
        }
Esempio n. 8
0
    Int32 DisplayBrands(string BrandFilter)
    {
        Int32  PhoneNo;   //var to store the primary key
        string PhoneName; //var to store the PhoneName
        string Brand;     // var to store the Brand

        ;                 //create an instance of the phone book class
        clsPhoneCollection PhoneBook = new clsPhoneCollection();

        PhoneBook.FilterByBrand(BrandFilter);                 //filter by brand
        Int32 RecordCount;                                    //var store the count of records
        Int32 Index = 0;                                      //var to store the index for the loop

        RecordCount = PhoneBook.Count;                        //get the count of records
        lstPhones.Items.Clear();                              //clear the list box
        while (Index < RecordCount)                           //while there are records to process
        {
            PhoneNo   = PhoneBook.PhoneList[Index].PhoneNo;   //get the primary key
            PhoneName = PhoneBook.PhoneList[Index].PhoneName; //get the phonename
            Brand     = PhoneBook.PhoneList[Index].Brand;     //get the brand
            //create a new entry for the list box
            ListItem NewEntry = new ListItem(Brand + " " + PhoneName, PhoneNo.ToString());
            lstPhones.Items.Add(NewEntry); // add the phone to the list
            Index++;                       // move the index to the next record
        }
        return(RecordCount);
    }
Esempio n. 9
0
        public void PhoneListOK()
        {
            //create an instance of the class we want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create some test data to assign to the property
            //in this case the data needs to be a list of objects
            List <clsPhone> TestList = new List <clsPhone>();
            //add an item to the list
            //create the item of test data
            clsPhone TestItem = new clsPhone();

            //set its properties
            TestItem.Active      = true;
            TestItem.PhoneID     = 1;
            TestItem.Capacity    = 128;
            TestItem.Price       = 100;
            TestItem.Colour      = "red";
            TestItem.DateAdded   = DateTime.Now.Date;
            TestItem.Description = "This is the latest phone.";
            TestItem.Make        = "Apple";
            TestItem.Model       = "C3500";
            TestItem.StockStatus = true;
            //add the item to the test list
            TestList.Add(TestItem);
            //assign the data to the property
            AllPhones.PhoneList = TestList;
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.PhoneList, TestList);
        }
Esempio n. 10
0
        public void InstanceOK()
        {
            //create an instance of the class we want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();

            //test to see that it exists
            Assert.IsNotNull(AllPhones);
        }
Esempio n. 11
0
        public void TestMethod1()
        {
            //create an instance of the class you want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();

            //test to see if it exists
            Assert.IsNotNull(AllPhones);
        }
Esempio n. 12
0
        void DeleteSelectedPhone()
        {
            //create an instance of the phone book
            clsPhoneCollection PhoneBook = new clsPhoneCollection();

            //find the record to delete
            PhoneBook.ThisPhone.Find(PhoneId);
            //delete the record
            PhoneBook.Delete();
        }
Esempio n. 13
0
        public void ReportByMakeNoneFound()
        //Report By Make None Found Method
        {
            //create an instance of the filtered data
            clsPhoneCollection FilteredPhones = new clsPhoneCollection();

            //apply a blank string (Should return all phones)
            FilteredPhones.ReportByMake(" xxxx");
            //test to see that the two values are the same
            Assert.AreEqual(0, FilteredPhones.Count);
        }
Esempio n. 14
0
        public void CountPropertyOk()
        {
            //create an instance of the class we want ot create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create some test data to assign to the property
            Int32 SomeCount = 0;

            //assign the data to the property
            AllPhones.Count = SomeCount;
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.Count, SomeCount);
        }
Esempio n. 15
0
        public void ReportByMakeMethodOK()
        //Report By Make Method
        {
            //create an instance of the class containing unfiltered results
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create an instance of the filtered data
            clsPhoneCollection FilteredPhones = new clsPhoneCollection();

            //apply a blank string (Should return all phones)
            FilteredPhones.ReportByMake("");
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.Count, FilteredPhones.Count);
        }
Esempio n. 16
0
    //function for updating new records
    void DisplayPhones()
    {
        //create an instance of the phone book
        clsPhoneCollection PhoneBook = new clsPhoneCollection();

        //find the record to update
        PhoneBook.ThisPhone.Find(PhoneID);
        //display the data for this record
        txtCapacity.Text       = PhoneBook.ThisPhone.Capacity.ToString();
        txtPrice.Text          = PhoneBook.ThisPhone.Price.ToString();
        txtColour.Text         = PhoneBook.ThisPhone.Colour;
        txtDateAdded.Text      = PhoneBook.ThisPhone.DateAdded.ToString();
        txtDescription.Text    = PhoneBook.ThisPhone.Description;
        txtMake.Text           = PhoneBook.ThisPhone.Make;
        txtModel.Text          = PhoneBook.ThisPhone.Model;
        chkStockStatus.Checked = PhoneBook.ThisPhone.StockStatus;
        chkActive.Checked      = PhoneBook.ThisPhone.Active;
    }
Esempio n. 17
0
    protected void btnYes_Click(object sender, EventArgs e)
    {
        //this function handles the click even of the yes button

        //create an instance of the class clsPhoneCollection called This phone
        clsPhoneCollection MyPhoneBook = new clsPhoneCollection();
        //declare a boolean variable for Found
        Boolean Found;

        //try and find the record to delete
        Found = MyPhoneBook.ThisPhone.Find(PhoneNo);
        //if the record is found
        if (Found)
        {
            //invoke the delete method
            MyPhoneBook.Delete();
        }
        Response.Redirect("Default.aspx");
    }
Esempio n. 18
0
        public void ThisPhonePropertyOk()
        {
            //create an instance of the class we want ot create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create some test data to assign to the property
            clsPhone TestPhone = new clsPhone();

            //set the properties to the test object
            TestPhone.PhoneId       = 1;
            TestPhone.Make          = "Apple";
            TestPhone.Model         = "IPhone X";
            TestPhone.PhoneNo       = "07749493975";
            TestPhone.Price         = "500";
            TestPhone.ScreenSize    = "7.2";
            TestPhone.CameraQuality = "FHD";
            //assign the data to the property
            AllPhones.ThisPhone = TestPhone;
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.ThisPhone, TestPhone);
        }
Esempio n. 19
0
        public void ThisPhonePropertyOK()
        {
            //create an instance of the class we want to create
            clsPhoneCollection AllPhones = new clsPhoneCollection();
            //create some test data to assign to the property
            clsPhone TestPhone = new clsPhone();

            //set the properties of the test object
            TestPhone.Active      = true;
            TestPhone.PhoneID     = 1;
            TestPhone.Capacity    = 128;
            TestPhone.Price       = 100;
            TestPhone.Colour      = "red";
            TestPhone.DateAdded   = DateTime.Now.Date;
            TestPhone.Description = "This is the latest phone.";
            TestPhone.Make        = "Apple";
            TestPhone.Model       = "C3500";
            TestPhone.StockStatus = true;
            //assign the data to the property
            AllPhones.ThisPhone = TestPhone;
            //test to see that the two values are the same
            Assert.AreEqual(AllPhones.ThisPhone, TestPhone);
        }
Esempio n. 20
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        //create an instance of the phone page class
        clsPhone ThisPhone = new clsPhone();
        //var to store any error messages
        string ErrorMessage;

        //test the data on the web form
        ErrorMessage = ThisPhone.PhoneValid(
            txtPhoneName.Text,
            txtBrand.Text,
            txtScreenSize.Text,
            txtOperatingSystem.Text,
            txtBackCamera.Text,
            txtBatterySize.Text,
            txtReleaseDate.Text);
        if (ErrorMessage == "")

        {
            //create a new instance of the phone collection class
            clsPhoneCollection PhoneCollection = new clsPhoneCollection();
            //do something with the data - insert or update
            //
            //if the Phone Number is -1
            if (PhoneNo == -1)
            {
                //copy the data from the interface to the object
                ThisPhone.PhoneName       = txtPhoneName.Text;
                ThisPhone.Brand           = txtBrand.Text;
                ThisPhone.ScreenSize      = txtScreenSize.Text;
                ThisPhone.OperatingSystem = txtOperatingSystem.Text;
                ThisPhone.BackCamera      = txtBackCamera.Text;
                ThisPhone.BatterySize     = txtBatterySize.Text;
                ThisPhone.CompanyNo       = Convert.ToInt32(ddlCompany.SelectedValue);
                ThisPhone.ReleaseDate     = Convert.ToDateTime(txtReleaseDate.Text);
                //add the new record
                PhoneCollection.Add();
            }
            else
            {
                //this is an existing record
                //copy the data from the interface to the object
                ThisPhone.PhoneNo         = Convert.ToInt32(PhoneNo);
                ThisPhone.PhoneName       = txtPhoneName.Text;
                ThisPhone.Brand           = txtBrand.Text;
                ThisPhone.ScreenSize      = txtScreenSize.Text;
                ThisPhone.OperatingSystem = txtOperatingSystem.Text;
                ThisPhone.BackCamera      = txtBackCamera.Text;
                ThisPhone.BatterySize     = txtBatterySize.Text;
                ThisPhone.CompanyNo       = Convert.ToInt32(ddlCompany.SelectedValue);
                ThisPhone.ReleaseDate     = Convert.ToDateTime(txtReleaseDate.Text);
                //update the exisiting record
                PhoneCollection.Update();
            }
            //redirect back to the main page
            Response.Redirect("Default.aspx");
        }
        else
        {
            //display the error message
            lblError.Text = ErrorMessage;
        }
    }