-
|
I implement many services which has a shared interface, and I want to test they all have the same behaviour. For instance, I want to test all implementations of the interface Many of the services require some server or hosted service before they can be integration tested. So I create an I do not want to create a test for each of my IMyService, but rather find the implementors on runtime through a ServiceCollection, and then generate the tests. Aha! This functionality is already provided - I implement a DataSourceGenerator: public sealed class ApplicationFixtureGeneratorAttribute<T> : DataSourceGeneratorAttribute<ApplicationFixture<T>> where T : notnull
{
/// <inheritdoc />
public override IEnumerable<Func<ApplicationFixture<T>>> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata)
{
...
foreach (var service in wantedServices)
{
var f = new ApplicationFixture<T>(...);
f.InitializeAsync().Wait();
yield return () => f;
}
}
}But ALAS! My test time goes up substantially! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Try this: public override IEnumerable<Func<ApplicationFixture<T>>> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata)
{
...
foreach (var service in wantedServices)
{
var f = new ApplicationFixture<T>(...);
dataGeneratorMetadata.TestBuilderContext.Current.Events.OnInitialize += async (_,_) =>
{
await f.InitializeAsync();
}
yield return () => f;
}
} |
Beta Was this translation helpful? Give feedback.
Try this: