Questions tagged [microsoft-fakes]

Microsoft Fakes is an isolation framework for creating delegate-based test stubs and shims in .NET Framework applications.

Microsoft Fakes is an isolation framework for creating delegate-based test stubs and shims in .NET Framework applications. The Fakes framework can be used to shim any .NET method, including non-virtual and static methods in sealed types.

The Fakes framework grew out of the Pex and Moles projects released by Microsoft Research. Microsoft notes that: "The Fakes Framework in Visual Studio 2012 and 2013 and 2015 is the next generation of Moles & Stubs. Fakes is different from Moles, however, so moving from Moles to Fakes will require some modifications to your code. Moles will not be developed further, so we recommend to migrate to Fakes." (source)"

(Aside: The Pex project evolved into the Intellitest feature in Visual Studio 2015.)

See also:

421 questions
7
votes
0 answers

InvalidProgramException with shims in Visual Studio 2015

An almost similar question has already been asked a while ago but not answered yet. And since my setup is a little different, I start a new try: I demonstrate a shortened version of my code, but even this short version produces the error. I have a…
7
votes
1 answer

System.Security.Cryptography.X509Certificates.X509Certificate2 is not available in the target framework version

I installed VS2015 RTM en VS2013 Update 5 RTM. Now my solution is not building because I have an interface that has as returntype a X509Certificate2. Now my fakes aren't build. I also created a test project and there I have the same problem so it…
LockTar
  • 5,364
  • 3
  • 46
  • 72
7
votes
0 answers

SPEmulator and Microsoft Fakes

Hi I'm trying to run a simple test replacing Features.Count on every SPSite, but I can't. Can you help me? I have this code: [TestMethod] public void AllInstances() { using (var context = new SPEmulationContext(IsolationLevel.Fake)) { …
Maurizio Pozzobon
  • 3,044
  • 7
  • 34
  • 44
7
votes
3 answers

Running a test using Shims on a Visual Studio 2013 Test Agent

I have found various iterations of this question across a number of websites, however so far I have not found anything that provides a full answer that worked. I have just set up a number of Visual Studio Test Agents that all appear to be behaving…
7
votes
1 answer

How do microsoft fakes' shims actually work internally?

So I am interested in the way that it is implemented. Basically: How can I re-implement the same thing myself? ... which I am not intending to do. Just understand. The fundamental question is: How is it possible to (?) intercept class instantiation…
Robetto
  • 739
  • 7
  • 20
7
votes
5 answers

Microsoft Fakes generates UnitTestIsolationException

I have written very simple unit test project to see abilities of Microsoft Fakes. And I have executed on System assembly the menu command "Add Fakes Assembly". public static class Y2KChecker { public static void Check() { if…
Vasiliy Mazhekin
  • 688
  • 8
  • 24
6
votes
1 answer

Shimmed method not used by test in Release mode

Within Visual Studio 2015 I have a test project to which I've added a fakes assembly. In the unit test itself I create a shim for a static generic method that returns an instance to the generic type, such as: using (ShimsContext.Create()) { …
Chrisgh
  • 1,016
  • 2
  • 10
  • 18
6
votes
1 answer

Fakes Broken in Visual Studio 2015

I have Visual Studio 2015 Enterprise and discovered that I cannot compile almost any of our existing 2013 projects. Further investigation reveals that Visual Studio 2015 isn't able to generate fakes for types that were fine in Visual Studio…
42vogons
  • 683
  • 7
  • 19
6
votes
4 answers

Need a work around Microsoft.QualityTools.Testing.Fakes

We been getting this on are most up to date systems VS 12 update 4 we have tried setting specific version to false and still get the test failing with this…
TechLiam
  • 137
  • 1
  • 3
  • 10
6
votes
2 answers

Can I Change Default Behavior For All Shims In A Test

I'm currently writing unit tests using Microsoft Fakes framework. I've noticed that if I don't supply a delegate for a given property, the default value is returned. However, when initializing my shim I change this behavior to NotImplemented. var…
Brett Janer
  • 517
  • 1
  • 4
  • 20
6
votes
1 answer

TFS 2012 + VS 2013 + Microsoft Fakes compile issue (only during TFSBuild)

We are using TFS 2012 (Update 3) and VS 2013 RC. We have a .sln file with a two projects - the main project / assembly, and a UnitTest project. The unit test project is leveraging Microsoft Fakes. Within Visual Studio (we are using Premium), I…
user2799559
  • 61
  • 1
  • 3
6
votes
2 answers

Does Microsoft Fakes support abstract methods on a shim?

I have a class setup in the following manner: public abstract FooClass { public FooClass() { // init stuff; } public void RandomMethod() { // do stuff; } public abstract WhatIWantToShim(); } What I want to do…
Bart Sipes
  • 921
  • 8
  • 21
6
votes
3 answers

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…
Edward
  • 1,407
  • 2
  • 10
  • 15
6
votes
1 answer

Using Microsoft Fakes to Shim a method with ref parameters

I have a static method with ref parameters in my legacy (untestable) dll. I am trying to write unit tests for a class that calls into this method. public static class Branding { ... ... static public bool GetBranding(Int32 providerId, …
5
votes
1 answer

Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables. When using shims

Test which use Microsoft Fakes Framework fail with exception: Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables …
Usama Aslam
  • 437
  • 7
  • 18