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
5
votes
3 answers

Ignore the CS7035 "Specified version does not conform to the recommended format" in the Fakes assembly

I use VS 2015 U1. I use an external library with a strange versioning - 1.0.4056.40164. I added a .Fakes file for this library. When fakes assembly is built, I get the following warning: C:\Somewhere.Test\f.cs(21,58): warning CS7035: The specified…
zaitsman
  • 8,984
  • 6
  • 47
  • 79
5
votes
2 answers

Setting out parameters with Microsoft Fakes

So I'm trying Microsoft Fakes and I like it, but I have a static method with an out parameter and I cannot figure out how to use it: Static method to fake: public static class Foo { public static bool TryBar(string str, out string stuff) { …
Maffelu
  • 2,018
  • 4
  • 24
  • 35
5
votes
1 answer

How to Stub the XMLDocument in VS 2013 using Microsoft Fakes

I have the below TestMethod I am testing with VS 2013 and I am using Microsoft Fakes. [TestMethod] public void ConstructorTestForCMAClass() { XmlDocument doc = new XmlDocument(); doc.LoadXml("
krrishna
  • 2,050
  • 4
  • 47
  • 101
5
votes
1 answer

Visual Studio 2013 Update 4 Changes MSFakes Shim Object Default Behaviour

We have a suite of unit tests some of which use MS Fakes. Prior to Update 4 they ran successfully. After applying Update 4 the tests that instantiate a shimmed type fail with a ShimNotImplemented exception. This has been confirmed by executing the…
R W
  • 53
  • 2
5
votes
2 answers

Mocking database with Microsoft Fakes

We are currently trying to implement Unit Testing on a VB.NET project but we get stucked about the best way to mock data access methods. We are working on VS2013 Premium so we can use Microsoft Fakes. As far as my understanding goes, Stubs and Shims…
realUser404
  • 2,111
  • 3
  • 20
  • 38
5
votes
1 answer

Build and test with TeamCity and Fakes Framework

We are running a TeamCity 8.1.4 buildserver with VS2013 installed on the machine. I've recently introduced tests which rely on the Microsoft Fakes Framework. Because of this I had to add some references to the new Fake assemblies and the…
Jan_V
  • 4,244
  • 1
  • 40
  • 64
5
votes
1 answer

Can I share a Microsoft Fakes unit test with a developer using Visual Studio Professional?

I'm running VS 2012 Premium and have written a few tests using Fakes. A member of my team is running VS 2010 Professional. After importing my unit tests, he's receiving compilation errors on that the references to both the Fakes assembly -…
gooddeeds
  • 53
  • 5
5
votes
2 answers

How to use Microsoft Fakes Assemblies on Process.Start

I would like to mock the System.Diagnostics.Process.Start call, so I've added a Fakes Assembly for the System Assembly. The problem is that Start is a static method on System.Diagnostics.Process so I'm not getting a shim to be able to hook a…
5
votes
1 answer

Microsoft Fakes "Assembly not supported"

I am attempting to add a Fakes assembly (in Visual Studio 2012 Ultimate) for an library that I reference in my code so that I can test independently of the libraries implementation. The the problem I'm having is that when I right click the…
5
votes
2 answers

Shim a void method

I have the following (legacy, inherited from predecessors) VB.Net (framework 2.0) Classes and Methods which creates a System Event Log on Exception: Public Interface IMyClass Function MyMethod(ByVal aValue As String) As Date End…
Shevek
  • 3,869
  • 5
  • 43
  • 63
5
votes
1 answer

Shimming with Microsoft Fakes and a static, generic method

I need to shim a static generic method for a unit test. However, I can't seem to get Fakes to create the shim object. Does anyone know how to accomplish this? In particular, I want to shim Newtonsoft's JsonConvert.DeserializeObject<>()
Chris
  • 1,690
  • 2
  • 17
  • 24
5
votes
1 answer

MS Fakes - The extern alias was not specified in a /reference option

I have a silverlight solution and I'am trying to create a fakes assembly for System.Windows.Controls.Data.DataForm.Toolkit (to play with DataForm). After I add the fakes assembly I get the following build error: Error 6 The extern alias 'swd' was…
5
votes
5 answers

Microsoft Fakes and .Net 4.0

we've been looking into using the new Fakes framework to help us increase the test coverage on some legacy code running under the .net 4.0 framework. Unfortunately, it seems like we're going to be unable to upgrade to .net 4.5. Would I be correct…
gmancoll
  • 53
  • 1
  • 6
5
votes
2 answers

Moles/Fakes: How do I implement a test setup?

I have been recently working with Moles and I am now switching to Fakes. In my old test project I had a test setup, which looked like this: [TestInitialize] public void Setup() { //... } In there I did some necessary setup just like setting up…
Thomas Mondel
  • 1,944
  • 3
  • 20
  • 25
5
votes
2 answers

How to Isolate (detour) constructor of class with Microsoft Fakes Shim?

Is there a possibility to isolate / replace an constructor of a class with Microsoft Fakes? In found an example for Mole (antecessor of Fakes): http://thecurlybrace.blogspot.co.at/2011/11/how-do-i-detour-mole-type-constructor.html I tried constructs…
Dresel
  • 2,375
  • 1
  • 28
  • 44