Moles creation does not create all objects

耗尽温柔 提交于 2019-12-11 07:46:28

问题


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.



来源:https://stackoverflow.com/questions/8748101/moles-creation-does-not-create-all-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!