Moles adding assembly to wrong project

2019-08-04 07:27发布

问题:

I'm trying to get started with Microsoft Moles in order to be able to mock my extension methods, but I'm falling short.

I've successfully installed Moles on my workstation, but when I go to my test project (a class library project referencing NUnit, not an MSTest project), navigate down through References, right-click the assembly I want to stub (NHibernate in this case) and click "Add moles assembly...", the NHibernate.moles file shows up in an entirely different project in my solution. It's only content is

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
  <Assembly Name="NHibernate" />
</Moles>

This doesn't seem to get me anywhere. I expected to be able to follow this screencast from Dime Casts to get started, but I don't have the "Moles and Stubs for Testing" item template shown in the screencast.

I don't seem to be able to get anywhere from here. What do I need to do to get those templates? And why does the moles "assembly" end up in the wrong project? How do I proceed from here to be able to start using Moles?

回答1:

The mole assemblies don't show up at the beginning in your References folder. Build the project, click "Show All Files" and you'll see a MolesAssemblies folder containing your generated Mole assemblies.