public void ConcreteSleepFunctionConstructorTest1()
 {
     SleepFunction function   = new SleepFunction();
     IZoneServer   zoneServer = null;
     Dictionary <int, IAudioDriver> audioDrivers = null;
     ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);
 }
        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          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);

            /* // not supported anymore; quick-fix, uncomment unit test ->
             *
             * // 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          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);

            /* not supported anymore; quick-fix, uncomment unit test ->
             *
             * // 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);
             *
             */
        }
 /// <summary>
 /// Constructor to instantiate a concrete sleep function.
 /// </summary>
 /// <param name="function">Configuration data for this sleep function.</param>
 /// <param name="zoneServer">Zone server, to get notification about zone changes.</param>
 /// <param name="audioDrivers">Audio Drivers, in case a sound needs to be played.</param>
 public ConcreteSleepFunction(SleepFunction function, IZoneServer zoneServer, Dictionary <int, IAudioDriver> audioDrivers)
     : base(zoneServer, function, audioDrivers)
 {
     if (function == null)
     {
         onFunctionError();
         throw new FunctionServerException("Function configuration is null. This is not allowed");
     }
     _function = function;
     subscribeZone(_function.ZoneId);
 }
        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 ConcreteSleepFunctionConstructorTest2()
 {
     try
     {
         SleepFunction function   = null;
         IZoneServer   zoneServer = null;
         Dictionary <int, IAudioDriver> audioDrivers = null;
         ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);
     }
     catch (FunctionServerException)
     {
         // ok, catch expection
         return;
     }
     Assert.Fail("Exception 'FunctionServerException' expected!");
 }
 public void calculateFunctionTest1()
 {
     try
     {
         SleepFunction function   = new SleepFunction();
         IZoneServer   zoneServer = null;
         Dictionary <int, IAudioDriver> audioDrivers = null;
         ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);
         //target.notifyOnZoneUpdate();
         DateTime aktTime = new DateTime();
         target.calculateFunction(aktTime);
     }
     catch (FunctionServerException)
     {
         // ok, catch expection
         return;
     }
     Assert.Fail("Exception 'FunctionServerException' expected!");
 }
        public void isFunctionActiveRightNowTest2()
        {
            SleepFunction function = new SleepFunction(SimpleId.NewGuid(), new Address(100, 1),
                                                       new TimeSpan(1, 0, 0), new TimeSpan(6, 0, 0), new TimeSpan(9, 0, 0));
            IZoneServer zoneServer = null;
            Dictionary <int, IAudioDriver> audioDrivers = null;
            ConcreteSleepFunction          target       = new ConcreteSleepFunction(function, zoneServer, audioDrivers);
            bool actual = false;

            // (a) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 10, 0, 0));
            Assert.AreEqual(false, actual);

            // (b) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 9, 0, 1));
            Assert.AreEqual(false, actual);

            // (c) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 5, 59, 59));
            Assert.AreEqual(false, actual);

            // (d) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 6, 0, 10));
            Assert.AreEqual(true, actual);

            // (e) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 8, 59, 59));
            Assert.AreEqual(true, actual);

            // (f) Function is not active, current time is outside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 0, 0, 0));
            Assert.AreEqual(false, actual);

            // (g) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 6, 0, 0));
            Assert.AreEqual(true, actual);

            // (h) Function is active, current time is inside the validFrom/validTo range
            actual = target.isFunctionActiveRightNow(new DateTime(2000, 1, 1, 9, 0, 0));
            Assert.AreEqual(true, actual);
        }
示例#9
0
        public void GetConfigurationTest()
        {
            // If the system configuration version changes, you need to adapt/review this test case
            Assert.AreEqual("3.0", SystemConfiguration.VERSION);

            string file = @"NuvoControlKonfigurationUnitTest2.xml";
            ConfigurationLoader target = new ConfigurationLoader(file);
            SystemConfiguration systemConfiguration = target.GetConfiguration();

            Assert.AreEqual("3.0", systemConfiguration.ConfigurationVersion);

            TestContext.WriteLine("Testing device communication parameters...");
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].Id, 100);
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].Communication.BaudRate, 9600);
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].Communication.DataBits, 8);
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].Communication.ParityBit, 1);
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].Communication.ParityMode, "None");

            TestContext.WriteLine("Testing device protocol driver parameters...");
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].ProtocolDriver.Name, "Nuvo Essentia Protokoll Driver");
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].ProtocolDriver.AssemblyName, "NuvoControl.Server.ProtocolDriver");
            Assert.AreEqual(systemConfiguration.Hardware.Devices[0].ProtocolDriver.ClassName, "NuvoControl.Server.ProtocolDriver.NuvoEssentiaProtocolDriver");

            TestContext.WriteLine("Testing audio driver parameters...");
            Assert.AreEqual(3, systemConfiguration.Hardware.Devices[0].AudioDevices.Count);
            Assert.AreEqual(new Address(100, 1), systemConfiguration.Hardware.Devices[0].AudioDevices[0].Id);
            Assert.AreEqual(1, systemConfiguration.Hardware.Devices[0].AudioDevices[0].Id.ObjectId);
            Assert.AreEqual(new Address(100, 2), systemConfiguration.Hardware.Devices[0].AudioDevices[1].Id);
            Assert.AreEqual(2, systemConfiguration.Hardware.Devices[0].AudioDevices[1].Id.ObjectId);
            Assert.AreEqual(3, systemConfiguration.Hardware.Devices[0].AudioDevices[2].Id.ObjectId);
            Assert.AreEqual("hw:0,0", systemConfiguration.Hardware.Devices[0].AudioDevices[0].Device);

            TestContext.WriteLine("Testing osc driver parameters...");
            Assert.AreEqual(3, systemConfiguration.Hardware.Devices[0].OscDevices.Count);
            // OSC Client 1
            Assert.AreEqual(eOSCDeviceType.OSCClient, systemConfiguration.Hardware.Devices[0].OscDevices[0].DeviceType);
            Assert.AreEqual(2, systemConfiguration.Hardware.Devices[0].OscDevices[0].Id.ObjectId);
            Assert.AreEqual(9000, systemConfiguration.Hardware.Devices[0].OscDevices[0].SendPort);
            Assert.AreEqual(-1, systemConfiguration.Hardware.Devices[0].OscDevices[0].ListenPort);
            // OSC Server
            Assert.AreEqual(eOSCDeviceType.OSCServer, systemConfiguration.Hardware.Devices[0].OscDevices[2].DeviceType);
            Assert.AreEqual(1, systemConfiguration.Hardware.Devices[0].OscDevices[2].Id.ObjectId);
            Assert.AreEqual(9000, systemConfiguration.Hardware.Devices[0].OscDevices[2].SendPort);
            Assert.AreEqual(8000, systemConfiguration.Hardware.Devices[0].OscDevices[2].ListenPort);
            // OSC Client 2
            Assert.AreEqual(eOSCDeviceType.OSCClient, systemConfiguration.Hardware.Devices[0].OscDevices[1].DeviceType);
            Assert.AreEqual(3, systemConfiguration.Hardware.Devices[0].OscDevices[1].Id.ObjectId);
            Assert.AreEqual(9002, systemConfiguration.Hardware.Devices[0].OscDevices[1].SendPort);
            Assert.AreEqual(-1, systemConfiguration.Hardware.Devices[0].OscDevices[1].ListenPort);
            Assert.AreEqual(18, systemConfiguration.Hardware.Devices[0].OscDevices[1].OscDeviceLayouts.Count);

            TestContext.WriteLine("Testing device zone parameters...");
            Assert.AreEqual(12, systemConfiguration.Hardware.Devices[0].ZoneList.Count);
            Assert.AreEqual(1, systemConfiguration.Hardware.Devices[0].ZoneList[0].Id.ObjectId);
            Assert.AreEqual(2, systemConfiguration.Hardware.Devices[0].ZoneList[1].Id.ObjectId);
            Assert.AreEqual(3, systemConfiguration.Hardware.Devices[0].ZoneList[2].Id.ObjectId);
            Assert.AreEqual(4, systemConfiguration.Hardware.Devices[0].ZoneList[3].Id.ObjectId);
            Assert.AreEqual(5, systemConfiguration.Hardware.Devices[0].ZoneList[4].Id.ObjectId);
            Assert.AreEqual(6, systemConfiguration.Hardware.Devices[0].ZoneList[5].Id.ObjectId);
            Assert.AreEqual(7, systemConfiguration.Hardware.Devices[0].ZoneList[6].Id.ObjectId);
            Assert.AreEqual(8, systemConfiguration.Hardware.Devices[0].ZoneList[7].Id.ObjectId);
            Assert.AreEqual(9, systemConfiguration.Hardware.Devices[0].ZoneList[8].Id.ObjectId);
            Assert.AreEqual(10, systemConfiguration.Hardware.Devices[0].ZoneList[9].Id.ObjectId);
            Assert.AreEqual(11, systemConfiguration.Hardware.Devices[0].ZoneList[10].Id.ObjectId);
            Assert.AreEqual(12, systemConfiguration.Hardware.Devices[0].ZoneList[11].Id.ObjectId);

            TestContext.WriteLine("Testing device source parameters...");
            Assert.AreEqual(6, systemConfiguration.Hardware.Devices[0].Sources.Count);
            Assert.AreEqual(1, systemConfiguration.Hardware.Devices[0].Sources[0].Id.ObjectId);
            Assert.AreEqual(2, systemConfiguration.Hardware.Devices[0].Sources[1].Id.ObjectId);
            Assert.AreEqual(3, systemConfiguration.Hardware.Devices[0].Sources[2].Id.ObjectId);
            Assert.AreEqual(4, systemConfiguration.Hardware.Devices[0].Sources[3].Id.ObjectId);
            Assert.AreEqual(5, systemConfiguration.Hardware.Devices[0].Sources[4].Id.ObjectId);
            Assert.AreEqual(6, systemConfiguration.Hardware.Devices[0].Sources[5].Id.ObjectId);

            TestContext.WriteLine("Testing some graphic parameters...");
            Assert.AreEqual(2, systemConfiguration.Graphic.Building.Floors.Count);
            Assert.AreEqual("Wohnbereich", systemConfiguration.Graphic.Building.Floors[0].Name);
            Assert.AreEqual(@".\Images\Wohnbereich.bmp", systemConfiguration.Graphic.Building.Floors[0].FloorPlanPath);
            Assert.AreEqual("bmp", systemConfiguration.Graphic.Building.Floors[0].FloorPlanType);
            Assert.AreEqual(9, systemConfiguration.Graphic.Building.Floors[0].Zones.Count);
            Assert.AreEqual(new Address(100, 1), systemConfiguration.Graphic.Building.Floors[0].Zones[0].Id);
            Assert.AreEqual("Esszimmer", systemConfiguration.Graphic.Building.Floors[0].Zones[0].Name);
            Assert.AreEqual(@".\Images\Esszimmer.jpg", systemConfiguration.Graphic.Building.Floors[0].Zones[0].PicturePath);
            Assert.AreEqual("jpg", systemConfiguration.Graphic.Building.Floors[0].Zones[0].PictureType);
            Assert.AreEqual(4, systemConfiguration.Graphic.Building.Floors[0].Zones[0].FloorPlanCoordinates.Count);
            Assert.AreEqual(485, systemConfiguration.Graphic.Building.Floors[0].Zones[0].FloorPlanCoordinates[1].X);
            Assert.AreEqual(210, systemConfiguration.Graphic.Building.Floors[0].Zones[0].FloorPlanCoordinates[1].Y);
            Assert.AreEqual(6, systemConfiguration.Graphic.Sources.Count);
            Assert.AreEqual(new Address(100, 1), systemConfiguration.Graphic.Sources[0].Id);
            Assert.AreEqual("DAB Hama DIR3100", systemConfiguration.Graphic.Sources[0].Name);
            Assert.AreEqual(systemConfiguration.Graphic.Sources[0].PicturePath, @".\Images\Tuner.jpg");
            Assert.AreEqual(systemConfiguration.Graphic.Sources[0].PictureType, "jpg");


            TestContext.WriteLine("Testing some function parameters...");
            Assert.AreEqual(12, systemConfiguration.Functions.Count);
            SleepFunction sleepFct = systemConfiguration.Functions[0] as SleepFunction;

            Assert.AreEqual(new SimpleId("2445f69e-a5a7-465e-95be-9179913d3780"), sleepFct.Id);
            Assert.AreEqual(new Address(100, 3), sleepFct.ZoneId);
            Assert.AreEqual(new TimeSpan(0, 60, 0), sleepFct.SleepDuration);
            Assert.AreEqual(new TimeSpan(20, 00, 0), sleepFct.ValidFrom);
            Assert.AreEqual(new TimeSpan(2, 0, 0), sleepFct.ValidTo);
            Assert.AreEqual(1, sleepFct.Commands.Count);

            AlarmFunction alarmFct = systemConfiguration.Functions[3] as AlarmFunction;

            Assert.AreEqual(new SimpleId("11111111-0001-1111-1111-111111111111"), alarmFct.Id);
            Assert.AreEqual(new Address(100, 2), alarmFct.ZoneId);
            Assert.AreEqual(new TimeSpan(6, 45, 0), alarmFct.AlarmTime);
            Assert.AreEqual(new TimeSpan(2, 0, 0), alarmFct.AlarmDuration);
            Assert.AreEqual(new Address(100, 1), alarmFct.SourceId);
            Assert.AreEqual(1, alarmFct.ValidOnDays.Count);
            Assert.AreEqual(DayOfWeek.Monday, alarmFct.ValidOnDays[0]);
            Assert.AreEqual(1, alarmFct.Commands.Count);

            ZoneChangeFunction zonechangeFct = systemConfiguration.Functions[6] as ZoneChangeFunction;

            Assert.AreEqual(new SimpleId("1234"), zonechangeFct.Id);
            Assert.AreEqual(1, zonechangeFct.ValidOnDays.Count);
            Assert.AreEqual(DayOfWeek.Tuesday, zonechangeFct.ValidOnDays[0]);
            Assert.AreEqual(0, zonechangeFct.Commands.Count);

            OscEventFunction oscFunc = systemConfiguration.Functions[7] as OscEventFunction;

            Assert.AreEqual(new SimpleId("504"), oscFunc.Id);
            Assert.AreEqual(1, oscFunc.ValidOnDays.Count);
            Assert.AreEqual(DayOfWeek.Friday, oscFunc.ValidOnDays[0]);
            Assert.AreEqual(2, oscFunc.Commands.Count);

            OscEventFunction oscFunc2 = systemConfiguration.Functions[8] as OscEventFunction;

            Assert.AreEqual(new SimpleId("505"), oscFunc2.Id);
            Assert.AreEqual("/4/toggle3", oscFunc2.OscLabel);
            Assert.AreEqual(null, oscFunc2.ValidOnDays);
            Assert.AreEqual(1, oscFunc2.Commands.Count);

            OscEventFunction oscFunc3 = systemConfiguration.Functions[9] as OscEventFunction;

            Assert.AreEqual(new SimpleId("506"), oscFunc3.Id);
            Assert.AreEqual("/4/toggle5", oscFunc3.OscLabel);
            Assert.AreEqual("100.1", oscFunc3.OscDevice.ToString());
            Assert.AreEqual("SwitchOff", oscFunc3.OscEvent);
            Assert.AreEqual(null, oscFunc3.ValidOnDays);
            Assert.AreEqual(1, oscFunc3.Commands.Count);
        }