>Some real world unit tests


The documents that we produce (invoices, confirmation letters etc.) are based on Microsoft Word documents. They are built using the standard Microsoft Word mail merge fields. We then merge in data from the database to generate the document.

This is great because our clients can produce their own templates in tools they are familiar with!

We use the .Net components from Aspose to generate these documents as it is not recommended to use Word as a server side component – and they do this very well indeed.

One of the things that we wanted to do was import HTML formatted text into the Word template. Now it turns out that this is not straightforward and initially Aspose did not support it. So we wrote our own.

Recently we contributed our code for the HTML import to help get the functionality into the core component. During the exchange Roman sent over some of the unit tests that they use to test their components.

A couple of them are reproduced (with permission) below for your benefit:




public void TestPlainTextAndWhitespace() {

    builder.InsertHtml(“<body>\r\n” +

    “\tTest paragraph 1.\r\n” +

    “\t<!– This contains white space which should be removed.–>\r\n” +

    ”    Test paragraph 1.\r\n” +



    // White space got converted into single space

    // at the end of each sentence like in MS Word.


    Assert.AreEqual(“Test paragraph 1. Test paragraph 1. \x000c”,builder.Doc.GetText());




public void TestBoldNested() {


    CheckRunBold(0, “Normal1”, false);

    CheckRunBold(1, “Bold1”, true);

    CheckRunBold(2, “Bold2”, true);

    CheckRunBold(3, “Bold3”, true);

    CheckRunBold(4, “Normal2”, false);



As you can see they have collected several HTML fragments that they use to feed the HTML to Word conversion classes, then they check that the text comes back out as expected. They have over 350 test for their Word component alone. No wonder we’ve never had any problems with them…


Aspose.Word 1.9.5 Released

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s