Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Fakes x64 not x86 and v4.5

I'm using the Microsoft Fakes testing framework. There's not much way around it as I need to use the shim/moles approach due to "legacy" code that I cannot change. It's code from a vendor with no source, it was written without testing in mind. So I'm stuck with 3 possible frameworks, TypeMock (expensive), Telerik's JustMock (expensive) or Microsoft's Fakes. As we already have VS Ultimate, we're opting for the fakes. As most people feel they need to suggest re-writing or modifying the code in some way to support using interfaces and/or dependency injection I'll tell you up front, this is not an option.

One of the issues I'm having is that the library I'm attempting to fake is huge and requires the use of the 64 bit version of fakes.exe and not the 32 bit (fakes.x86.exe), it runs into the memory limit of 32 bit apps.

The second issue is that I need to compile the fakes library using the v4.5 framework. It's possible through the command line, though undocumented. The reason is that in v4.5 they added the IReadOnly* interfaces in System.Collections.Generic and the library uses them. Compiling with v4, throws an error stating the types are not found, as expected.

The problem, Visual Studio is always using the x86 version and v4.0 framework and I can't find a way to override it. Does anybody know how to get it to use the 64 bit and v4.5 framework? My current idea is to not use visual studio's built-in stuff and just use the command line and manually reference the file. Then on every update of the dll, we would manually re-create it and update the reference. This file does not get updated very often so that is a possibility.

The command line I use to manually generate the fakes library (someone might find this useful) is:

"c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\fakes\fakes.exe" <assembly> /tfv:v4.5

The help command only shows that v2, v3.5 and v4 are possible options for tfv, but just for kicks I tried v4.5.

I have tried forcing the architecture on the app to x64 instead of any cpu, no change in which fakes.exe it ran. Looked in the .csproj file for the test, no change. Looked in the .csproj file that fakes.exe and it says to use v4 of the framework, opened in visual studio, changed to v4.5, compiled fine. Used the fakes command line, compiled fine. There is an attribute in the .fakes file in the project that allows the compiler version to be defined, but setting it to v4.5 still didn't work. I'm assuming that the version change in visual studio from v4 to v4.5 changed the assembly references as well. My next try is to try and change the template project if I can find it.

like image 866
Edward Avatar asked Feb 19 '13 23:02

Edward


2 Answers

@schellack - Here's how I was able to "reference the created fakes dll and make sure the required references are in your test project"

  1. Compile and run all unit tests locally, and make sure they pass
  2. In the project's main directory, same location as the .csproj file, there should now be a "FakesAssemblies" directory. In the directory will be the generated System.Web.Mvc.4.0.0.0.Fakes.dll (or whichever version number you're using). The project reference to System.Web.Mvc.4.0.0.0.Fakes has a hint path to this directory and dll already. Both this directory and the dll need to be added to source control. They do not need to be added to VS.
  3. In order for our CI build machine to compile, I also had to add the Microsoft.QualityTools.Testing.Fakes.dll to the project.
    1. I found Microsoft.QualityTools.Testing.Fakes.dll in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies
    2. In the project's main directory, same location as the .csproj file, there is a "Fakes" directory which is included in the project (visible in VS) as well as under source control. It has one .fakes file in it. I copied Microsoft.QualityTools.Testing.Fakes.dll into this directory, through VS so that it is also added to the project.
    3. The hint path in the project's .csproj file needs to be added / updated to look in the Fakes directory. I found the reference in my .csproj file and changed it to look like this:

<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
    <HintPath>Fakes\Microsoft.QualityTools.Testing.Fakes.dll</HintPath>
</Reference>

Now everything compiles and unit tests run

like image 130
jgerman Avatar answered Oct 26 '22 23:10

jgerman


Can only think of the following (apologies if it is already set):

'Test' --> 'Test Settings' --> 'Default Processor Architecture' --> 'X64'

like image 28
SpruceMoose Avatar answered Oct 27 '22 00:10

SpruceMoose