예제 #1
0
        public RunnerFacade()
        {
            //It is possible with DI
            var rotateLeftActionInvoker = new ActionDeciderByPositionActionInvoker(
                new RotateLeftNActionInvoker(),
                new RotateLeftSActionInvoker(),
                new RotateLeftWActionInvoker(),
                new RotateLeftEActionInvoker()
                );

            var rotaeRightActionInvoker = new ActionDeciderByPositionActionInvoker(
                new RotateRightNActionInvoker(),
                new RotateRightSActionInvoker(),
                new RotateRightWActionInvoker(),
                new RotateRightEActionInvoker()
                );

            var moveActionInvoker = new ActionDeciderByPositionActionInvoker(
                new MoveNActionInvoker(),
                new MoveSActionInvoker(),
                new MoveWActionInvoker(),
                new MoveEActionInvoker()
                );

            var singleCommandInvoker = new SingleCommandInvoker(moveActionInvoker, rotateLeftActionInvoker, rotaeRightActionInvoker);

            commandInvoker = new MultipleCommandInvoker(singleCommandInvoker);
        }
        public void Move_IfCommandR_CallRActionInvoker()
        {
            var instance = new SingleCommandInvoker(MActionInvoker.Object, LActionInvoker.Object, RActionInvoker.Object);

            instance.Move("R", null);

            MActionInvoker.Verify(x => x.Move(null), Times.Never);
            LActionInvoker.Verify(x => x.Move(null), Times.Never);
            RActionInvoker.Verify(x => x.Move(null), Times.Once);
        }
        public void Move_IfCommandUnKnown_ThrowsException()
        {
            var instance = new SingleCommandInvoker(MActionInvoker.Object, LActionInvoker.Object, RActionInvoker.Object);

            Assert.ThrowsException <System.Exception>(() => instance.Move("XYZ", null));
        }
        public void Move_IfCommandNull_ThrowsException()
        {
            var instance = new SingleCommandInvoker(MActionInvoker.Object, LActionInvoker.Object, RActionInvoker.Object);

            Assert.ThrowsException <System.ArgumentNullException>(() => instance.Move(null, null));
        }