Example #1
0
 public async Task <PersonExtended> ResolveLeaveRequestChain(LeaveRequest leaveRequest,
                                                             PersonWithStaff requestedBy,
                                                             OrgGroupWithSupervisor department,
                                                             OrgGroupWithSupervisor devision,
                                                             OrgGroupWithSupervisor supervisorGroup,
                                                             LeaveUseage leaveUseage)
 {
     return(await DoNotifyWork(leaveRequest, requestedBy, department, leaveUseage) ??
            await DoNotifyWork(leaveRequest, requestedBy, devision, leaveUseage) ??
            await DoNotifyWork(leaveRequest, requestedBy, supervisorGroup, leaveUseage));
 }
Example #2
0
        public async Task SendsExpectedEmails(string reason,
                                              LeaveRequest request,
                                              PersonWithStaff requestedBy,
                                              OrgGroupWithSupervisor department,
                                              OrgGroupWithSupervisor devision,
                                              OrgGroupWithSupervisor supervisorGroup,
                                              Guid expectedApproverId,
                                              bool expectApprovalEmailSent,
                                              int expectedNotifyEmailCount)
        {
            bool actualApprovalEmailSent = false;
            int  actualNotifyEmailCount  = 0;

            var emailMock = _servicesFixture.EmailServiceMock.As <IEmailService>();

            emailMock.Setup(service => service.SendTemplateEmail(It.IsAny <Dictionary <string, string> >(),
                                                                 It.IsAny <string>(),
                                                                 It.IsAny <EmailTemplate>(),
                                                                 It.IsAny <PersonWithStaff>(),
                                                                 It.IsAny <PersonWithStaff>()))
            .Returns(Task.CompletedTask)
            .Callback <Dictionary <string, string>, string, EmailTemplate, PersonWithStaff, PersonWithStaff>(
                (dictionary, subject, template, to, from) =>
            {
                if (template == EmailTemplate.RequestLeaveApproval)
                {
                    actualApprovalEmailSent = true;
                }
                else if (template == EmailTemplate.NotifyLeaveRequest)
                {
                    actualNotifyEmailCount++;
                }
            });


            var actualApprover = await _leaveService.ResolveLeaveRequestChain(request,
                                                                              requestedBy,
                                                                              department,
                                                                              devision,
                                                                              supervisorGroup, new LeaveUseage()
            {
                LeaveType = LeaveType.Sick, TotalAllowed = 20, Used = 0
            });

            Assert.True((expectedApproverId == Guid.Empty) == (actualApprover == null));
            if (actualApprover != null)
            {
                Assert.Equal(expectedApproverId, actualApprover.Id);
            }
            Assert.Equal(expectApprovalEmailSent, actualApprovalEmailSent);
            Assert.Equal(expectedNotifyEmailCount, actualNotifyEmailCount);
        }
Example #3
0
        private async ValueTask <PersonWithStaff> DoNotifyWork(LeaveRequest leaveRequest,
                                                               PersonWithStaff requestedBy,
                                                               OrgGroupWithSupervisor orgGroup, LeaveUseage leaveUseage)
        {
            //super and requested by will be the same if the requester is a supervisor
            if (orgGroup == null || requestedBy.Id == orgGroup.Supervisor)
            {
                return(null);
            }
            if (orgGroup.ApproverIsSupervisor && orgGroup.SupervisorPerson != null)
            {
                await SendRequestApproval(leaveRequest, requestedBy, orgGroup.SupervisorPerson, leaveUseage);

                return(orgGroup.SupervisorPerson);
            }

            if (orgGroup.SupervisorPerson != null)
            {
                await NotifyOfLeaveRequest(leaveRequest, requestedBy, orgGroup.SupervisorPerson, leaveUseage);
            }

            return(null);
        }