public static void ClassInitialize(TestContext context) { // Initialize Robots Robots = new Dictionary <string, IIdentifiableRobot>(); //Initialize in memory methods RobotMethodCache = new Dictionary <string, List <MethodSignature> >(); string id = null; MockNotificationRobot mockRobot = null; for (int i = 0; i < Constants.NumberOfTestRobots; i++) { id = Guid.NewGuid().ToString(); mockRobot = new MockNotificationRobot(); RobotMethodCache[id] = new List <MethodSignature>(); mockRobot.MethodCalled += (s, e) => { IIdentifiableRobot robot = Robots.Values.FirstOrDefault(x => x.Robot == s); if (robot != null) { RobotMethodCache[robot.Id].Add(e.MethodSignature); } }; Robots[id] = new IdentifiableRobot(id, Guid.NewGuid().ToString(), mockRobot); } }
public void Cache_Turn_Success() { Random random = new Random(Environment.TickCount); int robot1Index = random.Next(Constants.NumberOfTestRobots); IIdentifiableRobot identifiableRobot1 = Robots[Robots.Keys.ElementAt(robot1Index)]; Mock <IRobot> mockRobot = new Mock <IRobot>(); mockRobot.Setup(x => x.Turn(Constants.TurnAngle)); identifiableRobot1.Robot.Turn(Constants.TurnAngle); mockRobot.Object.Replay(RobotMethodCache[identifiableRobot1.Id].LastOrDefault()); mockRobot.Verify(x => x.Turn(Constants.TurnAngle), Times.Once); }