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

@ -67,10 +67,29 @@ jobs:
- run:
name: Building with Analyzers
command: dotnet build -c Analyze /p:PublishProfile=Linux
tests:
description: Unit Tests
executor: linux-build
steps:
- run: rm -rf ~/project/.git # CircleCI git caching is likely broken
- checkout
- restore_cache:
keys:
- dotnet-packages-linux-{{ checksum "Projects/Server/Server.csproj" }}-{{ checksum "Projects/Scripts/Scripts.csproj" }}
- run:
name: Install ModernUO dependencies
command: dotnet restore
- save_cache:
paths:
- ~/.nuget/packages
key: dotnet-packages-linux-{{ checksum "Projects/Server/Server.csproj" }}-{{ checksum "Projects/Scripts/Scripts.csproj" }}
- run:
name: Running unit tests
command: dotnet test
workflows:
build-and-test:
jobs:
- build_linux
- build_windows
- code_styling
- tests

7
.gitignore vendored
View file

@ -13,6 +13,7 @@
/Distribution/System.ComponentModel.Annotations.dll
/Distribution/System.Runtime.CompilerServices.Unsafe.dll
/Distribution/Data/modernuo.json
/Distribution/runtimes
# LibUv Dependencies
/Distribution/libuv.dylib
@ -29,10 +30,8 @@
/Distribution/Microsoft.Extensions.Options.dll
/Distribution/Microsoft.Extensions.Primitives.dll
/Projects/Scripts/obj
/Projects/Scripts/bin
/Projects/Server/obj
/Projects/Server/bin
/Projects/*/obj
/Projects/*/bin
*.log
*.user

View file

@ -6,6 +6,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Projects\Server\S
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Scripts", "Projects\Scripts\Scripts.csproj", "{83CF2484-BCCB-4B7C-9C5F-7AB43AEA5E8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Tests", "Projects\Server.Tests\Server.Tests.csproj", "{D7A5D3AF-D607-46EF-BAAD-0D424190311F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scripts.Tests", "Projects\Scripts.Tests\Scripts.Tests.csproj", "{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Analyze|Any CPU = Analyze|Any CPU
@ -25,6 +29,18 @@ Global
{83CF2484-BCCB-4B7C-9C5F-7AB43AEA5E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83CF2484-BCCB-4B7C-9C5F-7AB43AEA5E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83CF2484-BCCB-4B7C-9C5F-7AB43AEA5E8F}.Release|Any CPU.Build.0 = Release|Any CPU
{D7A5D3AF-D607-46EF-BAAD-0D424190311F}.Analyze|Any CPU.ActiveCfg = Debug|Any CPU
{D7A5D3AF-D607-46EF-BAAD-0D424190311F}.Analyze|Any CPU.Build.0 = Debug|Any CPU
{D7A5D3AF-D607-46EF-BAAD-0D424190311F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7A5D3AF-D607-46EF-BAAD-0D424190311F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7A5D3AF-D607-46EF-BAAD-0D424190311F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7A5D3AF-D607-46EF-BAAD-0D424190311F}.Release|Any CPU.Build.0 = Release|Any CPU
{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Analyze|Any CPU.ActiveCfg = Debug|Any CPU
{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Analyze|Any CPU.Build.0 = Debug|Any CPU
{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

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)
{
}