-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create and initialize the TestStore inside InitializeAsync
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(); } } ```
- Loading branch information
Showing
3 changed files
with
22 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters