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_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));
        }