예제 #1
0
 public void Init()
 {
     _commandRecorder     = new CommandRecorder();
     _robotCommandHandler = new RobotCommandHandler(_commandRecorder);
     _replayRobotCommand  = new ReplayRobotCommand(_robotCommandHandler);
     _beepRobotCommand    = new BeepRobotCommand(_commandRecorder);
     _moveRobotCommand    = new MoveRobotCommand(_commandRecorder);
     _turnRobotCommand    = new TurnRobotCommand(_commandRecorder);
     _robot = MockRepository.GenerateStub <IRobot>();
 }
예제 #2
0
        static void Main(string[] args)
        {
            ICommandRecorder    commandRecorder     = new CommandRecorder();
            RobotCommandHandler robotCammandHandler = new RobotCommandHandler(commandRecorder);
            RobotCommandType    drawingCommand      = RobotCommandType.None;

            Console.WriteLine("Welcome to the Mock Robot Interface:");
            Console.WriteLine("'Move' command will move Robot A. Syntax: M <Distance in Decimal number> Example: M 10.3");
            Console.WriteLine("'Turn' command will Turn Robot A. Syntax: T <Angle in Decimal number> Eg: T 45.8");
            Console.WriteLine("'Beep' command will Beep Robot A. Syntax: B");
            Console.WriteLine("'Replay' command will replay all the past commands sent to Robot A on Robot B. Syntax: R");
            Console.WriteLine("'Quit' command syntax not matched. Syntax: Q");
            do
            {
                IRobot robotA = new MockRobotA();
                IRobot robotB = new MockRobotB();
                IRobot robot;
                try
                {
                    Console.Write("Enter Command: ");
                    var commandStr = Console.ReadLine();
                    if (commandStr != null && commandStr.Trim().ToUpper() == "R")
                    {
                        robot = robotB;
                    }
                    else
                    {
                        robot = robotA;
                    }

                    drawingCommand = RobotCommandType.None;
                    try
                    {
                        drawingCommand = robotCammandHandler.Run(robot, commandStr);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            } while (drawingCommand != RobotCommandType.Quit);
            Console.WriteLine("Press a key to Quit");
            Console.ReadKey();
        }
예제 #3
0
        public void GetCommandAsListNegativeTest(string str)
        {
            var ex = Assert.Throws(typeof(ArgumentException), () => RobotCommandHandler.GetCommandAsList(str));

            Assert.That(ex.Message, Is.EqualTo("Invalid command. Command cannot be blank."));
        }
예제 #4
0
 public void GetCommandAsListPositiveTest(string str, List <string> result)
 {
     Assert.AreEqual(RobotCommandHandler.GetCommandAsList(str), result);
 }
예제 #5
0
 public void Init()
 {
     _commandRecorder     = new CommandRecorder();
     _robotCommandHandler = new RobotCommandHandler(_commandRecorder);
     _robot = MockRepository.GenerateStub <IRobot>();
 }