Jeremy Miller asked how do you know if your TDD approach is working earlier today. And then I wrote the following test which covers a particular bug \ feature of xsd.exe I found a while ago. It's incomplete, but then I started worrying, is this approach right? I'm testing one method which takes a schema and returns a CodeNamespace which has been altered. I need to make sure the result addresses the bug that was discovered which this test seems to do. But is it a unit test? Shouldn't it have fewer asserts as I've read in the past? Shouldn't I be satisfied with the tests I've also written on routines that perform the tweaking on the CodeNamespace once it has been generated, but which do not make sure that all those smaller routines work together to produce the overall result? What are your thoughts out there.

[Test]
public void Convert_ComplexTypeHasElementInChoiceWithNoType
   _GeneratedCodeFixesTypeOfObjectBug()
{
    XmlSchema schema = sb.CreateSchemaContaining(new XmlSchemaObject[] {
        sb.RootElementWithSeparateType(rootElementName, rootTypeName),
        sb.NamedComplexTypeContaining(rootTypeName, 
           sb.ChoiceOf(sb.DateStringAndEmptyElements(
              dateElementName, stringElementName, emptyElementName)))
    });
<span class="rem">//Convert it</span>
CodeNamespace ns = sc.ConvertSchemaToCodeNamespace(schema);

<span class="rem">//Check that the empty class has been generated</span>
CodeDomAssert.AssertClassExists(ns, emptyElementName + <span class="str">&quot;Class&quot;</span>);

<span class="rem">//Find the original class and check it has a choice element in it </span>
<span class="rem">//which isn't typeof(object) but which is typeof(emptyElementClass)</span>

<span class="kwrd">foreach</span> (CodeTypeDeclaration typeDec <span class="kwrd">in</span> ns.Types)
{
    <span class="kwrd">if</span> (typeDec.Name == rootTypeName)
    {
        <span class="rem">//Check that the choice element is fielded by a property of type </span>
        <span class="rem">//system object tagged with</span>
        <span class="rem">//[XmlElement(&quot;emptyElement&quot;, typeof(emptyElementClass))]</span>

        <span class="rem">//Create attributes to check</span>
        CustomAttribute emptyElementAttribute = <span class="kwrd">new</span> CustomAttribute(
        CustomAttributeType.Simple, elementAttributeName,
        <span class="kwrd">new</span> AttributeArgument[] {
           <span class="kwrd">new</span> AttributeArgument(
              CustomArgumentType.Simple, String.Empty, emptyElementName),
           <span class="kwrd">new</span> AttributeArgument(
              CustomArgumentType.TypeOf, String.Empty,  
                 emptyElementName + <span class="str">&quot;Class&quot;</span>)
        });

        CodeDomAssert.AssertFieldExists(
           typeDec.Members, MemberAttributes.Private, <span class="str">&quot;System.Object&quot;</span>,
        HelperFunctions.DefaultXsdGeneratedFieldName(defaultGeneratedPropertyName));

        CodeDomAssert.AssertTaggedPropertyExists(
           typeDec.Members, defaultGeneratedPropertyName, <span class="str">&quot;System.Object&quot;</span>,
           <span class="kwrd">true</span>, <span class="kwrd">true</span>, 
           HelperFunctions.DefaultXsdGeneratedFieldName(defaultGeneratedPropertyName),
           <span class="kwrd">new</span> CustomAttribute[] { emptyElementAttribute });
    }
}

}