microsoft-fakes

InvalidProgramException with shims in Visual Studio 2015

人盡茶涼 提交于 2019-12-08 18:22:43
问题 An almost similar question has already been asked a while ago but not answered yet. And since my setup is a little different, I start a new try: I demonstrate a shortened version of my code, but even this short version produces the error. I have a method that returns an instance of a System.Printing.LocalPrintServer : public class PrintServerProvider { public LocalPrintServer Provide() { return new LocalPrintServer(new string[0], PrintSystemDesiredAccess.EnumerateServer); } } For this method

How to stub 2nd call of method?

邮差的信 提交于 2019-12-08 07:24:40
问题 With MS Fakes, is there a way to supply a method body for the first call of a stubbed method and supply a different method body for the 2nd call of the same method? I'm testing a method that calls classA.MyMethod() twice. I've stubbed classA.MyMethod() in my unit test. But this means both calls to MyMethod() will return the same thing. I'd like the stubbed method to do this: public void MainMethod() { var result1 = classA.MyMethod(); //return null ... var result2 = classA.MyMethod(); //return

TFS 2017 doesn't build Fakes targets

筅森魡賤 提交于 2019-12-07 14:21:08
问题 I have a TFS 2017 Update 2 on-prem server with VS 2017 Enterprise installed. Our Build contains a Unit-Testing project which contains a Fakes assembly and works locally on the dev machines. When build on TFS, the build fails with The type or namespace name 'Fakes' does not exist in the namespace 'Our.Product' (are you missing an assembly reference?) (i.e. misses/fails to generate the Our.Product.Assembly.Fakes.dll file) I have additionally set up Fakes as suggested here. What baffles me is

Add Fakes Assembly option missing

被刻印的时光 ゝ 提交于 2019-12-06 23:36:33
问题 I'm trying to get the Microsoft Fakes up and running in a Unit test project that I've set up in my solution. For some reason the Add Fakes Assembly option is missing which means I can't create mockups of assemblies. And since this is the only alternative to add the Microsoft.QualityTools.Testing.Fakes assembly I can't use the Shim functionality either. I've recently installed Visual Studio 2012 Professional and installed update 3 and this is the first go in Visual Studio 2012 . And I haven't

Unable to run Unit Tests that uses Microsoft Fakes - Exception in ShimsContext.Create() Method

梦想与她 提交于 2019-12-06 14:37:51
问题 My problem is very similar to one reported here: UnitTestIsolationException when debugging tests using Fakes However, I am not even able to run the tests. Using the sample code provided here: Isolating Code Under Test with Microsoft Fakes (Getting Started with Shims), I get following exception on running the test below : the offending line is : using (ShimsContext.Create()) Exception on running the test: Test Name: TestMethod1 Test FullName: TestingShimsAndStubs.UnitTest1.TestMethod1 Test

How to use Microsoft Fakes framework to shim an instance method?

雨燕双飞 提交于 2019-12-06 07:25:38
问题 I am using Microsoft Fakes framework within VS2012. I use the following code to shim instance methods of my type. using (ShimsContext.Create()) { ShimDateTime.NowGet = () => { return new DateTime(1949, 10, 1); }; DateTime now = DateTime.Now; // shim works for the static property DateTime.Now. Class1 dependency = new Class1(); using (ShimsContext.Create()) { ShimClass1 shim1 = new ShimClass1(); StubClass1 stub1 = new StubClass1(); shim1.method1 = () => { return "shim method1"; }; shim1

Why there are no stubs for interfaces in Microsoft.Fakes

那年仲夏 提交于 2019-12-06 05:49:06
I'm about to use Microsoft.Fakes in my unit tests. I read a tutorial where Microsoft.Fakes creates a stub for an interface (implementred inside the solution), but in my solution stubs are available only for classes. Can you tell me what should I do to get stubs also for all the intercaes. Both interfaces and classes are defined as public. Fakes generates stubs for both classes and interfaces by default. You may have bumped into one of the current limitations, which is causing Fakes to skip your interface. To troubleshoot, open the .Fakes file and set Verbosity attribute of the Fakes element to

TFS 2017 doesn't build Fakes targets

て烟熏妆下的殇ゞ 提交于 2019-12-06 02:31:15
I have a TFS 2017 Update 2 on-prem server with VS 2017 Enterprise installed. Our Build contains a Unit-Testing project which contains a Fakes assembly and works locally on the dev machines. When build on TFS, the build fails with The type or namespace name 'Fakes' does not exist in the namespace 'Our.Product' (are you missing an assembly reference?) (i.e. misses/fails to generate the Our.Product.Assembly.Fakes.dll file) I have additionally set up Fakes as suggested here . What baffles me is that there are no mentions of Fakes in the build log (except for the error itself and the paths where

Fakes assembly is not generating

谁都会走 提交于 2019-12-05 20:51:40
问题 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/<assembly name>.fakes to my project and it built the project. There were a ton of warnings, but there are 0 errors and the build completed successfully. But it is not adding any reference to the generated .Fakes assembly. Most of the warnings were things like cannot generate stubs or shims for an enum, or some private class is not visible to

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

百般思念 提交于 2019-12-05 10:29:53
问题 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? 回答1: 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