public void ProgramStory1_Test() //one program //Weekly type , //2 exec time - one cross-midnight { var SN = "0da20764-60b2-4081-8"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); // set only one to be active for (int i = 1; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); program.StatusID = 0; Assert.IsTrue(Repository.ProgramSetting_Update(program)); } var Program = plist[0]; Program.DaysExecutionsTypeID = 0; Repository.ProgramSetting_Update(Program); var WeeklyDaysProgram = new WeeklyProgramSetting() { ProgramID = Program.ProgramID }; WeeklyDaysProgram.Sunday = true; WeeklyDaysProgram.Monday = false; WeeklyDaysProgram.Thursday = true; WeeklyDaysProgram.Wednesday = false; WeeklyDaysProgram.Thursday = true; WeeklyDaysProgram.Friday = false; WeeklyDaysProgram.Saturday = true; Assert.IsTrue(Repository.WeeklyProgramSetting_Update(WeeklyDaysProgram)); var ExecutionHours = new ExecutionHours[] { new ExecutionHours() { ExecTime = 28800 }, //8 am new ExecutionHours() { ExecTime = 82800 } //11 pm 23:00 //{ ExecTime = 64800 } 6 pm ,18:00 }; Assert.IsTrue(Repository.ExecutionHoursProgram_Update(Program.ProgramID, ExecutionHours)); var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = 1.1m, FertTime = 12, OrderNumber = x, ProgramID = Program.ProgramID, WaterAfter = 3, WaterBefore = 5, WaterDuration = 3600, WaterPrecipitation_Duration = 4, WaterPrecipitation_Quantity = 3, WaterQuantity = 6, ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } }
public void ProgramStory3_Test() //one program //CyclicDay type every3 day, //2 exec time - one cross-midnight { var SN = "c32ad0de-9610-419c-8"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); // set only one to be active for (int i = 1; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); program.StatusID = 0; Assert.IsTrue(Repository.ProgramSetting_Update(program)); } var Program = plist[0]; Program.DaysExecutionsTypeID = 1; var CyclicDay = new CyclicDayProgram() { DaysInterval = 3, ProgramID = Program.ProgramID, StartDate = new DateTime(2016, 9, 18) }; Repository.CyclicDayProgram_Update(CyclicDay); var ExecutionHours = new ExecutionHours[] { new ExecutionHours() { ExecTime = 28800 }, //8 am new ExecutionHours() { ExecTime = 82800 } //11 pm 23:00 //{ ExecTime = 64800 } 6 pm ,18:00 }; Assert.IsTrue(Repository.ExecutionHoursProgram_Update(Program.ProgramID, ExecutionHours)); Repository.ProgramSetting_Update(Program); var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = 1.1m, FertTime = 12, OrderNumber = x, ProgramID = Program.ProgramID, WaterAfter = 3, WaterBefore = 5, WaterDuration = 3600, WaterPrecipitation_Duration = 4, WaterPrecipitation_Quantity = 3, WaterQuantity = 6, ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } }
public void Program_Test() { var SN = "0b257467-640b-47db-a"; if (string.IsNullOrEmpty(SN)) { var device = CreateDevice(); SN = device.SN; } var plist = Repository.DevicePrograms_Get(SN); Assert.IsTrue(plist != null && plist.Length > 0); for (int i = 0; i < plist.Length; i++) { var p_fromList = plist[i]; var ProgramID = p_fromList.ProgramID; var program = Repository.ProgramSetting_Get(ProgramID); isProgramEqual(program, p_fromList); var now = DateTime.Now; var CyclicDayProgram = new CyclicDayProgram() { ProgramID = ProgramID }; var WeeklyDaysProgram = new WeeklyProgramSetting() { ProgramID = ProgramID }; for (int j = 0; j < 2; j++) { #region setting program.DaysExecutionsTypeID = (byte)(i % 2 == 0 ? 0 : 1); program.FinalEndDateLimit = now.AddMonths(i); program.FinalStartDateLimit = now.AddMonths(-i); program.FinalStartHoursLimit = i % 2 == 0 ? 10 : 100; program.FinalStopHoursLimit = i % 2 == 0 ? 2 : 234; program.HourlyCyclesPerDay = (byte)(i % 2 == 0 ? 11 : 12); program.HourlyCyclesStartTime = i % 2 == 0 ? 12 : 34; program.HourlyCyclesStopTime = i % 2 == 0 ? 34 : 345; program.HourlyCycleTime = i % 2 == 0 ? 34 : 67; program.HoursExecutionsTypeID = (byte)(i % 2 == 0 ? 1 : 0); program.IsFertilizerON = i % 2 == 0; program.Name = "name _" + i.ToString(); program.Priority = (byte)(i % 2 == 0 ? 17 : 0); program.StatusID = (byte)(i % 2 == 0 ? 1 : 0); program.WaterFactor = (byte)(i % 2 == 0 ? 45 : 78); program.WaterUnitID = (byte)(i % 2 == 0 ? 0 : 1); Assert.IsTrue(Repository.ProgramSetting_Update(program)); var program_db = Repository.ProgramSetting_Get(ProgramID); isProgramEqual(program, program_db); #endregion #region CyclicDayProgram CyclicDayProgram.DaysInterval = (byte)(2); CyclicDayProgram.StartDate = now.AddDays(i); Assert.IsTrue(Repository.CyclicDayProgram_Update(CyclicDayProgram)); var c_db = Repository.CyclicDayProgram_Get(ProgramID); Assert.IsTrue(CyclicDayProgram.DaysInterval == c_db.DaysInterval); Assert.IsTrue(EqualsDate(CyclicDayProgram.StartDate, c_db.StartDate)); #endregion #region WeeklyDaysProgram WeeklyDaysProgram.Sunday = (i % 2 == 0); WeeklyDaysProgram.Monday = !(i % 2 == 0); WeeklyDaysProgram.Thursday = (i % 2 == 0); WeeklyDaysProgram.Wednesday = !(i % 2 == 0); WeeklyDaysProgram.Thursday = (i % 2 == 0); WeeklyDaysProgram.Friday = !(i % 2 == 0); WeeklyDaysProgram.Saturday = (i % 2 == 0); Assert.IsTrue(Repository.WeeklyProgramSetting_Update(WeeklyDaysProgram)); var w_db = Repository.WeeklyProgramSetting_Get(ProgramID); Assert.IsTrue(WeeklyDaysProgram.Sunday == w_db.Sunday); Assert.IsTrue(WeeklyDaysProgram.Monday == w_db.Monday); Assert.IsTrue(WeeklyDaysProgram.Tuesday == w_db.Tuesday); Assert.IsTrue(WeeklyDaysProgram.Wednesday == w_db.Wednesday); Assert.IsTrue(WeeklyDaysProgram.Thursday == w_db.Thursday); Assert.IsTrue(WeeklyDaysProgram.Friday == w_db.Friday); Assert.IsTrue(WeeklyDaysProgram.Saturday == w_db.Saturday); #endregion #region ExecutionHours var ExecutionHours = new ExecutionHours[] { new ExecutionHours() { ExecTime = i }, new ExecutionHours() { ExecTime = 10800 }, new ExecutionHours() { ExecTime = 28800 }, new ExecutionHours() { ExecTime = 50400 } }; Assert.IsTrue(Repository.ExecutionHoursProgram_Update(ProgramID, ExecutionHours)); var e_db = Repository.ExecutionHoursProgram_Get(ProgramID); Assert.IsTrue(e_db.Length == ExecutionHours.Length); foreach (var item_db in e_db) { var item = ExecutionHours.Where(e => e.ExecTime == item_db.ExecTime).FirstOrDefault(); Assert.IsTrue(item != null); } #endregion #region ZoneInProgram var list_zone = new List <ZoneInProgram>(); for (int x = 0; x < 4; x++) { var zone = new ZoneInProgram() { FertQuant = (i % 2 == 0 ? 0.9m : 1.1m), FertTime = (i % 2 == 0 ? 11 : 12), OrderNumber = x, ProgramID = ProgramID, WaterAfter = (i % 2 == 0 ? 3 : 4), WaterBefore = (i % 2 == 0 ? 2 : 5), WaterDuration = (i % 2 == 0 ? 23 : 34), WaterPrecipitation_Duration = (i % 2 == 0 ? 3 : 4), WaterPrecipitation_Quantity = (i % 2 == 0 ? 6 : 8), WaterQuantity = (i % 2 == 0 ? 7 : 99), ZoneNumber = (byte)x, }; list_zone.Add(zone); Assert.IsTrue(Repository.ZoneInProgram_Update(zone)); } var list_zone_db = Repository.ZonesInProgram_Get(ProgramID); Assert.IsTrue(list_zone_db.Length == list_zone.Count); foreach (var item_db in list_zone_db) { var item = list_zone.Where(s => s.ZoneNumber == item_db.ZoneNumber).FirstOrDefault(); Assert.IsTrue(item != null); Assert.IsTrue(item.FertQuant == item_db.FertQuant); Assert.IsTrue(item.FertTime == item_db.FertTime); Assert.IsTrue(item.OrderNumber == item_db.OrderNumber); Assert.IsTrue(item.WaterAfter == item_db.WaterAfter); Assert.IsTrue(item.WaterBefore == item_db.WaterBefore); Assert.IsTrue(item.WaterDuration == item_db.WaterDuration); Assert.IsTrue(item.WaterPrecipitation_Duration == item_db.WaterPrecipitation_Duration); Assert.IsTrue(item.WaterPrecipitation_Quantity == item_db.WaterPrecipitation_Quantity); Assert.IsTrue(item.WaterQuantity == item_db.WaterQuantity); } #endregion } } }