Tag: microsoft fakes

Microsoft Fakes生成UnitTestIsolationException

我编写了非常简单的unit testing项目来查看Microsoft Fakes的function。 我已经在系统组件上执行了菜单命令“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(); } } } 但是在使用(ShimContext.Create())时,我总是得到UnitTestIsolationException: 在探查器库“C:\ […]

无法运行使用Microsoft Fakes的unit testing – ShimsContext.Create()方法中的exception

我的问题与这里报告的问题非常类似: 使用Fakes调试测试时的UnitTestIsolationException 但是,我甚至无法运行测试。 使用此处提供的示例代码: 使用Microsoft Fakes (Shims入门) 隔离测试代码 ,我在运行以下测试时遇到以下exception: 违规行是: using (ShimsContext.Create()) 运行测试的例外情况: 测试名称:TestMethod1 测试FullName:TestingShimsAndStubs.UnitTest1.TestMethod1 测试源:c:\ poc \ TestingShimsAndStubs \ TestingShimsAndStubs \ UnitTest1.cs:第12行 测试结果:失败 测试持续时间:0:00:00.0182403 结果消息: 测试方法TestingShimsAndStubs.UnitTest1.TestMethod1引发exception:Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException:无法获取探查器模块句柄’C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \的IntelliTrace \ 12.0.0 \ Microsoft.IntelliTrace.Profiler.12.0.0.dll”。 找不到指定的模块—> System.ComponentModel.Win32Exception:找不到指定的模块Result StackTrace:Microsoft.QualityTools上的Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.LibraryMethods.GetModuleHandle(String fileName)。 Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.LoadProfilerModule(String profilerPath)—内部exception堆栈跟踪的结束—在Microsoft.QualityTools.Testing的Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.LoadProfilerModule(String profilerPath)中。 Microsoft.QualityTools.Testing.Fakes上的Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()中的Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()中的Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.Initialize()。在C:\ poc […]

如何使用Microsoft Fakes获取基类的填充程序?

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 } } 如何在上面的代码示例中设置“名称”?

不为.NET方法生成填充程序

当我开始使用Microsoft Fakes时,我很高兴开始填补一些.NET方法。 我一直相信我能够使用任何.NET方法,静态或不静态: http : //msdn.microsoft.com/en-us/library/hh549176.aspx 。 但是,我一直试图在TcpClient中填充一些方法,只创建了存根,这对我没有好处,因为我希望能够改变一些方法来返回我自己的数据而不是依赖于直播TcpClient给我数据。 如果还有其他超越Microsoft Fakes的方法,我愿意接受有关如何执行此操作的任何建议。 编辑:添加代码来演示问题 [TestMethod] public void CommunicationTest() { var stubbedTcpClient = new System.Net.Sockets.Fakes.StubTcpClient { }; //No such ShimTcpClient exists var shimmedTcpClient = new System.Net.Sockets.Fakes.ShimTcpClient { }; }

MSBuild 15 – 命名空间中不存在类型或命名空间“Fakes”

我正在尝试为一个项目设置自动构建和unit testing,该项目使用Fakes库进行unit testing。 该项目在我的Windows 10 PC(安装了VS 2017 Enterprise)上构建和测试正常,但是使用相同的命令在构建服务器(也是VS 2017 Enterprise的Windows 10)上编译项目会产生关于Fakes not existing的几个错误。 确切的错误如下所示: 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.csproj] 根据我的研究,这是由使用旧版本的MSBuild引起的,但是我检查了服务器,并确认它已安装了visual studio的最新版本和更新。 我还确认构建脚本使用的是正确版本的MSBuild.exe,即c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe 。 在我的桌面上使用此版本正确编译项目。 为什么构建不能在(相同的设置)构建服务器上运行?

带伪造的unit testing中的Visual Studio 2015 InvalidProgramException

我正在使用Visual Studio 2015 Enterprise RTM为使用Unity Container的项目编写unit testing。 我发现为Unity添加一个fakes程序集的简单行为,甚至实际上不使用伪造,足以产生这个exception: System.InvalidProgramException:公共语言运行时检测到无效程序。 请考虑以下步骤来重现: 使用Visual Studio 2015 Enterprise RTM创建面向.NET 4.6的unit testing项目 添加NuGet包“Unity”版本3.5.1404.0 添加NuGet包“CommonServiceLocator”1.2.0版 像这样写一个unit testing: [TestClass] public class UnitTest1 : IDisposable { [TestMethod] public void TestMethod1() { new ResolvedArrayParameter(new IDisposable[] {this}); } void IDisposable.Dispose() { } } validation测试通过 右键单击Microsoft.Practices.Unity参考并选择“Add Fakes Assembly” 重新运行测试 观察以下显着的测试失败: 测试名称:TestMethod1 测试FullName:UnitTestProject11.UnitTest1.TestMethod1 测试源:c:\ temp \ UnitTestProject11 […]

Microsoft.Fakes不会在正常的unit testing上下文中运行

我正在使用一个简单的概念certificateFakes nUnit测试: [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)); } } 此测试在Visual Studio Test Explorer中运行,但不在以下位置运行: nUnit GUI nUnit控制台 JetBrains测试跑步者(dotCover OR Resharper) TestDriven.net测试运行器 在每个中,我收到以下错误: Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException:无法从COR_PROFILER_PATH和COR_PROFILER环境变量解析探查器路径 当我反思这个程序集时,似乎它正在寻找仅限VS Ultimate的Intellitracefunction – 我只安装了Premium。 有关如何解决此问题的任何建议(我们在构建服务器上使用nUnit runner,因此这是使用Fakes的阻止程序)

如何存根HttpControllerContext

我试图对从WebAPI(OData)控制器调用的一段代码进行unit testing,并接受一个HttpControllerContext: public string MethodToTest(HttpControllerContext context) { string pub = string.Empty; if (context != null) { pub = context.Request.RequestUri.Segments[2].TrimEnd(‘/’); } return pub; } 要对此进行unit testing,我需要一个HttpControllerContext对象。 我该怎么办呢? 我最初试图用Microsoft Fakes来存根,但HttpControllerContext似乎没有接口(为什么??),所以这似乎不是一个选项。 我应该只是新建一个新的HttpControllerContext对象,并可能存根其构造函数参数? 或者使用Moq框架(而不是!)

MS VisualStudio 2012中的ShimNotSupportedException

我只是想在Visual Studio 2012 RC中熟悉新的Fakes Isolation Framework,但我因此ShimNotSupportedException的问题。 在第一次尝试时,我尝试连接一个委托的每个单一的shim方法,在尝试运行/调试测试时抛出了ShimNotSupportedException 。 [TestMethod] public void GetFoo_ValidBar_ReturnsBaz() { using(ShimsContext.Create()) { ShimDateTime.NowGet = () => new DateTime(2012,08,11,10,20,59); const string expected = “20120811_102059”; string actual = GetFoo(); Assert.AreEqual(expected,actual); } } 这是相应的堆栈跟踪: GetFoo_ValidBar_ReturnsBaz测试方法抛出了一个exception:Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException:System.DateTime,位于Microsoft.QualityTools的Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InvokeEvent(T值,Action1 eh)。 Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InternalAttachDetour(Object optionalReceiver,MethodBase)中的Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.CheckInstrumentation(MethodBase方法)中的Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.OnAttachedUnsupportedMethod(MethodBase方法)在Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimMethod(Delegate optionalStub,Object optionalReceiver,Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.AttachDetour(Object optionalReceiver,MethodBase方法,Delegate detourDelegate)上的方法,委托detourDelegate), MethodBase方法) at Microsoft.QualityTools.Testing.Fakes.Sool.ThimRun .SetShimPublicStatic(Delegate optionalStub,Type receiverType,String name,Type returnType,Type [] parameterTypes)在BazTests.cs的GetFoo_ValidBar_ReturnsBaz()的System.Fakes.ShimDateTime.set_NowGet(Func’1值):第48行。 在阅读了我在MSDN上找到的两个线程处理这个问题后,我按照他们的指示(关闭CodeCoverage,删除.testsettings文件),这对我来说不起作用! 不过我找到了解决这个问题的方法: 首先从测试资源管理器运行所有测试(而不是直接从编码区域使用“MSTest测试(单击运行)”按钮)一切正常,没有抛出exception。 […]