private void tabFsBtnConfirm_Click(object sender, RoutedEventArgs e)
        {
            string           sCaption      = "Build a Bike";
            MessageBoxButton btnMessageBox = MessageBoxButton.OK;
            MessageBoxImage  icnMessageBox = MessageBoxImage.Information;

            if (tabFsLstModels.SelectedIndex == -1)
            {
                MessageBox.Show("You need to select a Finishing Set Model", sCaption, btnMessageBox, icnMessageBox);
            }
            else
            {
                FinishingSet finishingset = findFinishingSet(tabFsLstModels.SelectedItem.ToString());
                if (finishingset != null)
                {
                    try
                    {
                        bike.FinishingSet     = finishingset;
                        finishingsetCompleted = true;

                        TextBlock header = new TextBlock();
                        header.Text            = "Finishing Set";
                        header.Background      = Brushes.LightGreen;
                        tabFinishingSet.Header = header;
                    }
                    catch (ArgumentException error)
                    {
                        MessageBox.Show(error.Message, sCaption, btnMessageBox, MessageBoxImage.Error);
                    }
                }
            }
        }
        public void displaySelectedFinishingSet(string model)
        {
            FinishingSet finishingset = findFinishingSet(model);

            if (finishingset != null)
            {
                tabFsTxtModel.Text      = finishingset.Model;
                tabFsTxtPrice.Text      = "£" + finishingset.Cost.ToString();
                tabFsTxtHandlebars.Text = finishingset.Handlebars;
                tabFsTxtSaddle.Text     = finishingset.Saddle;

                if (finishingset.IsSpecialised)
                {
                    tabFsTxtSpecialised.Text = "Specialised Component";
                }
                else
                {
                    tabFsTxtSpecialised.Text = "Standard Component";
                }
                if (finishingset.Availability)
                {
                    tabFsTxtStock.Text = "In Stock!";
                }
                else
                {
                    tabFsTxtStock.Text = "Out of Stock";
                }
            }
        }
Beispiel #3
0
        public void FinishingSetTest()
        {
            string handlebars   = "Some handlebars";
            string saddle       = "Some saddle";
            double cost         = 214.99;
            bool   availability = true;

            FinishingSet finishingset = new FinishingSet();

            finishingset.Handlebars   = handlebars;
            finishingset.Saddle       = saddle;
            finishingset.Cost         = cost;
            finishingset.Availability = availability;

            Assert.AreEqual(handlebars, finishingset.Handlebars, "FinishingSet Test - Handlebars");
            Assert.AreEqual(saddle, finishingset.Saddle, "FinishingSet Test - Saddle");
            // default specialised is false (if nothing has been set)
            Assert.AreEqual(false, finishingset.IsSpecialised, "FinishingSet Test - Specialised");
            Assert.AreEqual(cost, finishingset.Cost, "FinishingSet Test - Cost");
            Assert.AreEqual(availability, finishingset.Availability, "FinishingSet Test - Availability");
        }
Beispiel #4
0
        private void btn_Submit_Click(object sender, RoutedEventArgs e)
        {
            Random rand = new Random();

            Business.Frame frame = new Business.Frame();
            if (rand.Next(0, 2) == 1)
            {
                frame.Type   = combo_frame_type.Text;
                frame.Colour = combo_frame_colour.Text;
                frame.Size   = combo_frame_size.Text;
            }
            else
            {
                MessageBox.Show("Frame OOS: Adding 2 days to Completion Time");
                frame.Type   = combo_frame_type.Text;
                frame.Colour = combo_frame_colour.Text;
                frame.Size   = combo_frame_size.Text;
                duration    += 2;
            }

            double frameTypeCost   = Double.Parse(((ComboBoxItem)combo_frame_type.SelectedItem).Tag.ToString());
            double frameColourCost = Double.Parse(((ComboBoxItem)combo_frame_colour.SelectedItem).Tag.ToString());
            double frameSizeCost   = Double.Parse(((ComboBoxItem)combo_frame_size.SelectedItem).Tag.ToString());

            frame.Cost = frameTypeCost + frameColourCost + frameSizeCost;

            Gears gears = new Gears();

            if (rand.Next(0, 2) == 1)
            {
                gears.Type = combo_gears.Text;
            }
            else
            {
                MessageBox.Show("Gears OOS: Adding 2 days to Completion Time");
                gears.Type = combo_gears.Text;
                duration  += 2;
            }

            gears.Cost = Double.Parse(((ComboBoxItem)combo_gears.SelectedItem).Tag.ToString());

            Breaks breaks = new Breaks();

            if (rand.Next(0, 2) == 1)
            {
                breaks.Type = combo_breaks.Text;
            }
            else
            {
                MessageBox.Show("Breaks OOS: Adding 2 days to Completion Time");
                breaks.Type = combo_breaks.Text;
                duration   += 2;
            }
            breaks.Cost = Double.Parse(((ComboBoxItem)combo_breaks.SelectedItem).Tag.ToString());

            GroupSet groupSet = new GroupSet();

            groupSet.Gears  = gears;
            groupSet.Breaks = breaks;
            groupSet.Cost   = groupSet.calculateGroupSet(gears, breaks);

            Wheels wheels = new Wheels();

            if (rand.Next(0, 2) == 1)
            {
                wheels.Type = combo_handlebars.Text;
            }
            else
            {
                MessageBox.Show("Wheels OOS: Adding 2 days to Completion Time");
                wheels.Type = combo_handlebars.Text;
                duration   += 2;
            }
            wheels.Cost = Double.Parse(((ComboBoxItem)combo_wheels.SelectedItem).Tag.ToString());

            Handlebars handleBars = new Handlebars();

            if (rand.Next(0, 2) == 1)
            {
                handleBars.Type = combo_handlebars.Text;
            }
            else
            {
                MessageBox.Show("Handlebars OOS: Adding 2 days to Completion Time");
                handleBars.Type = combo_handlebars.Text;
                duration       += 2;
            }
            handleBars.Cost = Double.Parse(((ComboBoxItem)combo_handlebars.SelectedItem).Tag.ToString());

            Saddle saddle = new Saddle();

            if (rand.Next(0, 2) == 1)
            {
                saddle.Type = combo_saddle.Text;
            }
            else
            {
                MessageBox.Show("Saddle OOS: Adding 2 days to Completion Time");
                saddle.Type = combo_saddle.Text;
                duration   += 2;
            }
            saddle.Cost = Double.Parse(((ComboBoxItem)combo_saddle.SelectedItem).Tag.ToString());

            FinishingSet finishingSet = new FinishingSet();

            finishingSet.HandleBars = handleBars;
            finishingSet.Saddle     = saddle;
            finishingSet.Cost       = finishingSet.calculateFinishingSet(handleBars, saddle);

            Bicycle bicycle = new Bicycle();

            bicycle.Frame        = frame;
            bicycle.GroupSet     = groupSet;
            bicycle.FinishingSet = finishingSet;
            bicycle.Cost         = bicycle.calculateFinalCost(frame, groupSet, finishingSet, wheels);
            if (check_warranty.IsChecked == true)
            {
                bicycle.Cost += 50.0;
            }
            bicycle.Duration = duration;
            duration         = 2;

            bikeList.Add(bicycle);
            string output    = "";
            int    bikeNum   = 1;
            double totalCost = 0.0;

            foreach (Bicycle bike in bikeList)
            {
                output += "Bike " + bikeNum + ":\n" + "Cost: " + bike.Cost + "\nCompletion Time: " + bike.Duration + " days.\n\n";
                bikeNum++;
                totalCost += bike.Cost;
            }
            MessageBox.Show(output + "\nTotal Cost: " + totalCost);
        }
Beispiel #5
0
        public void _fullBikeTestFail()
        {
            // Frame
            string model          = "Nukeproof Scout 290 Frame 2018";
            string invalid_colour = "Gray";
            int    size           = 17;
            bool   isSpecialised  = true;
            double cost           = 349.99;
            bool   availability   = false;

            BikeFrame frame = new BikeFrame();

            try
            {
                frame.Model         = model;
                frame.Colour        = invalid_colour;
                frame.Size          = size;
                frame.IsSpecialised = isSpecialised;
                frame.Cost          = cost;
                frame.Availability  = availability;
                Assert.Fail("No exception was thrown for an invalid colour");
            }
            catch (ArgumentException error)
            {
                Console.WriteLine(error.Message);
                Assert.AreEqual("Colour '" + invalid_colour + "' not available", error.Message);
            }


            // Group Set
            string gears  = "Some gears";
            string brakes = "Some brakes";

            isSpecialised = false;
            double invalid_cost = -50;

            availability = true;

            GroupSet groupset = new GroupSet();

            try
            {
                groupset.Gears        = gears;
                groupset.Brakes       = brakes;
                groupset.Cost         = invalid_cost;
                groupset.Availability = availability;
                Assert.Fail("No exception was thrown for an invalid cost");
            }
            catch (ArgumentException error)
            {
                Console.WriteLine(error.Message);
                Assert.AreEqual("Cost '" + invalid_cost + "' is not valid", error.Message);
            }

            // Wheels
            string invalid_model = "";

            isSpecialised = true;
            cost          = 180;
            availability  = false;

            Wheels wheels = new Wheels();

            try
            {
                wheels.Model         = invalid_model;
                wheels.IsSpecialised = isSpecialised;
                wheels.Cost          = cost;
                wheels.Availability  = availability;
                Assert.Fail("No exception was thrown for an invalid model");
            }
            catch (ArgumentException error)
            {
                Console.WriteLine(error.Message);
                Assert.AreEqual("Model '" + invalid_model + "' is not valid", error.Message);
            }


            // Finishing Set
            model = "Some model";
            string handlebars     = "Some handlebars";
            string invalid_saddle = "";

            isSpecialised = false;
            cost          = 214.99;
            availability  = true;

            FinishingSet finishingset = new FinishingSet();

            try
            {
                finishingset.Availability = availability;
                finishingset.Handlebars   = handlebars;
                finishingset.Saddle       = invalid_saddle;
                finishingset.Cost         = cost;
                finishingset.Availability = availability;
                Assert.Fail("No exception was thrown for an invalid saddle");
            }
            catch (ArgumentException error)
            {
                Console.WriteLine(error.Message);
                Assert.AreEqual("Saddle '" + invalid_saddle + "' is not valid", error.Message);
            }

            string invalid_type    = "invalid";
            bool   warrantyUpgrade = true;

            Bike bike = new Bike();

            try
            {
                bike.Type            = invalid_type;
                bike.WarrantyUpgrade = warrantyUpgrade;
                Assert.Fail("No exception was thrown for an invalid bike type");
            }
            catch (ArgumentException error)
            {
                Console.WriteLine(error.Message);
                Assert.AreEqual("Type '" + invalid_type + "' is not available", error.Message);
            }
        }
Beispiel #6
0
        public void _fullBikeTestPass()
        {
            // Frame
            string model         = "Nukeproof Scout 290 Frame 2018";
            string colour        = "Red";
            int    size          = 17;
            bool   isSpecialised = true;
            double cost          = 349.99;
            bool   availability  = false;

            BikeFrame frame = new BikeFrame();

            frame.Model         = model;
            frame.Colour        = colour;
            frame.Size          = size;
            frame.IsSpecialised = isSpecialised;
            frame.Cost          = cost;
            frame.Availability  = availability;

            // Group Set
            string gears  = "Some gears";
            string brakes = "Some brakes";

            isSpecialised = false;
            cost          = 469.99;
            availability  = true;

            GroupSet groupset = new GroupSet();

            groupset.Gears        = gears;
            groupset.Brakes       = brakes;
            groupset.Cost         = cost;
            groupset.Availability = availability;

            // Wheels
            model         = "Some wheels";
            isSpecialised = true;
            cost          = 240.99;
            availability  = false;

            Wheels wheels = new Wheels();

            wheels.Model         = model;
            wheels.IsSpecialised = isSpecialised;
            wheels.Cost          = cost;
            wheels.Availability  = availability;

            // Finishing Set
            string handlebars = "Some handlebars";
            string saddle     = "Some saddle";

            isSpecialised = false;
            cost          = 214.99;
            availability  = true;

            FinishingSet finishingset = new FinishingSet();

            finishingset.Handlebars   = handlebars;
            finishingset.Saddle       = saddle;
            finishingset.Cost         = cost;
            finishingset.Availability = availability;

            string type            = "Mountain Bike";
            bool   warrantyUpgrade = true;

            Bike bike = new Bike();

            bike.Frame           = frame;
            bike.GroupSet        = groupset;
            bike.Wheels          = wheels;
            bike.FinishingSet    = finishingset;
            bike.Type            = type;
            bike.WarrantyUpgrade = warrantyUpgrade;

            Assert.AreEqual(frame, bike.Frame, "FullBikeTest - Frame");
            Assert.AreEqual(groupset, bike.GroupSet, "FullBikeTest - Group Set");
            Assert.AreEqual(wheels, bike.Wheels, "FullBikeTest - Wheels");
            Assert.AreEqual(finishingset, bike.FinishingSet, "FullBikeTest - Finishing Set");
            Assert.AreEqual(type, bike.Type, "FullBikeTest - Type");
            Assert.AreEqual(warrantyUpgrade, bike.WarrantyUpgrade, "FullBikeTest - Warranty Upgrade");
            Assert.AreEqual(1325.96, bike.BikeCost, "FullBikeTest - Cost");
        }