public void TestMoveOnTable() { // Create an instance to test: ToyRobot robot = new ToyRobot(); // Define a test input and output value: int x = 0; int y = 0; Facing facing = Facing.North; robot.Place(x, y, facing); // Run the method under test and verify test when facing North robot.Move(); Assert.AreEqual(robot.X, 0); Assert.AreEqual(robot.Y, 1); Assert.AreEqual(robot.Facing, Facing.North); // Run the method under test and verify test when facing East robot.GetType().GetProperty("Facing").SetValue(robot, Facing.East); robot.Move(); Assert.AreEqual(robot.X, 1); Assert.AreEqual(robot.Y, 1); Assert.AreEqual(robot.Facing, Facing.East); // Run the method under test and verify test when facing South robot.GetType().GetProperty("Facing").SetValue(robot, Facing.South); robot.Move(); Assert.AreEqual(robot.X, 1); Assert.AreEqual(robot.Y, 0); Assert.AreEqual(robot.Facing, Facing.South); // Run the method under test and verify test when facing West robot.GetType().GetProperty("Facing").SetValue(robot, Facing.West); robot.Move(); Assert.AreEqual(robot.X, 0); Assert.AreEqual(robot.Y, 0); Assert.AreEqual(robot.Facing, Facing.West); }
public void TestMoveRobotWillFallException() { // Create an instance to test: ToyRobot robot = new ToyRobot(); // Define a test input and output value: int x = 4; int y = 4; Facing facing = Facing.North; robot.Place(x, y, facing); // Run the method under test and verify test when facing North try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } // Run the method under test and verify test when facing East robot.GetType().GetProperty("Facing").SetValue(robot, Facing.East); try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } // Run the method under test and verify test when facing South robot.GetType().GetProperty("Facing").SetValue(robot, Facing.South); robot.GetType().GetProperty("Y").SetValue(robot, 0); try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } // Run the method under test and verify test when facing West robot.GetType().GetProperty("Facing").SetValue(robot, Facing.West); robot.GetType().GetProperty("X").SetValue(robot, 0); try { robot.Move(); Assert.Fail("Robot will fall"); } catch (Exception ex) { Assert.AreEqual(typeof(RobotWillFallException), ex.GetType(), ex.Message); } }