Adds testing (#118)
This commit is contained in:
parent
e200f37e75
commit
60ee5eadd2
10 changed files with 143 additions and 13 deletions
13
Projects/Scripts.Tests/EmptyTests.cs
Normal file
13
Projects/Scripts.Tests/EmptyTests.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Xunit;
|
||||
|
||||
namespace Server.Tests
|
||||
{
|
||||
public class EmptyTests
|
||||
{
|
||||
[Fact]
|
||||
public void EmptyTest()
|
||||
{
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Projects/Scripts.Tests/Scripts.Tests.csproj
Normal file
12
Projects/Scripts.Tests/Scripts.Tests.csproj
Normal 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>
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Projects/Server.Tests/Server.Tests.csproj
Normal file
16
Projects/Server.Tests/Server.Tests.csproj
Normal 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>
|
||||
24
Projects/Server.Tests/ServerFixture.cs
Normal file
24
Projects/Server.Tests/ServerFixture.cs
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Server
|
|||
{
|
||||
get
|
||||
{
|
||||
while (World.FindMobile(LastMobile = LastMobile + 1) != null)
|
||||
while (World.FindMobile(LastMobile += 1) != null)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue