views:

198

answers:

2

I am trying to comment an API (.Net) that I am exposing to a customer. I am doing this by using XML comments, and extracting via SandCastle.

This is all fine and dandy, however I have unittesting for the API, and thought the code from these would be good to place in the example tags.

So does anyone know of a good way to extract unit test code and place in the example tags? Or does anyone have better ideas?

Of course I redistribute the unit tests with the API, but it would be good to have them in the documentation.

+1  A: 

I see that Jon Skeet har an answer, that requires some work: http://stackoverflow.com/questions/301365/automatically-unit-test-example-code#301423 Has anyone gone and implemented this? Is there an easier way? This question is about getting a metod body from a cs file: http://stackoverflow.com/questions/261741/get-a-methods-contents-from-a-cs-file

I have made a project to do this: http://code.google.com/p/addsourcetodocumentation/

khebbie
+2  A: 

Hi. I am using NUnit and Sandcastle Help File Builder. Please take a look at Sandcastle Help File Builder documentation about The Code Block Component.

Here is an example how I place unit tests code in the example tag:

    /// <summary>
    /// Returns a string representation of an object.
    /// </summary>
    /// <returns>Comma separated string.</returns>
    /// <example>
    /// <code source="UnitM.CentrallProcessingLib.Tests\Data\CSVDataRowTests.cs" region="ToString_a" />
    /// </example>
    public override string ToString()
    {
        return this.Data;
    }

Here is a referenced unit test (CSVDataRowTests.cs) (it should be inside the #region section):

  #region ToString_a

    [Test]
    public void ToString_a()
    {
        CSVDataRow res = new CSVDataRow 
        {
            Data = "1;2;3"
        };

        Assert.AreEqual(res.ToString(), res.Data);
    }

  #endregion

Best regards.