Пример #1
0
        public void TestTimeDurationInfoTimeStamp()
        {
            // Insert an employee role
            Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString());

            employeeRole.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.SetKnowledgeDate(DateTime.Now);
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime   = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            List <TimeDurationInfo> timeDurationList  = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);

            // Insert a leave info
            LeaveInfo leaveInfo = LeaveInfo.CreateLeaveInfo(employeeGuid, managerGuid, leaveTypeGuid, LeaveStatus.Accepted,
                                                            "For Test", "Test Description", timeDurationList);

            leaveInfo.Save();
            Guid leaveGuid = leaveInfo.PKLeaveInfoID;

            timeDurationInfo.FKLeaveInfoID = leaveGuid;
            timeDurationInfo.KnowledgeDate = DateTime.Now;
            timeDurationInfo.IsDeleted     = false;
            timeDurationInfo.Save();
            Guid tdGuid = timeDurationInfo.PKTDInfoID;

            // Get the inserted time duration info
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKTDInfoID", tdGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            TimeDurationInfo testTimeDuration1 = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions);

            TimeDurationInfo testTimeDuration2 = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions);

            // Update the inseted time duratioin info
            testTimeDuration1.EndTime = Convert.ToDateTime("02/10/2001");
            testTimeDuration1.Save();
            testTimeDuration2.EndTime = Convert.ToDateTime("02/11/2002");
            testTimeDuration2.Save();

            // Get the updated time duration info
            TimeDurationInfo updatedTimeDuration = CommonDAL <TimeDurationInfo> .GetSingleObject(conditions);

            Assert.AreEqual(testTimeDuration1.EndTime, updatedTimeDuration.EndTime);
            Assert.AreNotEqual(testTimeDuration2.EndTime, updatedTimeDuration.EndTime);

            // Delete inserted items
            timeDurationInfo.Delete();
            leaveInfo.Delete();
            leaveType.Delete();
            employee.Delete();
            manager.Delete();
            employeeRole.Delete();
            managerRole.Delete();
        }
Пример #2
0
        public void TestApproveLeave()
        {
            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive          = true;
            employee.ServiceYears      = 10;
            employee.FKReportManagerID = managerGuid;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime    = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo   = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            DateTime                durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime                durationEndTime2   = Convert.ToDateTime("02/05/2011");
            TimeDurationInfo        timeDurationInfo2  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
            List <TimeDurationInfo> timeDurationList   = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);
            timeDurationList.Add(timeDurationInfo2);

            LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList);

            // Approve the applying leave.
            LeaveBLL.ApproveLeave(managerGuid.ToString(), leave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted);

            // Get the employee's leave list
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("FKSubmitEmployeeID", employeeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            List <LeaveInfo> leaveList = CommonDAL <LeaveInfo> .GetObjects(conditions);

            Assert.IsTrue(leaveList[0].PKLeaveInfoID == leave.PKLeaveInfoID && leaveList[0].Status == LeaveStatus.Accepted);

            leave.Delete();
            leaveType.Delete();
            employee.Delete();
            role.Delete();
            manager.Delete();
            managerRole.Delete();
        }
Пример #3
0
        public void TestUpdateLeaveInfoTransact()
        {
            // Insert an employee role
            Role employeeRole = Role.CreateRole(Guid.NewGuid().ToString());

            employeeRole.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Tian", DateTime.Now, "Liu");

            employee.IsActive     = true;
            employee.ServiceYears = 10;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, employeeRole.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.SetKnowledgeDate(DateTime.Now);
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime   = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            List <TimeDurationInfo> timeDurationList  = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);

            // Insert a leave info
            LeaveInfo leaveInfo = LeaveInfo.CreateLeaveInfo(employeeGuid, managerGuid, leaveTypeGuid, LeaveStatus.Accepted,
                                                            "For Test", "Test Description", timeDurationList);

            leaveInfo.Save();
            Guid leaveGuid = leaveInfo.PKLeaveInfoID;

            // Get the leave info inserted just now
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("PKLeaveInfoID", leaveGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            LeaveInfo testLeaveInfo = CommonDAL <LeaveInfo> .GetSingleObject(conditions);

            // Update the leave info
            testLeaveInfo.Reason = "Update test leave reason";
            try
            {
                testLeaveInfo.Save();
            }
            catch
            {
                Console.WriteLine("Throw exception for transact unit test");
            }

            // Get the updated leave info
            LeaveInfo updatedLeaveInfo = CommonDAL <LeaveInfo> .GetSingleObject(conditions);

            Assert.AreNotEqual(testLeaveInfo.Reason, updatedLeaveInfo.Reason);

            // Delete the leave, leave type, employees and roles
            leaveInfo.Delete();
            leaveType.Delete();
            employee.Delete();
            manager.Delete();
            employeeRole.Delete();
            managerRole.Delete();
        }
Пример #4
0
        public void TestGetMyTeamLeaves()
        {
            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive          = true;
            employee.ServiceYears      = 10;
            employee.FKReportManagerID = managerGuid;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime    = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo   = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            DateTime                durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime                durationEndTime2   = Convert.ToDateTime("02/05/2011");
            TimeDurationInfo        timeDurationInfo2  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
            List <TimeDurationInfo> timeDurationList   = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);
            timeDurationList.Add(timeDurationInfo2);

            LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList);

            // Get the employee's leave list
            List <LeaveInfo> leaveList = LeaveBLL.GetMyTeamLeaves(managerGuid.ToString(), true);

            // Compare these two list
            bool result = leave.PKLeaveInfoID == leaveList[0].PKLeaveInfoID;

            if (result)
            {
                //foreach (LeaveInfo leave in leave)
                //{
                //    bool existAndEqual = false;
                //    foreach (LeaveInfo leaveItem in leaveList)
                //    {
                //        if (leave.FirstStartTime == leaveItem.FirstStartTime && leave.LastEndTime == leaveItem.LastEndTime)
                //        {
                //            existAndEqual = true;
                //            break;
                //        }
                //    }

                //    result = existAndEqual;
                //    if (!result) break;
                //}
            }

            Assert.IsTrue(result);

            //foreach (LeaveInfo leave in leave)
            //{
            leave.Delete();
            //}
            leaveType.Delete();
            employee.Delete();
            role.Delete();
            manager.Delete();
            managerRole.Delete();
        }
Пример #5
0
        public void TestDeleteEmployeeLeaveSummaryByApproveLeave()
        {
            // Insert a manager role
            Role managerRole = Role.CreateRole(Guid.NewGuid().ToString());

            managerRole.Save();

            // Insert an employee who is a manager
            Employee manager = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Female, "Helen", DateTime.Now, "Niu");

            manager.IsActive     = true;
            manager.ServiceYears = 8;
            List <EmployeeRoleRL> managerRoleList = new List <EmployeeRoleRL>();

            managerRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, managerRole.PKRoleID));
            manager.SetRoleList(managerRoleList);
            manager.Save();
            Guid managerGuid = manager.PKEmployeeID;

            // Insert a role
            Role role = Role.CreateRole(Guid.NewGuid().ToString());

            role.Save();

            // Insert an employee.
            Employee employee = Employee.CreateEmployee(Guid.NewGuid().ToString(), "123", Sex.Male, "Hui", DateTime.Now, "Ji");

            employee.IsActive          = true;
            employee.ServiceYears      = 10;
            employee.FKReportManagerID = managerGuid;
            List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>();

            employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID));
            employee.SetRoleList(employeeRoleList);
            employee.Save();
            Guid employeeGuid = employee.PKEmployeeID;

            // Insert a leave type
            DateTime  leaveTypeStartTime = Convert.ToDateTime("01/01/2000");
            DateTime  leaveTypeEndTime   = Convert.ToDateTime("01/01/3000");
            LeaveType leaveType          = LeaveType.CreateLeaveType(Guid.NewGuid().ToString(), 100, leaveTypeStartTime, leaveTypeEndTime);

            leaveType.PKLeaveTypeID = Guid.NewGuid();
            leaveType.Save();
            Guid leaveTypeGuid = leaveType.PKLeaveTypeID;

            // Insert a leave time duration for this leave
            DateTime                durationStartTime  = Convert.ToDateTime("02/02/2001");
            DateTime                durationEndTime    = Convert.ToDateTime("02/05/2001");
            TimeDurationInfo        timeDurationInfo   = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime, durationEndTime);
            DateTime                durationStartTime2 = Convert.ToDateTime("02/02/2011");
            DateTime                durationEndTime2   = Convert.ToDateTime("02/05/2011");
            TimeDurationInfo        timeDurationInfo2  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime2, durationEndTime2);
            List <TimeDurationInfo> timeDurationList   = new List <TimeDurationInfo>();

            timeDurationList.Add(timeDurationInfo);
            timeDurationList.Add(timeDurationInfo2);
            int leaveHours = CommonMethods.ComputeHours(timeDurationList);

            LeaveInfo leave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "Test", leaveType.Name, "Test Desc", timeDurationList);

            // Approve the applying leave.
            LeaveBLL.ApproveLeave(managerGuid.ToString(), leave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted);


            // Get the inserted employee leave summary
            List <SearchCondition> conditions = new List <SearchCondition>();

            conditions.Add(SearchCondition.CreateSearchCondition("FKEmployeeID", employeeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            conditions.Add(SearchCondition.CreateSearchCondition("FKLeaveTypeID", leaveTypeGuid.ToString(), SearchComparator.Equal, SearchType.SearchString));
            EmployeeLeaveSummary employeeLeaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

            // Apply another leave
            DateTime                durationStartTime3 = DateTime.Parse("03/04/2011");
            DateTime                durationEndtime3   = DateTime.Parse("03/08/2011");
            TimeDurationInfo        timeDurationInfo3  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime3, durationEndtime3);
            DateTime                durationStartTime4 = DateTime.Parse("03/10/2011");
            DateTime                durationEndtime4   = DateTime.Parse("03/11/2011");
            TimeDurationInfo        timeDurationInfo4  = TimeDurationInfo.CreateTimeDurationInfo(durationStartTime4, durationEndtime4);
            List <TimeDurationInfo> timeDurationList2  = new List <TimeDurationInfo>();

            timeDurationList2.Add(timeDurationInfo3);
            timeDurationList2.Add(timeDurationInfo4);
            int newLeaveHours = CommonMethods.ComputeHours(timeDurationList2);

            LeaveInfo newLeave = LeaveBLL.ApplyLeave(employeeGuid.ToString(), "New Leave", leaveType.Name, "New Leave Desc", timeDurationList2);
            LeaveInfo delLeave = LeaveBLL.ApproveLeave(managerGuid.ToString(), newLeave.PKLeaveInfoID.ToString(), LeaveStatus.Accepted);

            delLeave.Delete();

            // Get the update leave summary
            EmployeeLeaveSummary updatedLeaveSummary = CommonDAL <EmployeeLeaveSummary> .GetSingleObject(conditions);

            Assert.AreEqual(updatedLeaveSummary.UsedHours, leaveHours);

            // Delete inserted items
            employeeLeaveSummary.Delete();
            leave.Delete();
            leaveType.Delete();
            employee.Delete();
            manager.Delete();
            managerRole.Delete();
            role.Delete();
        }