Tests, finished for extensions

This commit is contained in:
martin
2023-07-09 19:58:32 +02:00
parent 0cb4367999
commit 31196886fd
12 changed files with 200 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\pac-man-board-game\pac-man-board-game.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
namespace BackendTests.Controllers;
public class GameControllerTests
{
}

View File

@ -0,0 +1,6 @@
namespace BackendTests.Game.Items;
public class DiceCupTests
{
}

View File

@ -0,0 +1,6 @@
namespace BackendTests.Game.Items;
public class DiceTests
{
}

View File

@ -0,0 +1,74 @@
namespace BackendTests.Services;
public class ActionServiceTests
{
#region RollDice()
[Test]
public void RollDice_ReturnsListOfIntegers()
{
Assert.Fail();
}
#endregion
#region PlayerInfo(ActionMessage message)
[Test]
public void PlayerInfo_DataIsNull()
{
Assert.Fail();
}
[Test]
public void PlayerInfo_DataIsNotPlayer()
{
Assert.Fail();
}
[Test]
public void PlayerInfo_DataIsPlayer()
{
Assert.Fail();
}
#endregion
#region DoAction(ActionMessage message)
[Test]
public void DoAction_NegativeAction()
{
Assert.Fail();
}
[Test]
public void DoAction_OutOfBoundsAction()
{
Assert.Fail();
}
#endregion
#region Ready()
[Test]
public void Ready_PlayerIsNull()
{
Assert.Fail();
}
[Test]
public void Ready_SomeReady()
{
Assert.Fail();
}
[Test]
public void Ready_AllReady()
{
Assert.Fail();
}
#endregion
}

View File

@ -0,0 +1,3 @@
namespace BackendTests.Services;
public class GameGroupTests { }

View File

@ -0,0 +1,3 @@
namespace BackendTests.Services;
public class WebSocketServiceTests { }

1
BackendTests/Usings.cs Normal file
View File

@ -0,0 +1 @@
global using NUnit.Framework;

View File

@ -0,0 +1,64 @@
using System.Text.Json;
using pacMan.Utils;
namespace BackendTests.Utils;
public class ExtensionsTests
{
#region ToArraySegment(this object obj)
[Test]
public void ToArraySegmentValidObject()
{
var obj = new { Test = "test" };
var segment = obj.ToArraySegment();
Assert.That(JsonSerializer.Serialize(obj), Has.Length.EqualTo(segment.Count));
}
[Test]
public void ToArraySegmentNullableObject()
{
string? s = null;
var segment = s!.ToArraySegment(); // Segment contains: null
Assert.That(segment, Has.Count.EqualTo(4));
}
#endregion
#region GetString(this byte[] bytes, int length)
private byte[] _bytes = null!;
[SetUp]
public void Setup()
{
_bytes = "Hello World!"u8.ToArray();
}
[Test]
public void GetString_ValidByteArray()
{
Assert.That(_bytes.GetString(_bytes.Length), Is.EqualTo("Hello World!"));
}
[Test]
public void GetString_EmptyByteArray()
{
Assert.That(new byte[] { }.GetString(0), Is.EqualTo(""));
}
[Test]
public void GetString_NegativeLength()
{
Assert.Throws(typeof(ArgumentOutOfRangeException), () => _bytes.GetString(-1));
}
[Test]
public void GetString_LengthGreaterThanByteArrayLength()
{
Assert.Throws(typeof(ArgumentOutOfRangeException), () => _bytes.GetString(_bytes.Length + 1));
}
#endregion
}