public void When_handle_Then_should_call_correct_methods()
        {
            //Given            
            var message = new SendHardCopyToOfficeEmail()
            {
                ChecklistId = Guid.NewGuid(),
                CAN = "SGG72",
                VisitDate = DateTime.Now,
                VisitBy = "Fred Flintstone",
                SubmittedBy = "Barney Rubble",
                SubmittedDate = DateTime.Now,        
                SiteAddressLine1 = "22 Acacia Avenue",
                SiteAddressLine2 = "Rubble Town",
                SiteAddressLine3 = "Rockville",
                SiteAddressLine4 = "",
                SiteAddressLine5 = "",        
                SitePostcode = "FF1 2RV"
            };          

            //When
            var handler = CreateTarget();
            handler.Handle(message);

            //Then
            _emailSender.Verify(x => x.Send(It.IsAny<RazorEmailResult>()));
        }
Exemplo n.º 2
0
        private void SendSubmitChecklistEmails(Checklist checklist)
        {
            _checklistRepository.SaveOrUpdate(checklist);
            _checklistRepository.Flush();

            // close the session to commit the transaction so that the new values can be accessed when generating the emails
            if (_businessSafeSessionManager != null)
                _businessSafeSessionManager.CloseSession();

            if (checklist.EmailReportToPerson || (checklist.EmailReportToOthers && checklist.OtherEmails.Any()))
            {
                _bus.Send(new SendSubmitChecklistEmail() {ChecklistId = checklist.Id});
            }

            if (checklist.PostReport)
            {
                var clientDetails = new List<CompanyDetails>();
                string can = GetClientAccountNumber(clientDetails, checklist.ClientId);

                 var site = checklist.SiteId.HasValue
                        ? _clientDetailsService.GetSite(checklist.ClientId.Value, checklist.SiteId.Value)
                        : null;

                SendHardCopyToOfficeEmail email = new SendHardCopyToOfficeEmail()
                                                      {
                                                          CAN = can,
                                                          ChecklistId = checklist.Id,
                                                          VisitDate = checklist.VisitDate,
                                                          VisitBy = checklist.ChecklistCompletedBy,
                                                          SubmittedBy = checklist.ChecklistSubmittedBy,
                                                          SubmittedDate = checklist.ChecklistSubmittedOn,
                                                          SiteName = site != null ? site.SiteName : "",
                                                          SiteAddressLine1 = site != null ? site.Address1 : "",
                                                          SiteAddressLine2 = site != null ? site.Address2 : "",
                                                          SiteAddressLine3 = site != null ? site.Address3 : "",
                                                          SiteAddressLine4 = site != null ? site.Address4 : "",
                                                          SiteAddressLine5 = site != null ? site.Address5 : "",
                                                          SitePostcode = site != null ? site.Postcode  : ""
                                                      };

                _bus.Send(email);
            }
        }