8c6d6aff6a
Moves the database-independent logic of the SQL Server historian backend into a new shared library for the upcoming QuestDB backend (#666): status codes and bits, value/column mapping, StoredSample + quality clamp, the AtTime and aggregate evaluators, BucketPlan, LiveWritePreparer and HistoryUpdatePlanner (both with a resolutionTicks parameter, default 1), tag-name rules, the bootstrap failure cache, health counters, alarm event ids, the event continuation and severity clamp. The SQL Server backend now calls it; its T-SQL, TVP builders, connection, bootstrapper and catalog stay. Tests: StatusCodeOracleTests, ValueWriterPrepareTests, the column half of SampleRowMapperTests and ProcessedReadTests.Every_enum_member_is_either_served_or_refused move to the new Sql.Common.Tests under the same names. SqlServer integration tests get mechanical renames only. Test-name set across the three projects is identical to the baseline (160 tests). Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common.Tests;
|
|
|
|
/// <summary>The column round-trip half of the former SQL Server <c>SampleRowMapperTests</c> (the TVP half stays there).</summary>
|
|
public sealed class SampleRowMapperTests
|
|
{
|
|
public static TheoryData<HistorianValue> Values => new()
|
|
{
|
|
HistorianValue.FromDouble(12.5),
|
|
HistorianValue.FromInt64(long.MinValue + 3),
|
|
HistorianValue.FromBoolean(true),
|
|
HistorianValue.FromBoolean(false),
|
|
HistorianValue.FromString("héllo"),
|
|
HistorianValue.FromString(""),
|
|
HistorianValue.FromDateTime(new DateTime(2026, 10, 9, 1, 2, 3, DateTimeKind.Utc).AddTicks(1234567)),
|
|
HistorianValue.Empty,
|
|
};
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Values))]
|
|
public void Every_kind_round_trips_through_the_column_quad(HistorianValue v)
|
|
{
|
|
var c = SampleColumnMapper.ToColumns(v);
|
|
SampleColumnMapper.FromColumns(c.ValueKind, c.NumValue, c.IntValue, c.StrValue).ShouldBe(v);
|
|
}
|
|
|
|
[Fact]
|
|
public void Columns_follow_the_spec_mapping()
|
|
{
|
|
SampleColumnMapper.ToColumns(HistorianValue.FromInt64(7)).ShouldBe(new SampleColumns(2, 7d, 7L, null));
|
|
SampleColumnMapper.ToColumns(HistorianValue.FromBoolean(true)).ShouldBe(new SampleColumns(3, 1d, 1L, null));
|
|
SampleColumnMapper.ToColumns(HistorianValue.FromDouble(1.5)).ShouldBe(new SampleColumns(1, 1.5, null, null));
|
|
SampleColumnMapper.ToColumns(HistorianValue.Empty).ShouldBe(new SampleColumns(0, null, null, null));
|
|
}
|
|
|
|
[Fact]
|
|
public void Status_is_stored_bit_for_bit()
|
|
{
|
|
SampleColumnMapper.ToDbStatus(0x80050000u).ShouldBeLessThan(0);
|
|
SampleColumnMapper.FromDbStatus(SampleColumnMapper.ToDbStatus(0x80050000u)).ShouldBe(0x80050000u);
|
|
}
|
|
}
|