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
}

View File

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pac-man-board-game", "pac-man-board-game\pac-man-board-game.csproj", "{60072632-A16F-4007-8A97-AC74B7E6703B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackendTests", "BackendTests\BackendTests.csproj", "{35336347-32EB-4764-A28E-3F8FF6CA54C4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{60072632-A16F-4007-8A97-AC74B7E6703B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60072632-A16F-4007-8A97-AC74B7E6703B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60072632-A16F-4007-8A97-AC74B7E6703B}.Release|Any CPU.Build.0 = Release|Any CPU
{35336347-32EB-4764-A28E-3F8FF6CA54C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35336347-32EB-4764-A28E-3F8FF6CA54C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35336347-32EB-4764-A28E-3F8FF6CA54C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35336347-32EB-4764-A28E-3F8FF6CA54C4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c5faef1f_002D6857_002D480d_002D9cae_002Da308bdf09365/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="GetStringValidByteArray" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;NUnit3x::35336347-32EB-4764-A28E-3F8FF6CA54C4::net7.0::BackendTests.Utils.ExtensionsTests&lt;/TestId&gt;
&lt;TestId&gt;NUnit3x::35336347-32EB-4764-A28E-3F8FF6CA54C4::net7.0::BackendTests.Services.ActionServiceTests&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

View File

@ -52,7 +52,7 @@ public class ActionService : IActionService // TODO tests
public List<IPlayer> PlayerInfo(ActionMessage message)
{
_player = JsonSerializer.Deserialize<Player>(message.Data);
_group = _wsService.AddPlayer(_player); // TODO missing some data?
_group = _wsService.AddPlayer(_player);
return _group.Players;
}