- Move ShortcutStoreTests from AcDream.Core.Tests to AcDream.Core.Net.Tests (Rule 6: tests live in the project matching the layer under test; ShortcutStore is Core.Net) - Replace fully-qualified System.Buffers.Binary.BinaryPrimitives. with BinaryPrimitives. in the two new BuildAddShortcut tests (file already has `using System.Buffers.Binary`) - Add `using System;` to ShortcutStore.cs; change System.Array.Clear → Array.Clear (matches sibling file style, no behavior change) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
116 lines
4.6 KiB
C#
116 lines
4.6 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
using AcDream.Core.Net.Messages;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Net.Tests.Messages;
|
|
|
|
public sealed class InventoryActionsTests
|
|
{
|
|
[Fact]
|
|
public void BuildStackableMerge_CarriesBothGuidsAndAmount()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableMerge(
|
|
seq: 1, mergeFromGuid: 0xAA, mergeToGuid: 0xBB, amount: 5);
|
|
|
|
Assert.Equal(24, body.Length);
|
|
Assert.Equal(InventoryActions.StackableMergeOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(0xAAu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
Assert.Equal(0xBBu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
|
|
Assert.Equal(5u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(20)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildStackableSplitToContainer_FourFields()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableSplitToContainer(
|
|
seq: 1, stackGuid: 0xAA, containerGuid: 0xBB, placement: 3, amount: 10);
|
|
|
|
Assert.Equal(28, body.Length);
|
|
Assert.Equal(InventoryActions.StackableSplitToContainerOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(3u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(20)));
|
|
Assert.Equal(10u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(24)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildStackableSplitTo3D_TwoFields()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableSplitTo3D(
|
|
seq: 1, stackGuid: 0xAA, amount: 3);
|
|
Assert.Equal(20, body.Length);
|
|
Assert.Equal(InventoryActions.StackableSplitTo3DOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildStackableSplitToWield_HasEquipLocation()
|
|
{
|
|
byte[] body = InventoryActions.BuildStackableSplitToWield(
|
|
seq: 1, stackGuid: 0xAA, equipLocation: 0x00400000, amount: 1);
|
|
Assert.Equal(0x00400000u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildGiveObjectRequest_TargetItemAmount()
|
|
{
|
|
byte[] body = InventoryActions.BuildGiveObjectRequest(
|
|
seq: 1, targetGuid: 0xAA, itemGuid: 0xBB, amount: 2);
|
|
Assert.Equal(InventoryActions.GiveObjectRequestOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(0xAAu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
Assert.Equal(0xBBu,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
|
|
Assert.Equal(2u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(20)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddShortcut_ItemShortcut_FieldLayout()
|
|
{
|
|
// ShortCutData = Index(u32), ObjectId(u32), SpellId(u16), Layer(u16). Item → spell/layer 0.
|
|
byte[] body = InventoryActions.BuildAddShortcut(seq: 1, index: 0, objectGuid: 0x3E1, spellId: 0, layer: 0);
|
|
Assert.Equal(24, body.Length);
|
|
Assert.Equal(InventoryActions.AddShortcutOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(0u, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12))); // index
|
|
Assert.Equal(0x3E1u, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16))); // objectGuid
|
|
Assert.Equal((ushort)0, BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(20))); // spellId
|
|
Assert.Equal((ushort)0, BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(22))); // layer
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildAddShortcut_SpellShortcut_PacksSpellAndLayerAsU16s()
|
|
{
|
|
byte[] body = InventoryActions.BuildAddShortcut(seq: 1, index: 2, objectGuid: 0, spellId: 0x1234, layer: 3);
|
|
Assert.Equal(0x1234, BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(20)));
|
|
Assert.Equal(3, BinaryPrimitives.ReadUInt16LittleEndian(body.AsSpan(22)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildRemoveShortcut_HasSlotOnly()
|
|
{
|
|
byte[] body = InventoryActions.BuildRemoveShortcut(seq: 1, slotIndex: 5);
|
|
Assert.Equal(16, body.Length);
|
|
Assert.Equal(5u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildTeleToPoi_SimpleIdPayload()
|
|
{
|
|
byte[] body = InventoryActions.BuildTeleToPoi(seq: 1, poiId: 42);
|
|
Assert.Equal(InventoryActions.TeleToPoiOpcode,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
|
|
Assert.Equal(42u,
|
|
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
|
|
}
|
|
}
|