Exemplo n.º 1
0
        public void RobotOperator_ShouldThrowException_WhenPassedNullReporter()
        {
            //Arrange
            IRobotOperator robotOperator;
            Mock <IRobot>  mockRobot = new Mock <IRobot>();
            //Act
            var ex = Record.Exception(() => robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, null));

            //Assert
            Assert.NotNull(ex);
            Assert.IsType <ArgumentNullException>(ex);
            Assert.Contains("Must provide or inject object implementing IReporter", ex.Message);
        }
Exemplo n.º 2
0
        public void RobotOperator_ShouldSucceed_WhenPassedValidArguments()
        {
            //Arrange
            Mock <IRobot>    mockRobot    = new Mock <IRobot>();
            Mock <IReporter> mockReporter = new Mock <IReporter>();

            //Act
            IRobotOperator robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);

            //Assert
            Assert.NotNull(robotOperator);
            Assert.IsAssignableFrom <IRobotOperator>(robotOperator);
            Assert.IsType <ToyRobotLibrary.RobotOperator.RobotOperator>(robotOperator);
        }
Exemplo n.º 3
0
        public void InterpretInstruction_MOVE_ShouldNotBeCalled_WhenRobotIsNotPlaced()
        {
            //Arrange
            Instruction   instruction = Instruction.MOVE;
            Mock <IRobot> mockRobot   = new Mock <IRobot>();

            mockRobot.Setup(robot => robot.IsPlaced).Returns(false);
            Mock <IReporter> mockReporter  = new Mock <IReporter>();
            IRobotOperator   robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);

            //Act
            robotOperator.InterpretInstruction(instruction);

            //Assert
            mockRobot.Verify(robot => robot.Move(), Times.Never());
        }
Exemplo n.º 4
0
        public void InterpretInstruction_Place_ThrowsException_WithIncorrectNumberOfArgs()
        {
            //Arrange
            Instruction   instruction = Instruction.PLACE;
            Mock <IRobot> mockRobot   = new Mock <IRobot>();

            mockRobot.Setup(robot => robot.IsPlaced).Returns(true);
            Mock <IReporter> mockReporter  = new Mock <IReporter>();
            IRobotOperator   robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);
            //Act
            Exception ex = Record.Exception(() => robotOperator.InterpretInstruction(instruction, new object[] { "Just the one argument here, buddy." }));

            //Assert
            Assert.NotNull(ex);
            Assert.IsType <ArgumentException>(ex);
            Assert.Contains("Expected 3 arguments; instead received 1", ex.Message);
        }
Exemplo n.º 5
0
        public void InterpretInstruction_Place_ThrowsException_WithNoArgs()
        {
            //Arrange
            Instruction   instruction = Instruction.PLACE;
            Mock <IRobot> mockRobot   = new Mock <IRobot>();

            mockRobot.Setup(robot => robot.IsPlaced).Returns(true);
            Mock <IReporter> mockReporter  = new Mock <IReporter>();
            IRobotOperator   robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);
            //Act
            Exception ex = Record.Exception(() => robotOperator.InterpretInstruction(instruction));

            //Assert
            Assert.NotNull(ex);
            Assert.IsType <ArgumentNullException>(ex);
            Assert.Contains("Place command requires 3 arguments.", ex.Message);
        }
Exemplo n.º 6
0
        [InlineData("-1", "-1", (Orientation)7)]   //Even invalid Orientations work
        public void InterpretInstruction_Place_ShouldBeCalled_WithCorrectNumberOfArgs(string x, string y, Orientation orientation)
        {
            //Arrange
            Instruction   instruction = Instruction.PLACE;
            Mock <IRobot> mockRobot   = new Mock <IRobot>();

            mockRobot.Setup(robot => robot.IsPlaced).Returns(true);
            Mock <IReporter> mockReporter      = new Mock <IReporter>();
            IRobotOperator   robotOperator     = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);
            string           orientationString = orientation.ToString();

            //Act
            robotOperator.InterpretInstruction(instruction, new object[] { x, y, orientation.ToString() });

            //Assert
            mockRobot.Verify(robot => robot.Place(It.IsAny <Position>(), orientation), Times.Once());
        }
Exemplo n.º 7
0
        public void InterpretInstruction_RIGHT_ShouldBeCalled_WhenRobotIsPlaced()
        {
            //Arrange
            Instruction   instruction = Instruction.RIGHT;
            Mock <IRobot> mockRobot   = new Mock <IRobot>();

            mockRobot.Setup(robot => robot.IsPlaced).Returns(true);
            Mock <IReporter> mockReporter  = new Mock <IReporter>();
            IRobotOperator   robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);

            //Act
            robotOperator.InterpretInstruction(instruction);

            //Assert
            mockRobot.Verify(robot => robot.IsPlaced, Times.Once());
            mockRobot.Verify(robot => robot.Rotate(SpinDirection.RIGHT), Times.Once());
        }
Exemplo n.º 8
0
        public void InterpretInstruction_REPORT_ShouldBeCalled_WhenRobotIsPlaced()
        {
            //Arrange
            Instruction   instruction = Instruction.REPORT;
            Mock <IRobot> mockRobot   = new Mock <IRobot>();

            mockRobot.Setup(robot => robot.GetOrientation()).Returns(Orientation.NORTH);
            mockRobot.Setup(robot => robot.IsPlaced).Returns(true);
            Mock <IReporter> mockReporter  = new Mock <IReporter>();
            IRobotOperator   robotOperator = new ToyRobotLibrary.RobotOperator.RobotOperator(mockRobot.Object, mockReporter.Object);

            //Act
            robotOperator.InterpretInstruction(instruction);

            //Assert
            mockRobot.Verify(robot => robot.IsPlaced, Times.Once());
            mockRobot.Verify(robot => robot.GetPosition(), Times.Once());
            mockRobot.Verify(robot => robot.GetOrientation(), Times.Once());
            mockReporter.Verify(reporter => reporter.Report(It.IsAny <Position>(), It.IsAny <Orientation>()), Times.Once());
        }