public void ConcreteZoneChangeFunctionCommandTest13()
        {
            List <Command> commands = new List <Command>();

            commands.Add(new SendNuvoCommand(new SimpleId(), false, false, false, true, true, true, true, new Address("100.1"), "OFF", "100.6", 10));
            commands.Add(new PlaySoundCommand(new SimpleId(), false, false, false, true, true, true, true, new Address("100.2"), "http://www.imfeld.net/mp3_stream"));
            ZoneChangeFunction             function     = new ZoneChangeFunction(new SimpleId(), new Address("100.1"), new Address(), 0, true, true, true, true, null, new TimeSpan(), new TimeSpan(), commands);
            ZoneServerMock                 zoneServer   = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = new Dictionary <int, IAudioDriver>();

            audioDrivers.Add(2, new AudioDriverMock());
            ConcreteZoneChangeFunction target = new ConcreteZoneChangeFunction(function, zoneServer, audioDrivers);

            target.calculateFunction(DateTime.Now);

            zoneServer.distributeZoneState(new ZoneState(new Address("100.6"), true, 10, ZoneQuality.Online));
            zoneServer.distributeZoneState(new ZoneState(new Address("100.5"), false, 20, ZoneQuality.Online));
            zoneServer.distributeZoneState(new ZoneState(new Address("100.4"), true, 20, ZoneQuality.Offline));

            target.calculateFunction(DateTime.Now);

            Assert.AreEqual(true, target.Active);                                                               // function is "active"
            Assert.AreEqual(1, zoneServer.ZoneStateList.Count);                                                 // OnValidityStart
            Assert.AreEqual("http://www.imfeld.net/mp3_stream", ((AudioDriverMock)audioDrivers[2]).Url);        // URL is playing
            Assert.AreEqual(true, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                                // URL is still playing
        }
        public void ConcreteZoneChangeFunctionCommandTest14()
        {
            List <Command> commands = new List <Command>();

            commands.Add(new SendNuvoCommand(new SimpleId(), false, false, false, true, true, true, true, new Address("100.1"), "OFF", "100.6", 10));
            commands.Add(new PlaySoundCommand(new SimpleId(), false, false, false, true, true, true, true, new Address("100.2"), "http://www.imfeld.net/mp3_stream"));
            ZoneChangeFunction             function     = new ZoneChangeFunction(new SimpleId(), new Address("100.1"), new Address(), 0, true, true, true, true, null, new TimeSpan(14, 0, 0), new TimeSpan(15, 0, 0), commands);
            ZoneServerMock                 zoneServer   = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = new Dictionary <int, IAudioDriver>();

            audioDrivers.Add(2, new AudioDriverMock());
            ConcreteZoneChangeFunction target = new ConcreteZoneChangeFunction(function, zoneServer, audioDrivers);

            target.calculateFunction(new DateTime(2016, 2, 24, 10, 0, 0));
            //Assert.AreEqual(false, target.Active);                                                              // function is not active
            Assert.AreEqual(0, zoneServer.ZoneStateList.Count);                                                 // no command in queue
            Assert.AreEqual("", ((AudioDriverMock)audioDrivers[2]).Url);                                        // no URL is playing
            Assert.AreEqual(false, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                               // not playing

            zoneServer.distributeZoneState(new ZoneState(new Address("100.6"), true, 10, ZoneQuality.Online));
            zoneServer.distributeZoneState(new ZoneState(new Address("100.5"), false, 20, ZoneQuality.Online));
            zoneServer.distributeZoneState(new ZoneState(new Address("100.4"), true, 20, ZoneQuality.Offline));

            target.calculateFunction(new DateTime(2016, 2, 24, 12, 0, 0));
            Assert.AreEqual(false, target.isActiveAt(new DateTime(2016, 2, 24, 12, 0, 0)));                     // function is not active
            Assert.AreEqual(0, zoneServer.ZoneStateList.Count);                                                 // no command in queue
            Assert.AreEqual("", ((AudioDriverMock)audioDrivers[2]).Url);                                        // no URL is playing
            Assert.AreEqual(false, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                               // not playing

            target.calculateFunction(new DateTime(2016, 2, 24, 13, 59, 59));
            Assert.AreEqual(false, target.isActiveAt(new DateTime(2016, 2, 24, 13, 59, 59)));                   // function is not active
            Assert.AreEqual(0, zoneServer.ZoneStateList.Count);                                                 // no command in queue
            Assert.AreEqual("", ((AudioDriverMock)audioDrivers[2]).Url);                                        // no URL is playing
            Assert.AreEqual(false, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                               // not playing

            target.calculateFunction(new DateTime(2016, 2, 24, 14, 0, 0));
            Assert.AreEqual(true, target.isActiveAt(new DateTime(2016, 2, 24, 14, 0, 0)));                      // function is active
            Assert.AreEqual(1, zoneServer.ZoneStateList.Count);                                                 // one command in queue
            Assert.AreEqual("http://www.imfeld.net/mp3_stream", ((AudioDriverMock)audioDrivers[2]).Url);        // URL is playing
            Assert.AreEqual(true, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                                // is playing

            target.calculateFunction(new DateTime(2016, 2, 24, 14, 0, 1));
            Assert.AreEqual(true, target.isActiveAt(new DateTime(2016, 2, 24, 14, 0, 1)));                      // function not active
            Assert.AreEqual(1, zoneServer.ZoneStateList.Count);                                                 // no new command in queue
            Assert.AreEqual("http://www.imfeld.net/mp3_stream", ((AudioDriverMock)audioDrivers[2]).Url);        // URL is still playing
            Assert.AreEqual(true, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                                // is playing

            target.calculateFunction(new DateTime(2016, 2, 24, 15, 0, 0));
            Assert.AreEqual(true, target.isActiveAt(new DateTime(2016, 2, 24, 15, 0, 0)));                      // function is active
            Assert.AreEqual(1, zoneServer.ZoneStateList.Count);                                                 // one command in queue
            Assert.AreEqual("http://www.imfeld.net/mp3_stream", ((AudioDriverMock)audioDrivers[2]).Url);        // URL is playing
            Assert.AreEqual(true, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                                // is playing

            target.calculateFunction(new DateTime(2016, 2, 24, 15, 0, 1));
            Assert.AreEqual(false, target.isActiveAt(new DateTime(2016, 2, 24, 15, 0, 1)));                     // function not active anymore
            Assert.AreEqual(2, zoneServer.ZoneStateList.Count);                                                 // second command in queue
            Assert.AreEqual("", ((AudioDriverMock)audioDrivers[2]).Url);                                        // no URL is playing
            Assert.AreEqual(false, ((AudioDriverMock)audioDrivers[2]).IsPlaying);                               // not playing anymore
        }
        public void ConcreteZoneChangeFunctionCommandTest7()
        {
            List <Command> commands = new List <Command>();

            commands.Add(new SendNuvoCommand(new SimpleId(), true, true, true, true, true, true, true, new Address("100.1"), "OFF", "100.6", 10));
            ZoneChangeFunction             function     = new ZoneChangeFunction(new SimpleId(), new Address("100.1"), new Address("100.6"), 10, null, commands);
            ZoneServerMock                 zoneServer   = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteZoneChangeFunction     target       = new ConcreteZoneChangeFunction(function, zoneServer, audioDrivers);

            zoneServer.distributeZoneState(new ZoneState(new Address("100.6"), true, 10, ZoneQuality.Online));
            zoneServer.distributeZoneState(new ZoneState(new Address("100.5"), false, 20, ZoneQuality.Online));

            target.calculateFunction(DateTime.Now);

            Assert.AreEqual(1, zoneServer.ZoneStateList.Count);     // OnValidityStart
        }
        public void calculateFunctionTest3()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(14, 0, 0), new TimeSpan(18, 00, 00));
            ZoneServerMock zoneServerMock = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServerMock, audioDrivers);

            Assert.AreEqual(1, zoneServerMock._monitoredZones.Count);   // 1 zone monitored

            // Distribute an 'old status. Simulate that the zone is ON since then.
            ZoneState oldState = new ZoneState(new Address(100, 1), true, 20, NuvoControl.Common.ZoneQuality.Online);

            oldState.LastUpdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 00, 0);
            zoneServerMock.distributeZoneState(oldState);

            // test 11:00 -> not active, no action
            DateTime simTime1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 00, 0);

            target.calculateFunction(simTime1);
            Assert.AreEqual(0, zoneServerMock.ZoneStates.Count);       // 0 command issued

            // test 14:00 -> just active, switch off.
            DateTime simTime2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 14, 00, 0);

            target.calculateFunction(simTime2);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 16:00 -> active, switch off.
            DateTime simTime3 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 16, 00, 0);

            target.calculateFunction(simTime3);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 18:00 -> still active, switch off.
            DateTime simTime4 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 18, 00, 0);

            target.calculateFunction(simTime4);
            Assert.AreEqual(1, zoneServerMock.ZoneStates.Count);       // 1 command issued
            zoneServerMock.ClearZoneStateList();

            // test 20:00 -> not active, no action
            DateTime simTime5 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 00, 0);

            target.calculateFunction(simTime5);
            Assert.AreEqual(0, zoneServerMock.ZoneStates.Count);       // 0 command issued
        }
        public void calculateFunctionTest4()
        {
            // (1) Day list: Monday, Wednesday, Friday, Sunday
            // (1) Function: AlarmTime=10:00, AlarmDuration=01:45
            #region Function1
            List <DayOfWeek> _dayOfWeeks1 = new List <DayOfWeek>();
            _dayOfWeeks1.Add(DayOfWeek.Monday);
            _dayOfWeeks1.Add(DayOfWeek.Wednesday);
            _dayOfWeeks1.Add(DayOfWeek.Friday);
            _dayOfWeeks1.Add(DayOfWeek.Sunday);
            AlarmFunction function1 = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 3), 50,
                new TimeSpan(10, 0, 0), new TimeSpan(1, 45, 0),
                _dayOfWeeks1);
            ZoneServerMock zoneServer1 = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteAlarmFunction          target1      = new ConcreteAlarmFunction(function1, zoneServer1, audioDrivers);
            #endregion

            // (2) Day list: Tuesday, Thursday, Saturday, Sunday
            // (2) Function: AlarmTime=10:00, AlarmDuration=01:45
            #region Function2
            List <DayOfWeek> _dayOfWeeks2 = new List <DayOfWeek>();
            _dayOfWeeks2.Add(DayOfWeek.Tuesday);
            _dayOfWeeks2.Add(DayOfWeek.Thursday);
            _dayOfWeeks2.Add(DayOfWeek.Saturday);
            _dayOfWeeks2.Add(DayOfWeek.Sunday);
            AlarmFunction function2 = new AlarmFunction(
                SimpleId.NewGuid(),
                new Address(100, 1), new Address(100, 6), 50,
                new TimeSpan(10, 0, 0), new TimeSpan(1, 45, 0),
                _dayOfWeeks2);
            ZoneServerMock        zoneServer2 = new ZoneServerMock();
            ConcreteAlarmFunction target2     = new ConcreteAlarmFunction(function2, zoneServer2, audioDrivers);
            #endregion

            ZoneState zoneStateOff1 = new ZoneState(new Address(100, 2), false, 20, ZoneQuality.Online);
            zoneStateOff1.LastUpdate = new DateTime(2009, 9, 12, 23, 0, 0);
            ZoneState zoneStateOn = new ZoneState(new Address(100, 2), true, 20, ZoneQuality.Online);
            zoneStateOn.LastUpdate = new DateTime(2009, 9, 12, 23, 5, 0);
            ZoneState zoneStateOff2 = new ZoneState(new Address(100, 2), false, 20, ZoneQuality.Online);
            zoneStateOff2.LastUpdate = new DateTime(2009, 9, 12, 23, 10, 0);

            // Sunday (13.9.2009 11:00)
            zoneServer1.distributeZoneState(zoneStateOff1);
            zoneServer1.distributeZoneState(zoneStateOn);    // sets the member LastChangeToON
            zoneServer1.distributeZoneState(zoneStateOff2);
            target1.calculateFunction(new DateTime(2009, 9, 13, 11, 0, 0));

            zoneServer2.distributeZoneState(zoneStateOff1);
            zoneServer2.distributeZoneState(zoneStateOn);                     // sets the member LastChangeToON
            zoneServer2.distributeZoneState(zoneStateOff2);
            target2.calculateFunction(new DateTime(2009, 9, 13, 11, 44, 59)); // last change before functions ends

            Assert.AreEqual(1, zoneServer1._monitoredZones.Count);
            Assert.AreEqual(1, zoneServer2._monitoredZones.Count);
            Assert.AreEqual(1, zoneServer1.ZoneStates.Count);  // 1 command has been sent
            Assert.AreEqual(true, zoneServer1.ZoneStates[new Address(100, 1)].PowerStatus);
            Assert.AreEqual(new Address(100, 3), zoneServer1.ZoneStates[new Address(100, 1)].Source);
            Assert.AreEqual(1, zoneServer2.ZoneStates.Count);  // 1 command has been sent
            Assert.AreEqual(true, zoneServer2.ZoneStates[new Address(100, 1)].PowerStatus);
            Assert.AreEqual(new Address(100, 6), zoneServer2.ZoneStates[new Address(100, 1)].Source);
            zoneServer1.ClearZoneStateList();
            zoneServer2.ClearZoneStateList();
        }