public static void Run() { Console.WriteLine($"{Environment.NewLine}*** DECORATOR PATTERN ***{Environment.NewLine}"); // Create Some Bikes MountainBike mBike = new MountainBike("Red", 16, 85, 2); mBike.Display(); RoadBike rBike = new RoadBike("Black", 29, 90, true); rBike.Display(); // Now Decorate both the bikes with brakes Brakes mountainBikeWithBrakes = new Brakes(mBike); mountainBikeWithBrakes.AddBrakes(BrakeType.Disc); mountainBikeWithBrakes.Display(); Brakes roadBikeWithBrakes = new Brakes(rBike); roadBikeWithBrakes.AddBrakes(BrakeType.Rim); roadBikeWithBrakes.Display(); // Now Decorate the mountain bike with shocks Shocks mountainBikeWithShocks = new Shocks(mBike); mountainBikeWithShocks.AddShocks(8); mountainBikeWithShocks.Display(); }
public static void Main(string[] args) { var mountainBike = new MountainBike(size: "S", frontShock: "Manitou", rearShock: "Fox"); Console.WriteLine(mountainBike.Size); // => S }
public void MountainBikeCanGoOnOwn() { MountainBike mountainBike = new MountainBike { SelfPropelled = true }; Assert.True(mountainBike.SelfPropelled); }
public void MountainBikeCanCostMore() { MountainBike mountainBike = new MountainBike { Cost = 500 }; Assert.Equal(500, mountainBike.Cost); }
public void MountainBikeHas4Wheels() { MountainBike mountainBike = new MountainBike { NumberOfWheels = 4 }; Assert.Equal(4, mountainBike.NumberOfWheels); }
public void MountainBikeRequresLicense() { MountainBike mountainBike = new MountainBike { RequiresLicense = true }; Assert.True(mountainBike.RequiresLicense); }
public void BrakesDecorator_AllValidInput_ReturnsInstanceOfBike() { // Arrange MountainBike bike = new MountainBike("Red", 26, 90, 1); // Act Brakes bikeWithBrakes = new Brakes(bike); bikeWithBrakes.AddBrakes(BrakeType.Disc); bikeWithBrakes.Display(); // Assert Assert.IsInstanceOfType(bikeWithBrakes, typeof(Bike)); }
public void ShocksDecorator_AllValidInput_ReturnsInstanceOfBike() { // Arrange MountainBike bike = new MountainBike("Red", 26, 90, 1); // Act Shocks bikeWithShocks = new Shocks(bike); bikeWithShocks.AddShocks(6); bikeWithShocks.Display(); // Assert Assert.IsInstanceOfType(bikeWithShocks, typeof(Bike)); }
public void TirePumpRobot_DoWork_ChangesTirePressure() { // Arrange BikeShop shop = new BikeShop(); IBike testBike = new MountainBike("Test"); int originalTirePressure = testBike.TirePressure; shop.Attach(testBike); // Act shop.AcceptVisitor(new TirePumpRobot()); // Assert Assert.IsFalse(testBike.TirePressure == originalTirePressure); }
public void PaintRobot_DoWork_ChangesBikeColour() { // Arrange BikeShop shop = new BikeShop(); IBike testBike = new MountainBike("Test"); ConsoleColor originalColour = testBike.Colour; shop.Attach(testBike); // Act shop.AcceptVisitor(new PainterRobot()); // Assert - This could fail if it randomly chooses the original colour again Assert.IsFalse(testBike.Colour == originalColour); }
private static void Homework1Examples() { Bicycle2 myBike = new Bicycle2("BMX"); MountainBike myMountain = new MountainBike(); DownHillBike myDownhillBike = new DownHillBike(); Console.WriteLine(myBike.WheelSpokes); Console.WriteLine(myMountain.WheelSpokes); Console.WriteLine(myDownhillBike.WheelSpokes); myMountain.MyMountainColor(); myDownhillBike.MyMountainColor(); }
public void MountainBike_BuildBike_CallsInstructions() { // Arrange IBike bike = new MountainBike(); Mock <IInstruction> inst = new Mock <IInstruction>(); // Act bike.BuildBike(); bike.ChangeInstructions(new List <IInstruction> { inst.Object }); bike.BuildBike(); // Assert inst.Verify(i => i.AddComponent(), Times.Once); }
static void Main(string[] args) { Turcell turcell = new Turcell(); Camry camry = new Camry(); BRZ brz = new BRZ(); MountainBike mountainBike = new MountainBike(); Motorcycle motorcycle = new Motorcycle(); Console.WriteLine($"Class: {turcell}. Inherited Number of Wheels: {turcell.NumberOfWheels}\n" + ""); Console.WriteLine($"Class: {camry}. Inherited Number of Doors: {camry.NumberOfDoors}\n" + ""); Console.WriteLine($"Class: {brz}. Inherited Backseat Space: {brz.BackseatSpace}\n" + ""); Console.WriteLine($"Class: {motorcycle}. Inherited Number of Wheels: {motorcycle.NumberOfWheels}\n" + ""); Console.WriteLine($"Class: {mountainBike}. Inherited Self-Propelled: {mountainBike.SelfPropelled}\n" + ""); }
private void buttonAdd_Click(object sender, EventArgs e) { if (this.radioButton1.Checked == true) { Bike aBike = new Bike(); MountainBike mBike = new MountainBike(); mBike.Type = "MBike"; mBike.SerialNumber = Convert.ToInt32(this.textBoxSerialNumber.Text); mBike.Made = (EnumMade)comboBoxMade.SelectedIndex; mBike.Model = (EnumModel)comboBoxModel.SelectedIndex; mBike.Speed = textBoxSpeed.Text; mBike.Color = (EnumColor)comboBoxColor.SelectedIndex; mBike.Day = Convert.ToInt32(textBoxDay.Text); mBike.Month = Convert.ToInt32(textBoxMonth.Text); mBike.Year = Convert.ToInt32(textBoxYear.Text); mBike.Suspension = (EnumSuspension)comboBoxSuspension.SelectedIndex; mBike.Height = textBoxHeight.Text; aBike = (Bike)mBike; this.myBikesList.Add(mBike); this.mountainBikesList.Add(mBike); } else if (this.radioButton2.Checked == true) { Bike aBike = new Bike(); RoadBike rBike = new RoadBike(); rBike.Type = "RBike"; rBike.SerialNumber = Convert.ToInt32(this.textBoxSerialNumber.Text); rBike.Made = (EnumMade)comboBoxMade.SelectedIndex; rBike.Model = (EnumModel)comboBoxModel.SelectedIndex; rBike.Speed = textBoxSpeed.Text; rBike.Color = (EnumColor)comboBoxColor.SelectedIndex; rBike.Day = Convert.ToInt32(textBoxDay.Text); rBike.Month = Convert.ToInt32(textBoxMonth.Text); rBike.Year = Convert.ToInt32(textBoxYear.Text); rBike.SeatHeight = textBoxSeatHeight.Text; aBike = (Bike)rBike; //MessageBox.Show("Bike" + rBike); this.myBikesList.Add(rBike); this.roadBikesList.Add(rBike); } }
private void update_Click(object sender, EventArgs e) { int indexInBikes = GetIndexOfInList(lastSelectedBike, BikeToObject(bikesList)); int indexInType = -1; Bike newObj; if (lastSelectedBike is Roadbike) { indexInType = GetIndexOfInList(lastSelectedBike, RoadBikeToObject(roadbikesList)); newObj = new Roadbike(long.Parse(serialTextBox.Text), makeInputTextBox.Text, Convert.ToInt32(speedTextBox.Text), (EnumColor)Enum.Parse(typeof(EnumColor), colorComboBox.Text), new Date(Convert.ToInt32(dayTextBox.Text), Convert.ToInt32(monthTextBox.Text), Convert.ToInt32(yearTextBox.Text)), Convert.ToInt32(seatHeightTextBox.Text)); roadbikesList.RemoveAt(indexInType); roadbikesList.Insert(indexInType, (Roadbike)newObj); } else //if (lastSelectedBike is MountainBike) { indexInType = GetIndexOfInList(lastSelectedBike, MountainBikeToObject(MountainBikesList)); newObj = new MountainBike(long.Parse(serialTextBox.Text), makeInputTextBox.Text, Convert.ToInt32(speedTextBox.Text), (EnumColor)Enum.Parse(typeof(EnumColor), colorComboBox.Text), new Date(Convert.ToInt32(dayTextBox.Text), Convert.ToInt32(monthTextBox.Text), Convert.ToInt32(yearTextBox.Text)), (EnumSuspension)Enum.Parse(typeof(EnumSuspension), suspensionComboBox.Text)); MountainBikesList.RemoveAt(indexInType); MountainBikesList.Insert(indexInType, (MountainBike)newObj); } bikesList.RemoveAt(indexInBikes); bikesList.Insert(indexInBikes, newObj); if (indexInBikes == -1 || indexInType == -1 || newObj == null) { MessageBox.Show("Cannot Update..!!"); } else { MessageBox.Show("Updated successfully..!!"); } }
private void button_Update_Click(object sender, EventArgs e) { int indexInBikes = GetIndexOfInList(SelectedBike, BikeToObject(bikeList)); int indexInType = -1; Bike newObj; if (SelectedBike is RoadBike) { indexInType = GetIndexOfInList(SelectedBike, RoadBikeToObject(roadBikeList)); newObj = new RoadBike(long.Parse(textBoxSeialNumber.Text), textBoxMake.Text, Convert.ToDouble(textBoxSpeed.Text), (EnumColor)Enum.Parse(typeof(EnumColor), comboBoxColor.Text), new Date(Convert.ToInt32(textBoxDay.Text), Convert.ToInt32(textBoxMonth.Text), Convert.ToInt32(textBoxYear.Text)), Convert.ToInt32(textBoxWarrenty.Text), Convert.ToDouble(textBoxPrice.Text), Convert.ToInt32(textBoxSeatHeight.Text), Convert.ToDouble(textBoxWeight.Text)); roadBikeList.RemoveAt(indexInType); roadBikeList.Insert(indexInType, (RoadBike)newObj); } else { indexInType = GetIndexOfInList(SelectedBike, MountainBikeToObject(mountainBikeList)); newObj = new MountainBike(long.Parse(textBoxSeialNumber.Text), textBoxMake.Text, Convert.ToDouble(textBoxSpeed.Text), (EnumColor)Enum.Parse(typeof(EnumColor), comboBoxColor.Text), new Date(Convert.ToInt32(textBoxDay.Text), Convert.ToInt32(textBoxMonth.Text), Convert.ToInt32(textBoxYear.Text)), Convert.ToInt32(textBoxWarrenty.Text), Convert.ToDouble(textBoxPrice.Text), Convert.ToDouble(textBoxGroundHeight.Text), (EnumSuspension)Enum.Parse(typeof(EnumSuspension), comboBoxSuspensionType.Text), Convert.ToInt32(textBoxGears.Text)); mountainBikeList.RemoveAt(indexInType); mountainBikeList.Insert(indexInType, (MountainBike)newObj); } bikeList.RemoveAt(indexInBikes); bikeList.Insert(indexInBikes, newObj); if (indexInBikes == -1 || indexInType == -1 || newObj == null) { MessageBox.Show("Could not Update..!!"); } else { MessageBox.Show("Updated successfully..!!"); } }
public static void Run() { Console.WriteLine($"{Environment.NewLine}*** STRATERGY PATTERN ***{Environment.NewLine}"); IBike mountainBike = new MountainBike(); // Build with default instructions mountainBike.BuildBike(); mountainBike.ChangeInstructions(new List <IInstruction> { new FrameInstruction(), new BrakesInstruction(), new LightsInstruction(), new WheelsInstruction(), new ShocksInstruction() }); // Build with new instructions. mountainBike.BuildBike(); }
public void TestMethod3() { var count = 0; var myobj = new List <object>(); myobj.Add(new Car(4)); myobj.Add(new Scooter(2)); myobj.Add(new MountainBike()); foreach (var value in myobj) { if (value.GetType().BaseType == typeof(Bicycle)) { count++; var attribs = value.GetType().GetCustomAttributes(typeof(AlternateName), false); var alt = (AlternateName)attribs[0]; if (alt.Name == "SC") { var scooter = new Scooter(2); int val = scooter.GetCylindersCount(); Console.WriteLine(val); } else { if (alt.Name == "MB") { var mountBike = new MountainBike(); mountBike.ShockAbsorberCount = 3; Console.WriteLine(mountBike.ShockAbsorberCount); } } } } Assert.AreEqual(count, 2); }
private static void Homework1() { Console.WriteLine("------------------------------------"); Console.WriteLine("Homework1 bicycle output begins here"); Console.WriteLine("------------------------------------"); Bicycle myBicycle = new Bicycle(); myBicycle.MoveForward(); myBicycle.NumofGears = 10; myBicycle.HandlebarType = "Bullhorn handlebars"; Console.WriteLine(myBicycle.HandlebarType); Console.WriteLine("----------------------------------------------"); Console.WriteLine("Homework1b bicycle in-class output begins here"); Console.WriteLine("----------------------------------------------"); Bicycle1b myBicycle1b = new Bicycle1b(); MountainBike myMountainBike = new MountainBike(); Console.WriteLine("------------------------------------------------------"); Console.WriteLine("Homework1b bicycle in-class output2 updates begin here"); Console.WriteLine("------------------------------------------------------"); Bicycle1b myBike = new Bicycle1b("BMX"); MountainBike myMountain = new MountainBike(); DownHillBike myDownhillBike = new DownHillBike(); Console.WriteLine(myBike.WheelSpokes); Console.WriteLine(myMountain.WheelSpokes); Console.WriteLine(myDownhillBike.WheelSpokes); myMountain.MyMountainColor(); myDownhillBike.MyMountainColor(); }
public void MountainBikeIsNotSelfPropelled() { MountainBike mountainBike = new MountainBike(); Assert.False(mountainBike.SelfPropelled); }
private void add_Click(object sender, EventArgs e) { string input; long serNum = 0; string make = ""; double speed = 0, seatHeight = 0; MyBikesStore.Date date; bool correct = false; if (bikeTypeDropDown.SelectedIndex == -1) { MessageBox.Show("\t...Not valid.. The input must be 12 digits only...\n"); return; } //-------------validation for serial number input = serialTextBox.Text; correct = MyBikesStore.Bus.RegExValidator.Is12Digit(input) && MyBikesStore.Bus.RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t...Not valid. The input must be digits and 12 digits only.. PLease try again...\n"); return; } serNum = long.Parse(input); correct = false; input = makeInputTextBox.Text; correct = MyBikesStore.Bus.RegExValidator.IsAlphabetLetter(input) && MyBikesStore.Bus.RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\tThe input must not be empty and must be alphabets only\n"); return; } make = input; correct = false; input = speedTextBox.Text; correct = MyBikesStore.Bus.RegExValidator.IsDigit(input) && MyBikesStore.Bus.RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\tThe input must not be empty and must be alphabets only. Please try again \n"); return; } speed = Convert.ToDouble(input); correct = false; input = speedTextBox.Text; correct = MyBikesStore.Bus.RegExValidator.IsDigit(dayTextBox.Text) && MyBikesStore.Bus.RegExValidator.IsDigit(monthTextBox.Text) && MyBikesStore.Bus.RegExValidator.IsDigit(yearTextBox.Text) && MyBikesStore.Bus.RegExValidator.IsEmpty(dayTextBox.Text) && MyBikesStore.Bus.RegExValidator.IsEmpty(monthTextBox.Text) && MyBikesStore.Bus.RegExValidator.IsEmpty(yearTextBox.Text); if (!correct) { MessageBox.Show("\t...The input must not be empty and must be digits only. Please try again...\n"); return; } while (!correct) { ; } date = new Date(Convert.ToInt32(dayTextBox.Text), Convert.ToInt32(monthTextBox.Text), Convert.ToInt32(yearTextBox.Text)); Bike bike; string successMsg = ""; if (bikeTypeDropDown.SelectedIndex == 1) { correct = false; input = seatHeightTextBox.Text; correct = MyBikesStore.Bus.RegExValidator.IsDigit(input) && MyBikesStore.Bus.RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t...The input must not be empty and must be digits only. Please try again..\n"); return; } seatHeight = Convert.ToInt32(input); Roadbike rbike = new Roadbike(serNum, make, speed, (EnumColor)Enum.Parse(typeof(EnumColor), colorComboBox.Text), date, seatHeight); roadbikesList.Add(rbike); bike = (Bike)rbike; successMsg = "Bike successfully added as a road bike and "; } else { MountainBike mbike = new MountainBike(serNum, make, speed, (EnumColor)Enum.Parse(typeof(EnumColor), colorComboBox.Text), date, (EnumSuspension)Enum.Parse(typeof(EnumSuspension), suspensionComboBox.Text)); MountainBikesList.Add(mbike); bike = (Bike)mbike; successMsg = "Bike successfully added as a mountain bike and "; } bikesList.Add(bike); successMsg += "a bike"; MessageBox.Show(successMsg); }
private void button_Add_Click(object sender, EventArgs e) { int gearNumber; long serialNumber; double price, warrenty, speed, gheight, sheight, bweight; string make, input, msg = ""; EnumSuspension suspensionType; EnumColor color; bool correct = false; Bike mountainBike = null; Bike roadBike = null; if (bikeType.SelectedIndex == -1) { MessageBox.Show("\t Please Select Bike type \n"); return; } input = textBoxSeialNumber.Text; correct = RegExValidator.Is12Digit(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t Serial Number must 12 digit \n"); return; } serialNumber = long.Parse(input); correct = false; input = textBoxMake.Text; correct = RegExValidator.IsAlphabetLetter(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t Must be in LETTER(S) and NOT EMPTY \n"); return; } make = input; correct = false; input = textBoxSpeed.Text; correct = RegExValidator.IsDigit(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t Speed must not be zero AND Must be degit \n"); return; } speed = Convert.ToDouble(input); Date made_date = new Date(); made_date.Day = Convert.ToInt32(textBoxDay.Text); made_date.Month = Convert.ToInt32(textBoxMonth.Text); made_date.Year = Convert.ToInt32(textBoxYear.Text); suspensionType = (EnumSuspension)positionsuspensioncombo; color = (EnumColor)positioncolorcombo; price = Convert.ToDouble(textBoxPrice.Text); warrenty = Convert.ToDouble(textBoxWarrenty.Text); if (bikeType.SelectedIndex == 1) { correct = false; input = textBoxSeatHeight.Text; correct = RegExValidator.IsDigit(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t Seat height must not be empty AND Must be degit \n"); return; } sheight = Convert.ToDouble(input); bweight = Convert.ToDouble(textBoxWeight.Text); roadBike = new RoadBike(serialNumber, make, speed, color, made_date, warrenty, price, sheight, bweight); bikeList.Add(roadBike); msg = "Bike successfully added as a road bike "; } else { gheight = Convert.ToDouble(textBoxGroundHeight.Text); gearNumber = Convert.ToInt32(textBoxGears.Text); mountainBike = new MountainBike(serialNumber, make, speed, color, made_date, warrenty, price, gheight, suspensionType, gearNumber); bikeList.Add(mountainBike); msg = "Bike successfully added as a mountain bike "; } msg += "with bikelist"; MessageBox.Show(msg); }
public void MountainBikeDoesNotRequiresLicense() { MountainBike mountainBike = new MountainBike(); Assert.False(mountainBike.RequiresLicense); }
public void MountainBikeHas2Wheels() { MountainBike mountainBike = new MountainBike(); Assert.Equal(2, mountainBike.NumberOfWheels); }
private void Button_Add_Click(object sender, EventArgs e) { long serialNumber; double warrenty, speed, gheight, sheight, bweight; string make, input, msg = ""; EnumSuspension suspensionType; EnumColor color; bool correct = false; Bike mountainBike = null; Bike roadBike = null; //Bike bike; if (bikeType.SelectedIndex == -1) { MessageBox.Show("\t...BAD INPUT..No bike type selected\n"); return; } input = textBoxSeialNumber.Text; correct = RegExValidator.Is12Digit(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t...BAD INPUT..Serial cant be empty and should be of 12 digits\n"); return; } serialNumber = long.Parse(input); correct = false; input = textBoxMake.Text; correct = RegExValidator.IsAlphabetLetter(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t...BAD INPUT..Make cannot be empty and should contain\n"); return; } make = input; correct = false; input = textBoxSpeed.Text; correct = RegExValidator.IsDigit(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t...BAD INPUT..Speed cannot be empty and should contain only digits\n"); return; } speed = Convert.ToDouble(input); Date made_date = new Date(); made_date.Day = Convert.ToInt32(textBoxDay.Text); made_date.Month = Convert.ToInt32(textBoxMonth.Text); made_date.Year = Convert.ToInt32(textBoxYear.Text); suspensionType = (EnumSuspension)positionsuspensioncombo; color = (EnumColor)positioncolorcombo; warrenty = Convert.ToDouble(textBoxWarrenty.Text); if (bikeType.SelectedIndex == 1) { correct = false; input = textBoxSeatHeight.Text; correct = RegExValidator.IsDigit(input) && RegExValidator.IsEmpty(input); if (!correct) { MessageBox.Show("\t...BAD INPUT..Seat height cannot be empty and should contain only digits\n"); return; } sheight = Convert.ToDouble(input); bweight = Convert.ToDouble(textBoxWeight.Text); roadBike = new RoadBike(serialNumber, make, speed, color, made_date, warrenty, sheight, bweight); bikeList.Add(roadBike); msg = "Bike successfully added as a road bike "; } else { gheight = Convert.ToDouble(textBoxGroundHeight.Text); mountainBike = new MountainBike(serialNumber, make, speed, color, made_date, warrenty, gheight, suspensionType); bikeList.Add(mountainBike); msg = "Bike successfully added as a mountain bike "; } msg += "with bikelist"; MessageBox.Show(msg); }
public void MountainBikeIsAVehicle() { MountainBike mountainBike = new MountainBike(); Assert.True(mountainBike is Vehicle); }
public void MountainBikeHasCorrectCost() { MountainBike mountainBike = new MountainBike(); Assert.Equal(250, mountainBike.Cost); }