Skip to content

Commit

Permalink
Add player output tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Sep 2, 2024
1 parent 5792633 commit 9a3f816
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
19 changes: 13 additions & 6 deletions GangsAPI/Data/PlayerWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using System.Diagnostics;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;

namespace GangsAPI.Data;
Expand All @@ -8,6 +9,9 @@ public class PlayerWrapper {
public readonly CCSPlayerController? Player;
public readonly ulong Steam;
public AdminData? Data;
private readonly List<string> chatOutput = [], consoleOutput = [];
public IReadOnlyList<string> ChatOutput => chatOutput;
public IReadOnlyList<string> ConsoleOutput => consoleOutput;

public PlayerWrapper(CCSPlayerController player) {
Player = player;
Expand All @@ -21,7 +25,8 @@ public PlayerWrapper(ulong steam, string? name) {
Steam = steam;
Name = name;

Data = new AdminData { Identity = Steam.ToString() };
chatOutput = new();
Data = new AdminData { Identity = Steam.ToString() };
}

private static char USER_CHAR => PermissionCharacters.UserPermissionChar;
Expand Down Expand Up @@ -99,19 +104,21 @@ public PlayerWrapper WithGroups(params string[] groups) {

public void PrintToChat(string message) {
if (Player == null) {
Console.WriteLine($"{Steam} {Player} received chat: {message}");
Debug.WriteLine($"{Steam} {Name} received chat: {message}");
chatOutput.Add(message);
return;
}

Player?.PrintToChat(message);
Player.PrintToChat(message);
}

public void PrintToConsole(string message) {
if (Player == null) {
Console.WriteLine($"{Steam} {Player} received console: {message}");
Console.WriteLine($"{Steam} {Name} received chat: {message}");
consoleOutput.Add(message);
return;
}

Player?.PrintToConsole(message);
Player.PrintToConsole(message);
}
}
16 changes: 16 additions & 0 deletions GangsTest/API/PlayerWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ public void PlayerWrapper_Init_Flags() {
Assert.True(player.Data.Flags.ContainsKey("test"));
}

[Fact]
public void PlayerWrapper_Print_Chat() {
Assert.Empty(testPlayer.ChatOutput);
testPlayer.PrintToChat("Test Message");
Assert.Single(testPlayer.ChatOutput);
Assert.Equal("Test Message", testPlayer.ChatOutput[0]);
}

[Fact]
public void PlayerWrapper_Print_Console() {
Assert.Empty(testPlayer.ConsoleOutput);
testPlayer.PrintToConsole("Test Message");
Assert.Single(testPlayer.ConsoleOutput);
Assert.Equal("Test Message", testPlayer.ConsoleOutput[0]);
}

[Theory]
[InlineData("test/flag")]
[InlineData("test/flag/child")]
Expand Down
19 changes: 10 additions & 9 deletions GangsTest/GangsTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
<PackageReference Include="FuzzDotNet.MSTest" Version="0.1.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0"/>
<PackageReference Include="Xunit.DependencyInjection" Version="9.3.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="FuzzDotNet.MSTest" Version="0.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.3.1" />
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
Expand All @@ -28,9 +29,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GangsImpl\Mock\Mock.csproj"/>
<ProjectReference Include="..\GangsImpl\SQLite\SQLite.csproj"/>
<ProjectReference Include="..\GangsImpl\SQL\SQL.csproj"/>
<ProjectReference Include="..\GangsImpl\Mock\Mock.csproj" />
<ProjectReference Include="..\GangsImpl\SQLite\SQLite.csproj" />
<ProjectReference Include="..\GangsImpl\SQL\SQL.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

Expand Down
6 changes: 5 additions & 1 deletion GangsTest/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using GangsAPI.Services;
using System.Text;
using GangsAPI.Services;
using GangsAPI.Services.Commands;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualBasic.CompilerServices;
using Mock;
using Xunit.Abstractions;
using Xunit.DependencyInjection.Logging;

namespace GangsTest;

Expand Down

0 comments on commit 9a3f816

Please sign in to comment.