コード例 #1
0
        public void AndTheCommandIsMoveForwardThenRoverMovedForwardWithLogging()
        {
            _roverDecorator.ProcessCommand(Command.MoveForward);

            _rover.Received(1).MoveForward();
            _logger.Received(1).Log("Rover moved forward.");
            _logger.Received(1).Log(Arg.Is <string>(s => s.StartsWith("Rover is at ")));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NoahCKnox/MarsRover
        static void Main(string[] args)
        {
            Rover theRover = new Rover();

            var     executingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var     path      = executingDirectory + "\\logger.txt";
            ILogger theLogger = new Logger(path);

            RoverDecorator rover = new RoverDecorator(theRover, theLogger);

            Console.WriteLine("Hi, welcome to the Mars Rover!");
            Command command = Command.Unknown;

            do
            {
                Console.WriteLine("Please enter a valid command: Move (F)orward, Move (B)ackward, Turn (L)eft, Turn (R)ight, or (Q)uit.");
                string input = Console.ReadLine();
                command = CommandParser.ParseCommand(input);
                if (command == Command.Unknown)
                {
                    System.Console.WriteLine("Invalid command!");
                }
                else
                {
                    rover.ProcessCommand(command);
                }
            } while (command != Command.Quit);

            Console.WriteLine($"Rover is at {theRover.X} , {theRover.Y} facing {theRover.Orientation}");
            Process.Start("notepad.exe", path);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a full path for logging. Press enter to use a default file.");
            var path = Console.ReadLine();

            ILogger logger           = CreateLogger(path);
            var     roverDecorator   = new RoverDecorator(new Rover(), logger);
            var     commandConverter = new UserInputToCommandConverter();
            Command command          = Command.Unknown;

            while (command != Command.Quit)
            {
                Console.WriteLine(roverDecorator.FormatRover());
                Console.WriteLine("Enter a valid command:");
                Console.WriteLine("Move (F)orward, Move (B)ackward, Turn (L)eft, Turn (R)ight, (Q)uit");
                var input = Console.ReadLine();
                command = commandConverter.ConvertToCommand(input);
                if (command == Command.Unknown)
                {
                    Console.WriteLine("Wasn't able to parse " + input + " as a valid command.");
                }
                else
                {
                    roverDecorator.ProcessCommand(command);
                }
            }
        }
コード例 #4
0
        public void AndTheCommandIsMoveForwardThenRoverMovedForward()
        {
            _decorator.ProcessCommand(Command.MoveForward);

            _rover.Verify(x => x.MoveForward(), Times.Once());
        }