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

ShimNotSupportedException in MS VisualStudio 2012

I'm just trying to get familiar with the new Fakes Isolation Framework in Visual Studio 2012 RC but I'm consequently facing issues with ShimNotSupportedExceptions. At the first tries, each single shim method I tried to hook up a delegate to, had…
Ben Sch
  • 2,909
  • 4
  • 20
  • 23
4
votes
2 answers

Internal static class contains private class. How to create object of private class for unit testing using microsoft fakes

I searched a lot regarding this issue but did not get any issue same as I'm looking for, finally asking the question. I'm using microsoft fakes to test the below C# code. I'm stuck in a situation where I have a below class to test internal static…
Amar Gadekar
  • 387
  • 4
  • 11
4
votes
1 answer

Fake static/singleton class/method using microsoft fakes

I have class which has private constructor and accessed through public static method ( singleton class). Not able to create singleton object of this class in fakes. public class MyBusinessManager : BusinessManager { private MyBusinessManager…
4
votes
0 answers

Visual Studio 2015, Microsoft Fakes and System.Security.Claims.Claim

I have an interface in a .NET 4.5 (not 4.6) class library, public interface IBrokenFakeInterface { Claim WhyWontItGenerateFakeOfThisInterface(); } In my unit test project (MSTest) when I have added the Fakes for the appropriate assembly…
BrettJ
  • 980
  • 8
  • 15
4
votes
1 answer

How can I fake Assembly.LoadFile and Assembly.GetTypes?

I'm struggling to fake these two lines of code: Assembly asm = Assembly.LoadFile(fileName); Type[] asmTypes = loggerAssembly.GetTypes(); When I type System.Reflection.ShimAssembly there is no such type as ShimAssembly like for example in the case…
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
4
votes
0 answers

Fakes assembly is not generated

I'm trying to use Microsoft Fakes for my unit tests. I've referenced assembly under test in test project, then right clicked it and clicked "Add Fakes Assembly". As a result *.fakes file was created under the Fakes folder, but Fakes Assembly was not…
polina
  • 41
  • 4
4
votes
1 answer

Microsoft Fakes and Shims with nunit

I'm trying to test userservice and I want to fake datetime using Fakes.ShimsContext like it was told on this page On test execution I'm getting UnitTestIsolation instrumentation failed to initialize. Please restart Visual Studio and rerun this…
user1765862
  • 13,635
  • 28
  • 115
  • 220
4
votes
1 answer

How to shim ObjectSet (EntityFramework)?

I've shimmed my data context. Now I need to shim a table get(). I'm running into issues with ObjectSet, since I don't know how to shim it. DataModel.Fakes.ShimMyEntities.Constructor = (inst) =>…
4thSpace
  • 43,672
  • 97
  • 296
  • 475
4
votes
1 answer

How to use Microsoft Fakes to isolate a web service without using Dependency Injection

I am testing a web service client and need to isolate the call to the web service. I have already been told that we can not use dependency injection. How can I isolate the webservice so that I can test the business logic that calls that service. …
4
votes
1 answer

Converting Moq C# code to equivalent c# Microsoft Fakes for unit testing

I am trying to do unit testing with a recent project I have been working on. It involves a SQL Server 2008 R2 database and a WCF Service using C#, .NET 4.5 and Visual Studio 2013 Premium. We use Entity Framework (EF) 6.0.1. I am trying to test the…
Kyle
  • 951
  • 3
  • 14
  • 31
4
votes
1 answer

How to call original method that includes a call to a faked method?

I'm using MS Fakes. Give the following class: public class Person { public void SaveQuotes() { DoSomething(); } private void DoSomething() { Console.WriteLine("Original DoSomething called."); } } and this…
Jason Evans
  • 28,906
  • 14
  • 90
  • 154
4
votes
1 answer

VS2013 - MSB3270: Mismatch between the processor architecture - Fakes Framework

In the same vein as this thread, I'm seeing a build warning when building the test assemblies in my cloud project that use the Visual Studio Fakes framework. There was a mismatch between the processor architecture of the project being built "MSIL"…
4
votes
1 answer

set properties for ShimFileCreationInformation object

I am writing some unit test cases using fakes framework. I am using an object ShimFileCreationInformation from Microsoft.SharePoint.Client.Fakes namespace. Now, I pass this object to a function. Inside the function, I am trying to assign a value to…
Aditi
  • 1,188
  • 2
  • 16
  • 44
4
votes
1 answer

Calling the original method from shim method

While creating shims for members of types in BCLs (or of any library for that matter). We often face a situation where we want to call the original method which we have overidden (be it inside the shim delegate or outside).…
Varun K
  • 3,593
  • 2
  • 25
  • 26
4
votes
1 answer

Running Unit Tests Fakes Framework on TFS build server | Error

Using the Microsoft Fakes Framework, I am trying to run my Unit Tests on our TFS build server. Local it works fine, but it doesn't work on the build server: It seems that not the correct files have been copied to the output directory. What files…
dpwulp94
  • 163
  • 1
  • 8