【问题标题】:How to add test authorization with inherited TestContext in BUnit?如何在 BUnit 中使用继承的 TestContext 添加测试授权?
【发布时间】:2021-06-07 10:47:37
【问题描述】:

我在 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
{
        public void CompTest()
        {
            TestContext ctx = new TestContext();
            ctx.AddTestAuthorization();
        }
}

所以我的问题是,如何在 BUnit 中使用 inherited TestContext 添加测试授权?

【问题讨论】:

    标签: c# xunit bunit


    【解决方案1】:

    由于AddTestAuthorization 是一种扩展方法,您需要使用this 来获取它。这是 C# 语言中的一个不幸的限制。

    例如:

    using Bunit;
    using Bunit.TestDoubles;
    public class TestClass : TestContext
    {
            [Fact]
            public void CompTest()
            {
                this.AddTestAuthorization();
            }
    }
    

    【讨论】:

      猜你喜欢
      • 2022-07-29
      • 1970-01-01
      • 2011-09-25
      • 2022-08-12
      • 2021-08-21
      • 2014-05-24
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多