コード例 #1
0
        public void CommandsIgnoredIfRobotNotPlacedOnMap()
        {
            var driver = new RobotDriver(robot.Object);

            robot.Setup(r => r.Place(-1, -1, "NORTH")).Throws <ArgumentOutOfRangeException>();

            driver.AddCommand("PLACE -1,-1,NORTH");
            driver.AddCommand("MOVE");
            driver.AddCommand("REPORT");
            driver.AddCommand("LEFT");
            driver.AddCommand("RIGHT");

            driver.AddCommand("PLACE 1,1,NORTH");

            driver.AddCommand("MOVE");
            driver.AddCommand("REPORT");
            driver.AddCommand("LEFT");
            driver.AddCommand("RIGHT");

            driver.Drive();

            robot.Verify(r => r.Move(), Times.Once);
            robot.Verify(r => r.Report(), Times.Once);
            robot.Verify(r => r.Left(), Times.Once);
            robot.Verify(r => r.Right(), Times.Once);
            robot.Verify(r => r.Place(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()), Times.Exactly(2));
        }
コード例 #2
0
        public void CanIssuePlaceCommandToRobot()
        {
            var driver = new RobotDriver(robot.Object);

            robot.Setup(r => r.Place(0, 0, "NORTH"));

            driver.AddCommand("PLACE 0,0,NORTH");

            driver.Drive();
            robot.Verify(r => r.Place(0, 0, "NORTH"), Times.Once);
        }
コード例 #3
0
        public void CanIssueLeftCommandToRobot()
        {
            var driver = new RobotDriver(robot.Object);

            robot.Setup(r => r.Left());
            driver.AddCommand("PLACE 0,0,NORTH");

            driver.AddCommand("LEFT");

            driver.Drive();
            robot.Verify(r => r.Left(), Times.Once);
        }
コード例 #4
0
        public void CanGetReportsFromDriver()
        {
            var    driver = new RobotDriver(robot.Object);
            string report = "0,0,NORTH";

            robot.Setup(r => r.Report()).Returns(report);
            driver.AddCommand($"PLACE {report}");
            driver.AddCommand("REPORT");

            driver.Drive();

            Assert.Equal(driver.Reports.First(), report);
        }
コード例 #5
0
        public void NoCommandsIssuedUntilRobotPlaced()
        {
            var driver = new RobotDriver(robot.Object);

            driver.AddCommand("MOVE");
            driver.AddCommand("REPORT");
            driver.AddCommand("LEFT");
            driver.AddCommand("RIGHT");
            driver.AddCommand("PLACE 0,0,NORTH");

            driver.Drive();

            robot.Verify(r => r.Move(), Times.Never);
            robot.Verify(r => r.Report(), Times.Never);
            robot.Verify(r => r.Left(), Times.Never);
            robot.Verify(r => r.Right(), Times.Never);
            robot.Verify(r => r.Place(0, 0, "NORTH"), Times.Once);
        }