using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Core.Abstractions; namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.SqlServer.Tests; public sealed class ValueWriterPrepareTests { private static readonly DateTime T = new(2026, 10, 9, 1, 2, 3, DateTimeKind.Utc); [Fact] public void Non_finite_doubles_become_Empty_keeping_status() { const uint status = 0x40000000u; var rows = SqlServerHistorianValueWriter.Prepare( [ new(T, HistorianValue.FromDouble(double.NaN), status), new(T.AddTicks(1), HistorianValue.FromDouble(double.PositiveInfinity), 0), new(T.AddTicks(2), HistorianValue.FromDouble(double.NegativeInfinity), 0), new(T.AddTicks(3), HistorianValue.FromDouble(1.5), 0), ], () => T); rows.Select(r => r.Value.Kind).ShouldBe([HistorianValueKind.Empty, HistorianValueKind.Empty, HistorianValueKind.Empty, HistorianValueKind.Double]); rows[0].StatusCode.ShouldBe(status); } [Fact] public void Duplicate_timestamps_keep_the_first_and_null_timestamp_uses_the_clock() { var rows = SqlServerHistorianValueWriter.Prepare( [ new(T, HistorianValue.FromInt64(1), 0), new(T, HistorianValue.FromInt64(2), 0), new(null, HistorianValue.FromInt64(3), 0), ], () => T.AddDays(1)); rows.Count.ShouldBe(2); rows[0].Value.Integer.ShouldBe(1); rows[1].TimeUtc.ShouldBe(T.AddDays(1)); } [Fact] public void Data_type_mapping_is_one_table() { SqlHistorianDataTypes.FromKind(HistorianValueKind.Double).ShouldBe((byte)DriverDataType.Float64); SqlHistorianDataTypes.FromKind(HistorianValueKind.Boolean).ShouldBe((byte)DriverDataType.Boolean); SqlHistorianDataTypes.FromKind(HistorianValueKind.Empty).ShouldBe((byte)DriverDataType.Float64); } }