コード例 #1
0
        public void testAddCustomer()
        {
            //create new customer collection
            clsCustomerCollection customerList = new clsCustomerCollection();

            //clear collection
            customerList.clear();
            //add 2 test customers
            clsCustomer tstCustomer1 = new clsCustomer();

            tstCustomer1.cusName = "Tester1";
            clsCustomer tstCustomer2 = new clsCustomer();

            tstCustomer2.cusName = "Tester2";
            //create new test list
            List <clsCustomer> tstList = new List <clsCustomer>();

            //add 2 test customers to test list and customerList
            tstList.Add(tstCustomer1);
            tstList.Add(tstCustomer2);
            customerList.add(tstCustomer1);
            customerList.add(tstCustomer2);
            //compare
            Assert.AreEqual(customerList.customerAtIndex(1), tstList[1]);
        }
コード例 #2
0
        public void customerCollectionCount()
        {
            //create new instance of class
            clsCustomerCollection allCustomers = new clsCustomerCollection();

            //clear class (because it is generated with the SQL db entries
            //in constructor as shown in Lab 23
            allCustomers.clear();
            //make new test customer without properties (it doesn't need them to show count works)
            clsCustomer tstCustomer1 = new clsCustomer();

            //add tst customer
            allCustomers.add(tstCustomer1);
            //compare contents of collection list count to actual count (1)
            Assert.AreEqual(allCustomers.Count, 1);
        }
コード例 #3
0
        public void testClear()
        {
            //create new customer collection
            clsCustomerCollection collection = new clsCustomerCollection();
            //make new test customer without properties (it doesn't need them to show clear works)
            clsCustomer tstCustomer1 = new clsCustomer();

            //add tst customer
            collection.add(tstCustomer1);
            //clear collection
            collection.clear();
            //create new empty list to compare to
            List <clsCustomer> emptyList = new List <clsCustomer>();

            //compare
            Assert.AreEqual(collection.Count, emptyList.Count);
        }
コード例 #4
0
    protected void OkButton_Click(object sender, EventArgs e)
    {
        clsCustomer           newCustomer = new clsCustomer();
        clsCustomerCollection collection  = new clsCustomerCollection();

        //validate user inputs
        String name     = NameTextBox.Text;
        String surname  = SurnameTextBox.Text;
        String phonenum = MobileTextBox.Text;
        String email    = EmailTextBox.Text;
        String dob      = DateTextBox.Text;
        String address  = AddressTextBox.Text;

        String error = newCustomer.Valid(name, surname, dob, phonenum, email, address);

        if (error == "")
        {
            //no errors, program goes ahead
            newCustomer.name        = name;
            newCustomer.surname     = surname;
            newCustomer.PhoneNumber = Convert.ToInt32(phonenum);
            newCustomer.email       = email;
            newCustomer.Address     = address;
            newCustomer.DOB         = DateTime.Parse(dob);
            newCustomer.toDelete    = false;

            //adds new customer to database
            int ID = collection.add(newCustomer);
            newCustomer.CustomerID = ID;

            //stores customer in session and redirects to account viewer
            Session["newCustomer"] = newCustomer;
            Response.Redirect("CustomerViewer.aspx");
        }
        else
        {
            outputErrors(error);
        }
    }