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 isFunctionActiveTodayTest3() { IZoneServer zoneServer = null; // (1) Empty day list List <DayOfWeek> _dayOfWeeks1 = new List <DayOfWeek>(); AlarmFunction function1 = new AlarmFunction( SimpleId.NewGuid(), new Address(100, 1), new Address(100, 1), 50, new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0), _dayOfWeeks1); Dictionary <int, IAudioDriver> audioDrivers = null; ConcreteAlarmFunction target1 = new ConcreteAlarmFunction(function1, zoneServer, audioDrivers); // (2) Full day list List <DayOfWeek> _dayOfWeeks2 = new List <DayOfWeek>(); _dayOfWeeks2.Add(DayOfWeek.Monday); _dayOfWeeks2.Add(DayOfWeek.Tuesday); _dayOfWeeks2.Add(DayOfWeek.Wednesday); _dayOfWeeks2.Add(DayOfWeek.Thursday); _dayOfWeeks2.Add(DayOfWeek.Friday); _dayOfWeeks2.Add(DayOfWeek.Saturday); _dayOfWeeks2.Add(DayOfWeek.Sunday); AlarmFunction function2 = new AlarmFunction( SimpleId.NewGuid(), new Address(100, 1), new Address(100, 1), 50, new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0), _dayOfWeeks2); ConcreteAlarmFunction target2 = new ConcreteAlarmFunction(function2, zoneServer, audioDrivers); // Monday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 7, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 7, 12, 0, 0))); // Tuesday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 8, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 8, 12, 0, 0))); // Wednesday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 9, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 9, 12, 0, 0))); // Thursday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 10, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 10, 12, 0, 0))); // Friday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 11, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 11, 12, 0, 0))); // Saturday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 12, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 12, 12, 0, 0))); // Sunday Assert.AreEqual(false, target1.isFunctionActiveToday(new DateTime(2009, 9, 13, 12, 0, 0))); Assert.AreEqual(true, target2.isFunctionActiveToday(new DateTime(2009, 9, 13, 12, 0, 0))); }
public void ConcreteAlarmFunctionConstructorTest2() { List <DayOfWeek> _dayOfWeeks = new List <DayOfWeek>(); AlarmFunction function = new AlarmFunction( SimpleId.NewGuid(), new Address(100, 1), new Address(100, 1), 50, new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0), _dayOfWeeks); IZoneServer zoneServer = null; Dictionary <int, IAudioDriver> audioDrivers = null; ConcreteAlarmFunction target = new ConcreteAlarmFunction(function, zoneServer, audioDrivers); }
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 isFunctionActiveTodayTest1() { List <DayOfWeek> _dayOfWeeks = new List <DayOfWeek>(); AlarmFunction function = new AlarmFunction( SimpleId.NewGuid(), new Address(100, 1), new Address(100, 1), 50, new TimeSpan(6, 0, 0), new TimeSpan(0, 45, 0), _dayOfWeeks); IZoneServer zoneServer = null; Dictionary <int, IAudioDriver> audioDrivers = null; ConcreteAlarmFunction target = new ConcreteAlarmFunction(function, zoneServer, audioDrivers); DateTime aktTime = DateTime.Now; bool actual = target.isFunctionActiveToday(aktTime); Assert.AreEqual(false, actual); }
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); }
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(); }
/// <summary> /// Private method to initialize the members. /// Call this method in each constructur at start. /// </summary> private void initMembers() { _commandList.Clear(); _createDateTime = DateTime.Now; _id = SimpleId.NewGuid(); }