private void TestTVInfoButtons(String command, String channel, Action <Mock <ITVInfoRemote> > setup, Action <Mock <ITVInfoRemote> > verify)
        {
            Dictionary <String, String> inputVals = new Dictionary <string, string>
            {
                { "Command", "remote" },
                { "remoteButton", command },
                { "channel", channel },
            };
            Mock <ITVInfoRemote> remote = SetupRemote <ITVInfoRemote>("Channel Remote");

            setup(remote);
            SetupRemote <IVolumeController>("Volume Remote");
            IOInterfaceReference ref2 = new IOInterfaceReference();

            ref2.Properties.Single(r => r.Name.Equals("References")).Setter("Channel Remote");
            ref2.Properties.Single(r => r.Name.Equals("Tag")).Setter("Channel");
            IOInterfaceReference ref3 = new IOInterfaceReference();

            ref3.Properties.Single(r => r.Name.Equals("References")).Setter("Volume Remote");
            List <IOInterfaceReference> refs = new List <IOInterfaceReference>
            {
                ref2,
                ref3,
            };

            CurrentConversation = new RemoteConversation(GetConfigurationManager(), refs);

            Assert.AreEqual("OK", RunSingleConversation <RemoteConversation>(inputVals));

            verify(remote);
        }
        public void FullConstructor()
        {
            IOInterfaceReference reference = new IOInterfaceReference("DNE Tag", "DNE IO Interface", GetConfigurationManager());

            Assert.AreEqual("DNE Tag", reference.Tag);
            Assert.AreEqual("DNE IO Interface", reference.Name);
        }
示例#3
0
        private void TurnToChannelTest(GameState?gameState, bool isOnTV, bool includesRemotes, String expectedResponse)
        {
            Dictionary <String, String> expectedParams = new Dictionary <string, string>
            {
                { "Command", "baseball" },
                { "Parameter", "TurnToGame" },
                { "Time", "DayOfWeek=today;" },
                { "Team", "mockteam" },
            };
            Mock <IBaseballSensor> sensor = new Mock <IBaseballSensor>(MockBehavior.Strict);

            sensor.Setup(s => s.IsValid).Returns(true);
            sensor.Setup(s => s.Teams).Returns(_mockTeams);
            sensor.Setup(s => s.League).Returns("MLB");
            if (gameState.HasValue)
            {
                List <String> channels = new List <string>();
                if (isOnTV)
                {
                    channels.Add("ESPN");
                }
                BaseballGame game = CreateBaseballGame(gameState.Value, 5, 2, true, channels);
                sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame> {
                    game
                });
            }
            else
            {
                sensor.Setup(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0])).Returns(new List <BaseballGame>());
            }
            AddComponentToConfigurationManager(sensor.Object);
            List <IOInterfaceReference> references = new List <IOInterfaceReference>();
            Mock <ITVRemote>            remote     = new Mock <ITVRemote>(MockBehavior.Strict);
            Semaphore channelTurn = new Semaphore(0, 1);

            if (includesRemotes)
            {
                remote.Setup(s => s.Name).Returns("Mock Name");
                remote.Setup(s => s.GetChannels()).Returns(new List <String> {
                    "ESPN"
                });
                remote.Setup(s => s.SendChannel("ESPN")).Callback(() => channelTurn.Release());
                AddComponentToConfigurationManager(remote.Object);
                IOInterfaceReference remoteRef = new IOInterfaceReference();
                remoteRef.Properties.Single(s => s.Name.Equals("References")).Setter("Mock Name");
                references.Add(remoteRef);
            }
            CurrentConversation = new BaseballConversation(GetConfigurationManager(), references);

            Assert.AreEqual(expectedResponse, RunSingleConversation <BaseballConversation>(expectedParams));

            sensor.Verify(s => s.LoadScoresForTeam(It.IsAny <DateTime>(), _mockTeams[0]), Times.Exactly(1));
            if (includesRemotes)
            {
                channelTurn.WaitOne();
                remote.Verify(s => s.SendChannel("ESPN"), Times.Exactly(1));
            }
        }
        public void PropertiesCorrectlySet()
        {
            IOInterfaceReference reference = new IOInterfaceReference();

            reference.Properties.Single(s => s.Name.Equals("References")).Setter("DNE IO Interface");
            reference.Properties.Single(s => s.Name.Equals("Tag")).Setter("DNE Tag");

            Assert.AreEqual("DNE Tag", reference.Tag);
            Assert.AreEqual("DNE IO Interface", reference.Name);
        }
示例#5
0
        public void IsValid()
        {
            RemoteApp            app  = new RemoteApp();
            IOInterfaceReference ref1 = new IOInterfaceReference();

            app.AddChild(ref1);

            Assert.IsTrue(app.IsValid);
            Assert.AreEqual(String.Empty, app.InvalidMessage);
        }
        public void IsInvalidWithIncorrectName()
        {
            Mock <IIOInterface> ioInterface = new Mock <IIOInterface>();

            ioInterface.Setup(s => s.IsValid).Returns(true);
            ioInterface.Setup(s => s.Name).Returns("Fake IO Interface");
            AddComponentToConfigurationManager(ioInterface.Object);
            IOInterfaceReference reference = new IOInterfaceReference();

            reference.Properties.Single(s => s.Name.Equals("References")).Setter("DNE IO Interface");

            Assert.IsFalse(reference.IsValid);
        }
        public void PowerUpWithChannel()
        {
            Semaphore powerLock   = new Semaphore(0, 1);
            Semaphore channelLock = new Semaphore(0, 1);
            Dictionary <String, String> inputVals = new Dictionary <string, string>
            {
                { "Command", "remote" },
                { "remoteButton", "powerup" },
                { "channel", "Channel" },
            };

            Mock <IPowerController> powerRemote = new Mock <IPowerController>();
            Mock <ITVRemote>        tvRemote    = powerRemote.As <ITVRemote>();

            powerRemote.Setup(s => s.IsValid).Returns(true);
            powerRemote.Setup(s => s.Name).Returns("Power Remote");
            AddComponentToConfigurationManager(powerRemote.Object);
            powerRemote.Setup(s => s.TurnOn()).Callback(() => powerLock.Release());
            tvRemote.Setup(s => s.TrySendChannel("Channel")).Returns(true).Callback(() => channelLock.Release());
            SetupRemote <IDVRRemote>("Channel Remote");
            SetupRemote <IVolumeController>("Volume Remote");
            IOInterfaceReference ref1 = new IOInterfaceReference();

            ref1.Properties.Single(r => r.Name.Equals("References")).Setter("Power Remote");
            ref1.Properties.Single(r => r.Name.Equals("Tag")).Setter("Power");
            IOInterfaceReference ref2 = new IOInterfaceReference();

            ref2.Properties.Single(r => r.Name.Equals("References")).Setter("Channel Remote");
            IOInterfaceReference ref3 = new IOInterfaceReference();

            ref3.Properties.Single(r => r.Name.Equals("References")).Setter("Volume Remote");
            List <IOInterfaceReference> refs = new List <IOInterfaceReference>
            {
                ref1,
                ref2,
                ref3,
            };

            CurrentConversation = new RemoteConversation(GetConfigurationManager(), refs);

            Assert.AreEqual("OK", RunSingleConversation <RemoteConversation>(inputVals));

            powerLock.WaitOne();
            powerRemote.Verify(s => s.TurnOn(), Times.Exactly(1));
            channelLock.WaitOne();
            tvRemote.Verify(s => s.TrySendChannel("Channel"), Times.Exactly(1));
        }
示例#8
0
        public void ReferencesAppearInProperty()
        {
            RemoteApp            app  = new RemoteApp();
            IOInterfaceReference ref1 = new IOInterfaceReference();

            app.AddChild(ref1);
            IOInterfaceReference ref2 = new IOInterfaceReference();

            app.AddChild(ref2);
            Mock <IParseable> notARef = new Mock <IParseable>(MockBehavior.Strict);

            notARef.Setup(s => s.IsValid).Returns(true);

            IEnumerable <IOInterfaceReference> references = app.References;

            Assert.AreEqual(2, references.Count());
            Assert.IsTrue(references.Contains(ref1));
            Assert.IsTrue(references.Contains(ref2));
        }
示例#9
0
        public void TurnTheVolumeUpOnSourceGrammar()
        {
            Dictionary <String, String> expectedVals = new Dictionary <string, string>
            {
                { "Command", "volume" },
                { "direction", "up" },
                { "levelNum", "-1" },
                { "source", "Test Source" },
            };
            Mock <IVolumeController> controller = new Mock <IVolumeController>(MockBehavior.Strict);

            controller.Setup(s => s.IsValid).Returns(true);
            controller.Setup(s => s.Name).Returns("Test Volume Controller");
            AddComponentToConfigurationManager(controller.Object);
            VolumeApp            app  = new VolumeApp();
            IOInterfaceReference ref1 = new IOInterfaceReference("", "Test Source", GetConfigurationManager());

            app.AddChild(ref1);
            TestGrammar(app, GetConfigurationManager(), "turn the volume up on the Test Source", expectedVals);
        }