Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.SqlServer.IntegrationTests/LongNameTests.cs
T

41 lines
1.8 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common;
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.SqlServer.IntegrationTests;
/// <summary>
/// Names longer than the 400-character <c>Tag.Name</c> / <c>Event.SourceName</c> columns are refused, never
/// truncated. Each test seeds a series under the 400-character PREFIX of the long name: a sized
/// <c>NVarChar(400)</c> parameter would silently cut the long name to that prefix and hit the wrong series.
/// </summary>
[Collection(SqlHistorianCollection.Name)]
public sealed class LongNameTests(SqlHistorianFixture fx)
{
private static readonly CancellationToken Ct = CancellationToken.None;
private static DateTime At(double s) => ReadTestDb.At(s);
private static readonly string Prefix = new('p', 400);
private static readonly string Long = Prefix + "-x";
[Fact]
public async Task An_event_read_filtered_by_a_long_source_matches_nothing()
{
var db = await ReadTestDb.CreateAsync(fx);
await using (var c = await db.Conn.OpenAsync(Ct))
await using (var cmd = db.Conn.CreateCommand(c,
$"INSERT {db.Conn.Q("Event")} (EventId, SourceName, AlarmId, AlarmName, AlarmTypeName, Severity, EventKind, Message, " +
"UserName, Comment, EventTimeUtc, ReceivedTimeUtc) VALUES ('e1', @src, 'a', 'n', 'T', 500, 'Activated', NULL, NULL, NULL, @t, @t)"))
{
cmd.Parameters.AddWithValue("@src", Prefix);
SqlHistorianConnection.AddDateTime2(cmd, "@t", At(0));
await cmd.ExecuteNonQueryAsync(Ct);
}
var src = db.Source();
(await src.ReadEventsAsync(Prefix, At(-1), At(10), 0, Ct)).Events.Count.ShouldBe(1); // control
(await src.ReadEventsAsync(Long, At(-1), At(10), 0, Ct)).Events.ShouldBeEmpty();
}
}