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);
        }
示例#2
0
        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();
        }
示例#3
0
        private void Button1_Click(object sender, EventArgs e)
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light          light       = new Light();
            LightOnCommand lightOn     = new LightOnCommand(light);

            remote.setCommand(lightOn);
            salida.Text = remote.buttonWasPressed();
        }
示例#4
0
        static void Command()
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();

            remote.SetCommand(new LightOnCommand(new Light()));
            remote.ButtonWasPressed();
            remote.SetCommand(new StereoCommand(new Stereo()));
            remote.ButtonWasPressed();
        }
示例#5
0
        static void Main(string[] args)
        {
            var remoteControl  = new SimpleRemoteControl();
            var light          = new Light();
            var lightOnCommand = new LightOnCommand(light);

            remoteControl.setCommand(lightOnCommand);
            remoteControl.buttonWasPressed();
        }
示例#6
0
        public void Run()
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();

            remote.Slot = new LightOnCommand(new Light());
            remote.ButtonPressed();

            remote.Slot = new GarageDoorOpenCommand(new Garage());
            remote.ButtonPressed();
        }
示例#7
0
        public void TestCommand()
        {
            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();
        }
    public static void User()
    {
        var remote         = new SimpleRemoteControl();
        var light          = new Light();
        var lightOnCommand = new LightOnCommand(light);

//        remote.SetCommand(lightOnCommand);
//        remote.ButtonWasPressed();

        var garageDoorOpen        = new GarageDoorOpen();
        var garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoorOpen);

        remote.ButtonWasPressed();
    }
示例#9
0
        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();
        }
示例#10
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 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 Run()
        {
            var remote = new SimpleRemoteControl();

            var light   = new Light();
            var lightOn = new LightOnCommand(light);

            remote.Command = lightOn;
            remote.ButtonWesPressed();

            var garageDoor     = new GarageDoor();
            var garageDoorOpen = new GarageDoorOpenCommand(garageDoor);

            remote.Command = garageDoorOpen;
            remote.ButtonWesPressed();
        }
示例#13
0
        static void Main(string[] args)
        {
            SimpleRemoteControl simpleRemoteControl = new SimpleRemoteControl();
            Light          light          = new Light();
            LightOnCommand lightOnCommand = new LightOnCommand(light);

            simpleRemoteControl.Command = lightOnCommand;

            simpleRemoteControl.PressButton();

            LightOffCommand lightOffCommand = new LightOffCommand(light);

            simpleRemoteControl.Command = lightOffCommand;

            simpleRemoteControl.PressButton();
        }
示例#14
0
        private static string ProcessSimpleRemote()
        {
            StringBuilder       sb                      = new StringBuilder();
            SimpleRemoteControl remote                  = new SimpleRemoteControl();
            Light                 light                 = new Light();
            LightOnCommand        lightOn               = new LightOnCommand(light);
            GarageDoor            garageDoor            = new GarageDoor();
            GarageDoorOpenCommand garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoor);

            remote.Slot = lightOn;
            sb.AppendLine(remote.ButtonWasPressed());
            remote.Slot = garageDoorOpenCommand;
            sb.AppendLine(remote.ButtonWasPressed());

            return(sb.ToString());
        }
示例#15
0
        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();
        }
示例#16
0
        static void Main(string[] args)
        {
            var remote = new SimpleRemoteControl();

            var light = new Light();

            var lightOnCommand  = new LightOnCommand(light);
            var lightOffCommand = new LightOffCommand(light);

            remote.SetOnCommand(lightOnCommand);
            remote.ButtonOnWasPressed();
            remote.Undo();

            remote.SetOffCommand(lightOffCommand);
            remote.ButtonOffWasPressed();
            remote.Undo();
        }
        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());
        }
示例#18
0
        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();
        }
示例#19
0
        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();
        }
示例#20
0
        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();
        }
示例#21
0
        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();
        }
 public void SetUp()
 {
     simpleRemoteControl = new SimpleRemoteControl();
 }
示例#23
0
        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);
        }