private static async Task SeedSeeds(Type?seedBucketStartupType, SeedBucketStartup?seedBucketStartup, IOutputSink?outputSink, params Type[] seedTypes) { // TODO: Assert type and startup object must not be specified at the same time. var output = outputSink ?? new InternalQueueOutputSink(); var seedBucketInfoBuilder = new ReflectionBasedSeedBucketInfoBuilder(); var seeder = new Seeder(seedBucketInfoBuilder, output); SeedingReport seedingReport; if (seedBucketStartupType != null) { seedingReport = await seeder.SeedSeeds(seedBucketStartupType, seedTypes); } else if (seedBucketStartup != null) { seedingReport = await seeder.SeedSeeds(seedBucketStartup, seedTypes); } else { seedingReport = await seeder.SeedSeeds(seedTypes); } // TODO: See the best way to get the error message, inner exception and those kind of things. Throw some rich exception accordingly e.g. SeedingSingleSeedFaildException. var outputAsString = output is InternalQueueOutputSink internalOutputSink?internalOutputSink.GetOutputAsString() : string.Empty; if (seedingReport.Status != SeedingStatus.Succeeded) { throw new Exception($"Seeding failed.{Environment.NewLine}{outputAsString}"); } }
/// <inheritdoc/> public override void Before(MethodInfo methodUnderTest) { base.Before(methodUnderTest); // It is not possible to come to the instance of the ITestOutputHelper. // This means, all the output from the seeding will not be provided within the test output. // TODO: Find a Startup within the test assembly. var outputSink = new InternalQueueOutputSink(); var seedBucketInfoBuilder = new ReflectionBasedSeedBucketInfoBuilder(); var seeder = new Seeder(seedBucketInfoBuilder, outputSink); // TODO: Is not null, IsSeedBucketSeedingType etc. var seedingStartupType = SeedingStartupType ?? FindSeedingStartupType(); var seedingReport = seedingStartupType is null ? seeder.SeedSeedBucket(seedBucketType).Result : seeder.SeedSeedBucket(seedBucketType, seedingStartupType).Result; // TODO: See the best way to get the error message, inner exception and those kind of things. Throw some rich exception accordingly e.g. SeedingSingleSeedFaildException. if (seedingReport.Status != SeedingStatus.Succeeded) { throw new Exception($"Seeding failed.{Environment.NewLine}{outputSink.GetOutputAsString()}"); } Type?FindSeedingStartupType() { var seedingStartupAttribute = methodUnderTest.GetCustomAttribute <UseSeedingStartupAttribute>(); if (seedingStartupAttribute != null) { return(seedingStartupAttribute.SeedingStartupType); // TODO: Check that it is not null, that is seeding startup type etc. } seedingStartupAttribute = methodUnderTest.DeclaringType.GetCustomAttribute <UseSeedingStartupAttribute>(); if (seedingStartupAttribute != null) { return(seedingStartupAttribute.SeedingStartupType); // TODO: Check that it is not null, that is seeding startup type etc. } seedingStartupAttribute = methodUnderTest.DeclaringType.Assembly.GetCustomAttribute <UseSeedingStartupAttribute>(); if (seedingStartupAttribute != null) { return(seedingStartupAttribute.SeedingStartupType); // TODO: Check that it is not null, that is seeding startup type etc. } return(null); } }
protected RequiresSeedBucketFixture(Type seedBucketType, Type?seedingStartupType) { // TODO: Check not null, must be seedbucket. var outputSink = new InternalQueueOutputSink(); var seedBucketInfoBuilder = new ReflectionBasedSeedBucketInfoBuilder(); var seeder = new Seeder(seedBucketInfoBuilder, outputSink); // TODO: Is not null, IsSeedBucketSeedingType etc. var seedingReport = seedingStartupType is null ? seeder.SeedSeedBucket(seedBucketType).Result : seeder.SeedSeedBucket(seedBucketType, seedingStartupType).Result; // TODO: See the best way to get the error message, inner exception and those kind of things. Throw some rich exception accordingly e.g. SeedingSingleSeedFaildException. if (seedingReport.Status != SeedingStatus.Succeeded) { throw new Exception($"Seeding failed.{Environment.NewLine}{outputSink.GetOutputAsString()}"); } }
public override IEnumerable <object[]> GetData(MethodInfo testMethod) { var parameters = testMethod.GetParameters(); // TODO: Proper detailed error message. if (!parameters.All(parameter => parameter.ParameterType.IsYieldType())) { throw new Exception("Some of the parameters are not yield types."); } var seedingStartupType = FindSeedingStartupType(); var outputSink = new InternalQueueOutputSink(); var seedBucketInfoBuilder = new ReflectionBasedSeedBucketInfoBuilder(); var seeder = new Seeder(seedBucketInfoBuilder, outputSink); yield return(seeder.GetYieldsFor(seedingStartupType, parameters.Select(parameter => parameter.ParameterType).ToArray()).Result); Type?FindSeedingStartupType() { var seedingStartupAttribute = testMethod.GetCustomAttribute <UseSeedingStartupAttribute>(); if (seedingStartupAttribute != null) { return(seedingStartupAttribute.SeedingStartupType); // TODO: Check that it is not null, that is seeding startup type etc. } seedingStartupAttribute = testMethod.DeclaringType.GetCustomAttribute <UseSeedingStartupAttribute>(); if (seedingStartupAttribute != null) { return(seedingStartupAttribute.SeedingStartupType); // TODO: Check that it is not null, that is seeding startup type etc. } seedingStartupAttribute = testMethod.DeclaringType.Assembly.GetCustomAttribute <UseSeedingStartupAttribute>(); if (seedingStartupAttribute != null) { return(seedingStartupAttribute.SeedingStartupType); // TODO: Check that it is not null, that is seeding startup type etc. } return(null); } }