Using Moles for TDD with HttpWebRequest
Asked Answered
H

1

3

I am using VS2010 with SP1 (also have VS2012 installed on the same machine). Moles 1.0 The project is using .NET 4 I added moles assembly to system.dll and get the following error on compile

Error 46 The type or namespace name 'IReadOnlyList' does not exist in the namespace 'System.Collections.Generic' (are you missing an assembly reference?) [C:\Test\obj\Debug\Moles\s\m.g.csproj] C:\Test\m.g.cs Test

IReadOnlyList .NET 4.5 as far as I know.

Anyone else got this issue?

Herzig answered 28/10, 2012 at 17:55 Comment(4)
It seems that if you .NET 4.5 and moles, moles wants to reflect .net 4.5 assemblies. Workaround is described here but it only gives example of mscore. If you want to use system.net you have to add more <remove> tagsHerzig
Thank you, Haroon. What are the <remove> tags you used for the System.Net assembly to resolve this issue?Accentual
you would add remove tag to remove the specific namespace the assembly <Remove Namespace="System.Net.whatever you dont need"/>Herzig
@Herzig are you able to post a more complete solution to this issue? I am having the same IReadOnlyList namespace issue in VS2010 on a machine that also needs .net 4.5. I found your link helpful and understand that we can tell Moles not to use the .net Framework 4.5 assemblies but I am having trouble finding exactly how to implement it (where to put the file etc). I have a MyClass.moles file and it didn't like it when added the remove tags there. I also tried to create a new mscorlib.moles file and that didn't see to help either. Any information you could provide would be appreciated. Thanks!Cutright
C
0

Updated Solution I was able to get Pex to run in VS 2010 with .Net Framework 4.5 installed. Maybe others have explained that this is the solution but my issue (being new to Moles and Pex) is that many of the explanations were vague. Thanks to the author of these posts because they got me headed in the right direction:

http://feherzsolt.wordpress.com/2013/02/13/moles-and-net-4-5/

http://www.daedtech.com/using-moles-with-the-system-assembly

So the solution is to create a new .moles file (System.moles) in the test project at the same level that Pex created the yourAssemblyUnderTest.moles file and add the following to the file.

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

You may have to clean (or manually delete the obj folder contents) and rebuild but this solution worked for me. I also noticed that the first build would report build errors, but the errors would go away on subsequent builds.

Alternative Solution I know this isn't THE solution but it is a (poor) workaround that allows Pex to run...plus this was too long for a comment. If anyone knows how to get PEX to run on a machine with the 4.5 .Net Framework PLEASE respond.

This was my scenario. I have a machine with the .Net Framework 4.5 and I have Visual Studio 2010 and 2012 installed. I installed Pex (en_visual_studio_2010_pex_0.94.51023.0_power_tools_x64_598803.exe) and could run Pex in a VS 2010 project that was targeting .Net Framework 4.0. I could run Pex and it identified issues...but once I promoted issues to Unit Tests the unit test project wouldn't compile because of the following build error

The type or namespace name 'IReadOnlyList' does not exist in the namespace 'System.Collections.Generic' (are you missing an assembly reference?)

After much searching, and reading that Pex or Moles was replacing 4.5 .Net Framework assemblies with 4.0 versions I decided to uninstall 4.5, install 4.0, and give it a try. Running on 4.0 works just fine and I didn't need to define Mole type filters to get it to work. Then I tried tried to upgrade to the 4.5 Framework again...but sadly I end up right back where I started with the IReadOnlyList namespace issue.

Cutright answered 16/8, 2013 at 22:16 Comment(1)
I gave up on VS2012 and Moles. VS2012 Ultimate has Fakes as the moles 2.0 version.Herzig

© 2022 - 2024 — McMap. All rights reserved.