public async Task Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data() { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data)).Options; var context = new FunctionUsageContext(options); var query = new FunctionsTotalUsageQuery(context); var functions = new[] { new FunctionTotalUsage { FunctionName = "testFunc", InvocationsCount = 1 }, new FunctionTotalUsage { FunctionName = "myFunc", InvocationsCount = 2 } }; context.FunctionsTotalUsage.AddRange(functions); await context.SaveChangesAsync(); var res = await query.Execute("my"); Assert.Equal(new [] { functions[1] }, res); }
private FunctionUsageContext BuildContext(string testName) { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(KnownFunctionQueryTests) + testName).Options; var context = new FunctionUsageContext(options); return(context); }
public void Given_empty_context_When_executing_projection_query_Then_it_should_return_Null() { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(Given_empty_context_When_executing_projection_query_Then_it_should_return_Null)).Options; var context = new FunctionUsageContext(options); var query = new FindProjectionQuery(context); var result = query.Execute("testName", "projector", "testEvent"); Assert.Null(result); }
public async Task Given_empty_context_When_executing_query_Then_it_should_return_nothing() { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(Given_empty_context_When_executing_query_Then_it_should_return_nothing)).Options; var context = new FunctionUsageContext(options); var query = new FunctionsTotalUsageQuery(context); var res = await query.Execute(""); Assert.Empty(res); }
public async Task Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data() { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(FunctionUsageQueryTests) + nameof( Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data )).Options; var context = new FunctionUsageContext(options); var query = new FunctionsUsageQuery(context); var periodStart = DateTimeOffset.Now; var functions = new[] { new FunctionUsage { FunctionName = "testFunc", InvocationsCount = 1, CalculatorName = "calcA", Period = TimeSpan.FromMinutes(1), PeriodStart = periodStart, PeriodEnd = periodStart + TimeSpan.FromMinutes(1) }, new FunctionUsage { FunctionName = "myFunc", InvocationsCount = 2, CalculatorName = "calcB", Period = TimeSpan.FromHours(1), PeriodStart = periodStart, PeriodEnd = periodStart + TimeSpan.FromHours(1) }, new FunctionUsage { FunctionName = "myFunc", InvocationsCount = 2, CalculatorName = "calcB", Period = TimeSpan.FromHours(1), PeriodStart = periodStart - TimeSpan.FromHours(1), PeriodEnd = periodStart }, }; context.FunctionsUsage.AddRange(functions); await context.SaveChangesAsync(); var res = await query.Execute("calcB", DateTimeOffset.Now - TimeSpan.FromHours(2), DateTimeOffset.Now); Assert.Equal(functions[2], res.Single()); }
private static void OnStart(ActorSystem system, string readModelConnectionString) { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseNpgsql(readModelConnectionString) .Options; using (var myDbContext = new FunctionUsageContext(options)) { Console.WriteLine("Migrating db at " + myDbContext.Database.GetDbConnection().ConnectionString); myDbContext.Database.Migrate(); } system.InitReportingExtension(new ReportingDependencies(options)).Start(); var pool = new AkkaCalculatorPool(system); }
public async Task Given_context_with_data_When_executing_projection_query_Then_it_should_return_data() { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(Given_context_with_data_When_executing_projection_query_Then_it_should_return_data)).Options; var context = new FunctionUsageContext(options); var query = new FindProjectionQuery(context); var projection = new Projection { Event = "testEvent", Name = "testName", Projector = "projector", Sequence = 10 }; context.Projections.Add(projection); await context.SaveChangesAsync(); var res = query.Execute(projection.Name, projection.Projector, projection.Event); Assert.Equal(projection, res); }
public static async Task TruncateTables(string connectionString, bool resetIdentity = true, params string[] tables) { var journalOptions = new DbContextOptionsBuilder <FunctionUsageContext>().UseNpgsql(connectionString).Options; var identityResetCommand = resetIdentity ? "RESTART IDENTITY" : ""; using (var context = new FunctionUsageContext(journalOptions)) { foreach (var table in tables) { await context.Database.ExecuteSqlCommandAsync(@" do $$ begin perform 1 from information_schema.tables where table_name = '" + table + @"'; if found then execute format('truncate %I " + identityResetCommand + " cascade', '" + table + @"'); end if; end $$;"); } } }
public IFindProjectionQuery CreateFindProjectionQuery(FunctionUsageContext context = null) { return(new FindProjectionQuery(context ?? CreateFunctionUsageContext())); }