public SiteAddressDto Build()
        {
            var siteAddressDto = new SiteAddressDto(_id, _addressLine1, _addressLine2, _addressLine3, _addressLine4,_addressLine5,_county,
                                                    _postcode, _telephone, _contactDto);

            return siteAddressDto;
        }
        public void given_submitted_checklists_has_a_client_document_when_Handle_then_attachment_added_to_email()
        {
            //GIVEN
            var handler = GetTarget();
            var message = new SendSubmitChecklistEmail() {ChecklistId = Guid.NewGuid()};
            var clientDocumentId = 12345;
            var docLibraryId = 123456;
            var checklist = new Checklist()
                                {
                                    Id = Guid.NewGuid(),
                                    MainPersonSeenName = "Test User",
                EmailReportToPerson = true,
                                    EmailAddress = "*****@*****.**",
                                    Jurisdiction = "UK",
                                    ExecutiveSummaryDocumentLibraryId = clientDocumentId,
                                    ClientId = 123123,
                                    ActionPlan = new ActionPlan() {ExecutiveSummaryDocumentLibraryId = clientDocumentId},
                                    VisitDate = new DateTime(2014, 05, 01),
                                    SiteId = 1
                                };

            var docLibDocument = new DocumentDto()
                                     {
                                         PhysicalFilePath = @"C:\docLib\2014\1\1\",
                                         PhysicalFilename = "thefilename.pdf",
                                         Extension = ".pdf"
                                     };

            var siteAddress = new SiteAddressDto() {AddressLine1 = "Address", Postcode = "M1 1AA"};

            _checklistRepository.Setup(c => c.GetById(It.IsAny<Guid>()))
                .Returns(() => checklist);

            _clientDocumentService.Setup(x => x.GetById(clientDocumentId))
                .Returns(() => new ClientDocumentDto() {Id = clientDocumentId, DocumentLibraryId = docLibraryId});

            _docLibraryService.Setup((x => x.GetDocumentsByIds(It.IsAny<GetDocumentsByIdsRequest>())))
                .Returns(() => new[] {docLibDocument});

            _clientService.Setup(x => x.GetSite(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => siteAddress);

            AttachmentType[] emailedAttachments = new AttachmentType[0];

            _emailSender.Setup(x => x.SendWithDifferentAttachmentName(It.IsAny<RazorEmailResult>(), It.IsAny<AttachmentType[]>()))
                .Callback<RazorEmailResult, AttachmentType[]>(
                    (emailResult, attachments) => emailedAttachments = attachments);

            //WHEN
            handler.Handle(message);

            //THEN
            Assert.That(emailedAttachments.Length, Is.GreaterThan(0));
            Assert.That(emailedAttachments[0].NewFileName,
                        Is.EqualTo(String.Format("Visit Report - {0} - {1} - {2}{3}", siteAddress.AddressLine1,
                                                 siteAddress.Postcode, checklist.VisitDate.Value.ToShortDateString(), docLibDocument.Extension)));
            Assert.That(emailedAttachments[0].OldFileName, Is.EqualTo(docLibDocument.PhysicalFilePath + docLibDocument.PhysicalFilename));
        }
        public void Given_that_ContactDto_is_null_When_siteContact_property_is_used_Then_value_is_empty()
        {
            //Given            
            var target2 = new SiteAddressDto(1, default(string), default(string), default(string), default(string),
                                            default(string), default(string), default(string), default(string),
                                            null);

            var target = SiteAddressDtoBuilder.Create().WithSiteContact(null).Build();

            //When
            var result = target.SiteContact;

            //Then
            Assert.That(result, Is.EqualTo(null));
        }
        public void Setup()
        {
            _bus = new Mock<IBus>();
            _clientService = new Mock<IClientService>();
            _emailTemplateService = new Mock<IEmailTemplateService>();
            _templateEngine = new Mock<ITemplateEngine>();
            _emailSenderService = new Mock<IEmail>();
            _companyId = 735L;
            _peninsulaSiteId = 763476L;
            _siteStructureId = 111L;

            _siteAddressDto = new SiteAddressDto
                                  {
                                      AddressLine1 = "Add1",
                                      AddressLine2 = "Add2",
                                      AddressLine3 = "Add3",
                                      AddressLine4 = "Add4",
                                      Postcode = "PC",
                                      Telephone = "01234 567890",
                                      SiteId = _peninsulaSiteId
                                  };

            _can = "my can";
            var _companyDetails = new CompanyDetailsDto(123, "companyName", _can, "address_line1", "address_line2", "address_line3", "address_line4", 123456L, "postcode", "telephone", "website", "main contact"

            );

            _bus.Setup(x => x.Send(It.IsAny<SendSiteDetailsUpdatedEmail>()));

            _clientService
                .Setup(x => x.GetSite(_companyId, _peninsulaSiteId))
                .Returns(_siteAddressDto);

            _clientService
                .Setup(x => x.GetCompanyDetails(_companyId))
                .Returns(_companyDetails);

            _emailTemplateDto = new EmailTemplateDto
                                    {
                                        Subject = "TEST SUBJECT"
                                    };

            _emailTemplateService
                .Setup(x => x.GetByEmailTemplateName(EmailTemplateName.SiteAddressChangeNotification))
                .Returns(_emailTemplateDto);

            _emailBody = "TEST EMAIL BODY";

            _templateEngine
                .Setup(x => x.Render(It.IsAny<CompanyDetails>(), It.IsAny<string>()))
                .Returns(_emailBody);

            _viewModel = new SiteDetailsViewModel
                             {
                                 AddressLine1 = "Add1",
                                 AddressLine2 = "Add2",
                                 AddressLine3 = "Add3",
                                 AddressLine4 = "Add4",
                                 Postcode = "PC",
                                 Telephone = "01234 567890",
                                 SiteId = _peninsulaSiteId,
                                 SiteStructureId = _siteStructureId,
                                 ClientId = _companyId,
                                 SiteStatusUpdated = SiteStatus.NoChange
                             };

            _emailSenderService.SetupSet(x => x.Body = It.IsAny<string>()).Verifiable();
            _emailSenderService.SetupSet(x => x.Subject = It.IsAny<string>()).Verifiable();
            _emailSenderService.SetupSet(x => x.From = It.IsAny<string>()).Verifiable();
        }
 private static string GetSiteDetails(SiteAddressDto siteDetailsDto)
 {
     return String.Format("{0},{1},{2}", siteDetailsDto.AddressLine1, siteDetailsDto.Postcode, siteDetailsDto.AddressLine4);
 }
        public void given_qaAdvisor_has_no_email_address_when_sent_then_no_CCRecipents()
        {
            //GIVEN
            // var handler = GetTarget();
            var handler = new SendSubmitChecklistEmailHandler(_emailSender.Object, _checklistRepository.Object, _urlConfiguration.Object, _docLibraryService.Object, _clientDocumentService.Object, _clientService.Object);
            var message = new SendSubmitChecklistEmail() { ChecklistId = Guid.NewGuid() };
            var qaAdvisor = new QaAdvisor() { Id = Guid.NewGuid(), Email = "" };

            var checklist = new Checklist()
            {
                Id = message.ChecklistId,
                MainPersonSeenName = "Test User",
                EmailAddress = "*****@*****.**",
                Jurisdiction = "UK",
                ClientId = 123123,
                VisitDate = new DateTime(2014, 05, 01),
                SiteId = 1,
                QaAdvisor = qaAdvisor
            };

            var siteAddress = new SiteAddressDto() { AddressLine1 = "Address", Postcode = "M1 1AA" };

            _checklistRepository.Setup(c => c.GetById(It.IsAny<Guid>()))
                .Returns(() => checklist);

            _clientService.Setup(x => x.GetSite(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => siteAddress);

            RazorEmailResult sentEmail = null;

            _emailSender.Setup(x => x.SendWithDifferentAttachmentName(It.IsAny<RazorEmailResult>(), It.IsAny<AttachmentType[]>()))
                .Callback<RazorEmailResult, AttachmentType[]>(
                    (emailResult, attachments) => sentEmail = emailResult);

            //WHEN
            handler.Handle(message);

            //THEN
            Assert.That(sentEmail.Mail.CC.Count, Is.EqualTo(0));
        }
        public void given_submitted_checklist_has_no_document_returned_by_client_document_library_then_send_email_without_attachment_details()
        {
            //GIVEN
            var handler = GetTarget();
            var message = new SendSubmitChecklistEmail() {ChecklistId = Guid.NewGuid()};
            var clientDocumentId = 12345;
            var docLibraryId = 123456;
            var checklist = new Checklist()
                                {
                                    Id = Guid.NewGuid(),
                                    MainPersonSeenName = "Test User",
                                    EmailAddress = "*****@*****.**",
                                    Jurisdiction = "UK",
                                    ExecutiveSummaryDocumentLibraryId = docLibraryId,
                                    ClientId = 123123,
                                    ActionPlan = new ActionPlan() {ExecutiveSummaryDocumentLibraryId = clientDocumentId},
                                    VisitDate = new DateTime(2014, 05, 01),
                                    SiteId = 1
                                };

            var docLibDocument = new DocumentDto()
                                     {
                                         PhysicalFilePath = @"C:\docLib\2014\1\1\",
                                         PhysicalFilename = "thefilename.pdf",
                                         Extension = ".pdf"
                                     };

            var siteAddress = new SiteAddressDto() {AddressLine1 = "Address", Postcode = "M1 1AA"};

            _checklistRepository.Setup(c => c.GetById(It.IsAny<Guid>()))
                .Returns(() => checklist);

            _clientDocumentService.Setup(x => x.GetById(clientDocumentId))
                .Returns(() => null);

            _docLibraryService.Setup((x => x.GetDocumentsByIds(It.IsAny<GetDocumentsByIdsRequest>())))
                .Returns(() => new[] {docLibDocument});

            _clientService.Setup(x => x.GetSite(It.IsAny<long>(), It.IsAny<long>()))
                .Returns(() => siteAddress);

            AttachmentType[] emailedAttachments = new AttachmentType[0];

            _emailSender.Setup(x => x.SendWithDifferentAttachmentName(It.IsAny<RazorEmailResult>(), It.IsAny<AttachmentType[]>()))
                .Callback<RazorEmailResult, AttachmentType[]>(
                    (emailResult, attachments) => emailedAttachments = attachments);

            //WHEN
            handler.Handle(message);

            //THEN
            Assert.That(emailedAttachments.Length, Is.EqualTo(0));
        }