2025-01-27 18:24:55 +05:00
|
|
|
|
using DD.Persistence.Database.Entity;
|
2025-01-28 12:15:58 +05:00
|
|
|
|
using Mapster;
|
2025-01-28 12:42:01 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2025-01-27 18:24:55 +05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-01-28 12:15:58 +05:00
|
|
|
|
using Npgsql;
|
2025-01-27 18:24:55 +05:00
|
|
|
|
|
|
|
|
|
namespace DD.Persistence.Database.Postgres.Test;
|
|
|
|
|
|
2025-01-28 12:30:58 +05:00
|
|
|
|
public class UnitTestCheckHyperTables : IClassFixture<DbFixture>
|
2025-01-27 18:24:55 +05:00
|
|
|
|
{
|
2025-01-28 12:15:58 +05:00
|
|
|
|
private ServiceProvider _serviceProvider;
|
2025-01-27 18:24:55 +05:00
|
|
|
|
|
2025-01-28 12:30:58 +05:00
|
|
|
|
public UnitTestCheckHyperTables(DbFixture fixture)
|
2025-01-27 18:24:55 +05:00
|
|
|
|
{
|
2025-01-28 12:15:58 +05:00
|
|
|
|
_serviceProvider = fixture.serviceProvider;
|
2025-01-27 18:24:55 +05:00
|
|
|
|
}
|
2025-01-28 12:15:58 +05:00
|
|
|
|
|
2025-01-27 18:24:55 +05:00
|
|
|
|
[Fact]
|
2025-01-28 12:30:58 +05:00
|
|
|
|
public void CreateHyperTable_For_ParameterData_Return_Success()
|
2025-01-27 18:24:55 +05:00
|
|
|
|
{
|
2025-01-28 12:42:01 +05:00
|
|
|
|
var chunksCount = 0;
|
|
|
|
|
|
2025-01-28 12:15:58 +05:00
|
|
|
|
var entity = new ParameterData()
|
|
|
|
|
{
|
2025-01-27 18:24:55 +05:00
|
|
|
|
DiscriminatorId = Guid.NewGuid(),
|
|
|
|
|
ParameterId = 1,
|
|
|
|
|
Timestamp = DateTime.UtcNow,
|
|
|
|
|
Value = "123"
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-28 12:15:58 +05:00
|
|
|
|
using (var context = _serviceProvider.GetService<PersistenceDbContext>()!)
|
|
|
|
|
{
|
|
|
|
|
context.ParameterData.Add(entity);
|
|
|
|
|
|
|
|
|
|
var entity2 = entity.Adapt<ParameterData>();
|
|
|
|
|
entity2.ParameterId = 2;
|
|
|
|
|
context.ParameterData.Add(entity2);
|
|
|
|
|
|
|
|
|
|
var entity3 = entity2.Adapt<ParameterData>();
|
|
|
|
|
entity3.ParameterId = 3;
|
|
|
|
|
entity3.Timestamp = DateTime.UtcNow.AddDays(2);
|
|
|
|
|
context.ParameterData.Add(entity3);
|
|
|
|
|
|
|
|
|
|
var entity4 = entity3.Adapt<ParameterData>();
|
|
|
|
|
entity4.ParameterId = 4;
|
|
|
|
|
context.ParameterData.Add(entity4);
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
string sql = "select count(*) from (select show_chunks('parameter_data'));";
|
2025-01-28 12:42:01 +05:00
|
|
|
|
var queryRow = context.Database.SqlQueryRaw<int>(sql);
|
2025-01-28 12:15:58 +05:00
|
|
|
|
|
2025-01-28 12:42:01 +05:00
|
|
|
|
chunksCount = queryRow.AsEnumerable().FirstOrDefault();
|
2025-01-28 12:15:58 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, chunksCount);
|
2025-01-27 18:24:55 +05:00
|
|
|
|
}
|
|
|
|
|
}
|