public void calculateFunctionTest2()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(0, 0, 0), new TimeSpan(23, 59, 59));
            ZoneServerMock zoneServer = new ZoneServerMock();
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction_Accessor target       = new ConcreteSleepFunction_Accessor(function, zoneServer, audioDrivers);

            // notify the first time, the update time is set to the current update time
            ZoneStateEventArgs e1 = new ZoneStateEventArgs(new NuvoControl.Common.ZoneState(new Address(100, 1), true, 20, NuvoControl.Common.ZoneQuality.Online));

            target.notifyOnZoneUpdate(e1);
            Assert.AreEqual(e1.ZoneState.LastUpdate, target._lastZoneChangeToON);

            DateTime aktTime = DateTime.Now;

            target.calculateFunction(aktTime);

            DateTime nextTime = DateTime.Now + new TimeSpan(1, 0, 0);

            target.calculateFunction(nextTime);

            Assert.AreEqual(1, zoneServer._monitoredZones.Count);                           // 1 zone monitored
            Assert.AreEqual(1, zoneServer.ZoneStates.Count);                                // 1 command issued
            Assert.AreEqual(false, zoneServer.ZoneStates[new Address(100, 1)].PowerStatus); // switch off
        }
        public void notifyOnZoneUpdateTest()
        {
            SleepFunction function   = new SleepFunction();
            IZoneServer   zoneServer = null;
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction_Accessor target       = new ConcreteSleepFunction_Accessor(function, zoneServer, audioDrivers);

            // notify the first time, the update time is set to the current update time
            ZoneStateEventArgs e1 = new ZoneStateEventArgs(new NuvoControl.Common.ZoneState(new Address(100, 1), true, 20, NuvoControl.Common.ZoneQuality.Online));

            target.notifyOnZoneUpdate(e1);
            Assert.AreEqual(e1.ZoneState.LastUpdate, target._lastZoneChangeToON);

            // notify volume change, the last zone change to On time stays the same
            ZoneStateEventArgs e2 = new ZoneStateEventArgs(new NuvoControl.Common.ZoneState(new Address(100, 1), true, 30, NuvoControl.Common.ZoneQuality.Online));

            target.notifyOnZoneUpdate(e2);
            Assert.AreEqual(e1.ZoneState.LastUpdate, target._lastZoneChangeToON);

            // notify switch off, the last zone change to On time stays the same
            ZoneStateEventArgs e3 = new ZoneStateEventArgs(new NuvoControl.Common.ZoneState(new Address(100, 1), false, 30, NuvoControl.Common.ZoneQuality.Online));

            target.notifyOnZoneUpdate(e3);
            Assert.AreEqual(e1.ZoneState.LastUpdate, target._lastZoneChangeToON);

            // notify switch on, the last zone change to On time updates
            ZoneStateEventArgs e4 = new ZoneStateEventArgs(new NuvoControl.Common.ZoneState(new Address(100, 1), true, 30, NuvoControl.Common.ZoneQuality.Online));

            target.notifyOnZoneUpdate(e4);
            Assert.AreEqual(e4.ZoneState.LastUpdate, target._lastZoneChangeToON);
        }
        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_Accessor target       = new ConcreteSleepFunction_Accessor(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
        }