acdream/tests/AcDream.Core.Net.Tests/Messages/GameEventsInventoryTests.cs
Erik 43afcc2adb feat(net): D.2b-B B-Wire — ParseViewContents (0x0196)
GameEvents.ParseViewContents parses the ViewContents GameEvent payload:
containerGuid + count + [guid, containerType]×count. Records
ViewContentsEntry and ViewContents added. 3 unit tests added in
GameEventsInventoryTests.cs (two-entry, zero-count, truncated).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 18:54:25 +02:00

45 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Buffers.Binary;
using AcDream.Core.Net.Messages;
using Xunit;
namespace AcDream.Core.Net.Tests.Messages;
public sealed class GameEventsInventoryTests
{
[Fact]
public void ParseViewContents_twoEntries_returnsContainerAndItems()
{
// containerGuid + count(2) + 2×{guid, containerType}
var b = new byte[4 + 4 + 2 * 8];
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(0), 0x500000C9u); // containerGuid
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), 2u); // count
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(8), 0x50000A01u); // guid 1
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(12), 0u); // type 1 (item)
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(16), 0x50000A02u);// guid 2
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(20), 1u); // type 2 (container)
var p = GameEvents.ParseViewContents(b);
Assert.NotNull(p);
Assert.Equal(0x500000C9u, p!.Value.ContainerGuid);
Assert.Equal(2, p.Value.Items.Count);
Assert.Equal(0x50000A01u, p.Value.Items[0].Guid);
Assert.Equal(0u, p.Value.Items[0].ContainerType);
Assert.Equal(0x50000A02u, p.Value.Items[1].Guid);
Assert.Equal(1u, p.Value.Items[1].ContainerType);
}
[Fact]
public void ParseViewContents_zeroCount_returnsEmptyList()
{
var b = new byte[8];
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(0), 0x500000C9u);
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), 0u);
var p = GameEvents.ParseViewContents(b);
Assert.NotNull(p);
Assert.Empty(p!.Value.Items);
}
[Fact]
public void ParseViewContents_truncated_returnsNull()
=> Assert.Null(GameEvents.ParseViewContents(new byte[4]));
}