Skip to content

Commit

Permalink
Add pre/post test hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
wazzamatazz committed Jan 12, 2022
1 parent a11393d commit 4eec1d3
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/DataCore.Adapter.Tests.Helpers/AdapterTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ protected virtual IAdapterCallContext CreateCallContext(TestContext context) {
}


/// <summary>
/// Called immediately prior to the callback in <see cref="RunAdapterTest"/>, after the
/// <paramref name="adapter"/> has been started.
/// </summary>
/// <param name="adapter">
/// The adapter for the test.
/// </param>
/// <param name="context">
/// The call context for the test.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token for the test.
/// </param>
/// <returns>
/// A <see cref="Task"/> that will perform any pre-test actions.
/// </returns>
protected virtual Task BeforeAdapterTestAsync(TAdapter adapter, IAdapterCallContext context, CancellationToken cancellationToken) {
return Task.CompletedTask;
}


/// <summary>
/// Called immediately after the callback in <see cref="RunAdapterTest"/>.
/// </summary>
/// <param name="adapter">
/// The adapter for the test.
/// </param>
/// <param name="context">
/// The call context for the test.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token for the test.
/// </param>
/// <returns>
/// A <see cref="Task"/> that will perform any post-test actions.
/// </returns>
protected virtual Task AfterAdapterTestAsync(TAdapter adapter, IAdapterCallContext context, CancellationToken cancellationToken) {
return Task.CompletedTask;
}


/// <summary>
/// Creates and initialises a <typeparamref name="TAdapter"/> instance and runs an adapter
/// test.
Expand Down Expand Up @@ -104,7 +145,9 @@ protected async Task RunAdapterTest(Func<TAdapter, IAdapterCallContext, Cancella
await adapter.StartAsync(CancellationToken).ConfigureAwait(false);
}
var context = CreateCallContext(TestContext);
await BeforeAdapterTestAsync(adapter, context, CancellationToken).ConfigureAwait(false);
await callback(adapter, context, CancellationToken).ConfigureAwait(false);
await AfterAdapterTestAsync(adapter, context, CancellationToken).ConfigureAwait(false);
}
finally {
if (adapter is IAsyncDisposable iad) {
Expand Down

0 comments on commit 4eec1d3

Please sign in to comment.