diff --git a/GangsAPI/Data/PlayerWrapper.cs b/GangsAPI/Data/PlayerWrapper.cs index 4e45aa5..eb1a303 100644 --- a/GangsAPI/Data/PlayerWrapper.cs +++ b/GangsAPI/Data/PlayerWrapper.cs @@ -1,4 +1,5 @@ -using CounterStrikeSharp.API.Core; +using System.Diagnostics; +using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; namespace GangsAPI.Data; @@ -8,6 +9,9 @@ public class PlayerWrapper { public readonly CCSPlayerController? Player; public readonly ulong Steam; public AdminData? Data; + private readonly List chatOutput = [], consoleOutput = []; + public IReadOnlyList ChatOutput => chatOutput; + public IReadOnlyList ConsoleOutput => consoleOutput; public PlayerWrapper(CCSPlayerController player) { Player = player; @@ -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; @@ -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); } } \ No newline at end of file diff --git a/GangsTest/API/PlayerWrapperTests.cs b/GangsTest/API/PlayerWrapperTests.cs index 4f737df..a694d70 100644 --- a/GangsTest/API/PlayerWrapperTests.cs +++ b/GangsTest/API/PlayerWrapperTests.cs @@ -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")] diff --git a/GangsTest/GangsTest.csproj b/GangsTest/GangsTest.csproj index 7241a51..9b49c5b 100644 --- a/GangsTest/GangsTest.csproj +++ b/GangsTest/GangsTest.csproj @@ -10,15 +10,16 @@ - - - - - + + + + + + - + @@ -28,9 +29,9 @@ - - - + + + diff --git a/GangsTest/Startup.cs b/GangsTest/Startup.cs index 782009d..3ccbb30 100644 --- a/GangsTest/Startup.cs +++ b/GangsTest/Startup.cs @@ -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;