public async Task Execute(string htmlDocument, string documentType, string documentId)
        {
            ILetterParser parser = _getParser.ForType(documentType);

            if (parser == null)
            {
                Console.WriteLine($"Letter type invalid {documentType}");
                throw new NonSupportedException();
            }
            var htmlInput = parser.Execute(htmlDocument);

            var css = CompileCss(htmlInput);

            var header = ParsingHelpers.FormatLetterHeader(htmlInput.AddressLines, htmlInput.RightSideOfHeader, htmlInput.LetterHead);

            var fullHtml = "<!DOCTYPE html><html><head><style>"
                           + css
                           + "</style></head><body>"
                           + header
                           + htmlInput.MainBody
                           + "</body></html>";

            var pdfBytes = await _parseHtmlToPdf.Convert(fullHtml, documentId);

            Console.WriteLine("Writing PDF to temp file");
            await File.WriteAllBytesAsync($"/tmp/{documentId}.pdf", pdfBytes);

            Console.WriteLine("Successfully written to file");
        }
        public void FormatHeadersCompressesAddressesToMaxSevenLines()
        {
            var addressLines = new List <string>
            {
                "Name",
                "Address Line 1",
                "Address Line 2",
                "Address Line 3",
                "Address Line 4",
                "Address Line 5",
                "Address Line 6",
                "City",
                "County",
                "Postcode"
            };

            var expectedAddressString = "Name<br />" +
                                        "Address Line 1<br />" +
                                        "Address Line 2, Address Line 3<br />" +
                                        "Address Line 4, Address Line 5, Address Line 6<br />" +
                                        "City<br />" +
                                        "County<br />" +
                                        "Postcode";

            var result = ParsingHelpers.FormatLetterHeader(addressLines, "");

            result.Should().Contain(expectedAddressString);
        }
        public void FormatHeaderReturnsFormattedTableIncludingTheRightSideOfHeader()
        {
            var rightSideOfHeader = "<p>Lots of html and CSS</p>";

            var result = ParsingHelpers.FormatLetterHeader(new List <string> {
                "Name"
            }, rightSideOfHeader);

            result.Should().Contain(rightSideOfHeader);
        }
        public void FormatHeaderReturnsFormattedTableIncludingTheAddress()
        {
            var addressLines = new List <string>
            {
                "Name",
                "Address Line 1",
                "Address Line 2",
                "City",
                "County",
                "Postcode"
            };

            var expectedAddressString = @"Name<br />Address Line 1<br />Address Line 2<br />City<br />County<br />Postcode";

            var result = ParsingHelpers.FormatLetterHeader(addressLines, "");

            result.Should().Contain(expectedAddressString);
        }
        public void FormatHeaderStripsWhitespaceFromAddressLines()
        {
            var addressLines = new List <string>
            {
                "Name",
                "      ",
                "Address Line 1",
                "        ",
                "\n",
                "\n      ",
                "Postcode"
            };

            var expectedAddressString = @"Name<br />Address Line 1<br />Postcode";

            var result = ParsingHelpers.FormatLetterHeader(addressLines, "");

            result.Should().Contain(expectedAddressString);
        }