29 lines
986 B
C#
29 lines
986 B
C#
using ZB.MOM.WW.SPHistorianClient.Protocol;
|
|
|
|
namespace ZB.MOM.WW.SPHistorianClient.Tests;
|
|
|
|
public sealed class FrameTests
|
|
{
|
|
[Fact]
|
|
public async Task FrameWriterAndReader_RoundTrip()
|
|
{
|
|
HistorianFrame frame = new((HistorianMessageType)42, 123u, new byte[] { 1, 2, 3, 4 });
|
|
byte[] bytes = HistorianFrameWriter.ToArray(frame);
|
|
|
|
HistorianFrame actual = await HistorianFrameReader.ReadAsync(new MemoryStream(bytes), CancellationToken.None);
|
|
|
|
Assert.Equal(frame.MessageType, actual.MessageType);
|
|
Assert.Equal(frame.CorrelationId, actual.CorrelationId);
|
|
Assert.True(frame.Payload.Span.SequenceEqual(actual.Payload.Span));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task FrameReader_RejectsInvalidLength()
|
|
{
|
|
byte[] bytes = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
await Assert.ThrowsAsync<FrameFormatException>(async () =>
|
|
await HistorianFrameReader.ReadAsync(new MemoryStream(bytes), CancellationToken.None));
|
|
}
|
|
}
|