Esempio n. 1
0
        /// <summary>
        ///     Outputs the <see cref="Console" /> to a file located in the <see cref="AppDomain" /> base directory.
        /// </summary>
        /// <param name="rover">A <see cref="LandRover" /> to be moved.</param>
        /// <param name="movementInstructions">A list of instructions to be passed to the <see cref="LandRover" />.</param>
        /// <param name="fileName">
        ///     The name of the file containing output strings which report the <see cref="LandRover" /> current
        ///     position after each instruction.
        /// </param>
        private static void ExecuteAndLogToFile(LandRover rover, string movementInstructions, string fileName)
        {
            FileStream file;

            if (File.Exists(fileName))
            {
                file = new FileStream($"{fileName}", FileMode.Append);
            }
            else
            {
                file = new FileStream($"{fileName}", FileMode.OpenOrCreate);
            }
            var consoleOutput = Console.Out;

            using (var sWriter = new StreamWriter(file))
            {
                //  Trace the console out to the file.
                Console.SetOut(sWriter);
                var currentPos = rover.ExecuteInstructions(movementInstructions);
                Console.WriteLine(currentPos);

                //  Restore the original console output.
                Console.SetOut(consoleOutput);
            }
        }
Esempio n. 2
0
        public void RoverTurnsLeftCorrectly(char startDirection, char expected)
        {
            var rover = new LandRover(0, 0, 0, startDirection);

            rover.TurnLeft();

            Assert.AreEqual(expected, rover.Direction);
        }
Esempio n. 3
0
        public void RoverHasProperValuesWhenCreated()
        {
            var rover = new LandRover(1, 2, 3, 'W');

            Assert.AreEqual(new[] { 1, 2 }, rover.GetCoords());
            Assert.AreEqual(3, rover.RoverId);
            Assert.AreEqual('W', rover.Direction);
        }