Moles creation does not create all objects

2019-07-24 20:30发布

问题:

While trying to create a mole for some unit tests I noticed that some functions were not being 'moled'. Some functions were appearing in the xxx.moles.xml file while others were not.

To resolve this issue, I've tried reinstalling 'Pex and Moles', deleted files in the MolesAssembly folder, restarted the computer, etc.

Finally, I simply opened a console window and ran the moles.exe command from the command prompt.

"c:\program files\microsoft moles\bin\moles.exe" assembly.dll /op:"MolesAssemblies" /msbuild:"c:\windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

The first time I ran this, I received a message:

Moles : info : compilation : assembly metadata hash unchanged, skipping code generation.

After deleting the moles in the MolesAssemblies folder, I ran the moles.exe command again and all my functions are now appearing in the xxx.moles.dll and xxx.moles.xml files.

Does anyone know why the mole generation does not work when building inside Visual Studio 2010, but it works perfectly from the command prompt?

回答1:

I found the issue...I modified the .moles file before and only certain classes were added. I simply had to add more 'TypeName' and the classes/functions were included.

The reason that it 'worked' by using the moles.exe command was because I did not use the .moles file (I simply referenced the assembly). I changed the parameters for moles.exe to include the .moles file and the assembly and the results were identical to the output generated by Visual Studio. Once I notice that other parts of the code was breaking, I realized that the .moles file was incorrect.

I had something like this...

<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
  <Assembly Name="Assembly.name" />
    <StubGeneration>
        <Types>
            <Clear />
            <Add FullName="Fullname_1_0" />
        </Types>
    </StubGeneration>
    <MoleGeneration>
        <Types>
            <Clear />
            <Add FullName ="Fullname_1_0" />
        </Types>
    </MoleGeneration> 
</Moles>

I needed a second 'Add'

<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
  <Assembly Name="Assembly.name" />
    <StubGeneration>
        <Types>
            <Clear />
            <Add FullName="Fullname_1_0" />
        </Types>
    </StubGeneration>
    <MoleGeneration>
        <Types>
            <Clear />
            <Add FullName ="Fullname_1_0" />
            <Add TypeName="AdditionalClass"/>
        </Types>
    </MoleGeneration> 
</Moles>


回答2:

Be sure to REBUILD the test project, after modifying an assembly that is moled. Using the "clean" action on the test project will also fix this issue.



标签: moles