Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/docs/test-lifecycle/event-subscribing.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class DatabaseConnectionAttribute : Attribute, ITestStartEventReceiver
await _connection.OpenAsync();

// Store connection in test context for use by hooks and test
context.GetOrAdd("DbConnection", () => _connection);
context.StateBag.GetOrAdd("DbConnection", _ => _connection);
}
}

Expand All @@ -77,15 +77,15 @@ public class MyTests
public async Task TestWithDatabase()
{
// Database connection is already open and available
var connection = TestContext.Current!.Get<IDbConnection>("DbConnection");
TestContext.Current!.StateBag.TryGetValue<IDbConnection>("DbConnection", out var connection);
// ... test logic
}

[Before(Test)]
public void BeforeTest()
{
// Database connection is already available here
var connection = TestContext.Current!.Get<IDbConnection>("DbConnection");
TestContext.Current!.StateBag.TryGetValue<IDbConnection>("DbConnection", out var connection);
// ... setup that needs the database
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public class DependencyInjectionClassConstructor : IClassConstructor, ITestEndEv
{
private readonly IServiceProvider _serviceProvider = CreateServiceProvider();
private AsyncServiceScope _scope;

public Task<object> Create([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, ClassConstructorMetadata classConstructorMetadata)
{
_scope = _serviceProvider.CreateAsyncScope();
Expand All @@ -138,7 +138,7 @@ public class DependencyInjectionClassConstructor : IClassConstructor, ITestEndEv
}

public ValueTask OnTestEnd(TestContext testContext)
{
{
return _scope.DisposeAsync();
}

Expand Down