microsoft-fakes

Visual Studio 2015 InvalidProgramException in Unit Test With Fakes

半腔热情 提交于 2019-12-03 23:15:44
问题 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 exception: System.InvalidProgramException: Common Language Runtime detected an invalid program. Consider the following steps to reproduce: Using Visual Studio 2015 Enterprise RTM create a Unit Test project targeting .NET 4.6 Add the NuGet package

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

徘徊边缘 提交于 2019-12-03 22:39:04
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 = "foo"; // I can see that c.NameGet = "bar"; // This DOES NOT exists } } How can I set the "name" in the above code sample? The generated class for Parent will have a constructor that looks like: ShimParent(Parent p) . All you need to do is: var child = new ShimChild(); var parent = new ShimParent(child); And set the appropriate values on the respective Shim's. You'll have to

MSB3270: Mismatch between the processor architecture - Fakes Framework

可紊 提交于 2019-12-03 19:07:00
问题 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 "DocumentServiceModel", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and

Shims are not generated for .NET methods

耗尽温柔 提交于 2019-12-03 10:37:06
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 trying to shim some of the methods in TcpClient and only stubs are created, which does me no good, since I want to be able to change some of the methods to return my own data rather than depending on a live TcpClient to give me data. I'm open to any suggestions on how to do this if there is another way beyond Microsoft Fakes. EDIT: Adding code to

Fakes Broken in Visual Studio 2015

你离开我真会死。 提交于 2019-12-03 01:39:02
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 2013. Consider the following steps to reproduce: Create a unit test project targeting .NET 4.5 Right-click on "System" in the references tab and choose "Add Fakes Assembly" To eliminate the noise for this example, edit the subsequent "System.fakes" file: <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true"> <Assembly Name="System"

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

半世苍凉 提交于 2019-12-01 17:39:23
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 the project on the build server (also windows 10 with VS 2017 Enterprise) gives several errors about the Fakes not existing. The exact errors look like this: XControllerTests.cs(10,20): error CS0234: The type or namespace 'Fakes' does not exist in the namespace 'System.Data.Common' (are you missing an assembly reference?) [C:\Runner\builds\xxx\XTests

Visual Studio 2015 InvalidProgramException in Unit Test With Fakes

大憨熊 提交于 2019-12-01 02:07:12
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 exception: System.InvalidProgramException: Common Language Runtime detected an invalid program. Consider the following steps to reproduce: Using Visual Studio 2015 Enterprise RTM create a Unit Test project targeting .NET 4.6 Add the NuGet package "Unity" version 3.5.1404.0 Add the NuGet package "CommonServiceLocator" version 1.2.0 Write a single unit

UnitTestIsolationException: Throws Exception while running Shims test in Release/Debug mode

╄→гoц情女王★ 提交于 2019-11-30 16:02:26
I am trying to run this unit test using Microsoft Shims, but it throws me exception in Shims.Context.Create(); method. Environment: VS 2012, Win2K8 R2 namespace MyShimsUnitTest { [TestClass] public class MyUnitTest { [TestMethod] public void GetCurrentYear() { using (Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()) { // Some Logic... } } } } Detailed Exception: Result Message: Test method MyShimsUnitTest.MyUnitTest.GetCurrentYear threw exception: Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: UnitTestIsolation instrumentation failed to initialize.

ShimNotSupportedException in MS VisualStudio 2012

和自甴很熟 提交于 2019-11-30 09:02:23
问题 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 ShimNotSupportedException s. At the first tries, each single shim method I tried to hook up a delegate to, had thrown a ShimNotSupportedException when trying to run/debug the test. [TestMethod] public void GetFoo_ValidBar_ReturnsBaz() { using(ShimsContext.Create()) { ShimDateTime.NowGet = () => new DateTime(2012,08,11,10,20,59); const string expected =

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

回眸只為那壹抹淺笑 提交于 2019-11-30 08:10:14
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); }; Assert.That(DateTime.Now.Year, Is.EqualTo(2000)); } } This test runs in the Visual Studio Test Explorer, but doesn't run in: nUnit GUI nUnit console The JetBrains test runner (dotCover OR Resharper) TestDriven.net test runner In each of these, I receive the following error: Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException : Failed to resolve profiler path