public void ConfigureServices(IServiceCollection services) { var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .BuildServiceProvider(); services.AddDbContext <TestContext>(builder => { builder.UseInMemoryDatabase("BasicTestDatabase"); builder.UseInternalServiceProvider(serviceProvider); }); services.AddGraphity <TestContext>(); var sp = services.BuildServiceProvider(); using (var scope = sp.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <TestContext>(); // Ensure the database is created. db.Database.EnsureCreated(); // Seed the database with test data. ContextFixture.SeedTestData(db); } }
public void ConfigureServices(IServiceCollection services) { #pragma warning disable ASP0000 // Do not call 'IServiceCollection.BuildServiceProvider' in 'ConfigureServices' var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .BuildServiceProvider(); services.AddDbContext <TestContext>(builder => { builder.UseInMemoryDatabase("ComplexTestDatabase"); builder.UseInternalServiceProvider(serviceProvider); }); services.AddGraphity <TestContext>(options => { options .QueryName("RandomName") .SetDefaultTake(5) .AddHasScopeAuthorisationPolicy("scopeCheck", "scope1") .AddFuncAuthorisationPolicy("fail-on-first-call", FailOnFirstCall); options.ConfigureSet(ctx => ctx.Animals) .TypeName("FaunaType") .FieldName("filteredAnimals") .Filter(a => a.Id > 1) .DefaultOrderBy(a => a.Name) .ConfigureProperty(a => a.Id).Exclude() .ConfigureProperty(a => a.LivesInId).Exclude(); options.ConfigureSet(ctx => ctx.Countries) .SetAuthorisationPolicy("fail-on-first-call"); options.ConfigureSet(ctx => ctx.CountryProperties) .SetAuthorisationPolicy("scopeCheck"); options.AddProjection("averageEyelashesPerAnimalType", ctx => ctx.Animals .GroupBy(a => a.AnimalType) .Select(g => new AnimalTypeEyelashes { AnimalType = g.Key, AverageNumberOfEyelashes = g.Average(x => x.NumberOfEyelashes) })); }); var sp = services.BuildServiceProvider(); using var scope = sp.CreateScope(); var scopedServices = scope.ServiceProvider; using var db = scopedServices.GetRequiredService <TestContext>(); // Ensure the database is created. db.Database.EnsureCreated(); // Seed the database with test data. ContextFixture.SeedTestData(db); }
public void ConfigureServices(IServiceCollection services) { var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .BuildServiceProvider(); services.AddDbContext <TestContext>(builder => { builder.UseInMemoryDatabase("ComplexTestDatabase"); builder.UseInternalServiceProvider(serviceProvider); }); services.AddGraphity <TestContext>(options => { options .QueryName("RandomName") .SetDefaultTake(5) .AddHasScopeAuthorisationPolicy("scopeCheck", "scope1") .AddFuncAuthorisationPolicy("fail-on-first-call", FailOnFirstCall); options.ConfigureSet(ctx => ctx.Animals) .TypeName("FaunaType") .FieldName("filteredAnimals") .Filter(a => a.Id > 1) .DefaultOrderBy(a => a.Name) .ConfigureProperty(a => a.Id).Exclude() .ConfigureProperty(a => a.LivesInId).Exclude(); options.ConfigureSet(ctx => ctx.Countries) .SetAuthorisationPolicy("fail-on-first-call"); options.ConfigureSet(ctx => ctx.CountryProperties) .SetAuthorisationPolicy("scopeCheck"); }); var sp = services.BuildServiceProvider(); using (var scope = sp.CreateScope()) { var scopedServices = scope.ServiceProvider; var db = scopedServices.GetRequiredService <TestContext>(); // Ensure the database is created. db.Database.EnsureCreated(); // Seed the database with test data. ContextFixture.SeedTestData(db); } }