Ejemplo n.º 1
0
        public void TestOnCancel()
        {
            _changeLedAsyncCount = 0;
            Mock <IRobotMessenger> robotMessengerMock = new Mock <IRobotMessenger>();
            UnitTestExampleSkill   moqExampleSkill    = new UnitTestExampleSkill();

            IRobotCommandResponse successfulActionResponse = new RobotCommandResponse
            {
                ResponseType = MessageType.ActionResponse,
                Status       = ResponseStatus.Success
            };

            //Setup mock to ensure Change LED Async has been called the appropriate amount of times
            robotMessengerMock.Setup
            (
                x => x.ChangeLEDAsync
                (
                    It.IsAny <uint>(),
                    It.IsAny <uint>(),
                    It.IsAny <uint>()
                )
            ).Returns(Task.Factory.StartNew(() =>
            {
                ++_changeLedAsyncCount;
                return(successfulActionResponse);
            }).AsAsyncOperation());

            //Load mock messenger into skill
            moqExampleSkill.LoadRobotConnection(robotMessengerMock.Object);

            //OnCancel will trigger the skill's cancellation
            moqExampleSkill.OnCancel(this, null);

            //Test
            Assert.IsTrue(_changeLedAsyncCount == 1);
        }