Outgoing Packet Tests (Pass #1) (#129)

This commit is contained in:
Kamron Batman 2020-05-04 01:34:51 -07:00 • committed by GitHub
parent 11227391d3
commit d9f417ee19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 1084 additions and 381 deletions

View file

@ -0,0 +1,55 @@
using System;
using Server.Network;
using Xunit;
namespace Server.Tests.Network.Packets
{
public class DamagePacketTests : IClassFixture<ServerFixture>
{
private readonly Mobile mobile;
public DamagePacketTests(ServerFixture fixture) => mobile = fixture.fromMobile;
[Theory]
[InlineData(10, 10)]
[InlineData(-5, 0)]
[InlineData(1024, 0xFF)]
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
{
Span<byte> data = new DamagePacketOld(mobile, inputAmount).Compile();
Span<byte> expectedData = stackalloc byte[] {
0xBF, // Packet
0x00, 0x0B, // Length
0x00, 0x22, // Sub-packet
0x01, // Command
0x00, 0x00, 0x00, 0x00, // Mobile Serial
expectedAmount // Amount
};
mobile.Serial.CopyTo(expectedData.Slice(6, 4));
AssertThat.Equal(data, expectedData);
}
[Theory]
[InlineData(10, 10)]
[InlineData(-5, 0)]
[InlineData(1024, 1024)]
[InlineData(100000, 0xFFFF)]
public void TestDamagePacket(int inputAmount, ushort expectedAmount)
{
Span<byte> data = new DamagePacket(mobile, inputAmount).Compile();
Span<byte> expectedData = stackalloc byte[] {
0x0B, // Packet
0x00, 0x00, 0x00, 0x00, // Mobile Serial
0x00, 0x00 // Amount
};
mobile.Serial.CopyTo(expectedData.Slice(1, 4));
expectedAmount.CopyTo(expectedData.Slice(5, 2));
AssertThat.Equal(data, expectedData);
}
}
}