public void TestReportsWithNoComputers() { Lab lab = new Lab(); lab.LabId = 3000; ReportModel model = new ReportModel(controller); List<int> list = new List<int>(); DateTime startDate = new DateTime(2010, 5, 10); DateTime endDate = new DateTime(2010, 5, 20); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; LabReport lr; //lab with no computers lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(0, lr.ComputersReport.Count, "no computers report expected"); Assert.AreEqual(0, lr.AverageUsage, "no usage- 0 expected"); ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 4, 10, 10, 0, 0); cl.Exit = new DateTime(2010, 4, 15, 12, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); // lab with no computers in the report duration lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(0, lr.ComputersReport.Count, "no computers report expected"); Assert.AreEqual(0, lr.AverageUsage, "no usage- 0 expected"); }
public void AddComputerToLab(int compId, int labId) { using (var db = new CAMS_DatabaseEntities()) { Computer comp = db.Computers.Find(compId); //already in lab- nothing to update if (comp.CurrentLab == labId) { return; } ComputerLab cL = new ComputerLab { ComputerId = compId, LabId = labId, Entrance = DateTime.Now, Exit = null }; comp.CurrentLab = labId; db.ComputerLabs.Add(cL); db.SaveChanges(); } }
public void TestOccReportsWithNoActtivities() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 4, 10, 10, 0, 0); cl.Exit = new DateTime(2010, 4, 15, 12, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); ReportModel model = new ReportModel(controller); DateTime startDate = new DateTime(2010, 4, 5); DateTime endDate = new DateTime(2010, 4, 10); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; LabOccupancyReport lr; //report duration befor computer exsist in lab string msg = "report duration befor computer exsist in lab"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, "no computers -no max day occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, "no computers -no min day occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, "no computers -no avg day occupancy expected"); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, "no computers -no max hour occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, "no computers -no min hour occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, "no computers -no avg hour occupancy expected"); } //report duration after computer exsist in lab msg = "report duration after computer exsist in lab"; startDate = new DateTime(2010, 4, 16); endDate = new DateTime(2010, 4, 20); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected"); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected"); } //report duration with one computer - no user activities(only off) Activity act1 = new Activity(); act1.ComputerId = cl.ComputerId; act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 4, 11, 10, 0, 0); act1.Logout = new DateTime(2010, 4, 11, 12, 0, 0); act1.Mode = ActivityType.Off; msg = "report duration with one computer - no user activities(only off) "; startDate = new DateTime(2010, 4, 11); endDate = new DateTime(2010, 4, 12); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected"); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected"); } //report duration with computer with no activities in this time msg = "report duration with computer with no activities in this time"; startDate = new DateTime(2010, 4, 13); endDate = new DateTime(2010, 4, 14); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected"); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected"); } Activity act2 = new Activity(); act2.ComputerId = cl.ComputerId; act2.Computer = cl.Computer; cl.Computer.Activities.Add(act2); act2.Login = new DateTime(2010, 3, 11, 10, 0, 0); act2.Logout = new DateTime(2010, 3, 11, 12, 0, 0); act2.Mode = ActivityType.User; //report duration with computer not in the lab (but have activity in that time) msg = "report duration with computer not in the lab (but have activity in that time)"; startDate = new DateTime(2010, 3, 11); endDate = new DateTime(2010, 3, 12); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected"); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected"); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected"); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected"); } }
public void TestReportsWithComputers() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 2, 15); cl.Exit = new DateTime(2010, 3, 15, 10, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); ComputerLab cl2 = new ComputerLab(); cl2.Computer = new Computer(); cl2.Computer.ComputerId = 3001; cl2.Lab = lab; cl2.Entrance = new DateTime(2010, 2, 15); cl2.Exit = new DateTime(2010, 3, 15, 10, 0, 0); lab.ComputerLabs.Add(cl2); cl2.Computer.ComputerLabs.Add(cl2); Activity act1 = new Activity(); act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 2, 16, 10, 0, 0); act1.Logout = new DateTime(2010, 2, 16, 12, 0, 0); act1.Mode = ActivityType.User; Activity act2 = new Activity(); act2.Computer = cl2.Computer; cl2.Computer.Activities.Add(act2); act2.Login = new DateTime(2010, 2, 16, 10, 0, 0); act2.Logout = new DateTime(2010, 2, 16, 12, 0, 0); act2.Mode = ActivityType.User; ReportModel model = new ReportModel(controller); List <int> list = new List <int>(); DateTime startDate = new DateTime(2010, 2, 16); DateTime endDate = new DateTime(2010, 2, 17); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; LabOccupancyReport lr; //2h out of 12h (for 2/2 computers) string msg = "one 2 hour activity in 1 day of both computers"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 2/2"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/2"); Assert.AreEqual(0.2, item.AvgOccupancy, msg + "-avg by day: (0*8+1*2)/10"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour >= 10 && item.Hour < 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(1, item.MinOccupancy, msg + " -min by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(1, item.AvgOccupancy, msg + " -avg by Hour: 2/2 on: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } endDate = new DateTime(2010, 2, 18); msg = "one 2 hour activity in 2 day (for both computers)"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 2/2"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/2"); Assert.AreEqual(0.2, item.AvgOccupancy, msg + "-avg by day: (0*8+1*2)/10"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour >= 10 && item.Hour < 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 0/2 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: (2/2+0/2)/2 on: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } endDate = new DateTime(2010, 2, 17); Activity act3 = new Activity(); act3.Computer = cl2.Computer; cl2.Computer.Activities.Add(act3); act3.Login = new DateTime(2010, 2, 16, 11, 30, 0); act3.Logout = new DateTime(2010, 2, 16, 12, 10, 0); act3.Mode = ActivityType.User; act2.Login = new DateTime(2010, 2, 16, 11, 10, 0); act2.Logout = new DateTime(2010, 2, 16, 11, 20, 0); act1.Login = new DateTime(2010, 2, 16, 12, 30, 0); act1.Logout = new DateTime(2010, 2, 16, 13, 40, 0); msg = "activities 1 day (for 2 computers)"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 2/2"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/2"); Assert.AreEqual(0.2, item.AvgOccupancy, msg + "-avg by day: (0.5+1+0.5)/10"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour == 11) { Assert.AreEqual(0.5, item.MaxOccupancy, msg + " -max by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.5, item.MinOccupancy, msg + " -min by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: 1/2: " + item.Hour); } else if (item.Hour == 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(1, item.MinOccupancy, msg + " -min by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(1, item.AvgOccupancy, msg + " -avg by Hour: 2/2: " + item.Hour); } else if (item.Hour == 13) { Assert.AreEqual(0.5, item.MaxOccupancy, msg + " -max by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.5, item.MinOccupancy, msg + " -min by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: 1/2: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } endDate = new DateTime(2010, 2, 18); Activity act4 = new Activity(); act4.Computer = cl.Computer; cl.Computer.Activities.Add(act4); act4.Login = new DateTime(2010, 2, 17, 12, 10, 0); act4.Logout = new DateTime(2010, 2, 17, 12, 40, 0); act4.Mode = ActivityType.User; Activity act5 = new Activity(); act5.Computer = cl.Computer; cl.Computer.Activities.Add(act5); act5.Login = new DateTime(2010, 2, 17, 12, 50, 0); act5.Logout = new DateTime(2010, 2, 17, 15, 10, 0); act5.Mode = ActivityType.User; Activity act6 = new Activity(); act6.Computer = cl2.Computer; cl2.Computer.Activities.Add(act6); act6.Login = new DateTime(2010, 2, 17, 12, 05, 0); act6.Logout = new DateTime(2010, 2, 17, 12, 10, 0); act6.Mode = ActivityType.User; msg = "activities 1 day (for 2 computers)"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 2/2 on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/2 on: " + item.DayOfWeek); Assert.AreEqual(0.2, item.AvgOccupancy, msg + "-avg by day: (0.5+1+0.5)/10 on: " + item.DayOfWeek); } else if (item.DayOfWeek == act4.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 2/2 on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/2 on: " + item.DayOfWeek); Assert.AreEqual(0.25, item.AvgOccupancy, msg + "-avg by day: (0.5+1+0.5)/10 on: " + item.DayOfWeek); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour == 11) { Assert.AreEqual(0.5, item.MaxOccupancy, msg + " -max by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.25, item.AvgOccupancy, msg + " -avg by Hour: 1/2: " + item.Hour); } else if (item.Hour == 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(1, item.MinOccupancy, msg + " -min by Hour: 2/2 on: " + item.Hour); Assert.AreEqual(1, item.AvgOccupancy, msg + " -avg by Hour: 2/2: " + item.Hour); } else if (item.Hour == 13) { Assert.AreEqual(0.5, item.MaxOccupancy, msg + " -max by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.5, item.MinOccupancy, msg + " -min by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: 1/2: " + item.Hour); } else if (item.Hour == 14) { Assert.AreEqual(0.5, item.MaxOccupancy, msg + " -max by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.25, item.AvgOccupancy, msg + " -avg by Hour: 1/2: " + item.Hour); } else if (item.Hour == 15) { Assert.AreEqual(0.5, item.MaxOccupancy, msg + " -max by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 1/2 on: " + item.Hour); Assert.AreEqual(0.25, item.AvgOccupancy, msg + " -avg by Hour: 1/2: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } var a = lr.GetDaysAvg(); var b = lr.GetDaysOfWeek(); var c = lr.GetHours(); var d = lr.GetHoursMax(); } }
public void TestReportsWithOneComputer() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 2, 15); cl.Exit = new DateTime(2010, 3, 15, 10, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); Activity act1 = new Activity(); act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 2, 16, 10, 0, 0); act1.Logout = new DateTime(2010, 2, 16, 12, 0, 0); act1.Mode = ActivityType.User; ReportModel model = new ReportModel(controller); List <int> list = new List <int>(); DateTime startDate = new DateTime(2010, 2, 16); DateTime endDate = new DateTime(2010, 2, 17); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; LabOccupancyReport lr; //2h out of 12h string msg = "one 2 hour activity in 1 day"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 1/1"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/1"); Assert.AreEqual(0.2, item.AvgOccupancy, msg + "-avg by day: (0*8+1*2)/10"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour >= 10 && item.Hour < 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 1/1 on: " + item.Hour); Assert.AreEqual(1, item.MinOccupancy, msg + " -min by Hour: 1/1 on: " + item.Hour); Assert.AreEqual(1, item.AvgOccupancy, msg + " -avg by Hour: 1/1 on: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } endDate = new DateTime(2010, 2, 18); msg = "one 2 hour activity in 2 day"; lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 1/1"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/1"); Assert.AreEqual(0.2, item.AvgOccupancy, msg + "-avg by day: (0*8+1*2)/10"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour >= 10 && item.Hour < 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 1/1 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 0/1 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: (1/1+0/1)/2 on: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } // msg = "one hour of the activity should be included in the report out of 2 hours (out of 2 days)"; startHour = new DateTime().Date + new TimeSpan(11, 0, 0); endHour = new DateTime().Date + new TimeSpan(13, 0, 0); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 1/1"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/1"); Assert.AreEqual(0.5, item.AvgOccupancy, msg + "-avg by day: (0/1+1/1)/2"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if (item.Hour >= 10 && item.Hour < 12) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 1/1 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 0/1 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: (1/1+0/1)/2 on: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } msg = "no computer activity should be included in the report out of 2 hours (out of 2 days)"; startHour = new DateTime().Date + new TimeSpan(13, 00, 0); endHour = new DateTime().Date + new TimeSpan(15, 00, 0); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } // two activities 10-12,13-15 Activity act2 = new Activity(); act2.Computer = cl.Computer; cl.Computer.Activities.Add(act2); act2.Login = new DateTime(2010, 2, 16, 13, 0, 0); act2.Logout = new DateTime(2010, 2, 16, 15, 0, 0); act2.Mode = ActivityType.User; // msg = "no computer activity should be included in the report out of 1 hours"; startHour = new DateTime().Date + new TimeSpan(12, 00, 0); endHour = new DateTime().Date + new TimeSpan(13, 00, 0); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } //10-12,13-15 msg = "two activities of total 4 hours should be included in the report out of 10 hours"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { if (item.DayOfWeek == act1.Login.DayOfWeek) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by day: 1/1"); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by day: 0/1"); Assert.AreEqual(0.4, item.AvgOccupancy, msg + "-avg by day: 4/10"); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } } foreach (var item in lr.ByHours) { if ((item.Hour >= 10 && item.Hour < 12) || (item.Hour >= 13 && item.Hour < 15)) { Assert.AreEqual(1, item.MaxOccupancy, msg + " -max by Hour: 1/1 on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -min by Hour: 0/1 on: " + item.Hour); Assert.AreEqual(0.5, item.AvgOccupancy, msg + " -avg by Hour: (1/1+0/1)/2 on: " + item.Hour); } else { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } } // msg = "no activities should be included in the report out of 20 hours"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); startDate = new DateTime(2010, 2, 17); endDate = new DateTime(2010, 2, 19); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } // msg = "no activities computer exit the lab during the report"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(12, 00, 0); startDate = new DateTime(2010, 3, 15); endDate = new DateTime(2010, 3, 16); lr = model.CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, true); foreach (var item in lr.ByDay) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min day occupancy expected on: " + item.DayOfWeek); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg day occupancy expected on: " + item.DayOfWeek); } foreach (var item in lr.ByHours) { Assert.AreEqual(0, item.MaxOccupancy, msg + " -no max hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.MinOccupancy, msg + " -no min hour occupancy expected on: " + item.Hour); Assert.AreEqual(0, item.AvgOccupancy, msg + " -no avg hour occupancy expected on: " + item.Hour); } }
public void UnusedNotificationTest() { User user = new User(); user.DisconnectedPeriod = 2; user.NotActivePeriod = 5; Computer comp = new Computer(); Lab lab = new Lab(); comp.Lab = lab; lab.Computers.Add(comp); ComputerLab cl = new ComputerLab(); cl.Computer = comp; cl.Lab = lab; cl.Entrance = DateTime.Now.Date.AddDays(-10); lab.ComputerLabs.Add(cl); comp.ComputerLabs.Add(cl); Department dep = new Department(); dep.Labs.Add(lab); lab.Department = dep; UserDepartment ud = new UserDepartment(); ud.Department = dep; ud.User = user; user.UserDepartments.Add(ud); Activity act1 = new Activity(); act1.Mode = ActivityType.Off; act1.Login = DateTime.Now.Date.AddDays(-3); comp.Activities.Add(act1); act1.Computer = comp; NotificationViewModel vm = new NotificationViewModel(user, new NotificationsController()); Assert.AreEqual(1, vm.Notifications.Count, "computer disconnected 3 days"); Assert.AreEqual(Constant.NotificationType.Disconnected, vm.Notifications[0].NotificationType, "notification type should be discconnected"); Assert.AreEqual(3, vm.Notifications[0].Days, "wrong nomber of disconnected days"); act1.Login = DateTime.Now.Date.AddDays(-3); act1.Logout = DateTime.Now.Date; Assert.AreEqual(1, vm.Notifications.Count, "computer is connected but no user activities"); Assert.AreEqual(Constant.NotificationType.NotUsed, vm.Notifications[0].NotificationType, "notification type should be unused"); //there are no user activites at all so the days without user activity should be since the computer is in the lab Assert.AreEqual(10, vm.Notifications[0].Days, "wrong nomber of disconnected days"); Activity act2 = new Activity(); act2.Mode = ActivityType.User; act2.Login = DateTime.Now.Date.AddDays(-3); comp.Activities.Add(act2); act2.Computer = comp; Assert.AreEqual(0, vm.Notifications.Count, "user loged on"); act2.Logout = DateTime.Now.Date.AddDays(-1); Assert.AreEqual(0, vm.Notifications.Count, "no user activity for only 1 day"); act2.Login = DateTime.Now.Date.AddDays(-6); act2.Logout = DateTime.Now.Date.AddDays(-5); Assert.AreEqual(1, vm.Notifications.Count, "no user activity for 3 days"); Assert.AreEqual(Constant.NotificationType.NotUsed, vm.Notifications[0].NotificationType, "notification type should be unused"); Assert.AreEqual(5, vm.Notifications[0].Days, "wrong nomber of disconnected days"); }
private void LoadComputersActivities(string compName) { try { // Open the text file using a stream reader. CAMS.Controllers.BaseController bC = new Controllers.BaseController(); ComputerLab cl = null; int labId = 17; int compId = bC.GetComputerId(compName); using (StreamReader sr = new StreamReader(@"D:\olladi\computers\\" + compName + ".txt")) { string line; while (sr.Peek() >= 0) { line = sr.ReadLine(); string[] param = line.Split(' '); if (param[0].ToLower() != "login") { continue; } string userName = param[1]; string time = param[2] + " " + param[3]; DateTime login = DateTime.Parse(time); line = sr.ReadLine(); param = line.Split(' '); if (param[0].ToLower() != "logout") { line = sr.ReadLine(); param = line.Split(' '); if (param[0].ToLower() != "logout") { continue; } } time = param[2] + " " + param[3]; DateTime logout = DateTime.Parse(time); if (logout.Date != login.Date) { continue; } if (cl == null) { cl = new ComputerLab { LabId = labId, ComputerId = compId, Entrance = login.Date }; bC.AddComputerLab(cl); } Activity act = new Activity { Login = login, Logout = logout, UserName = userName, ComputerId = compId, Mode = CAMS.Models.ActivityType.User, Weekend = IsWeekend(login.DayOfWeek) }; bC.AddActivity(act); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
public void TestReportsWithNoActtivities() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 4, 10, 10, 0, 0); cl.Exit = new DateTime(2010, 4, 15, 12, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); ReportModel model = new ReportModel(controller); DateTime startDate = new DateTime(2010, 4, 5); DateTime endDate = new DateTime(2010, 4, 10); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; LabReport lr; //report duration befor computer exsist in lab string msg = "report duration befor computer exsist in lab"; lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(0, lr.ComputersReport.Count, "one computer report expected: " + msg); Assert.AreEqual(0, lr.AverageUsage, "no usage expected: " + msg); //report duration after computer exsist in lab msg = "report duration after computer exsist in lab"; startDate = new DateTime(2010, 4, 16); endDate = new DateTime(2010, 4, 20); lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(0, lr.ComputersReport.Count, "one computer report expected: " + msg); Assert.AreEqual(0, lr.AverageUsage, "no usage expected: " + msg); //report duration with one computer - no user activities(only off) Activity act1 = new Activity(); act1.ComputerId = cl.ComputerId; act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 4, 11, 10, 0, 0); act1.Logout = new DateTime(2010, 4, 11, 12, 0, 0); act1.Mode = ActivityType.Off; msg = "report duration with one computer - no user activities(only off) "; startDate = new DateTime(2010, 4, 11); endDate = new DateTime(2010, 4, 12); lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); Assert.AreEqual(0, lr.AverageUsage, "no usage expected: " + msg); //report duration with computer with no activities in this time msg = "report duration with computer with no activities in this time"; startDate = new DateTime(2010, 4, 13); endDate = new DateTime(2010, 4, 14); lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); Assert.AreEqual(0, lr.AverageUsage, "no usage expected: " + msg); Activity act2 = new Activity(); act2.ComputerId = cl.ComputerId; act2.Computer = cl.Computer; cl.Computer.Activities.Add(act2); act2.Login = new DateTime(2010, 3, 11, 10, 0, 0); act2.Logout = new DateTime(2010, 3, 11, 12, 0, 0); act2.Mode = ActivityType.User; //report duration with computer not in the lab (but have activity in that time) msg = "report duration with computer not in the lab (but have activity in that time)"; startDate = new DateTime(2010, 3, 11); endDate = new DateTime(2010, 3, 12); lr = model.CreateLabReport(startDate, endDate, startHour, endDate, lab, true); Assert.AreEqual(0, lr.ComputersReport.Count, "no computer report expected: " + msg); Assert.AreEqual(0, lr.AverageUsage, "no usage expected: " + msg); }
public void TestReportsWithOneComputer_includeClasses() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 2, 15); cl.Exit = new DateTime(2010, 3, 15, 10, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); Activity act1 = new Activity(); act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 2, 16, 10, 0, 0); act1.Logout = new DateTime(2010, 2, 16, 12, 0, 0); act1.Mode = ActivityType.User; Activity cact1 = new Activity(); cact1.Computer = cl.Computer; cl.Computer.Activities.Add(cact1); cact1.Login = new DateTime(2010, 2, 16, 10, 0, 0); cact1.Logout = new DateTime(2010, 2, 16, 12, 0, 0); cact1.Mode = ActivityType.Class; ReportModel model = new ReportModel(controller); List<int> list = new List<int>(); DateTime startDate = new DateTime(2010, 2, 16); DateTime endDate = new DateTime(2010, 2, 17); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; // string msg = "2h user activity, 2h user activity - union 2h"; LabReport lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total activity time (with classes)"); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); cact1.Login = new DateTime(2010, 2, 16, 9, 0, 0); cact1.Logout = new DateTime(2010, 2, 16, 11, 0, 0); // msg = "2h user activity, 2h user activity- union 3h"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(3, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total activity time (with classes)"); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); Assert.AreEqual(30, item.ScheduleAverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(30, lr.ScheduleAverageUsage, msg + "- avarageUsage of lab "); cact1.Login = new DateTime(2010, 2, 16, 9, 0, 0); cact1.Logout = new DateTime(2010, 2, 16, 14, 0, 0); // msg = "2h user activity, 5h user activity- union 5h"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(5, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total activity time (with classes)"); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); Assert.AreEqual(50, item.ScheduleAverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(50, lr.ScheduleAverageUsage, msg + "- avarageUsage of lab "); cact1.Login = new DateTime(2010, 2, 16, 13, 0, 0); cact1.Logout = new DateTime(2010, 2, 16, 15, 0, 0); // msg = "2h user activity, 2h user activity- union 4h"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(4, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total activity time (with classes)"); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); Assert.AreEqual(40, item.ScheduleAverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(40, lr.ScheduleAverageUsage, msg + "- avarageUsage of lab "); // Activity cact2 = new Activity(); cact2.Computer = cl.Computer; cl.Computer.Activities.Add(cact2); cact2.Login = new DateTime(2010, 2, 16, 10, 30, 0); cact2.Logout = new DateTime(2010, 2, 16, 12, 30, 0); cact2.Mode = ActivityType.Class; msg = "1h out of 2h, 1.5h union with class"; startHour = new DateTime().Date + new TimeSpan(11, 0, 0); endHour = new DateTime().Date + new TimeSpan(13, 0, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(1, item.GetComputerTotalActiveTime().TotalHours, msg + ": computer total activity time "); Assert.AreEqual(1.5, item.GetComputerTotalActiveTimeWithClasses().TotalHours, msg + ": computer total class activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(50, item.AverageUsage, msg + "- avarageUsage of comp "); Assert.AreEqual(75, item.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of comp "); } Assert.AreEqual(50, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(75, lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); // msg = "1h out of 2h, class union-1h"; startHour = new DateTime().Date + new TimeSpan(9, 0, 0); endHour = new DateTime().Date + new TimeSpan(11, 0, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(1, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(1, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total class activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(50, item.AverageUsage, msg + "- avarageUsage of comp "); Assert.AreEqual(50, item.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of comp "); } Assert.AreEqual(50, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(50, lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); // msg = "no user activity out of 2h, class union- 2h"; startHour = new DateTime().Date + new TimeSpan(13, 00, 0); endHour = new DateTime().Date + new TimeSpan(15, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total class activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); Assert.AreEqual(100, item.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(100, lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); cact2.Login = new DateTime(2010, 2, 16, 10, 30, 0); cact2.Logout = new DateTime(2010, 2, 16, 11, 30, 0); Activity cact3 = new Activity(); cact3.Computer = cl.Computer; cl.Computer.Activities.Add(cact3); cact3.Login = new DateTime(2010, 2, 16, 11, 30, 0); cact3.Logout = new DateTime(2010, 2, 16, 12, 30, 0); cact3.Mode = ActivityType.Class; // two activities 10-12,13-15 Activity act2 = new Activity(); act2.Computer = cl.Computer; cl.Computer.Activities.Add(act2); act2.Login = new DateTime(2010, 2, 16, 13, 0, 0); act2.Logout = new DateTime(2010, 2, 16, 15, 0, 0); act2.Mode = ActivityType.User; // msg = "0h out of 1h, class union- 0.5h"; startHour = new DateTime().Date + new TimeSpan(12, 00, 0); endHour = new DateTime().Date + new TimeSpan(13, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().TotalHours, msg + ": computer total activity time "); Assert.AreEqual(0.5, item.GetComputerTotalActiveTimeWithClasses().TotalHours, msg + ": computer total class activity time "); Assert.AreEqual(1, item.GetComputerTotalTime(), msg + ": computer total time"); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(50, lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); Activity act3 = new Activity(); act3.Computer = cl.Computer; cl.Computer.Activities.Add(act3); act3.Login = new DateTime(2010, 2, 16, 8, 0, 0); act3.Logout = new DateTime(2010, 2, 16, 9, 0, 0); act3.Mode = ActivityType.User; Activity act4 = new Activity(); act3.Computer = cl.Computer; cl.Computer.Activities.Add(act4); act4.Login = new DateTime(2010, 2, 16, 9, 30, 0); act4.Logout = new DateTime(2010, 2, 16, 10, 0, 0); act4.Mode = ActivityType.User; Activity cact4 = new Activity(); act3.Computer = cl.Computer; cl.Computer.Activities.Add(cact4); cact4.Login = new DateTime(2010, 2, 16, 8, 30, 0); cact4.Logout = new DateTime(2010, 2, 16, 9, 30, 0); cact4.Mode = ActivityType.Class; cact1.Login = new DateTime(2010, 2, 16, 14, 0, 0); cact1.Logout = new DateTime(2010, 2, 16,16, 0, 0); // msg = "5.5h out of 10h, class union-7.5h"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(5.5, item.GetComputerTotalActiveTime().TotalHours, msg + ": computer total activity time "); Assert.AreEqual(7.5, item.GetComputerTotalActiveTimeWithClasses().TotalHours, msg + ": computer total class activity time "); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); } Assert.AreEqual((int)55, (int)lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(75, lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); // msg = "2h out of 3h, class union-2.5h"; startHour = new DateTime().Date + new TimeSpan(11, 00, 0); endHour = new DateTime().Date + new TimeSpan(14, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2.5, item.GetComputerTotalActiveTimeWithClasses().TotalHours, msg + ": computer total class activity time "); Assert.AreEqual(3, item.GetComputerTotalTime(), msg + ": computer total time"); } Assert.AreEqual(Math.Round(((double)2 / 3) * 100,2), lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(Math.Round(((double)2.5 / 3) * 100, 2), lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); // msg = "no activities should be included in the report out of 20 hours"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); startDate = new DateTime(2010, 2, 17); endDate = new DateTime(2010, 2, 19); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(0, item.GetComputerTotalActiveTimeWithClasses().Hours, msg + ": computer total class activity time "); Assert.AreEqual(20, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); Assert.AreEqual(0, lr.ScheduleAverageUsage, msg + "- ScheduleAverageUsage of lab "); // msg = "no activities computer exit the lab during the report"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(12, 00, 0); startDate = new DateTime(2010, 3, 15); endDate = new DateTime(2010, 3, 16); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); }
public void TestReportsWithOneComputer() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 2, 15); cl.Exit = new DateTime(2010, 3, 15,10,0,0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); Activity act1 = new Activity(); act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 2, 16, 10, 0, 0); act1.Logout = new DateTime(2010, 2, 16, 12, 0, 0); act1.Mode = ActivityType.User; ReportModel model = new ReportModel(controller); List<int> list = new List<int>(); DateTime startDate = new DateTime(2010, 2, 16); DateTime endDate = new DateTime(2010, 2, 17); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; //2h out of 12h string msg = "one 2 hour activity"; LabReport lr = model.CreateLabReport(startDate, endDate, startHour, endHour,lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2,item.GetComputerTotalActiveTime().Hours, msg+": computer total activity time "); Assert.AreEqual(10, item.GetComputerTotalTime(), msg+ ": computer total time"); Assert.AreEqual(20,item.AverageUsage , msg + "- avarageUsage of comp "); } Assert.AreEqual(20,lr.AverageUsage, msg + "- avarageUsage of lab " ); // msg = "one hour of the activity should be included in the report out of 2 hours"; startHour = new DateTime().Date + new TimeSpan(11,0,0); endHour = new DateTime().Date + new TimeSpan(13, 0, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(1, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(50, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(50, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "one hour of the activity should be included in the report out of 2 hours"; startHour = new DateTime().Date + new TimeSpan(9, 0, 0); endHour = new DateTime().Date + new TimeSpan(11, 0, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(1, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(50, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(50, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "one hour of the activity should be included in the report out of 1 hours"; startHour = new DateTime().Date + new TimeSpan(10, 30, 0); endHour = new DateTime().Date + new TimeSpan(11, 30, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(1, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(1, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(100, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(100, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "no computer activity should be included in the report out of 2 hours"; startHour = new DateTime().Date + new TimeSpan(13, 00, 0); endHour = new DateTime().Date + new TimeSpan(15, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); // two activities 10-12,13-15 Activity act2 = new Activity(); act2.Computer = cl.Computer; cl.Computer.Activities.Add(act2); act2.Login = new DateTime(2010, 2, 16, 13, 0, 0); act2.Logout = new DateTime(2010, 2, 16, 15, 0, 0); act2.Mode = ActivityType.User; // msg = "no computer activity should be included in the report out of 1 hours"; startHour = new DateTime().Date + new TimeSpan(12, 00, 0); endHour = new DateTime().Date + new TimeSpan(13, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(1, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "two activities of total 4 hours should be included in the report out of 10 hours"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(4, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(40, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(40, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "two activities of total 2 hours should be included in the report out of 3 hours"; startHour = new DateTime().Date + new TimeSpan(11, 00, 0); endHour = new DateTime().Date + new TimeSpan(14, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(3, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(Math.Round(((double)2 / 3) * 100, 2), item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(Math.Round(((double)2 / 3) * 100,2), lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "no activities should be included in the report out of 20 hours"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); startDate = new DateTime(2010, 2, 17); endDate = new DateTime(2010, 2, 19); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(20, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "no activities computer exit the lab during the report"; startHour = new DateTime().Date + new TimeSpan(8, 00, 0); endHour = new DateTime().Date + new TimeSpan(12, 00, 0); startDate = new DateTime(2010, 3, 15); endDate = new DateTime(2010, 3, 16); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(2, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); }
public void TestReportWithoutWeekends() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2018, 4, 15); cl.Exit = new DateTime(2018, 5, 15); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); Activity act1 = new Activity(); act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2018, 4, 16, 10, 0, 0); act1.Logout = new DateTime(2018, 4, 16, 12, 0, 0); act1.Mode = ActivityType.User; ReportModel model = new ReportModel(controller); List<int> list = new List<int>(); DateTime startDate = new DateTime(2018, 4, 16); DateTime endDate = new DateTime(2018, 4, 17); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(9, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(19, 00, 0); endHour = endHour.Date + ts; // string msg = "one 2 hour activity"; LabReport lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "one 2 hour activity no weekends"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, false); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); // two activities (16/4)10-12, (20/4)13-15 Activity act2 = new Activity(); act2.Computer = cl.Computer; cl.Computer.Activities.Add(act2); act2.Login = new DateTime(2018, 4, 20, 13, 0, 0); act2.Logout = new DateTime(2018, 4, 20, 15, 0, 0); act2.Mode = ActivityType.User; act2.Weekend = true; // msg = "activity in weekend-report include weekend"; startDate = new DateTime(2018, 4, 20); endDate = new DateTime(2018, 4, 21); startHour = new DateTime().Date + new TimeSpan(08, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(10, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(20, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(20, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "activity in weekend-day report disclude weekend"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, false); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(0, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "activity in weekend-week report include weekend"; startDate = new DateTime(2018, 4, 12); endDate = new DateTime(2018, 4, 21); startHour = new DateTime().Date + new TimeSpan(08, 00, 0); endHour = new DateTime().Date + new TimeSpan(18, 00, 0); lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(4, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(60, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(Math.Round(((double)4/60)*100,2), item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(Math.Round(((double)4 / 60) * 100,2), lr.AverageUsage, msg + "- avarageUsage of lab "); // msg = "activity in weekend-week report disclude weekend"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab, false); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(2, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(50, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(4, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(4, lr.AverageUsage, msg + "- avarageUsage of lab "); }
public void TestComputerEnterAndExitDuringReport() { Lab lab = new Lab(); lab.LabId = 3000; ComputerLab cl = new ComputerLab(); cl.Computer = new Computer(); cl.Computer.ComputerId = 3000; cl.Lab = lab; cl.Entrance = new DateTime(2010, 10, 10, 10, 0, 0); cl.Exit = new DateTime(2010, 10, 15, 12, 0, 0); lab.ComputerLabs.Add(cl); cl.Computer.ComputerLabs.Add(cl); ReportModel model = new ReportModel(controller); List<int> list = new List<int>(); DateTime startDate = new DateTime(2010, 10, 9); DateTime endDate = new DateTime(2010, 10, 16); DateTime startHour = new DateTime(); TimeSpan ts = new TimeSpan(8, 00, 0); startHour = startHour.Date + ts; DateTime endHour = new DateTime(); ts = new TimeSpan(18, 00, 0); endHour = endHour.Date + ts; // string msg = "computer enter and exit the lab during the report"; LabReport lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(0, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(52, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(0, item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(0, lr.AverageUsage, msg + "- avarageUsage of lab "); Activity act1 = new Activity(); act1.Computer = cl.Computer; cl.Computer.Activities.Add(act1); act1.Login = new DateTime(2010, 10, 10, 10, 0, 0); act1.Logout = new DateTime(2010, 10, 10, 19, 0, 0); act1.Mode = ActivityType.User; // msg = "computer enter and exit the lab during the report and have one activity"; lr = model.CreateLabReport(startDate, endDate, startHour, endHour, lab,true); Assert.AreEqual(1, lr.ComputersReport.Count, "one computer report expected: " + msg); foreach (var item in lr.ComputersReport) { Assert.AreEqual(8, item.GetComputerTotalActiveTime().Hours, msg + ": computer total activity time "); Assert.AreEqual(52, item.GetComputerTotalTime(), msg + ": computer total time"); Assert.AreEqual(Math.Round(((double)8 /52)*100,2), item.AverageUsage, msg + "- avarageUsage of comp "); } Assert.AreEqual(Math.Round(((double)8 / 52) * 100, 2), lr.AverageUsage, msg + "- avarageUsage of lab "); }