Exemple #1
0
        public void TurnDrillOn_WritesMessage()
        {
            var expectedString = "Turned drill on." + Environment.NewLine;
            var robot          = new ConsoleRobot();

            string outputString;

            using (var newOut = new StringWriter(CultureInfo.InvariantCulture))
            {
                var previousOut = Console.Out;
                Console.SetOut(newOut);

                robot.TurnDrillOn();

                Console.SetOut(previousOut);
                outputString = newOut.ToString();
            }

            Assert.That(outputString, Is.EqualTo(expectedString));
        }
Exemple #2
0
        public void Turn_WritesMessage()
        {
            const double TurnAngle       = -0.25D;
            var          expectedPattern = @"^Turned left \d+\.\d{2} degrees." + Environment.NewLine + "$";
            var          robot           = new ConsoleRobot();

            string outputString;

            using (var newOut = new StringWriter(CultureInfo.InvariantCulture))
            {
                var previousOut = Console.Out;
                Console.SetOut(newOut);

                robot.Turn(TurnAngle);

                Console.SetOut(previousOut);
                outputString = newOut.ToString();
            }

            Assert.That(outputString, Does.Match(expectedPattern));
        }
Exemple #3
0
        public void Move_WritesMessage()
        {
            const double MoveDistance   = 20.75D;
            var          expectedString = "Moved forwards 20.75 metres." + Environment.NewLine;
            var          robot          = new ConsoleRobot();

            string outputString;

            using (var newOut = new StringWriter(CultureInfo.InvariantCulture))
            {
                var previousOut = Console.Out;
                Console.SetOut(newOut);

                robot.Move(MoveDistance);

                Console.SetOut(previousOut);
                outputString = newOut.ToString();
            }

            Assert.That(outputString, Is.EqualTo(expectedString));
        }