Adds testing (#118)

This commit is contained in:
Kamron Batman 2020-04-27 19:27:05 -07:00 committed by GitHub
parent e200f37e75
commit 60ee5eadd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 143 additions and 13 deletions

View file

@ -0,0 +1,13 @@
using Xunit;
namespace Server.Tests
{
public class EmptyTests
{
[Fact]
public void EmptyTest()
{
Assert.True(true);
}
}
}

View file

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,36 @@
using System;
using System.Buffers.Binary;
using Server.Network;
using Xunit;
namespace Server.Tests.Network.Packets
{
public class DamageOldPacketTests : IClassFixture<ServerFixture>
{
private Mobile mobile;
public DamageOldPacketTests(ServerFixture fixture) => mobile = fixture.mobile;
[Theory]
[InlineData(10, 10)]
[InlineData(-5, 0)]
[InlineData(1024, 255)]
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
{
DamagePacketOld packet = new DamagePacketOld(mobile, inputAmount);
Span<byte> data = packet.Compile(false, out int length).AsSpan(0, length);
byte[] expectedData = {
0xBF, // Packet
0x00, 0x0B, // Length
0x00, 0x22, // Sub-packet
0x01, // Command
0x00, 0x00, 0x00, 0x01, // Serial
expectedAmount // Amount
};
Assert.Equal(data.ToArray(), expectedData);
}
}
}

View file

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="coverlet.collector" Version="1.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Scripts\Scripts.csproj" />
<ProjectReference Include="..\Server\Server.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,24 @@
using System;
using Server.Misc;
namespace Server.Tests
{
public class ServerFixture : IDisposable
{
public Mobile mobile { get; }
public ServerFixture()
{
// Configure / Initialize
MapDefinitions.Configure();
World.Load();
mobile = new Mobile(0x1);
}
public void Dispose()
{
}
}
}

View file

@ -1130,13 +1130,8 @@ namespace Server
public bool CanSpawnMobile(Point2D p, int z) => CanSpawnMobile(p.m_X, p.m_Y, z);
public bool CanSpawnMobile(int x, int y, int z)
{
if (!Region.Find(new Point3D(x, y, z), this).AllowSpawn())
return false;
return CanFit(x, y, z, 16);
}
public bool CanSpawnMobile(int x, int y, int z) =>
Region.Find(new Point3D(x, y, z), this).AllowSpawn() && CanFit(x, y, z, 16);
public Sector GetSector(Point3D p) => InternalGetSector(p.m_X >> SectorShift, p.m_Y >> SectorShift);

View file

@ -35,7 +35,7 @@ namespace Server
{
get
{
while (World.FindMobile(LastMobile = LastMobile + 1) != null)
while (World.FindMobile(LastMobile += 1) != null)
{
}