86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
|
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<PersistencePostgresContext>(options =>
|
|||
|
options.UseNpgsql(connectionString));
|
|||
|
|
|||
|
builder.Services.AddScoped<DbContext>(provider => provider.GetRequiredService<PersistencePostgresContext>());
|
|||
|
|
|||
|
host = builder.Build();
|
|||
|
using var scope = host.Services.CreateScope();
|
|||
|
var provider = scope.ServiceProvider;
|
|||
|
|
|||
|
var context = provider.GetRequiredService<PersistencePostgresContext>();
|
|||
|
context.Database.EnsureCreatedAndMigrated();
|
|||
|
context.Database.AddPartitioning();
|
|||
|
context.SaveChanges();
|
|||
|
|
|||
|
|
|||
|
//using var scope2 = builder..CreateScope();
|
|||
|
//var scopedServices = scope.ServiceProvider;
|
|||
|
|
|||
|
//var dbContext = scopedServices.GetRequiredService<PersistencePostgresContext>();
|
|||
|
//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<PersistencePostgresContext>();
|
|||
|
|
|||
|
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<Startup>();
|
|||
|
// });
|
|||
|
}
|