我正在使用带有 Update 3 的 VS2015。我有一个简单的 hello world 单元测试项目,我试图在其中获取 shimContext ,下面是代码片段。我在 shimContext 中收到异常以创建调用:*
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException' 发生在 Microsoft.QualityTools.Testing.Fakes.dll 中附加信息:无法从 COR_PROFILER_PATH 和 COR_PROFILER 环境变量解析探查器路径。
*
[TestClass]
public class UnitTest1
{
private IDisposable shimsContext;
[TestMethod]
public void TestMethod1()
{
shimsContext = ShimsContext.Create();
Assert.IsTrue(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我在 StackOverflow、MSDN 上浏览了很多关于建议的解决方法的文章,但似乎都没有解决该问题。以下是我尝试过的解决方法列表。
创建了一个尝试创建 shimsContext 的示例演示单元测试,以验证问题是否与环境隔离。
通过命令行运行 vstest.console.exe 以验证测试是否在命令行中运行,这也给出了相同的异常。
有什么建议/建议吗?
谢谢-克尔蒂。
我只是想熟悉Visual Studio 2012 RC中新的Fakes Isolation Framework,但我因此面临着ShimNotSupportedExceptions的问题.
在第一次尝试时,我尝试连接一个委托的每个单一的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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是相应的堆栈跟踪:
GetFoo_ValidBar_ReturnsBaz测试方法抛出了一个异常: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.UnitsTestIsolation.UnitTestIsolationRuntime.OnAttachedUnsupportedMethod(MethodBase方法)方法,委托detourDelegate)Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.AttachDetour(Object optionalReceiver,MethodBase方法,Delegate detourDelegate)在Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShimMethod(Delegate optionalStub,Object optionalReceiver, MethodBase方法)在Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime的Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.SetShim(Delegate optionalStub,Type receiverType,Object optionalReceiver,String name,ShimBinding flags,Type returnType,Type [] parameterTypes) .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测试(点击运行)"按钮)一切正常,没有抛出任何异常.之后我甚至可以调试测试,并且对shim方法的赋值也按预期工作.
这适用于我使用的所有后续垫片.
但是,当我尝试实现MS Enterprise Library的伪造数据库访问时,我又遇到了同样的问题.
这是测试的样子:
[TestMethod]
public void GetFooFromEF_NonEmptyDataReader_ObjectsCorrectlyInstantiated()
{
using(ShimsContext.Create()){
var dataReader = new StubIDataReader() …Run Code Online (Sandbox Code Playgroud) I noticed in several MDN Array method shims, such as this one on line 7, that they use the following syntax:
var t = Object(this);
Run Code Online (Sandbox Code Playgroud)
this数组在哪里.它不仅没有暗示我的验证器,我对它的作用也毫无头绪.
任何人都可以光明吗?
我有以下(遗留的,继承自前辈)VB.Net(框架2.0)创建系统事件日志异常的类和方法:
Public Interface IMyClass
Function MyMethod(ByVal aValue As String) As Date
End Interface
Public Class MyClass
Implements IMyClass
Public Function MyMethod(ByVal aValue As String) As Date Implements IMyClass.MyMethod
Try
' Calculate return date based on aValue
Catch ex As Exception
Call MyUtilityClass.LogError("MyClass", "MyMethod", ex)
Throw
End Try
End Function
End Class
Partial Public NotInheritable Class MyUtilityClass
Public Shared Sub LogError(ByVal className As String,
ByVal methodName As String,
ByVal ex As Exception)
' Write details to Event Log
End Sub
End …Run Code Online (Sandbox Code Playgroud) 我是 Containerd 的新手,我正在尝试使用 Containerd 运行 Windows 容器。安装 Containerd 后,我只是尝试从注册表中提取映像,但遇到了以下问题。我遇到的问题来自处理图像时的容器运行时 hcssshim::ProcessBaseLayer 方法。请帮助我解决问题。我正在使用containerd 1.6.0-rc.1(预发布)。我之所以使用它是因为我想尝试 Windows HostProcess 容器。PFB 问题。
PS C:\Program Files\containerd> .\crictl.exe pull mcr.microsoft.com/windows/nanoserver:20H2
time="2022-01-21T07:29:44Z" level=fatal msg="pulling image: rpc error: code = Unknown desc = failed to pull and unpack image \"mcr.microsoft.com/windows/nanoserver:20H2\": failed to extract layer sha256:4370934b39e53babdf58bfe6ff2bcc662e068d3b71bd015ea280a402a89e6673: hcsshim::ProcessBaseLayer \\\\?\\C:\\ProgramData\\containerd\\root\\io.containerd.snapshotter.v1.windows\\snapshots\\12: The specified module could not be found.: unknown"
Run Code Online (Sandbox Code Playgroud) 我想模拟System.Diagnostics.Process.Start调用,所以我为系统程序集添加了一个Fakes Assembly.
问题是Start是System.Diagnostics.Process上的一个静态方法,所以我没有得到一个垫片,能够在Start方法的委托上进行操作.
这样做的正确方法是什么?
为BCL(或任何库)中的类型成员创建填充程序时.我们经常面临一种情况,我们想要调用我们已经覆盖的原始方法(无论是在垫片代理内部还是外部).例如:
System.Fakes.ShimDateTime.NowGet = () => DateTime.Now.AddDays(-1);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,调用DateTime.Now时我们想要做的就是返回一个小于实际日期的日期.也许这看起来像一个人为的例子,所以其他(更多)现实的场景是
我面对真实应用中的最后一个场景,无法找到Fakes on SO的答案.但是,在深入了解Fakes文档后,我找到了答案,因此将其与社区问题一起发布.
我正在使用Microsoft Fakes来填充异步方法,该方法调用另一个方法来获取已实现的DbContext。因为在async方法内部调用的方法需要它时,单元测试中没有提供数据库连接字符串。Shim不仅会跳过使用连接字符串的方法,还会返回可自定义的DbContext。
这是aysnc方法的实现:
public async Task<AccountDataDataContext> GetAccountDataInstance(int accountId)
{
var account = await this.Accounts.FindAsync(accountId);
return AccountDataDataContext.GetInstance(account.AccountDataConnectionString);
}
Run Code Online (Sandbox Code Playgroud)
但是,我不熟悉Shim异步方法。我所做的看起来像这样:
ConfigurationEntities.Fakes.ShimConfigurationDataContext.AllInstances.GetAccountDataInstanceInt32NullableOfInt32 = (x, y, z) => new Task<AccountDataEntities.AccountDataDataContext>(() =>
{
return new SampleContext();// This is the fake context I created for replacing the AccountDataDataContext.
});
Run Code Online (Sandbox Code Playgroud)
SampleContext正在实现AccountDataDataContext,如下所示:
public class SampleContext: AccountDataDataContext
{
public SampleContext()
{
this.Samples = new TestDbSet<Sample>();
var data = new AccountDataRepository();
foreach (var item in data.GetFakeSamples())
{
this.Samples.Add(item);
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是测试案例的代码片段:
[TestMethod]
public async Task SampleTest()
{
using (ShimsContext.Create()) …Run Code Online (Sandbox Code Playgroud) 我希望String.prototype.matchAll()方法也能在边缘浏览器中工作。于是想到使用“string.prototype.matchall”npmjs包
我已经安装了这个包并main.js像这样导入到我的文件中
import 'string.prototype.matchall';
Run Code Online (Sandbox Code Playgroud)
我必须在其他文件中使用这种方法,Input.js.所以我使用如下
const matchAll = require('string.prototype.matchall');
Run Code Online (Sandbox Code Playgroud)
在我实际匹配字符串的方法中
replace = (original_string) => {
const regex_pattern = /\\d+@*)]/g;
const matchAll = require('string.prototype.matchall');
const matches = original_string.matchAll(regex_pattern);
return matches;
}
Run Code Online (Sandbox Code Playgroud)
但matchAll变量未使用。我如何使用这个string.prototype.matchall polyfill。有人可以帮我解决这个问题吗?谢谢。
shim ×10
c# ×5
javascript ×3
stub ×2
unit-testing ×2
asynchronous ×1
constructor ×1
containerd ×1
css ×1
css3 ×1
fallback ×1
isolation ×1
object ×1
vb.net ×1
void ×1
vstest ×1