public async Task Test4() { output.WriteLine($"Test {nameof(Test4)} is running"); // Seed seeds using the specified startup object. // This way we can provide data from the test to the startup. // Typical case, we want the inmemory database to be unique per test. // We will create the database root in the test and provide it both to // the startup and to the object creator. var databaseName = Guid.NewGuid().ToString(); var databaseRoot = new InMemoryDatabaseRoot(); var outputSink = new InternalQueueOutputSink(); var startup = new SampleStartupForUnitTests(outputSink) { DatabaseName = databaseName, DatabaseRoot = databaseRoot }; var baseCampTrack = await Get.Yield <MountEverestBaseCampTrack.Yield>(startup, outputSink); output.WriteLine(outputSink.GetOutputAsString()); var projectService = objectCreator.WithLocalInMemoryDatabase(databaseName, databaseRoot).Create <IProjectService>(); var projects = (await projectService.GetAll()).Value; Assert.Contains(projects, project => project.Name == SomeAlwaysRequiredProject.Yield.SomeAlwaysRequiredProjectName); Assert.Equal(2, projects.Count); projectService = objectCreator.WithLocalInMemoryDatabase(Guid.NewGuid().ToString(), new InMemoryDatabaseRoot()).Create <IProjectService>(); projects = (await projectService.GetAll()).Value; Assert.Empty(projects); }
/// <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()}"); } }