using System; using System.Buffers.Binary; using AcDream.Core.Net.Messages; using Xunit; namespace AcDream.Core.Net.Tests.Messages; public sealed class CastSpellTests { [Fact] public void BuildUntargeted_EmitsCorrectWireBytes() { byte[] body = CastSpellRequest.BuildUntargeted(gameActionSequence: 5, spellId: 0x3E1); Assert.Equal(16, body.Length); Assert.Equal(CastSpellRequest.GameActionEnvelope, BinaryPrimitives.ReadUInt32LittleEndian(body)); Assert.Equal(5u, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(4))); Assert.Equal(CastSpellRequest.UntargetedSubOpcode, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8))); Assert.Equal(0x3E1u, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12))); } [Fact] public void BuildTargeted_EmitsCorrectWireBytes() { byte[] body = CastSpellRequest.BuildTargeted( gameActionSequence: 7, targetGuid: 0xAAAAu, spellId: 0x3E1); Assert.Equal(20, body.Length); Assert.Equal(CastSpellRequest.TargetedSubOpcode, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8))); Assert.Equal(0xAAAAu, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12))); Assert.Equal(0x3E1u, BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16))); } [Fact] public void ParseMagicUpdateSpell_RoundTrip() { byte[] payload = new byte[4]; BinaryPrimitives.WriteUInt32LittleEndian(payload, 0x3E1u); Assert.Equal(0x3E1u, GameEvents.ParseMagicUpdateSpell(payload)); } [Fact] public void ParseMagicUpdateEnchantment_RoundTrip() { byte[] payload = new byte[16]; BinaryPrimitives.WriteUInt32LittleEndian(payload, 42u); // spellId BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(4), 7u); // layerId BinaryPrimitives.WriteSingleLittleEndian(payload.AsSpan(8), 300.0f); // duration BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(12), 0xBEEFu); // caster var parsed = GameEvents.ParseMagicUpdateEnchantment(payload); Assert.NotNull(parsed); Assert.Equal(42u, parsed!.Value.SpellId); Assert.Equal(7u, parsed.Value.LayerId); Assert.Equal(300f, parsed.Value.Duration, 4); Assert.Equal(0xBEEFu, parsed.Value.CasterGuid); } [Fact] public void ParseMagicRemoveEnchantment_RoundTrip() { byte[] payload = new byte[8]; BinaryPrimitives.WriteUInt32LittleEndian(payload, 7u); // layerId BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(4), 42u); // spellId var parsed = GameEvents.ParseMagicRemoveEnchantment(payload); Assert.NotNull(parsed); Assert.Equal(7u, parsed!.Value.LayerId); Assert.Equal(42u, parsed.Value.SpellId); } }