using DD.Persistence.Database.Entity; using DD.Persistence.Database.Model; using DD.Persistence.Database.Postgres.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace DD.Persistence.Database.Postgres.Test; public class UnitTest1 { private string connectionString; private IHost host; public UnitTest1() { connectionString = "Host=localhost;Port=5462;Username=postgres;Password=postgres;Database=persistence5"; var builder = Host.CreateApplicationBuilder(); builder.Services.AddDbContext(options => options.UseNpgsql(connectionString)); builder.Services.AddScoped(provider => provider.GetRequiredService()); host = builder.Build(); using var scope = host.Services.CreateScope(); var provider = scope.ServiceProvider; var context = provider.GetRequiredService(); context.Database.EnsureCreatedAndMigrated(); context.Database.AddPartitioning(); context.SaveChanges(); //using var scope2 = builder..CreateScope(); //var scopedServices = scope.ServiceProvider; //var dbContext = scopedServices.GetRequiredService(); //dbContext.Database.EnsureCreatedAndMigrated(); //dbContext.SaveChanges(); } [Fact] public void CreateHyperTable() { var entity = new ParameterData() { DiscriminatorId = Guid.NewGuid(), ParameterId = 1, Timestamp = DateTime.UtcNow, Value = "123" }; var scope = host.Services.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); context.ParameterData.Add(entity); context.SaveChanges(); entity.Timestamp = DateTime.UtcNow.AddDays(1); context.ParameterData.Add(entity); context.SaveChanges(); entity.Timestamp = DateTime.UtcNow.AddDays(2); context.ParameterData.Add(entity); context.SaveChanges(); entity.Timestamp = DateTime.UtcNow.AddDays(3); context.ParameterData.Add(entity); context.SaveChanges(); entity.Timestamp = DateTime.UtcNow.AddDays(4); context.ParameterData.Add(entity); context.SaveChanges(); } //public static IHostBuilder CreateHostBuilder(string[] args) => // Host.CreateDefaultBuilder(args) // .ConfigureWebHostDefaults(webBuilder => // { // webBuilder.UseStartup(); // }); }