Exemple #1
0
        public void Set_Unit_Door_Open_Should_Send_One_Event_To_EventStore()
        {
            DoorOpenCommand cmd = new DoorOpenCommand(Guid.NewGuid());

            var p = new Domain.Unit(cmd.UnitId, moqEventMetadata.Object, moqEventStore.Object).DoorOpen(eventMetadata, moqEventStore.Object, cmd);

            moqEventStore.Verify(m => m.SaveEvents(It.IsAny <CompositeAggregateId>(), It.IsAny <IEnumerable <IEvent> >()), Times.Exactly(1));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            #region SimpleRemoteControl
            //var remote = new SimpleRemoteControl();

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

            //remote.Slot = lightOn;
            //remote.ButtonWasPressed();

            //Console.WriteLine("-----------------------------------------------------------");

            //var doorOpen = new DoorOpenCommand(new Door());

            //remote.Slot = doorOpen;
            //remote.ButtonWasPressed();
            #endregion

            #region RemoteControl
            var remote         = new RemoteControl();
            var light          = new Light();
            var lightOn        = new LightOnCommand(light);
            var lightOff       = new LightOffCommand(light);
            var door           = new Door();
            var doorOpen       = new DoorOpenCommand(door);
            var doorClose      = new DoorCloseCommand(door);
            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, doorOpen, doorClose);
            remote.SetCommand(2, stereoOnWithCD, stereoOff);

            Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
            remote.OnButtonWasPressed(2);
            remote.OffButtonWasPressed(2);
            remote.UndoButtonWasPressed();
            #endregion

            Console.ReadKey();
        }
Exemple #3
0
        /// <summary>
        /// 将请求封装成对象 以便使用不同的请求,队列或日志
        /// 来参数化其他对象 命令模式也支持可撤销的操作
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //相当于命令的调用者 会传入一个命令对象 可以用来发送请求
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light light = new Light();
            Door  door  = new Door();

            //创建打开电灯动作的类 并传入接收者light
            LightOnCommand  lightOn  = new LightOnCommand(light);
            DoorOpenCommand doorOpen = new DoorOpenCommand(door);

            remote.SetCommand(lightOn);
            remote.ButtonWasPressed();

            remote.SetCommand(doorOpen);
            remote.ButtonWasPressed();

            Console.ReadKey();
        }
Exemple #4
0
        public ICommand CreateRandomCommand()
        {
            Random random    = new Random();
            int    randomInt = random.Next(1, 4);

            ICommand createdCommand = null;

            switch (randomInt)
            {
            case 1:
                createdCommand = new GenericCommand(_lastId, DateTime.Now, "Just a random generic command");
                break;

            case 2:
                createdCommand = new DoorOpenCommand(_lastId, DateTime.Now, "Just a random door open command", 100);
                break;

            case 3:
                createdCommand = new TempAlertCommand(_lastId, DateTime.Now, "Just a random temp alertcommand", 35, 30);
                break;
            }
            _lastId++;
            return(createdCommand);
        }