public void Drive_AgeLessThan18_DoesNotDrive() { var driver = new Driver(14); ICar carProxy = new CarProxy(driver); var drive = carProxy.Drive(); Assert.That(drive, Is.EqualTo("too young")); }
public void Drive_AgeGreaterThan18_DoesNotDrive() { var driver = new Driver(30); ICar carProxy = new CarProxy(driver); var drive = carProxy.Drive(); Assert.That(drive, Is.EqualTo("driving")); }
public void TestDriveWithAdultDriver() { var carProxy = new CarProxy(new Driver(21)); carProxy.Drive(); // OUTPUT: Driving car. }
static void RunProtectionProxy() { ICar car = new CarProxy(new Driver(12)); car.Drive(); car = new CarProxy(new Driver(17)); car.Drive(); }
public void TestProxyPattern() { Driver driver = new Driver(); driver.Age = 22; ICar car = new CarProxy(driver); car.Drive(); }
public static void Main() { ICar car1 = new CarProxy(new Driver(16)); car1.MoveCar(); ICar car2 = new CarProxy(new Driver(23)); car2.MoveCar(); }
private static void UseProxy(Car car1, Car car2, Car car3) { var car = new CarProxy(new DriverProxy("Otto ", true, false), car1); car.Drive(); car = new CarProxy(new DriverProxy("Adolf ", false, true), car2); car.Drive(); car = new CarProxy(new DriverProxy("To-Iama_To_Kanava ", true, true), car3); car.Drive(); Console.WriteLine(new string('-', 30)); }
private void ThreadLoader() { using (CarProxy proxy = new CarProxy(Program.CarUrl)) { IEnumerable<Car> cars = proxy.GetAll(); carDataGridView.Invoke((MethodInvoker)(() => { carDataGridView.DataSource = cars; })); } }
private void Test() { CarCustomer customer = new CarCustomer("Tom"); CarProxy proxy = new CarProxy(customer, CarProxyType.Benz); proxy.CreateCar(); proxy.SellCar(); proxy = new CarProxy(customer, CarProxyType.Bmw); proxy.CreateCar(); proxy.SellCar(); }
public static void Run() { Console.WriteLine("--- Start Question 3 ---"); CarControl methods = new CarControl(); Console.WriteLine(methods.Gas()); Console.WriteLine(methods.Location()); IProxyMethod proxy = new CarProxy(); Console.WriteLine(proxy.Gas()); Console.WriteLine(proxy.Location()); Console.WriteLine("--- End Question 3 ---"); }
internal static void Proxy() { Console.WriteLine("Proxy Pattern Demo"); Console.WriteLine("----------------------------"); ICar car = new CarProxy(new Driver(17, true)); car.Drive(); Console.WriteLine(""); Console.WriteLine("----------------------------"); Console.WriteLine("Proxy Pattern Demo 2"); Console.WriteLine("----------------------------"); var person = new ProxyPerson(new Person(0)); Console.WriteLine(person.Eat()); }
static void Main(string[] args) { Console.WriteLine(); ICar proxy = new CarProxy(new Driver { Age = 17 }); Console.Write("Driver is 17 years old => "); proxy.Drive(); Console.WriteLine(); Console.WriteLine(); proxy = new CarProxy(new Driver { Age = 25 }); Console.Write("Driver is 25 years old => "); proxy.Drive(); Console.WriteLine(); Console.WriteLine(Console.ReadKey()); }
private void AddButton_Click(object sender, EventArgs e) { string chekingCost = CostBox.Text.Trim(); string chekingMark = MarkBox.Text.Trim(); string chekingColor = ColorBox.Text.Trim(); float cost; bool chekParse = float.TryParse(chekingCost, out cost); if (!string.IsNullOrEmpty(chekingCost) && !string.IsNullOrEmpty(chekingMark) && !string.IsNullOrEmpty(chekingColor) && chekParse && TrunkChoseBox.SelectedIndex > -1) { Car newCar = new Car(); newCar.Cost = cost; newCar.Mark = chekingMark; newCar.Color = chekingColor; Trunk selectedTrunk = (TrunkChoseBox.SelectedValue as Trunk); if (selectedTrunk != null) { newCar.TrunkId = selectedTrunk.Id; selectedTrunk.Cars.Add(newCar); selectedTrunk.CarCount++; using (TrunkProxy proxy = new TrunkProxy(Program.TrunkUrl)) { proxy.Update(selectedTrunk); //Program.trunkRepo.Update(selectedTrunk); } } using (CarProxy carproxy = new CarProxy(Program.CarUrl)) { carproxy.Add(newCar); } //Program.carRepo.Add(newCar); this.Close(); } else MessageBox.Show("Maybe, You forgot fill some fields or You enter a wrong cost or don't chose a trunk"); }
public static void Run() { ICar car = new CarProxy(new Driver(22)); car.Drive(); }
public static void Run() { var car = new CarProxy(new Driver(18)); car.Drive(); }
// In this case we want to implement functionality that car cannot be driven by too young people // We need to make a car proxy which has the same interface but performs additional checks // In general to create a proxy we have to replicate existing interface of an object and add relevant functionality. public static void ProtectionProxyDemo() { ICar car = new CarProxy(new Driver(12)); car.Drive(); }
static void Main(string[] args) { ICar car = new CarProxy(new Driver(18)); car.Drive(); }
public void ActByCallingDrive() { var carProxy = new CarProxy(_driver, _realCar); carProxy.Drive(); }
public void TestDriveWithYoungDriverThrowsInvalidArgumentException() { var carProxy = new CarProxy(new Driver(16)); Assert.That(() => carProxy.Drive(), Throws.ArgumentException); }
static void Main(string[] args) { //Question 1 Context ctx = new Context(new ShipSafe(0)); ctx.LevelUp(); ctx.LevelUp(); ctx.TakeDamage(); ctx.LevelUp(); ctx.LevelUp(); ctx.LevelUp(); ctx.TakeDamage(); ctx.TakeDamage(); //Question 2 Component root = new Composite(2); Component circle1 = new Leaf(1); Component rectangle = new Leaf(2); root.AddChild(circle1); root.AddChild(rectangle); Component container1 = new Composite(1); Component circle2 = new Leaf(3); Component circle3 = new Leaf(1); container1.AddChild(circle2); container1.AddChild(circle3); root.AddChild(container1); Component container2 = new Composite(1); Component t1 = new Leaf(5); Component t2 = new Leaf(1); Component t3 = new Leaf(1); container2.AddChild(t1); container2.AddChild(t2); container2.AddChild(t3); root.AddChild(container2); root.Draw(""); Console.WriteLine(root.countLeaf()); //Console.WriteLine(container1.countLeaf()); //Console.WriteLine(container2.countLeaf()); //Console.WriteLine(t1.countLeaf()); Console.WriteLine(isZugi(root)); //Question 3 CarProxy car = new CarProxy(); // Drive the car car.StartDriving(); car.showLocation(); //Question 5 FatalLogger fatal = new FatalLogger(); ErrorLogger error = new ErrorLogger(); InfoLogger info = new InfoLogger(); LogBase chainRoot = fatal; fatal.SetNext(error); error.SetNext(info); info.SetNext(null); chainRoot.Log("tell me why", 2); Console.WriteLine("=================="); //Question 8 GymAccessObject gymthings = new GymBase(); gymthings.Run(); //Question 10 IWindow window = new BaseWindow(); IWindow Tlatmeimad = new TlatMeimadWindow(window); IWindow super = new FlashingWindow(Tlatmeimad); Console.WriteLine(super.GetDetails()); IWindow myfavoriteWindow = new Colors(new TlatMeimadWindow(new FlashingWindow(new BaseWindow()))); Console.WriteLine(myfavoriteWindow.GetDetails()); //Question 12 ComputerFactoryMethod cf = new ComputerFactoryMethod(); Computer v1 = cf.GetComputer("Gaming"); }