C# 如何在BUnit中使用继承的TestContext添加测试授权?
我在BUnit中继承了TestContext,我想添加Testauthorization 这不起作用:C# 如何在BUnit中使用继承的TestContext添加测试授权?,c#,xunit,bunit,C#,Xunit,Bunit,我在BUnit中继承了TestContext,我想添加Testauthorization 这不起作用: using Bunit; using Bunit.TestDoubles; public class TestClass : TestContext { [Fact] public void CompTest() { AddTestAuthorization(); } } 如果我使用“普通”版本和下面的样
using Bunit;
using Bunit.TestDoubles;
public class TestClass : TestContext
{
[Fact]
public void CompTest()
{
AddTestAuthorization();
}
}
如果我使用“普通”版本和下面的样板代码,它就可以工作了
这项工作:
using Bunit;
using Bunit.TestDoubles;
public class TestClass
{
public void CompTest()
{
TestContext ctx = new TestContext();
ctx.AddTestAuthorization();
}
}
因此,我的问题是,如何在BUnit中添加继承了TestContext的测试授权?由于
AddTestAuthorization
是一种扩展方法,您需要使用this
来实现它。这在C语言中是一个不幸的限制
例如:
使用Bunit;
使用Bunit.TestDoubles;
公共类TestClass:TestContext
{
[事实]
公共测试()
{
此.AddTestAuthorization();
}
}