示例#1
0
        public void Backend_ReportBackend_Generate_Weekly_Report_Attendance_Overlap_Should_Pass()
        {
            //arrange
            var dateTimeHelper = DateTimeHelper.Instance;

            dateTimeHelper.EnableForced(true);
            dateTimeHelper.SetForced(new DateTime(2018, 10, 20, 0, 0, 0));
            var dateTimeUTCNow = dateTimeHelper.GetDateTimeNowUTC();

            var reportBackend = ReportBackend.Instance;
            var testReport    = new WeeklyReportViewModel
            {
                SelectedWeekId = 1
            };
            var testStudent = DataSourceBackend.Instance.StudentBackend.GetDefault();

            testReport.Student   = testStudent;
            testReport.StudentId = testStudent.Id;

            var dayNow = dateTimeUTCNow.Date;                                                  //today's date

            var thisMonday = dayNow.AddDays(-((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //this Monday's date

            var attendanceMon1 = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(12)),
                Emotion = EmotionStatusEnum.VeryHappy
            };

            var attendanceMon2 = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(9)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(11)),
                Emotion = EmotionStatusEnum.VeryHappy
            };

            var attendanceMon3 = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(13)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(14)),
                Emotion = EmotionStatusEnum.VeryHappy
            };


            testStudent.Attendance.Add(attendanceMon1);
            testStudent.Attendance.Add(attendanceMon2);
            testStudent.Attendance.Add(attendanceMon3);

            testReport.DateEnd = dateTimeUTCNow;

            //act
            var result = reportBackend.GenerateWeeklyReport(testReport);

            //reset
            DataSourceBackend.Instance.Reset();

            //assert
            Assert.IsTrue(result.Stats.AccumlatedTotalHours.Equals(new TimeSpan(4, 0, 0)), TestContext.TestName);
        }
示例#2
0
        public void Backend_StudentBackend_CalculateTokens_Attendance_2hr_Should_Pass()
        {
            // Arrange
            var expect = 2;

            var firstDay = DataSourceBackend.Instance.SchoolCalendarBackend.GetDefault();
            var data     = new AttendanceModel
            {
                Out = firstDay.Date,
                In  = firstDay.Date
            };

            data.In  = data.In.AddMinutes(firstDay.TimeStart.TotalMinutes);
            data.Out = data.In.AddHours(2);   // Attended class for 2 hrs

            data.In  = UTCConversionsBackend.KioskTimeToUtc(data.In);
            data.Out = UTCConversionsBackend.KioskTimeToUtc(data.Out);

            // Act
            var result = DataSourceBackend.Instance.StudentBackend.CalculateTokens(data);

            // Reset
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual(expect, result, TestContext.TestName);
        }
示例#3
0
        public ActionResult Create([Bind(Include =
                                             "Id," +
                                             "StudentId," +
                                             "In," +
                                             "Out," +
                                             "Emotion," +
                                             "IsNew," +
                                             "")] AttendanceModel data)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(data.Id))
            {
                // Send back for edit
                return(View(data));
            }

            //create a new attendance using the data
            var myAttendance = new AttendanceModel
            {
                StudentId = data.StudentId,
                //update the time
                In         = UTCConversionsBackend.KioskTimeToUtc(data.In),
                Out        = UTCConversionsBackend.KioskTimeToUtc(data.Out),
                Emotion    = data.Emotion,
                EmotionUri = Emotion.GetEmotionURI(data.Emotion),

                IsNew = data.IsNew
            };

            //add the attendance to the student's attendance
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(myAttendance.StudentId);

            myStudent.Attendance.Add(myAttendance);
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            return(RedirectToAction("Read", new { id = myAttendance.StudentId }));
        }
示例#4
0
        public void Backend_ReportBackend_GenerateLeaderboard_Valid_Data_Should_Pass()
        {
            //arrange
            var studentList = DataSourceBackend.Instance.StudentBackend.Index();

            var dayNow = UTCConversionsBackend.UtcToKioskTime(DateTime.UtcNow).Date;           //today's date

            var thisMonday = dayNow.AddDays(-((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //this Monday's date

            var attendanceMon = new AttendanceModel
            {
                In  = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(8)),
                Out = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(9)),
            };
            var attendanceTue = new AttendanceModel
            {
                In  = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(10)),
                Out = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(12)),
            };

            var student1 = studentList.Where <StudentModel>(x => x.Name == "Doug").FirstOrDefault();

            student1.Attendance.Add(attendanceMon);
            DataSourceBackend.Instance.StudentBackend.Update(student1);

            var student2 = studentList.Where <StudentModel>(x => x.Name == "Jea").FirstOrDefault();

            student2.Attendance.Add(attendanceMon);
            student2.Attendance.Add(attendanceTue);
            DataSourceBackend.Instance.StudentBackend.Update(student2);

            //act
            var result = ReportBackend.Instance.GenerateLeaderboard();

            //reset
            DataSourceBackend.Instance.StudentBackend.Reset();

            Assert.IsNotNull(result[1].Name, TestContext.TestName);

            //assert
            // TODO:  Need to rework this test, after getting the date/time wrapped.

            //Assert.AreEqual(student1.Name, result[1].Name, TestContext.TestName);
            //Assert.AreEqual(student2.Name, result[0].Name, TestContext.TestName);
        }
示例#5
0
        public void Backend_ReportBackend_Generate_Quarter_Report_Quarter_Id_Is_4_Should_Pass()
        {
            //arrange
            var dateTimeHelper = DateTimeHelper.Instance;

            dateTimeHelper.EnableForced(true);
            dateTimeHelper.SetForced(new DateTime(2018, 10, 20, 0, 0, 0));
            var dateTimeUTCNow = dateTimeHelper.GetDateTimeNowUTC();

            var reportBackend = ReportBackend.Instance;
            var testReport    = new QuarterReportViewModel
            {
                SelectedQuarterId = 4
            };
            var testStudent = DataSourceBackend.Instance.StudentBackend.GetDefault();

            testReport.Student   = testStudent;
            testReport.StudentId = testStudent.Id;

            var dayNow = dateTimeUTCNow.Date;                                                      //today's date

            var thisMonday = dayNow.AddDays(-7 - ((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //this Monday's date

            var attendanceMon = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(9)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(12)),
                Emotion = EmotionStatusEnum.VeryHappy
            };
            var attendanceTue = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(1).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(1).AddHours(12)),
                Emotion = EmotionStatusEnum.Happy
            };
            var attendanceWed = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(2).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(2).AddHours(12)),
                Emotion = EmotionStatusEnum.Neutral
            };
            var attendanceThu = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(3).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(3).AddHours(12)),
                Emotion = EmotionStatusEnum.Sad
            };
            var attendanceFri = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(4).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(4).AddHours(12)),
                Emotion = EmotionStatusEnum.VerySad
            };

            testStudent.Attendance.Add(attendanceMon);
            testStudent.Attendance.Add(attendanceTue);
            testStudent.Attendance.Add(attendanceWed);
            testStudent.Attendance.Add(attendanceThu);
            testStudent.Attendance.Add(attendanceFri);

            testReport.DateEnd = dateTimeUTCNow;

            //act
            var result = reportBackend.GenerateQuarterReport(testReport);

            //reset
            DataSourceBackend.Instance.Reset();

            //assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
示例#6
0
        public void Backend_ReportBackend_GenerateOverallReport_Valid_Report_Should_Pass()
        {
            //arrange
            var reportBackend = ReportBackend.Instance;
            var testReport    = new MonthlyReportViewModel();
            var testStudent   = DataSourceBackend.Instance.StudentBackend.GetDefault();

            testReport.Student   = testStudent;
            testReport.StudentId = testStudent.Id;

            var dayNow = UTCConversionsBackend.UtcToKioskTime(DateTime.UtcNow).Date;               //today's date

            var thisMonday = dayNow.AddDays(-7 - ((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //this Monday's date

            var attendanceMon = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(8)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(9)),
                Emotion = EmotionStatusEnum.VeryHappy
            };
            var attendanceTue = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(1).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(1).AddHours(12)),
                Emotion = EmotionStatusEnum.Happy
            };
            var attendanceWed = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(2).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(2).AddHours(12)),
                Emotion = EmotionStatusEnum.Neutral
            };
            var attendanceThu = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(3).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(3).AddHours(12)),
                Emotion = EmotionStatusEnum.Sad
            };
            var attendanceFri = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(4).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(4).AddHours(12)),
                Emotion = EmotionStatusEnum.VerySad
            };

            testStudent.Attendance.Add(attendanceMon);
            testStudent.Attendance.Add(attendanceTue);
            testStudent.Attendance.Add(attendanceWed);
            testStudent.Attendance.Add(attendanceThu);
            testStudent.Attendance.Add(attendanceFri);

            testReport.DateEnd = DateTime.UtcNow;

            //act
            var result = reportBackend.GenerateOverallReport(testReport);

            //reset
            DataSourceBackend.Instance.Reset();

            //assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
示例#7
0
        public ActionResult Update([Bind(Include =
                                             "Id," +
                                             "StudentId," +
                                             "In," +
                                             "Out," +
                                             "Emotion," +
                                             "IsNew," +
                                             "EmotionUri," +
                                             "")] AttendanceModel data)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            // The emotionURI is passed in as the AttendanceID because of conflicts with the model, it is then converted
            if (string.IsNullOrEmpty(data.EmotionUri))
            {
                // Send back for edit
                return(View(data));
            }
            data.Id = data.EmotionUri;  //copy the ID back to Data.Id

            if (string.IsNullOrEmpty(data.StudentId))
            {
                return(View(data));
            }

            //get the attendance with given id
            var myAttendance = DataSourceBackend.Instance.StudentBackend.ReadAttendance(data.StudentId, data.Id);

            if (myAttendance == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            //update the time
            myAttendance.In  = UTCConversionsBackend.KioskTimeToUtc(data.In);
            myAttendance.Out = UTCConversionsBackend.KioskTimeToUtc(data.Out);

            //update the emotion
            myAttendance.Emotion    = data.Emotion;
            myAttendance.EmotionUri = Emotion.GetEmotionURI(myAttendance.Emotion);
            DataSourceBackend.Instance.StudentBackend.UpdateAttendance(myAttendance);

            return(RedirectToAction("Details", new { id = myAttendance.StudentId, item = myAttendance.Id }));
        }