问题
I need to unit test a method that is using the System.Net.WebClient
in the System.dll
. I tried to Mole the System.dll
, but when I tried to compile the project to add references to the System.dll
mole, I got a bunch of errors like the following:
Error 2
'System.Net.Moles.SFileWebResponse.Dispose(bool)': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 251374 33 DGALib.IO.Tests
Error 3
'System.Net.Moles.SFileWebResponse.SupportsHeaders': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 251575 30 DGALib.IO.Tests
Error 4
'System.Net.Moles.SHttpWebResponse.Dispose(bool)': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 255264 33 DGALib.IO.Tests
Error 5
'System.Net.Moles.SHttpWebResponse.SupportsHeaders': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 255465 30 DGALib.IO.Tests
Error 6
'System.Net.Moles.SWebResponse.Dispose(bool)': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 303123 33 DGALib.IO.Tests
Error 7
'System.Net.Moles.SWebResponse.SupportsHeaders': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 303324 30 DGALib.IO.Tests
Error 8
'System.Net.Moles.SFileWebResponse.Dispose(bool)': no suitable method found to override [C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\s\m.g.csproj] C:\DGALibrary\DGALib.IO.Tests\m.g.cs 251374 33 DGALib.IO.Tests
And finally
Error 28
The command ""C:\Program Files\Microsoft Moles\bin\moles.exe" @C:\DGALibrary\DGALib.IO.Tests\obj\x86\Debug\Moles\moles.args" exited with code -1002. DGALib.IO.Tests
Are we not able to mole system.dll
?
回答1:
try this
<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
<Assembly Name="System" ExportedTypes="true" ReflectionOnly="true"/>
</Moles>
回答2:
I'm new to Pex/Moles so I can't provide you with an answer as to why the errors are occurring. However, so long as the errors aren't for types you actually need to Mole you can resolve your problem by editing the system.moles file to restrict the types to mole to just the ones you care about.
来源:https://stackoverflow.com/questions/8144653/moling-system-dll