static void Command() { SimpleRemoteControl remote = new SimpleRemoteControl(); remote.SetCommand(new LightOnCommand(new Light())); remote.ButtonWasPressed(); remote.SetCommand(new StereoCommand(new Stereo())); remote.ButtonWasPressed(); }
public void ButtonWasPressed_ForLight_LightIsOn() { // Arrange var light = new Light(); var lightOn = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOn); // Act string actual = simpleRemoteControl.ButtonWasPressed(); // Assert Assert.That(actual, Is.EqualTo("Light is On")); }
public void Quando_eu_pressionar_o_botao_de_ligar() { //arrange var simpleRemoteControl = new SimpleRemoteControl(new List <ICommand>(7) { new LightOnCommand(new Light()), new NoCommand(), new NoCommand(), new NoCommand(), new NoCommand(), new NoCommand(), new NoCommand() }, new List <ICommand>(7) { new LightOffCommand(new Light()), new NoCommand(), new NoCommand(), new NoCommand(), new NoCommand(), new NoCommand(), new NoCommand() }, new NoCommand()); //action simpleRemoteControl.SetCommand(0, new LightOnCommand(new Light()), new LightOffCommand(new Light())); simpleRemoteControl.OnButtonWasPressed(0); simpleRemoteControl.OffButtonWasPressed(0); }
public void Command_pattern_test() { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); Stereo stereo = new Stereo(); //we can change command dynamically remote.SetCommand(new LightOnCommand(light)); string actualValueLight = remote.ButtonWasPressed(); remote.SetCommand(new StereoOnWithDVDCommand(stereo)); string actualValueStereo = remote.ButtonWasPressed(); Assert.AreEqual(actualValueLight, "Light is on"); Assert.AreEqual(actualValueStereo, "Stereo is on All set to set DVD"); }
public void Test() { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); Stereo stereo = new Stereo(); // we can change command dynamically remote.SetCommand(new LightOnCommand(light)); remote.ButtonWasPressed(); remote.SetCommand(new StereoOnWithCDCommand(stereo)); remote.ButtonWasPressed(); remote.SetCommand(new StereoOffCommand(stereo)); remote.ButtonWasPressed(); Assert.True(true); }
public void Load() { SimpleRemoteControl remoteControl = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remoteControl.SetCommand(lightOn); remoteControl.ButtonWasPressed(); GarageDoor garageDoor = new GarageDoor(); GarageDoorUpCommand garageDoorOpenCommand = new GarageDoorUpCommand(garageDoor); remoteControl.SetCommand(garageDoorOpenCommand); remoteControl.ButtonWasPressed(); }
public static void Main(string[] args) { Console.Clear(); Console.WriteLine(); Console.WriteLine("Chapter6 - Command"); Console.WriteLine(); SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonWasPressed(); RemoteControl rc = new RemoteControl(); Console.WriteLine(rc.ToString()); Light lightInBedroom = new Light(); LightOnCommand lightInBedroom_OnCommand = new LightOnCommand(lightInBedroom); LightOffCommand lightInBedroom_OffCommand = new LightOffCommand(lightInBedroom); Stereo myStereo = new Stereo(); StereoOnWithCDCommand myStereo_On = new StereoOnWithCDCommand(myStereo); StereoOffWithCDCommand myStereo_Off = new StereoOffWithCDCommand(myStereo); CeilingFan fan = new CeilingFan("Living room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(fan); MacroCommand macroCommand_On = new MacroCommand(new ICommand[] { lightInBedroom_OnCommand, myStereo_On, ceilingFanHighCommand }); MacroCommand macroCommand_Off = new MacroCommand(new ICommand[] { lightInBedroom_OffCommand, myStereo_Off, ceilingFanOffCommand }); rc.SetCommand(0, lightInBedroom_OnCommand, lightInBedroom_OffCommand); rc.SetCommand(1, myStereo_On, myStereo_Off); rc.SetCommand(2, ceilingFanHighCommand, ceilingFanOffCommand); rc.SetCommand(6, macroCommand_On, macroCommand_Off); Console.WriteLine(rc.ToString()); rc.OnButtonWasPressed(0); rc.OnButtonWasPressed(1); rc.OffButtonWasPressed(0); rc.UndoButtonWasPressed(); rc.OnButtonWasPressed(2); rc.UndoButtonWasPressed(); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Call macro command"); rc.OnButtonWasPressed(6); rc.OffButtonWasPressed(6); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Macro command finished"); Console.WriteLine(); Console.WriteLine(rc.ToString()); Console.ReadKey(); }
public void TestTurningSimpleOn()//Command Pattern Client { //Command Pattern Invoker SimpleRemoteControl remote = new SimpleRemoteControl(); //Command Pattern Receivers Light light = new Light("Kitchen"); GarageDoor garageDoor = new GarageDoor(""); //Commands for the receivers LightOnCommand lightOn = new LightOnCommand(light); GarageDoorUpCommand garageDoorOpen = new GarageDoorUpCommand(garageDoor); //Passing the light on command to the invoker remote.SetCommand(lightOn); //Simulate the button being pressed on the invoker Assert.AreEqual("Kitchen light is on", remote.ButtonWasPressed()); //Passing the garage door open command to the invoker remote.SetCommand(garageDoorOpen); //Simulate the button being pressed on the invoker Assert.AreEqual("Garage door is up", remote.ButtonWasPressed()); }
static void TrySimpleRemoteControl() { Console.WriteLine("\n----- Simple remote control -----\n"); var simpleRemoteControl = new SimpleRemoteControl(); var light = new Light("Living room"); var lightsOnCommand = new LightsOnCommand(light); simpleRemoteControl.SetCommand(lightsOnCommand); simpleRemoteControl.PressTheButton(); var garageDoor = new GarageDoor(); var garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoor); simpleRemoteControl.SetCommand(garageDoorOpenCommand); simpleRemoteControl.PressTheButton(); }
private static void Command() { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonWasPressed(); LightOffCommand lightOff = new LightOffCommand(light); remote.SetCommand(lightOff); remote.ButtonWasPressed(); Console.ReadKey(); }
public static void Run() { // Invoker SimpleRemoteControl remote = new SimpleRemoteControl(); // Receiver Light light = new Light(); // Command LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonWasPressed(); GarageDoor garageDoor = new GarageDoor(); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); remote.SetCommand(garageOpen); remote.ButtonWasPressed(); }
private static void CommandGeneric() { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); TV tv = new TV(); Radio radio = new Radio(); var lightOn = new Command <Light>(light, l => l.TurnOn()); var lightOff = new Command <Light>(light, l => l.TurnOff()); var securityLightOn = new Command <Light>(light, l => l.TurnOn()); var securityLightOff = new Command <Light>(light, l => l.TurnOff()); var tvOn = new Command <TV>(tv, l => l.TurnOn()); var tvOff = new Command <TV>(tv, l => l.TurnOff()); var radioOn = new Command <Radio>(radio, l => l.TurnOn()); var radioOff = new Command <Radio>(radio, l => l.TurnOff()); remote.SetCommand(lightOn); remote.ButtonWasPressed(); remote.SetCommand(lightOff); remote.ButtonWasPressed(); //----------------------------- remote.SetCommand(securityLightOn); remote.ButtonWasPressed(); remote.SetCommand(securityLightOff); remote.ButtonWasPressed(); //----------------------------- remote.SetCommand(tvOn); remote.ButtonWasPressed(); remote.SetCommand(tvOff); remote.ButtonWasPressed(); //----------------------------- remote.SetCommand(radioOn); remote.ButtonWasPressed(); remote.SetCommand(radioOff); remote.ButtonWasPressed(); Console.ReadKey(); }
static void Main() { var remote = new SimpleRemoteControl(); var light = new Light(); var garageDoor = new GarageDoor(); var ceilingFan = new CeilingFan(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var garageDoorOpen = new GarageDoorOpenCommand(garageDoor); var garageDoorClose = new GarageDoorCloseCommand(garageDoor); var ceilingFanTurnOn = new CeilingFanTurnOnHighCommand(ceilingFan); var ceilingFanTurnOff = new CeilingFanTurnOffCommand(ceilingFan); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageDoorOpen, garageDoorClose); remote.SetCommand(2, ceilingFanTurnOn, ceilingFanTurnOff); Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.OffButtonWasPressed(0); remote.OnButtonWasPressed(1); remote.OffButtonWasPressed(1); remote.OnButtonWasPressed(2); //remote.OffButtonWasPressed(2); remote.UndoButtonWasPressed(); //remote.UndoButtonWasPressed(); //remote.UndoButtonWasPressed(); Console.ReadKey(); }
static void Main(string[] args) { Remote remote = new Remote(); Light livingroomlight = new Light("livingroom"); LightOnCommand livingroomlighton = new LightOnCommand(livingroomlight); LightOffCommand livingroomlightoff = new LightOffCommand(livingroomlight); remote.SetCommand(0, livingroomlighton, livingroomlightoff); remote.OnButtonWasPushed(0); //livingroom light is on SimpleRemoteControl remote2 = new SimpleRemoteControl(); remote2.SetCommand(livingroomlighton); remote2.ButtonWasPressed(); //livingroom light is on string z = Console.ReadLine(); }
static void Main(string[] args) // Client { // Example 1 SimpleRemoteControl remote = new SimpleRemoteControl(); // Invoker LightBulb light = new LightBulb(); // Receiver LightOnCommand lightOnCommand = new LightOnCommand(light); // Command remote.SetCommand(lightOnCommand); remote.ButtonWasPressed(); remote.UndoButtonWasPressed(); // Example 2 AdvancedRemote remote2 = new AdvancedRemote(); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo(); GarageDoorUpCommand garageDoorUpCommand = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDownCommand = new GarageDoorDownCommand(garageDoor); StereoOnCommand stereoOnCommand = new StereoOnCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); remote2.SetCommand(0, garageDoorUpCommand, garageDoorDownCommand); remote2.SetCommand(1, stereoOnCommand, stereoOffCommand); remote2.OnButtonWasPressed(0); remote2.OnButtonWasPressed(1); remote2.OffButtonWasPressed(0); remote2.OffButtonWasPressed(1); remote2.UndoButtonWasPressed(); // Example 3 AdvancedRemote remote3 = new AdvancedRemote(); Fan fan = new Fan(); FanHighCommand fanHighCommand = new FanHighCommand(fan); FanMeduimCommand fanMeduimCommand = new FanMeduimCommand(fan); FanLowCommand fanLowCommand = new FanLowCommand(fan); FanOffCommand fanOffCommand = new FanOffCommand(fan); // Remote from Example 2 Reused remote3.SetCommand(0, fanHighCommand, fanOffCommand); remote3.SetCommand(1, fanMeduimCommand, fanOffCommand); remote3.OnButtonWasPressed(0); // High remote3.OffButtonWasPressed(0); // Off remote3.UndoButtonWasPressed(); // Back To High // Example 4 RoomTV roomTV = new RoomTV(); HotTub hotTub = new HotTub(); HotTubOnCommand hotTubOnCommand = new HotTubOnCommand(hotTub); TVOnCommand tvOnCommand = new TVOnCommand(roomTV); Command[] PartyCommands = new Command[2]; PartyCommands[0] = hotTubOnCommand; PartyCommands[1] = tvOnCommand; MacroCommand macroCommand = new MacroCommand(PartyCommands); // Put All Commands in this MacroCommand AdvancedRemote remote4 = new AdvancedRemote(); remote4.SetCommand(0, macroCommand, new NoCommand()); // No Command for Off Button remote4.OnButtonWasPressed(0); }