Static member error with instance member, xUnit

不打扰是莪最后的温柔 提交于 2020-04-16 02:28:31

问题


"An object reference is required for the non-static field" I have a static member which cannot be an instance member. This static member uses an instance of an object that is initialized in the constructor of the class through dependency injection, so it cannot be static. How could I solve this error?

public class My
{
    private readonly Fixture _fixture;

    public MyClass(Fixture fixture)
    {
        _fixture = fixture;
    }

    public static IEnumerable<object[]> TestCases()
    {
        yield return new object[] { Urls.BuildUrl(_fixture.WebAppUrl)};

    }

    [Theory]
    [MemberData(nameof(TestCases))]
    ...

public static class Urls
{
    public static string BuildUrl(string url)
    {
    ...

The error is thrown here:

yield return new object[] { Urls.**BuildUrl**(_fixture.WebAppUrl)};

来源:https://stackoverflow.com/questions/60605398/static-member-error-with-instance-member-xunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!