public async Task WhereBefore() { var parent1 = new ParentEntity { Property = "Value1" }; var parent2 = new ParentEntity { Property = "Ignore" }; var parent3 = new ParentEntity { Property = "OtherIgnore" }; var database1 = await sqlInstance.Build(); await database1.AddDataUntracked(parent1, parent2, parent3); using (var database = database1) using (database.Context.FilterResults(BuildFilters())) { var result = await database.Context.ParentEntities.Where(x => x.Property != "OtherIgnore").ToListAsync(); ObjectApprover.Verify(result); } }
public async Task ExplicitModel() { await using var database = await sqlInstance.Build(); var dbContext = database.Context; await AddData(dbContext); var services = BuildServiceCollection(); services.AddSingleton <DependencySchema>(); EfGraphQLConventions.RegisterInContainer( services, userContext => ((UserContextSingleDb <DependencyDbContext>)userContext).DbContext, sqlInstance.Model); await using var provider = services.BuildServiceProvider(); using var schema = provider.GetRequiredService <DependencySchema>(); var executionOptions = new ExecutionOptions { Schema = schema, Query = query, UserContext = new UserContextSingleDb <DependencyDbContext>(dbContext), Inputs = null }; await ExecutionResultData(executionOptions); }
public async Task TheTest() { #region EfBuildLocalDbInstance using (var database = await sqlInstance.Build()) { #endregion #region EfBuildContext using (var dbContext = database.NewDbContext()) { #endregion var entity = new TheEntity { Property = "prop" }; dbContext.Add(entity); dbContext.SaveChanges(); } using (var dbContext = database.NewDbContext()) { Assert.Single(dbContext.TestEntities); } } }
public async Task ExplicitModel() { using var database = await sqlInstance.Build(); var dbContext = database.Context; await AddData(dbContext); var services = BuildServiceCollection(); EfGraphQLConventions.RegisterInContainer( services, userContext => (DependencyDbContext)userContext, ModelBuilder.Instance); using var provider = services.BuildServiceProvider(); using var schema = new DependencySchema(provider); var executionOptions = new ExecutionOptions { Schema = schema, Query = query, UserContext = dbContext, Inputs = null }; await ExecutionResultData(executionOptions); }
public async Task TheTest() { #region EfBuildDatabase await using var database = await sqlInstance.Build(); #endregion #region EfBuildContext await using (var data = database.NewDbContext()) { #endregion TheEntity entity = new() { Property = "prop" }; data.Add(entity); await data.SaveChangesAsync(); } await using (var data = database.NewDbContext()) { Assert.Single(data.TestEntities); } #endregion }
public async Task Resolve() { await using var database = await sqlInstance.Build(); var parent = new MappingParent(); var child = new MappingChild { Parent = parent }; await database.AddDataUntracked(child, parent); var services = new ServiceCollection(); services.AddSingleton <MappingQuery>(); EfGraphQLConventions.RegisterInContainer(services, _ => database.NewDbContext(), model: sqlInstance.Model); await using var provider = services.BuildServiceProvider(); var mappingQuery = provider.GetRequiredService <MappingQuery>(); var resolve = await(Task <IEnumerable <MappingChild> >) mappingQuery.Fields .Single(x => x.Name == "children") .Resolver ! .Resolve(new ResolveFieldContext()) !; await Verify(resolve); }
public async Task SqlServerSchema() { await using var database = await sqlInstance.Build(); var connection = database.Connection; await Verifier.Verify(connection); }
public async Task SeedData() { var entity = new TestEntity { Property = "prop" }; using var database = await instance.Build(new List <object> { entity }); Assert.NotNull(await database.Context.TestEntities.FindAsync(entity.Id)); }
public async Task TheTest() { #region BuildDatabase await using var database = await sqlInstance.Build(); #region BuildContext await TestDbBuilder.AddData(database.Connection); Assert.Single(await TestDbBuilder.GetData(database.Connection)); #endregion #endregion }
public async Task SeedData() { TestEntity entity = new() { Property = "prop" }; await using var database = await instance.Build(new List <object> { entity }); Assert.NotNull(await database.Context.TestEntities.FindAsync(entity.Id)); Assert.True(callbackCalled); }
public async Task WithRebuild() { var dateTime = DateTime.Now; var instance1 = new SqlInstance( "rebuild", TestDbBuilder.CreateTable, timestamp: dateTime); int data; using (var database1 = await instance1.Build()) { data = await TestDbBuilder.AddData(database1.Connection); } var instance2 = new SqlInstance( "rebuild", connection => throw new Exception(), timestamp: dateTime); using (var database = await instance2.Build()) { var connection1 = database.Connection; Assert.DoesNotContain(data, await TestDbBuilder.GetData(connection1)); } }
public async Task Multiple() { var lastModified = GetType().Assembly.LastModified(); var stopwatch = Stopwatch.StartNew(); var instance = new SqlInstance("Multiple", TestDbBuilder.CreateTable, timestamp: lastModified); using (var database = await instance.Build(databaseSuffix: "one")) { await database.Delete(); } using (var database = await instance.Build(databaseSuffix: "two")) { await database.Delete(); } Trace.WriteLine(stopwatch.ElapsedMilliseconds); }
public Task <SqlDatabase <TheDbContext> > LocalDb( [CallerFilePath] string testFile = "", string?databaseSuffix = null, [CallerMemberName] string memberName = "") { return(sqlInstance.Build(testFile, databaseSuffix, memberName)); }
public async Task WithRebuildDbContext() { var dateTime = DateTime.Now; var instance1 = new SqlInstance <WithRebuildDbContext>( constructInstance: builder => new WithRebuildDbContext(builder.Options), timestamp: dateTime); await using (var database1 = await instance1.Build()) { var entity = new TestEntity { Property = "prop" }; await database1.AddData(entity); } var instance2 = new SqlInstance <WithRebuildDbContext>( constructInstance: builder => new WithRebuildDbContext(builder.Options), buildTemplate: x => throw new Exception(), timestamp: dateTime); await using var database2 = await instance2.Build(); Assert.Empty(database2.Context.TestEntities); }
public async Task NoFileAndNoDb() { LocalDbApi.StopAndDelete("TestDbContext_EfNoFileAndNoDb"); var directory = DirectoryFinder.Find("TestDbContext_EfNoFileAndNoDb"); if (Directory.Exists(directory)) { Directory.Delete(directory, true); } var instance = new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), instanceSuffix: "EfNoFileAndNoDb"); var entity = new TestEntity { Property = "prop" }; using (var database = await instance.Build(new List <object> { entity })) { Assert.NotNull(database.Context.TestEntities.FindAsync(entity.Id)); } }
static DbContextBuilder() { var sqlInstance = new SqlInstance <GraphQlEfSampleDbContext>( buildTemplate: CreateDb, constructInstance: builder => new GraphQlEfSampleDbContext(builder.Options)); database = sqlInstance.Build("GraphQLEntityFrameworkSample").GetAwaiter().GetResult(); }
public async Task StartAsync(CancellationToken cancellationToken) { var sqlInstance = new SqlInstance <SampleDbContext>( buildTemplate: CreateDb, constructInstance: builder => new SampleDbContext(builder.Options)); database = await sqlInstance.Build("GraphQLEntityFrameworkSample"); }
public async Task Test() { await using var database = await sqlInstance.Build(); await TestDbBuilder.AddData(database.Connection); Assert.Single(await TestDbBuilder.GetData(database.Connection)); }
public async Task Assembly_TimeStamp() { var instance = new SqlInstance <TestDbContext>( constructInstance: connection => new TestDbContext(connection), instanceSuffix: "Assembly_TimeStamp"); using var database = await instance.Build(); Assert.Equal(Timestamp.LastModified <Tests>(), File.GetCreationTime(instance.Wrapper.TemplateDataFile)); }
public async Task Delegate_TimeStamp() { var instance = new SqlInstance( name: "Delegate_TimeStamp", buildTemplate: TestDbBuilder.CreateTable); await using var database = await instance.Build(); Assert.Equal(Timestamp.LastModified <Tests>(), File.GetCreationTime(instance.Wrapper.TemplateDataFile)); }
public async Task Multiple() { var stopwatch = Stopwatch.StartNew(); var instance = new SqlInstance("Multiple", TestDbBuilder.CreateTable); await using (var database = await instance.Build(databaseSuffix: "one")) { } await using (var database = await instance.Build(databaseSuffix: "two")) { } await using (var database = await instance.Build(databaseSuffix: "three")) { } Trace.WriteLine(stopwatch.ElapsedMilliseconds); }
static async Task AddAndVerifyData(SqlInstance instance) { using (var database = await instance.Build()) { var connection = database.Connection; var data = await TestDbBuilder.AddData(connection); Assert.Contains(data, await TestDbBuilder.GetData(connection)); } }
public async Task TheTest() { using var database = await sqlInstance.Build(); using (var dbContext = database.NewDbContext()) { var entity = new TheEntity { Property = "prop" }; dbContext.TestEntities.Add(entity); await dbContext.SaveChangesAsync(); } using (var dbContext = database.NewDbContext()) { Assert.Single(dbContext.TestEntities); } }
static async Task CreateDb(SampleDbContext context) { await context.Database.EnsureCreatedAsync(); Company company1 = new() { Id = 1, Content = "Company1" }; Employee employee1 = new() { Id = 2, CompanyId = company1.Id, Content = "Employee1", Age = 25 }; Employee employee2 = new() { Id = 3, CompanyId = company1.Id, Content = "Employee2", Age = 31 }; Company company2 = new() { Id = 4, Content = "Company2" }; Employee employee4 = new() { Id = 5, CompanyId = company2.Id, Content = "Employee4", Age = 34 }; Company company3 = new() { Id = 6, Content = "Company3" }; Company company4 = new() { Id = 7, Content = "Company4" }; context.AddRange(company1, employee1, employee2, company2, company3, company4, employee4); await context.SaveChangesAsync(); } public static Task <SqlDatabase <SampleDbContext> > GetDatabase(string suffix) { return(sqlInstance.Build(suffix)); } }
public async Task Delegate_TimeStamp() { var instance = new SqlInstance <TestDbContext>( constructInstance: builder => new TestDbContext(builder.Options), buildTemplate: async context => { await context.Database.EnsureCreatedAsync(); }, instanceSuffix: "Delegate_TimeStamp"); await using var database = await instance.Build(); Assert.Equal(Timestamp.LastModified <Tests>(), File.GetCreationTime(instance.Wrapper.TemplateDataFile)); }
public async Task Resolve() { await using var database = await sqlInstance.Build(); var context = database.Context; var parent = new MappingParent(); var child = new MappingChild { Parent = parent }; await database.AddDataUntracked(child, parent); var graphQlService = new EfGraphQLService <MappingContext>(context.Model, _ => context); var resolve = await(Task <IEnumerable <MappingChild> >) new MappingQuery(graphQlService).Fields .Single(x => x.Name == "children") .Resolver .Resolve(new ResolveFieldContext()); await Verifier.Verify(resolve); }
public async Task Simple() { var instance = new SqlInstance("Name", TestDbBuilder.CreateTable); await using var database = await instance.Build(); var connection = database.Connection; var data = await TestDbBuilder.AddData(connection); Assert.Contains(data, await TestDbBuilder.GetData(connection)); }
public async Task Defined_TimeStamp() { var dateTime = DateTime.Now; var instance = new SqlInstance( name: "Defined_TimeStamp", buildTemplate: TestDbBuilder.CreateTable, timestamp: dateTime); await using var database = await instance.Build(); Assert.Equal(dateTime, File.GetCreationTime(instance.Wrapper.TemplateDataFile)); }
static DbContextBuilder() { var sqlInstance = new SqlInstance <GraphQlEfSampleDbContext>( buildTemplate: (connection, builder) => { CreateDb(builder); }, constructInstance: builder => new GraphQlEfSampleDbContext(builder.Options)); database = sqlInstance.Build("GraphQLEntityFrameworkSample").GetAwaiter().GetResult(); using (var context = database.NewDbContext()) { Model = context.Model; } }
public async Task Test() { TheEntity entity = new() { Property = "prop" }; List <object> data = new(){ entity }; using var database = await sqlInstance.Build(data); Assert.Single(database.Context.TestEntities); } }