2

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?

Anne
  • 26,765
  • 9
  • 65
  • 71
Chris
  • 1,690
  • 2
  • 17
  • 24

2 Answers2

3

try this

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
  <Assembly Name="System" ExportedTypes="true" ReflectionOnly="true"/>  
</Moles>
Maks Matsveyeu
  • 866
  • 5
  • 11
  • yes, I think you are right. I was watching a vidoe on Pex, Moles and Code Contracts and they manually inserted the moles file with correct filtering – Chris Dec 12 '11 at 19:44
  • at least that actually helped me – Maks Matsveyeu Dec 14 '11 at 07:47
  • 1
    I actually added the text below and it worked. It seems there are some types in they system.dll that can't be stubbed – Chris Dec 15 '11 at 17:42
0

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.

wekempf
  • 2,738
  • 15
  • 16