Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var invoker   = new ModifyRectangleSize();
            var rectangle = new Rectangle();

            var setHeight20Command = new SetHeightCommand(rectangle, 20);
            var setHeight30Command = new SetHeightCommand(rectangle, 30);
            var setWidth20Command  = new SetWidthCommand(rectangle, 20);

            invoker.SetCommand(setHeight20Command);
            invoker.Invoke();
            invoker.SetCommand(setWidth20Command);
            invoker.Invoke();
            invoker.SetCommand(setHeight30Command);
            invoker.Invoke();

            Console.ReadLine();
        }
        public void MultipleCommandInvoke_ShouldSetCorrectValue()
        {
            var rectangle = new Rectangle();

            var setHeight20Command = new SetHeightCommand(rectangle, 20);
            var setHeight30Command = new SetHeightCommand(rectangle, 30);
            var setWidth20Command  = new SetWidthCommand(rectangle, 20);

            _invoker.SetCommand(setHeight20Command);
            _invoker.Invoke();
            _invoker.SetCommand(setWidth20Command);
            _invoker.Invoke();
            _invoker.SetCommand(setHeight30Command);
            _invoker.Invoke();

            Assert.Equal(30, rectangle.Height);
            Assert.Equal(20, rectangle.Width);
        }
        public void WidthUndo_ShouldUndoLastCommand()
        {
            var rectangle         = new Rectangle();
            var setWidth20Command = new SetWidthCommand(rectangle, 20);
            var setWidth30Command = new SetWidthCommand(rectangle, 30);


            _invoker.SetCommand(setWidth20Command);
            _invoker.Invoke();
            _invoker.SetCommand(setWidth30Command);
            _invoker.Invoke();

            Assert.Equal(30, rectangle.Width);

            setWidth30Command.Undo();
            _invoker.Invoke();

            Assert.Equal(20, rectangle.Width);
        }