microsoft-fakes

Microsoft.Win32.ShimRegistryKey not working on build machine

此生再无相见时 提交于 2019-12-12 01:36:33
问题 I Have lots of unit tests where I shim the Microsoft.Win32.RegistryKey using Microsoft Fakes. When I run the build on my local machine the unit test passed. But if I run it on build machine the unit test fails with the following error for these tests. System.TypeLoadException: Could not load type 'Microsoft.Win32.Fakes.ShimRegistryKey' from assembly 'mscorlib.4.0.0.0.Fakes, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0ae41878053f6703'. The curious thing is that both my local machine and

Why doesn't Microsoft Fakes create ShimFtpWebRequest?

▼魔方 西西 提交于 2019-12-11 22:23:51
问题 Performing the following steps: Creating a default WCF Service Library project Creating a default Unit Test project and referencing the service library Creating a Fakes assembly for System in the unit test project I was expecting there to be a type ShimFtpWebRequest in System.4.0.0.0.Fakes. There is not. Setting the Diagnostics property to true on System.Net.Fakes emits a huge slew of warning messages mostly talking about failure to generate stubs , including for FtpWebRequest - because those

Unit test won't “cover” simple get method. (c#)

耗尽温柔 提交于 2019-12-11 14:16:38
问题 I have a simple "Get" method. Ex: public class Foo : IFoo { public Dictionary<string,string> GetSomething(string xyz) { var result = new Dictionary<string,string> ... Go to DB and return some key value pairs return result; } } I wrote a simple test that execute and passes successfully but I'm not getting code coverage on the method. [TestMethod()] public void GetSomething() { var target = new StubIFoo(); var expected = new Dictionary<string, string> { {"blahKey","blahValue"} }; var results =

How can use Microsoft Fakes to mock User.Identity.Name

依然范特西╮ 提交于 2019-12-11 12:23:50
问题 How can I use Microsoft Fakes to mock User.Identity.Name when unit testing MVC 4 application with Visual Studio 2012. I'm writing unit test for item create action method. [HttpPost] public ActionResult Create([Bind(Include = "Name")]Category category) { if (categoryService.IsNameExists(category.Name)) { ModelState.AddModelError("Name", "Category name already exists!"); return View(category); } try { if (ModelState.IsValid) { UserProfile p = new UserProfile(); p.UserName = User.Identity.Name;

Unable to use Microsoft Fakes in VS2015 Enterprise - COR_PROFILER missing

风格不统一 提交于 2019-12-11 10:37:04
问题 I am attempting to use Microsoft Fakes in VS 2015 Enterprise. I have been unable to get any of the tests to even run. I do not have a testsettings or runsettings file. Simple test project has references to: Microsoft.QualityTools.Testing.Fakes Microsoft.VisualStudio.QualityTools.UnitTestFramework Single class of the following: using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.QualityTools.Testing.Fakes; namespace UnitTestProjectfortemp1 { [TestClass] public

How to shim OpenFileDialog.ShowDialog method

大兔子大兔子 提交于 2019-12-11 08:43:00
问题 I have a WPF ViewModel, that has a command which opens a File dialog like this: var dlg = new OpenFileDialog(); var result = dlg.ShowDialog(); Now I would like to unit test that command. ShowDialog is a method inherited from the CommonDialog, so I assumed I can shim it like this: Microsoft.Win32.Fakes.ShimCommonDialog.AllInstances.ShowDialog = () => true; but I'm getting the following compilation error: Delegate Microsoft.QualityTools.Testing.Fakes.FakesDelegates.Func<Microsoft.Win32

Microsoft Fakes generates UnitTestIsolationException

眉间皱痕 提交于 2019-12-10 13:26:19
问题 I have written very simple unit test project to see abilities of Microsoft Fakes. And I have executed on System assembly the menu command "Add Fakes Assembly". public static class Y2KChecker { public static void Check() { if (DateTime.Now == new DateTime(2000, 1, 1)) throw new ApplicationException("y2kbug!"); } } [TestClass] public class UnitTest1 { [TestMethod] public void TestYear() { using (ShimsContext.Create()) { ShimDateTime.NowGet = () => new DateTime(2000, 1, 1); Y2KChecker.Check(); }

Why there are no stubs for interfaces in Microsoft.Fakes

こ雲淡風輕ζ 提交于 2019-12-10 11:07:54
问题 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. 回答1: 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

Any alternative to shim feature provided in Microsoft fake framework?

廉价感情. 提交于 2019-12-09 14:36:54
问题 I am wondering is there any alternative lib to the shim feature provided in Microsoft fake framework since it is only supported in ultimate version? 回答1: There are three frameworks to my knowledge that allow you to mock non virtual methods and sealed classes like Fakes' Shims. There are Microsofts' Moles or Fakes Teleriks JustMock TypeMocks They are all commercial because they use the Profiling API, which is very hairy and poorly documented, so coding them is a real pain. And for the record I

Can Microsoft Fakes be used in Visual Studio 2010?

耗尽温柔 提交于 2019-12-09 08:35:47
问题 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 Framework for unit testing? 回答1: Currently Microsoft Fakes does not work in VS 2010. Project will compile however tests which use Fakes throw NotSupportedException with following stack trace. at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation