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

Error "The type or namespace xxxx does not exist" when compiling Moles in Visual Studio 2012

I am attempting to compile an existing project (targets .NET4) developed in Visual Studio 2010 and now testing migration to VS2012. When I compile my existing project with moles, I get the following error a lot. The type or namespace name 'Claim'…
10
votes
2 answers

How do Install Microsoft Fakes (Unit Test Isolation) on VS 2013 Professional edition

I want to start writing unit test cases using the Microsoft Fakes framework in Visual Studio 2013 Professional. Please advise on how I can achieve this.
Neeraj Dubey
  • 4,401
  • 8
  • 30
  • 49
10
votes
1 answer

How to mock/isolate internal classes in VS 2012 with Fakes Framework shims?

So, the issue is that I have a bunch of internal classes in my assembly that are used by the class I want to test. Since accessors have been removed from VS2012, I'm fine with using [InternalsVisibleTo] and that works great... except when I try to…
Finster
  • 499
  • 1
  • 7
  • 25
9
votes
1 answer

Error "The extern alias 'snh' was not specified in a /reference option " in a C# test project using Microsoft Fakes

I have a C# test project that uses Microsoft fakes. An external library (abc.dll) that the project is referencing was recently updated to .net standard 2.0. After updating the abc.dll library reference to the latest version, the test project…
MAK
  • 307
  • 2
  • 12
9
votes
3 answers

Error generating fakes with ITuple

We've been using the Microsoft Fakes framework in our solution for a long time to fake System.DateTime.UtcNow during testing. More recently, though several weeks ago, we started using C# 7 features (with VS 2017), including tuples as return values…
SvenAelterman
  • 1,532
  • 1
  • 15
  • 26
9
votes
2 answers

Fakes stopped working after installing Visual Studio 2015

I've installed Visual Studio 2015 as a try-out and since then my unit tests that use fakes won't compile anymore, not even on VS 2013. The unit test project targets .net 4.5. Msdn suggest changing the target framework version. The error is gone if I…
Carra
  • 17,808
  • 7
  • 62
  • 75
9
votes
1 answer

Visual Studio Community Edition and Fakes Framework?

I can't see the "Add Fakes Assembly" item in my test project's references' shortcut menu. Is Microsoft Fakes Framework available in Visual Studio Community 2013 edition?
tomppa
  • 91
  • 1
  • 2
9
votes
1 answer

.Net Fakes - How to shim an inherited property when the base class is abstract?

I am trying to write a unit test that covers the following line var fileFullName = fileInfo.FullName; where fileInfo is an instance of FileInfo. I am using fakes to shim the FileInfo object, but I am unable to provide a value for the FullName…
lextechnica
  • 103
  • 2
  • 6
9
votes
1 answer

Microsoft Fakes & TFS 2012 Visual Studio Test Runner - unit test fail sporadically

Environment Visual Studio 2012 Premium Update 3 Team Foundation Server 2012 Update 3 edit: .NET Framework 4 DefaultTemplate (DefaultTemplate.11.1.xaml) Visual Studio Test Runner Target Platform: X86 Problem I have 2…
9
votes
1 answer

ShimNotSupportedException when running tests from MSTest or Resharper

I am currently working with Microsoft Visual Studio 2012 and the new Fakes framework. And after adding my unit tests to the MSBuild and continuous integration process, the Fakes unit tests happen to raise a ShimNotSupportedException. I tried…
Thomas Mondel
  • 1,944
  • 3
  • 20
  • 25
9
votes
3 answers

How can I verify that a Microsoft Fakes (beta) stub/shim was called (like AssertWasCalled in Rhino Mocks)?

I'm using the beta of Microsoft Fakes in Visual Studio 11. How can I verify that a dependency's method was called by my system under test?
lance
  • 16,092
  • 19
  • 77
  • 136
8
votes
3 answers

MSBuild 15 - The type or namespace 'Fakes' does not exist in the namespace

I'm trying to set up automated builds and unit testing for a project which uses the Fakes library for it's unit tests. The project builds and tests fine on my Windows 10 PC (VS 2017 Enterprise installed), however using the same command to compile…
Foxocube
  • 710
  • 9
  • 32
8
votes
1 answer

Fakes assembly is not generating

I can't figure out what I need to do to generate Fakes. In my test project I included a reference to the assembly that I want to fake. It added /Fakes/.fakes to my project and it built the project. There were a ton of warnings, but…
Nick
  • 4,556
  • 3
  • 29
  • 53
8
votes
1 answer

How does one refer to a stub which has a generic parameter of itself using Microsoft Fakes?

I'm using Microsoft Fakes in some unit tests I'm working on. My interface looks like this: interface ISecuredItem where TChildType : class, ISecuredItem { SecurityDescriptor Descriptor { get; } IEnumerable
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
7
votes
0 answers

Running MS Fakes before build properly while using the new NetSDK project format

I am trying to get Microsoft Fakes to work properly with my unit test project (net47) wherein my project file format is using the new NetSDK format. With Visual Studio 2019, I can add a Fakes Assembly and things seem to work fine, until we try to…
michael
  • 14,844
  • 28
  • 89
  • 177
1 2
3
28 29