Adds more unit tests (#133)

This commit is contained in:
Kamron Batman 2020-05-08 20:32:59 -07:00 • committed by GitHub
parent e138706536
commit 8278694105
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 1406 additions and 996 deletions

View file

@ -0,0 +1,59 @@
using System;
using Server.Network;
using Xunit;
namespace Server.Tests.Network.Packets
{
public class DamagePacketTests : IClassFixture<ServerFixture>
{
[Theory]
[InlineData(10, 10)]
[InlineData(-5, 0)]
[InlineData(1024, 0xFF)]
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
Span<byte> data = new DamagePacketOld(m, 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
};
m.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)
{
var m = new Mobile(0x1);
m.DefaultMobileInit();
Span<byte> data = new DamagePacket(m, inputAmount).Compile();
Span<byte> expectedData = stackalloc byte[]
{
0x0B, // Packet
0x00, 0x00, 0x00, 0x00, // Mobile Serial
0x00, 0x00 // Amount
};
m.Serial.CopyTo(expectedData.Slice(1, 4));
expectedAmount.CopyTo(expectedData.Slice(5, 2));
AssertThat.Equal(data, expectedData);
}
}
}