Tests, finished for extensions
This commit is contained in:
23
BackendTests/BackendTests.csproj
Normal file
23
BackendTests/BackendTests.csproj
Normal 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>
|
6
BackendTests/Controllers/GameControllerTests.cs
Normal file
6
BackendTests/Controllers/GameControllerTests.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace BackendTests.Controllers;
|
||||
|
||||
public class GameControllerTests
|
||||
{
|
||||
|
||||
}
|
6
BackendTests/Game/Items/DiceCupTests.cs
Normal file
6
BackendTests/Game/Items/DiceCupTests.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace BackendTests.Game.Items;
|
||||
|
||||
public class DiceCupTests
|
||||
{
|
||||
|
||||
}
|
6
BackendTests/Game/Items/DiceTests.cs
Normal file
6
BackendTests/Game/Items/DiceTests.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace BackendTests.Game.Items;
|
||||
|
||||
public class DiceTests
|
||||
{
|
||||
|
||||
}
|
74
BackendTests/Services/ActionServiceTests.cs
Normal file
74
BackendTests/Services/ActionServiceTests.cs
Normal 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
|
||||
}
|
3
BackendTests/Services/GameGroupTests.cs
Normal file
3
BackendTests/Services/GameGroupTests.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace BackendTests.Services;
|
||||
|
||||
public class GameGroupTests { }
|
3
BackendTests/Services/WebSocketServiceTests.cs
Normal file
3
BackendTests/Services/WebSocketServiceTests.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace BackendTests.Services;
|
||||
|
||||
public class WebSocketServiceTests { }
|
1
BackendTests/Usings.cs
Normal file
1
BackendTests/Usings.cs
Normal file
@ -0,0 +1 @@
|
||||
global using NUnit.Framework;
|
64
BackendTests/Utils/ExtensionsTests.cs
Normal file
64
BackendTests/Utils/ExtensionsTests.cs
Normal 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
|
||||
}
|
Reference in New Issue
Block a user