Exemplo n.º 1
0
        public void Page_size()
        {
            const string expectedDocumentContent = "Expected document content";
            var          html = string.Format(HtmlDocumentFormat, expectedDocumentContent);

            var result = Pdf.From(html).OfSize(PaperSize.A4).Content();

            TextAssert.AreEqual(expectedDocumentContent, PdfDocumentReader.ToText(result));
            Assert.AreEqual(_210mmInPostScriptPoints, PdfDocumentReader.WidthOfFirstPage(result));
            Assert.AreEqual(_297mmInPostScriptPoints, PdfDocumentReader.HeightOfFirstPage(result));
        }
Exemplo n.º 2
0
        public void Document_title()
        {
            const string expectedTitle           = "Expected title";
            const string expectedDocumentContent = "Expected document content";
            var          html = string.Format(HtmlDocumentFormat, expectedDocumentContent);

            var result = Pdf.From(html).WithTitle(expectedTitle).Content();

            Assert.AreEqual(expectedTitle, PdfDocumentReader.Title(result));
            TextAssert.AreEqual(expectedDocumentContent, PdfDocumentReader.ToText(result));
        }
Exemplo n.º 3
0
        public void Convert_multiple_documents_sequently()
        {
            const string expectedDocumentContent = "Expected document content";
            var          html = string.Format(HtmlDocumentFormat, expectedDocumentContent);

            var first  = Pdf.From(html).Content();
            var second = Pdf.From(html).Content();
            var third  = Pdf.From(html).Content();

            TextAssert.AreEqual(expectedDocumentContent, PdfDocumentReader.ToText(first));
            TextAssert.AreEqual(expectedDocumentContent, PdfDocumentReader.ToText(second));
            TextAssert.AreEqual(expectedDocumentContent, PdfDocumentReader.ToText(third));
        }
Exemplo n.º 4
0
        public void Convert_massive_number_of_documents()
        {
            const string expectedDocumentContent = "Expected document content";
            const int    documentCount           = 100;
            var          html  = string.Format(HtmlDocumentFormat, expectedDocumentContent);
            var          tasks = new List <Task <byte[]> >();

            for (var i = 0; i < documentCount; i++)
            {
                tasks.Add(Task.Run(() => Pdf.From(html).Content()));
            }

            Task.WaitAll(tasks.OfType <Task>().ToArray());

            foreach (var task in tasks)
            {
                TextAssert.AreEqual(expectedDocumentContent, PdfDocumentReader.ToText(task.Result));
            }
        }
Exemplo n.º 5
0
        public void WhenEqual()
        {
            var expected = @"
namespace RoslynSandbox
{
    class Foo
    {
        private readonly int _value;
    }
}";

            var actual = @"
namespace RoslynSandbox
{
    class Foo
    {
        private readonly int _value;
    }
}";

            TextAssert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public static void WhenEqual()
        {
            var expected = @"
namespace N
{
    class C
    {
        private readonly int _value;
    }
}";

            var actual = @"
namespace N
{
    class C
    {
        private readonly int _value;
    }
}";

            TextAssert.AreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public void WhenNotEqual()
        {
            var expectedCode = @"
namespace RoslynSandbox
{
    class Foo
    {
        private readonly int _value;
    }
}";

            var actualCode = @"
namespace RoslynSandbox
{
    class Foo
    {
        private readonly int bar;
    }
}";
            var exception  = Assert.Throws <NUnit.Framework.AssertionException>(() => TextAssert.AreEqual(expectedCode, actualCode));
            var expected   = "Mismatch on line 6\r\n" +
                             "Expected:         private readonly int _value;\r\n" +
                             "Actual:           private readonly int bar;\r\n" +
                             "                                       ^\r\n";

            Assert.AreEqual(expected, exception.Message);
        }