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

Mock framework vs MS Fakes frameworks

A bit confused on the differences of Mock frameworks like NMock vs the VS 2011 Fakes Framework. Going through MSDN, what I understand is that Fakes allow you to mock your dependencies just like RhinoMock or NMock, however the approach is different,…
Nairooz NIlafdeen
  • 1,150
  • 2
  • 9
  • 13
56
votes
4 answers

How to pass in a mocked HttpClient in a .NET test?

I have a service which uses Microsoft.Net.Http to retrieve some Json data. Great! Of course, I don't want my unit test hitting the actual server (otherwise, that's an integration test). Here's my service ctor (which uses dependency…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
32
votes
1 answer

How do I add a fakes assembly in VS 2012 Professional RC?

According to the two articles below on VS 2012 and Microsoft Fakes Test Framework, I should be able to right click on an assembly in my test project's references and choose "Add Fakes Assembly" to create a new Microsoft Fakes Framework Assembly in…
Dan Sorensen
  • 11,403
  • 19
  • 67
  • 100
29
votes
5 answers

MSB3270: Mismatch between the processor architecture - Fakes Framework

Since I use Fakes Framework in my UnitTest, I get the following MSBuild warning. warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference…
Snowcrack
  • 549
  • 1
  • 5
  • 13
27
votes
1 answer

Visual Studio 2015 InvalidProgramException in Unit Test With Fakes

I am using Visual Studio 2015 Enterprise RTM to write unit tests for a project that uses Unity Container. I have discovered that the simple act of adding a fakes assembly for Unity, not even actually using the fake, is sufficient to generate this…
26
votes
2 answers

Visual Studio Unit Tests running slower on TFS Build

My project has 1000+ unit tests that, in a local machine, all run in less than 10 seconds. But when they run on TFS Build, some tests run significantly slower than others. 3 of them run in about 1-2 minutes, other 4 in 5-30 seconds, and the others…
sshm
  • 269
  • 2
  • 4
24
votes
1 answer

How should I use Mocking and Fakes under .NET Core 1.1 or higher?

I have been using .NET Framework 4.X for years and I just switched to .NET Core . Since I want to do TDD, I want to use a mocking framework and microsoft fakes. However, it is not clear to me how to do that for .NET Core since the classical…
Daan
  • 2,478
  • 3
  • 36
  • 76
23
votes
3 answers

Any alternative for Microsoft Fakes in .NET Core?

I am looking for an alternative to Microsoft Fakes in .NET Core. I know it is no longer supported in .NET Core. I just do not understand why not, I think it was a good solution in certain situations. My problem is that I want to mock DateTime.Now.…
Undeadparade
  • 1,512
  • 2
  • 14
  • 30
22
votes
3 answers

Microsoft.Fakes won't run in normal unit test contexts

I'm using a simple proof-of-concept Fakes nUnit test: [Test] public void TestFakes() { using (var ctx = ShimsContext.Create()) { System.Fakes.ShimDateTime.NowGet = () => { return new DateTime(2000, 1, 1); }; …
pattermeister
  • 3,132
  • 2
  • 25
  • 27
19
votes
2 answers

Testing.Fakes Exception: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables

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 VS…
19
votes
4 answers

How to mock/fake SmtpClient in a UnitTest?

I want to use it to fake System.Net.Mail.SmtpClient in a MS-Test UnitTest. Therefor I added a Fakes Assembmly of System.dll. Then I create a ShimsContext and a StubSmtpClient. using (ShimsContext.Create()) { StubSmtpClient client = new…
user2900970
  • 751
  • 1
  • 5
  • 24
19
votes
4 answers

How do I get shims for base classes using Microsoft Fakes?

class Parent{ public string Name{ get; set; } } class Child :Parent{ public string address{ get; set; } } [TestClass] class TestClass{ [TestMethod] public void TestMethod() { var c = new Fakes.Child(); c.addressGet =…
kalrashi
  • 1,423
  • 3
  • 14
  • 15
18
votes
5 answers

MS Fakes unit tests failing after Visual Studio 2013 Update 4

I have recently upgrade from Microsoft Visual Studio 2013 Update 3 (Premium edition) to Microsoft Visual Studio 2013 Update 4 (Premium edition) and now my existing unit test projects have stopped compiling. It fails with the error: The type…
Kyle
  • 951
  • 3
  • 14
  • 31
17
votes
1 answer

Can Microsoft Fakes be used in Visual Studio 2010?

We have developers using Visual Studio 2010 professional and some trying out Visual Studio 2012. Project compatibility between the two versions has been good. Will a Visual Studio project still be compatible with 2010 if we introduce the new Fakes…
Dan Sorensen
  • 11,403
  • 19
  • 67
  • 100
16
votes
2 answers

Shims are not generated for .NET methods

When I began using Microsoft Fakes, I was excited to start shimming some .NET methods. I was lead to believe that I would be able to shim ANY .NET method, static or not: http://msdn.microsoft.com/en-us/library/hh549176.aspx. However, I've been…
David J
  • 263
  • 2
  • 10
1
2 3
28 29