Excluding files in assembly from being moled

928 Views Asked by At

I am using moles to generate mock classes for the legacy code my team uses. Is it possible to exclude certain classes in the assembly from being moled? I am getting a lot of errors for some autogenerated classes we have in the legacy code which I want to exclude from being moled.

1

There are 1 best solutions below

0
On

To include and exclude types from stub/mole generation, you need to modify the .moles file for your assembly. Although the section "Type Filtering" of the reference manual describes only the StubGeneration element, there is also the MoleGeneration element which works similarly but manages mole generation.

To exclude a type from stub and mole generation specify the type name in a Remove element so that the .moles file for your assembly looks like this:

<Moles xmlns="http://schemas.microsoft.com/moles/2010/" Diagnostic="true">
    <Assembly Name="your_assembly" />
    <StubGeneration>
        <Types>
            <Remove FullName="Your.Type.Full.Name!" />
        </Types>
    </StubGeneration>
    <MoleGeneration>
        <Types>
            <Remove FullName="Your.Type.Full.Name!" />
        </Types>
    </MoleGeneration>
</Moles>

Here's how to enable stub and mole generation only for one class Your.Type.Full.Name:

<Moles xmlns="http://schemas.microsoft.com/moles/2010/" Diagnostic="true">
    <Assembly Name="your_assembly" />
    <StubGeneration>
        <Types>
            <Clear />
            <Add FullName="Your.Type.Full.Name!" />
        </Types>
    </StubGeneration>
    <MoleGeneration>
        <Types>
            <Clear />
            <Add FullName="Your.Type.Full.Name!" />
        </Types>
    </MoleGeneration>
</Moles>