Esempio n. 1
0
        public void getFordPriceTest()
        {
            decimal price = 0;

            // Test default car price
            Car ford = new FordFocus();

            price = ford.GetPrice();

            Assert.AreEqual((decimal)9000.5, price);

            // Test car price with AirCo
            Car airco = new AirCo(ford);

            price = airco.GetPrice();

            Assert.AreEqual((decimal)9150.5, price);

            // Test car price with 2 or more accessories
            Car gps = new GPS(airco);

            price = gps.GetPrice();

            Assert.AreEqual((decimal)9250.75, price);
        }
Esempio n. 2
0
        public void getVWPriceTest()
        {
            decimal price = 0;

            // Test default car price
            Car golf = new VolkswagenGolf();

            price = golf.GetPrice();

            Assert.AreEqual((decimal)10000.5, price);

            // Test car price with AirCo
            Car airco = new AirCo(golf);

            price = airco.GetPrice();

            Assert.AreEqual((decimal)10150.5, price);

            // Test car price with 2 or more accessories
            Car gps = new GPS(airco);

            price = gps.GetPrice();

            Assert.AreEqual((decimal)10250.75, price);
        }
Esempio n. 3
0
        private void chkbox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;

            if (checkBox.Checked)
            {
                switch (checkBox.Name)
                {
                case "chkAir_VW":
                    Car airco = new AirCo(VWList.Last());
                    VWList.Add(airco);
                    tb_VW.Text = airco.GetPrice().ToString();
                    break;

                case "chkGPS_VW":
                    Car gps = new GPS(VWList.Last());
                    VWList.Add(gps);
                    tb_VW.Text = gps.GetPrice().ToString();
                    break;

                case "chkTires_VW":
                    Car tires = new SnowTires(VWList.Last());
                    VWList.Add(tires);
                    tb_VW.Text = tires.GetPrice().ToString();
                    break;

                case "chkAir_Ford":
                    Car aircoF = new AirCo(FordList.Last());
                    FordList.Add(aircoF);
                    tb_Ford.Text = aircoF.GetPrice().ToString();
                    break;

                case "chkGPS_Ford":
                    Car gpsF = new GPS(FordList.Last());
                    FordList.Add(gpsF);
                    tb_Ford.Text = gpsF.GetPrice().ToString();
                    break;

                case "chkTires_Ford":
                    Car tiresF = new SnowTires(FordList.Last());
                    FordList.Add(tiresF);
                    tb_Ford.Text = tiresF.GetPrice().ToString();
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (checkBox.Name)
                {
                case "chkAir_VW":
                    Car airco =
                        VWList.Select(car => car).Where(car => car.GetName() == "Air Conditioner").ToList().First();
                    if (airco == null)
                    {
                        return;
                    }
                    LinkNextWithPreviousCarObjects(airco, VWList);
                    VWList.RemoveAll(car => car.GetName().Equals(airco.GetName()));
                    tb_VW.Text = VWList.Last().GetPrice().ToString();
                    break;

                case "chkGPS_VW":
                    Car gps =
                        VWList.Select(car => car).Where(car => car.GetName() == "GPS Navigation").ToList().First();
                    if (gps == null)
                    {
                        return;
                    }
                    LinkNextWithPreviousCarObjects(gps, VWList);
                    VWList.RemoveAll(car => car.GetName().Equals(gps.GetName()));
                    tb_VW.Text = VWList.Last().GetPrice().ToString();
                    break;

                case "chkTires_VW":
                    Car tires =
                        VWList.Select(car => car).Where(car => car.GetName() == "Snow Tires").ToList().First();
                    if (tires == null)
                    {
                        return;
                    }
                    LinkNextWithPreviousCarObjects(tires, VWList);
                    VWList.RemoveAll(car => car.GetName().Equals(tires.GetName()));
                    tb_VW.Text = VWList.Last().GetPrice().ToString();
                    break;

                case "chkAir_Ford":
                    Car aircoF =
                        FordList.Select(car => car)
                        .Where(car => car.GetName() == "Air Conditioner")
                        .ToList()
                        .First();
                    if (aircoF == null)
                    {
                        return;
                    }
                    LinkNextWithPreviousCarObjects(aircoF, FordList);
                    FordList.RemoveAll(car => car.GetName().Equals(aircoF.GetName()));
                    tb_Ford.Text = FordList.Last().GetPrice().ToString();
                    break;

                case "chkGPS_Ford":
                    Car gpsF =
                        FordList.Select(car => car).Where(car => car.GetName() == "GPS Navigation").ToList().First();
                    if (gpsF == null)
                    {
                        return;
                    }
                    LinkNextWithPreviousCarObjects(gpsF, FordList);
                    FordList.RemoveAll(car => car.GetName().Equals(gpsF.GetName()));
                    tb_Ford.Text = FordList.Last().GetPrice().ToString();
                    break;

                case "chkTires_Ford":
                    Car tiresF =
                        FordList.Select(car => car).Where(car => car.GetName() == "Snow Tires").ToList().First();
                    if (tiresF == null)
                    {
                        return;
                    }
                    LinkNextWithPreviousCarObjects(tiresF, FordList);
                    FordList.RemoveAll(car => car.GetName().Equals(tiresF.GetName()));
                    tb_Ford.Text = FordList.Last().GetPrice().ToString();
                    break;

                default:
                    break;
                }
            }
        }