Exemple #1
0
        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 Turn_Success()
        {
            Mock <IRobot> mockRobot = new Mock <IRobot>();

            mockRobot.Setup(x => x.Turn(It.IsAny <double>()));

            IIdentifiableRobot identifiableRobot = new IdentifiableRobot(Guid.NewGuid().ToString(), Constants.DefaultRobotName, mockRobot.Object);

            identifiableRobot.Robot.Turn(Constants.TurnAngle);

            mockRobot.Verify(x => x.Turn(Constants.TurnAngle), Times.Once);
        }
        public void Beep_Success()
        {
            Mock <IRobot> mockRobot = new Mock <IRobot>();

            mockRobot.Setup(x => x.Beep());

            IIdentifiableRobot identifiableRobot = new IdentifiableRobot(Guid.NewGuid().ToString(), Constants.DefaultRobotName, mockRobot.Object);

            identifiableRobot.Robot.Beep();

            mockRobot.Verify(x => x.Beep(), Times.Once);
        }
        public void Name_Matches_Success()
        {
            IIdentifiableRobot identifiableRobot = new IdentifiableRobot(Guid.NewGuid().ToString(), Constants.DefaultRobotName, new Mock <IRobot>().Object);

            Assert.IsTrue(identifiableRobot.Name.Equals(Constants.DefaultRobotName, StringComparison.Ordinal));
        }
 public void Ctor_NullRobot_Fails()
 {
     Mock <IRobot>      mockRobot = new Mock <IRobot>();
     IIdentifiableRobot robot     = new IdentifiableRobot(Guid.NewGuid().ToString(), Constants.DefaultRobotName, null);
 }
 public void Ctor_WhitespaceName_Fails()
 {
     Mock <IRobot>      mockRobot = new Mock <IRobot>();
     IIdentifiableRobot robot     = new IdentifiableRobot(Guid.NewGuid().ToString(), " ", mockRobot.Object);
 }
 public void Ctor_NullName_Fails()
 {
     Mock <IRobot>      mockRobot = new Mock <IRobot>();
     IIdentifiableRobot robot     = new IdentifiableRobot(Guid.NewGuid().ToString(), null, mockRobot.Object);
 }
 public void Ctor_NullId_Fails()
 {
     Mock <IRobot>      mockRobot = new Mock <IRobot>();
     IIdentifiableRobot robot     = new IdentifiableRobot(null, Constants.DefaultRobotName, mockRobot.Object);
 }