Пример #1
0
        public void Move_ShouldDoNothing_WhenInvalidMovement(int initX, int initY, int orientation)
        {
            //Arrange
            var    mockTable        = new Mock <RectangularTable>(5, 5);
            IRobot robot            = new ToyRobotLibrary.Robot.Robot(mockTable.Object);
            var    positionField    = robot.GetType().GetField("_position", BindingFlags.NonPublic | BindingFlags.Instance);
            var    orientationField = robot.GetType().GetField("_orientation", BindingFlags.NonPublic | BindingFlags.Instance);

            var initialPosition = new Position {
                x = initX, y = initY
            };

            positionField.SetValue(robot, initialPosition);
            orientationField.SetValue(robot, (Orientation)orientation);

            //Act
            robot.Move();

            //Assert
            Assert.Equal((Orientation)orientation, orientationField.GetValue(robot));
            Assert.NotNull(positionField.GetValue(robot));
            Assert.IsType <Position>(positionField.GetValue(robot));
            Assert.Equal(initX, (positionField.GetValue(robot) as Position).x);
            Assert.Equal(initY, (positionField.GetValue(robot) as Position).y);
        }
Пример #2
0
        public void Move_ShouldSucceed_WhenValidMovement(int initX, int initY, int orientation, int expectedX, int expectedY)
        {
            //Arrange
            var    mockTable        = new Mock <RectangularTable>(5, 5);
            IRobot robot            = new ToyRobotLibrary.Robot.Robot(mockTable.Object);
            var    positionField    = robot.GetType().GetField("_position", BindingFlags.NonPublic | BindingFlags.Instance);
            var    orientationField = robot.GetType().GetField("_orientation", BindingFlags.NonPublic | BindingFlags.Instance);
            var    isPlacedProperty = robot.GetType().GetProperty("IsPlaced", BindingFlags.Public | BindingFlags.Instance);

            positionField.SetValue(robot, new Position {
                x = initX, y = initY
            });
            orientationField.SetValue(robot, (Orientation)orientation);
            isPlacedProperty.SetValue(robot, true);

            //Act
            robot.Move();

            //Assert
            Assert.Equal((Orientation)orientation, orientationField.GetValue(robot));

            //TODO: Implement an overload of the Equals method to simplify these assertions.
            Assert.NotNull(positionField.GetValue(robot));
            Assert.IsType <Position>(positionField.GetValue(robot));
            Assert.Equal(expectedX, (positionField.GetValue(robot) as Position).x);
            Assert.Equal(expectedY, (positionField.GetValue(robot) as Position).y);
        }
Пример #3
0
        public void Move_ShouldDoNothing_IfNotYetPlaced()
        {
            //Arrange
            var    mockTable        = new Mock <RectangularTable>(5, 5);
            IRobot robot            = new ToyRobotLibrary.Robot.Robot(mockTable.Object);
            var    positionField    = robot.GetType().GetField("_position", BindingFlags.NonPublic | BindingFlags.Instance);
            var    orientationField = robot.GetType().GetField("_orientation", BindingFlags.NonPublic | BindingFlags.Instance);

            //Act
            robot.Move();

            //Assert
            Assert.Null(orientationField.GetValue(robot));
            Assert.Null(positionField.GetValue(robot));
        }