public void Given_a_PRA_when_the_email_checklist_command_has_been_sent_to_the_queue_then_EmployeeChecklistStatus_equals_Generating() { //given long riskAssId = 3248; var personalRiskAssessment = new PersonalRiskAssessment(); personalRiskAssessment.Id = riskAssId; personalRiskAssessment.PersonalRiskAssessementEmployeeChecklistStatus = PersonalRiskAssessementEmployeeChecklistStatusEnum.NotSet; _log = new Mock<IPeninsulaLog>(); _log.Setup(x => x.Add(It.IsAny<object>())); _userRepo = new Mock<IUserForAuditingRepository>(); _riskAssessmentRepo = new Mock<IPersonalRiskAssessmentRepository>(); _riskAssessmentRepo.Setup(x => x.GetById(riskAssId)) .Returns(personalRiskAssessment); _employeeRepository = new Mock<IEmployeeRepository>(); _checklistRepository = new Mock<IChecklistRepository>(); _bus = new Mock<IBus>(); var request = new GenerateEmployeeChecklistEmails {RiskAssessmentId = riskAssId}; var target = GetTarget(); //when target.SetAsGenerating(request.RiskAssessmentId); //then _riskAssessmentRepo.Verify(x=> x.GetById(riskAssId)); _riskAssessmentRepo.Verify(x => x.SaveOrUpdate(It.Is<PersonalRiskAssessment>(pra => pra.Id == riskAssId))); _riskAssessmentRepo.Verify(x => x.SaveOrUpdate(It.Is<PersonalRiskAssessment>(pra => pra.PersonalRiskAssessementEmployeeChecklistStatus == PersonalRiskAssessementEmployeeChecklistStatusEnum.Generating))); }
public void When_handle_Then_should_call_correct_methods() { //Given var handler = CreateTarget(); var message = new GenerateEmployeeChecklistEmails() { Message = "Hello Message", RequestEmployees = new List<EmployeeWithNewEmail> { new EmployeeWithNewEmail() { EmployeeId = Guid.NewGuid() } }, ChecklistIds = new List<long>() { 1 }, GeneratingUserId = Guid.NewGuid() }; var ids = new List<Guid>() { Guid.NewGuid() }; _emailChecklistEmailService .Setup(x => x.Generate(It.Is<GenerateEmployeeChecklistEmailRequest>(y => y.GeneratingUserId == message.GeneratingUserId && y.Message == message.Message && y.RequestEmployees.Count == message.RequestEmployees.Count && y.ChecklistIds == message.ChecklistIds))) .Returns(ids); var employeeChecklistEmailDto = new EmployeeChecklistEmailDto() { RecipientEmail = "*****@*****.**", EmployeeChecklists =new[]{new EmployeeChecklistDto()}, Message = message.Message }; var emailsChecklistEmails = new[] { employeeChecklistEmailDto }; _emailChecklistEmailService .Setup(x => x.GetByIds(ids)) .Returns(emailsChecklistEmails); //When handler.Handle(message); //Then _emailChecklistEmailService.VerifyAll(); _bus.Verify(x => x.Publish(It.Is<EmployeeChecklistEmailGenerated>(y => y.Message == message.Message && y.RecipientEmail == employeeChecklistEmailDto.RecipientEmail && y.EmployeeChecklistEmailId == employeeChecklistEmailDto.Id ))); }
private GenerateEmployeeChecklistEmails CreateGenerateEmployeeChecklistEmailsCommand(EmployeeChecklistGeneratorViewModel viewModel) { var command = new GenerateEmployeeChecklistEmails { GeneratingUserId = CurrentUser.UserId, Message = viewModel.Message, RiskAssessmentId = viewModel.RiskAssessmentId, RequestEmployees = viewModel.ChecklistsToGenerate.RequestEmployees.Select(x => new EmployeeWithNewEmail { EmployeeId = x.EmployeeId, NewEmail = x.NewEmail }).ToList(), ChecklistIds = viewModel.ChecklistsToGenerate.ChecklistIds.ToList(), SendCompletedChecklistNotificationEmail = viewModel.SendCompletedChecklistNotificationEmail, CompletionDueDateForChecklists = viewModel.CompletionDueDateForChecklists, CompletionNotificationEmailAddress = viewModel.CompletionNotificationEmailAddress }; if (viewModel.NewEmployeeEmailVisible) { command.RequestEmployees[0].NewEmail = viewModel.NewEmployeeEmail; } return command; }