Skip to content
Discussion options

You must be logged in to vote

@verdie-g You could convert the MyService property into a lazy method so that it is evaluated on first use:

internal static class TestSetup
{
    private static MyService _myService;

    public static async Task<MyService> GetMyService()
    {
        If (_myService is null)
            _myService = await CreateService()
        return _myService;
    }
}

With your use case converted to:

[TestCaseSource(nameof(TestCases))]
public async Task Test(string x)
{
}

private static IAsyncEnumerable<string> TestCases()
{
    return (await TestSetup.GetMyService()).EnumerateTestCases();
}

Note I'm not behind a PC and haven't tried the above.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@verdie-g
Comment options

Answer selected by verdie-g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants