Retargets RioJoy.Core/Overlay/Tray + tests from net8.0-windows to net48 so the app can be tested as a framework-dependent build (relies on the in-box .NET Framework 4.8 on Windows 10/11). Builds clean; all 241 tests pass. Polyfills (no behavior change): - PolySharp source generator for init/records/Index/Range/required members. - System.Memory, System.Text.Json, Microsoft.Bcl.HashCode, System.Threading.Channels (tests) NuGet packages. - Compat/Net48Polyfills.cs: GetValueOrDefault, KeyValuePair.Deconstruct, Math.Clamp; tests/TestPolyfills.cs: Task.WaitAsync. Source adjustments for APIs absent on net48: - ArgumentNullException/ArgumentException.ThrowIf* inlined to manual guards. - Convert.ToHexString, Encoding.Latin1, Environment.ProcessPath, ApplicationConfiguration.Initialize, Enum.GetNames<T>/GetValues<T>, string.StartsWith(char), string.Split(char, opts), TextBox.PlaceholderText, PeriodicTimer, Memory-based Stream Read/WriteAsync, array range-slicing. - Dropped [SupportedOSPlatform] hints (net48 is single-platform). deploy/build-package.ps1: publish framework-dependent (no self-contained). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using RioJoy.Core.Protocol;
|
|
using Xunit;
|
|
|
|
namespace RioJoy.Core.Tests.Protocol;
|
|
|
|
public class PacketBuilderTests
|
|
{
|
|
[Fact]
|
|
public void AnalogRequest_HasCommandAndChecksumOnly()
|
|
{
|
|
// 0x82, checksum = 0x82 & 0x7F = 0x02
|
|
Assert.Equal(new byte[] { 0x82, 0x02 }, PacketBuilder.AnalogRequest());
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetRequest_EncodesTarget()
|
|
{
|
|
// 0x83, payload [0x00], checksum = 0x03
|
|
Assert.Equal(new byte[] { 0x83, 0x00, 0x03 }, PacketBuilder.ResetRequest(RioResetTarget.All));
|
|
// 0x83, payload [0x01], checksum = 0x04
|
|
Assert.Equal(new byte[] { 0x83, 0x01, 0x04 }, PacketBuilder.ResetRequest(RioResetTarget.Throttle));
|
|
}
|
|
|
|
[Fact]
|
|
public void LampRequest_EncodesLampAndState()
|
|
{
|
|
// 0x84, payload [0x05, 0x3C], checksum = (0x04 + 0x05 + 0x3C) & 0x7F = 0x45
|
|
Assert.Equal(new byte[] { 0x84, 0x05, 0x3C, 0x45 }, PacketBuilder.LampRequest(5, 0x3C));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_ValidatesPayloadLength()
|
|
{
|
|
Assert.Throws<ArgumentException>(() => PacketBuilder.Build(RioCommand.LampRequest, new byte[] { 0x01 }));
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_AppendsCorrectChecksum_ForFullPayload()
|
|
{
|
|
var payload = new byte[] { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0 };
|
|
byte[] packet = PacketBuilder.Build(RioCommand.AnalogReply, payload);
|
|
|
|
Assert.Equal((byte)RioCommand.AnalogReply, packet[0]);
|
|
Assert.Equal(payload, packet.AsSpan(1, packet.Length - 2).ToArray());
|
|
Assert.Equal(RioChecksum.Compute(packet.AsSpan(0, packet.Length - 1)), packet[^1]);
|
|
}
|
|
}
|