Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and initialize the TestStore inside InitializeAsync #22429

Conversation

0xced
Copy link
Contributor

@0xced 0xced commented Sep 7, 2020

Before this commit, it was impossible to create a concrete implementation of SharedStoreFixtureBase that requires a TestStoreFactory which is initialized asynchronously (the purpose of IAsyncLifetime).

After this commit, it becomes possible because the TestStoreFactory and the StoreName properties are not accessed in the constructor anymore:

public class MySharedStoreFixture<TContext> : SharedStoreFixtureBase<TContext> where TContext : DbContext
{
    private string? _storeName;
    private ITestStoreFactory? _testStoreFactory;

    protected override string StoreName => _storeName ?? throw new InvalidOperationException($"The {nameof(StoreName)} property is only available after {nameof(InitializeAsync)} has executed.");
    protected override ITestStoreFactory TestStoreFactory => _testStoreFactory ?? throw new InvalidOperationException($"The {nameof(TestStoreFactory)} property is only available after {nameof(InitializeAsync)} has executed.");

    public override async Task InitializeAsync()
    {
        var someInfo = await GetSomeInfoAsync();

        _storeName = someInfo.Name;
        _testStoreFactory = new MyTestStoreFactory(someInfo);

        await base.InitializeAsync();
    }
}

@0xced
Copy link
Contributor Author

0xced commented Sep 7, 2020

Ping @AndriySvyryd

@0xced 0xced force-pushed the SharedStoreFixtureBase-InitializeAsync branch 2 times, most recently from 01dc10a to 8485fe8 Compare September 8, 2020 08:17
@AndriySvyryd AndriySvyryd changed the base branch from main to release/5.0-rc2 September 8, 2020 19:19
@AndriySvyryd
Copy link
Member

@0xced Please rebase this on release/5.0-rc2

@AndriySvyryd AndriySvyryd removed the request for review from dougbu September 8, 2020 19:21
Before this commit, it was impossible to create a concrete implementation of SharedStoreFixtureBase that requires a `TestStoreFactory` which is initialized asynchronously (the purpose of `IAsyncLifetime`).

After this commit, it becomes possible because the `TestStoreFactory` and the `StoreName` properties are not accessed in the constructor anymore:

```csharp
public class MySharedStoreFixture<TContext> : SharedStoreFixtureBase<TContext> where TContext : DbContext
{
    private string? _storeName;
    private ITestStoreFactory? _testStoreFactory;

    protected override string StoreName => _storeName ?? throw new InvalidOperationException($"The {nameof(StoreName)} property is only available after {nameof(InitializeAsync)} has executed.");
    protected override ITestStoreFactory TestStoreFactory => _testStoreFactory ?? throw new InvalidOperationException($"The {nameof(TestStoreFactory)} property is only available after {nameof(InitializeAsync)} has executed.");

    public override async Task InitializeAsync()
    {
        var someInfo = await GetSomeInfoAsync();

        _storeName = someInfo.Name;
        _testStoreFactory = new MyTestStoreFactory(someInfo);

        await base.InitializeAsync();
    }
}
```
@0xced 0xced force-pushed the SharedStoreFixtureBase-InitializeAsync branch from 8485fe8 to e4c11f7 Compare September 8, 2020 19:37
@0xced
Copy link
Contributor Author

0xced commented Sep 8, 2020

I just rebased on release/5.0-rc2, let's see if all tests passes like they did on main. 🤞🏻

@AndriySvyryd
Copy link
Member

@Pilchie FYI

@AndriySvyryd AndriySvyryd merged commit cbe5fca into dotnet:release/5.0-rc2 Sep 8, 2020
@AndriySvyryd
Copy link
Member

@0xced Thanks for your contribution

@0xced 0xced deleted the SharedStoreFixtureBase-InitializeAsync branch September 8, 2020 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants