From dc0921f1c5f0823aa13e221c0c7a6d461f313fdb Mon Sep 17 00:00:00 2001 From: MSWS Date: Fri, 6 Sep 2024 12:55:18 -0700 Subject: [PATCH] Cleanup --- Commands/CommandManager.cs | 7 ++-- Commands/GangCommand.cs | 2 +- Commands/gang/CreateCommand.cs | 2 +- Commands/gang/HelpCommand.cs | 2 +- Gangs/GangServiceCollection.cs | 1 - GangsAPI/Data/Command/CommandInfoWrapper.cs | 6 +-- GangsAPI/Data/Gang/IGang.cs | 5 +-- GangsAPI/Data/Gang/IGangPlayer.cs | 4 +- GangsAPI/Services/IGangStatManager.cs | 40 +++++++++++-------- GangsAPI/Services/IPlayerManager.cs | 2 +- GangsAPI/Services/IPlayerStatManager.cs | 40 +++++++++++-------- GangsImpl/AbstractDB/AbstractDBGangManager.cs | 8 ++-- GangsImpl/AbstractDB/DBGang.cs | 1 - GangsImpl/Mock/MockCommandManager.cs | 12 +++--- GangsImpl/Mock/MockGang.cs | 2 - GangsImpl/Mock/MockInstanceStatManager.cs | 36 ++++++++--------- GangsImpl/Mock/MockPlayer.cs | 2 - GangsImpl/Mock/MockStat.cs | 9 +++-- GangsImpl/SQLite/SQLiteGangManager.cs | 25 +++++++----- GangsImpl/Stats/GangBankStat.cs | 2 +- GangsTest/Commands/CommandTestData.cs | 3 +- GangsTest/Commands/CreateTests.cs | 3 +- GangsTest/Commands/GangCommandTests.cs | 5 +-- .../Commands/ManagerTests/CommandTestData.cs | 2 +- .../Commands/ManagerTests/ManagerTests.cs | 2 +- GangsTest/Commands/PermissionTests.cs | 2 +- GangsTest/GangTests/GangFetchTests.cs | 4 +- GangsTest/GangTests/GangMutabilityTests.cs | 1 - GangsTest/Startup.cs | 1 - 29 files changed, 118 insertions(+), 113 deletions(-) diff --git a/Commands/CommandManager.cs b/Commands/CommandManager.cs index 0dcd0c0..8f30212 100644 --- a/Commands/CommandManager.cs +++ b/Commands/CommandManager.cs @@ -9,20 +9,20 @@ namespace Commands; -public class CommandManager(IGangManager gangMgr, IPlayerManager playerMgr) +public class CommandManager(IGangManager gangMgr) : MockCommandManager, IPluginBehavior { private BasePlugin? plugin; public void Start(BasePlugin? basePlugin, bool hotReload) { plugin = basePlugin; - RegisterCommand(new GangCommand(gangMgr, playerMgr)); + RegisterCommand(new GangCommand(gangMgr)); } public override bool RegisterCommand(ICommand command) { var result = base.RegisterCommand(command); if (result == false) return false; - foreach (var alias in command.Aliases) { + foreach (var alias in command.Aliases) plugin?.AddCommand(alias, command.Description ?? string.Empty, (player, info) => { var wrapper = player == null ? null : new PlayerWrapper(player); @@ -31,7 +31,6 @@ public override bool RegisterCommand(ICommand command) { await ProcessCommand(wrapper, wrappedInfo); }); }); - } return true; } diff --git a/Commands/GangCommand.cs b/Commands/GangCommand.cs index 153e29a..ac38c13 100644 --- a/Commands/GangCommand.cs +++ b/Commands/GangCommand.cs @@ -7,7 +7,7 @@ namespace Commands; -public class GangCommand(IGangManager gangMgr, IPlayerManager playerMgr) : ICommand { +public class GangCommand(IGangManager gangMgr) : ICommand { private readonly Dictionary sub = new() { // ["delete"] = new DeleteGangCommand(), // ["invite"] = new InviteGangCommand(), diff --git a/Commands/gang/CreateCommand.cs b/Commands/gang/CreateCommand.cs index c330622..278f8d7 100644 --- a/Commands/gang/CreateCommand.cs +++ b/Commands/gang/CreateCommand.cs @@ -8,7 +8,7 @@ namespace Commands.gang; // create [name] public class CreateCommand(IGangManager gangs) : ICommand { public string Name => "create"; - public string? Description => "Creates a new gang"; + public string Description => "Creates a new gang"; public string Usage => "[name]"; public async Task Execute(PlayerWrapper? executor, diff --git a/Commands/gang/HelpCommand.cs b/Commands/gang/HelpCommand.cs index 6929996..4c93599 100644 --- a/Commands/gang/HelpCommand.cs +++ b/Commands/gang/HelpCommand.cs @@ -6,7 +6,7 @@ namespace Commands.gang; public class HelpCommand : ICommand { public string Name => "help"; - public string? Description => "Displays help for gangs"; + public string Description => "Displays help for gangs"; public Task Execute(PlayerWrapper? executor, CommandInfoWrapper info) { diff --git a/Gangs/GangServiceCollection.cs b/Gangs/GangServiceCollection.cs index 5ad4d1f..5aa3751 100644 --- a/Gangs/GangServiceCollection.cs +++ b/Gangs/GangServiceCollection.cs @@ -5,7 +5,6 @@ using GangsAPI.Services.Commands; using Microsoft.Extensions.DependencyInjection; using Mock; -using SQLImpl; namespace GangsImpl; diff --git a/GangsAPI/Data/Command/CommandInfoWrapper.cs b/GangsAPI/Data/Command/CommandInfoWrapper.cs index 8be4c80..c981adc 100644 --- a/GangsAPI/Data/Command/CommandInfoWrapper.cs +++ b/GangsAPI/Data/Command/CommandInfoWrapper.cs @@ -1,15 +1,15 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands; namespace GangsAPI.Data.Command; public class CommandInfoWrapper(PlayerWrapper? executor, int offset = 0, params string[] args) { + private readonly string[] args = args; + public readonly CommandCallingContext CallingContext = CommandCallingContext.Console; public readonly PlayerWrapper? CallingPlayer = executor; - private readonly string[] args = args; public CommandInfoWrapper(CommandInfo info, int offset = 0) : this( info.CallingPlayer == null ? null : new PlayerWrapper(info.CallingPlayer), diff --git a/GangsAPI/Data/Gang/IGang.cs b/GangsAPI/Data/Gang/IGang.cs index 38d7dc2..c20ca8b 100644 --- a/GangsAPI/Data/Gang/IGang.cs +++ b/GangsAPI/Data/Gang/IGang.cs @@ -1,7 +1,4 @@ -using System.Collections; -using GangsAPI.Permissions; - -namespace GangsAPI.Data.Gang; +namespace GangsAPI.Data.Gang; /// /// Represents an instance of a gang. diff --git a/GangsAPI/Data/Gang/IGangPlayer.cs b/GangsAPI/Data/Gang/IGangPlayer.cs index 8099ea2..8bd59f0 100644 --- a/GangsAPI/Data/Gang/IGangPlayer.cs +++ b/GangsAPI/Data/Gang/IGangPlayer.cs @@ -1,6 +1,4 @@ -using GangsAPI.Permissions; - -namespace GangsAPI.Data.Gang; +namespace GangsAPI.Data.Gang; /// /// A gang player is a player tracked by the gangs plugin. diff --git a/GangsAPI/Services/IGangStatManager.cs b/GangsAPI/Services/IGangStatManager.cs index 064f469..17a14b4 100644 --- a/GangsAPI/Services/IGangStatManager.cs +++ b/GangsAPI/Services/IGangStatManager.cs @@ -13,8 +13,9 @@ public interface IGangStatManager : ICacher { #region Get - Task GetForGang(IGang gang, string statId, out TV? holder) - => GetForGang(gang.GangId, statId, out holder); + Task GetForGang(IGang gang, string statId, out TV? holder) { + return GetForGang(gang.GangId, statId, out holder); + } async Task GetForGang(IGang gang, IStat holder) { var success = await GetForGang(gang, holder.StatId, out TV? tmp); @@ -23,34 +24,41 @@ async Task GetForGang(IGang gang, IStat holder) { return true; } - Task GetForGang(IGang gang, IStat stat, out TV? holder) - => GetForGang(gang, stat.StatId, out holder); + Task GetForGang(IGang gang, IStat stat, out TV? holder) { + return GetForGang(gang, stat.StatId, out holder); + } #endregion #region Set - Task SetForGang(int gangId, IStat stat) - => SetForGang(gangId, stat.StatId, stat.Value); + Task SetForGang(int gangId, IStat stat) { + return SetForGang(gangId, stat.StatId, stat.Value); + } - Task SetForGang(IGang gang, IStat stat) - => SetForGang(gang.GangId, stat); + Task SetForGang(IGang gang, IStat stat) { + return SetForGang(gang.GangId, stat); + } - Task SetForGang(IGang gang, string statId, TV value) - => SetForGang(gang.GangId, statId, value); + Task SetForGang(IGang gang, string statId, TV value) { + return SetForGang(gang.GangId, statId, value); + } #endregion #region Remove - Task RemoveFromGang(int gangId, IStat stat) - => RemoveFromGang(gangId, stat.StatId); + Task RemoveFromGang(int gangId, IStat stat) { + return RemoveFromGang(gangId, stat.StatId); + } - Task RemoveFromGang(IGang gang, string statId) - => RemoveFromGang(gang.GangId, statId); + Task RemoveFromGang(IGang gang, string statId) { + return RemoveFromGang(gang.GangId, statId); + } - Task RemoveFromGang(IGang gang, IStat stat) - => RemoveFromGang(gang, stat.StatId); + Task RemoveFromGang(IGang gang, IStat stat) { + return RemoveFromGang(gang, stat.StatId); + } #endregion diff --git a/GangsAPI/Services/IPlayerManager.cs b/GangsAPI/Services/IPlayerManager.cs index c57b685..c58d874 100644 --- a/GangsAPI/Services/IPlayerManager.cs +++ b/GangsAPI/Services/IPlayerManager.cs @@ -37,7 +37,7 @@ public interface IPlayerManager : IPluginBehavior, ICacher { /// The name of the player. /// The new player. Task CreatePlayer(ulong steamId, string? name = null); - + Task UpdatePlayer(IGangPlayer player); /// diff --git a/GangsAPI/Services/IPlayerStatManager.cs b/GangsAPI/Services/IPlayerStatManager.cs index 3aebb46..6c34c18 100644 --- a/GangsAPI/Services/IPlayerStatManager.cs +++ b/GangsAPI/Services/IPlayerStatManager.cs @@ -13,8 +13,9 @@ public interface IPlayerStatManager : IPluginBehavior, ICacher { #region Get Task GetForPlayer(PlayerWrapper wrapper, string statId, - out TV? holder) - => GetForPlayer(wrapper.Steam, statId, out holder); + out TV? holder) { + return GetForPlayer(wrapper.Steam, statId, out holder); + } async Task GetForPlayer(ulong steam, IStat holder) { var success = await GetForPlayer(steam, holder.StatId, out TV? tmp); @@ -23,34 +24,41 @@ async Task GetForPlayer(ulong steam, IStat holder) { return true; } - Task GetForPlayer(PlayerWrapper wrapper, IStat holder) - => GetForPlayer(wrapper.Steam, holder); + Task GetForPlayer(PlayerWrapper wrapper, IStat holder) { + return GetForPlayer(wrapper.Steam, holder); + } #endregion #region Set - Task SetForPlayer(ulong steam, IStat stat) - => SetForPlayer(steam, stat.StatId, stat.Value); + Task SetForPlayer(ulong steam, IStat stat) { + return SetForPlayer(steam, stat.StatId, stat.Value); + } - Task SetForPlayer(PlayerWrapper wrapper, IStat stat) - => SetForPlayer(wrapper.Steam, stat); + Task SetForPlayer(PlayerWrapper wrapper, IStat stat) { + return SetForPlayer(wrapper.Steam, stat); + } - Task SetForPlayer(PlayerWrapper wrapper, string statId, TV value) - => SetForPlayer(wrapper.Steam, statId, value); + Task SetForPlayer(PlayerWrapper wrapper, string statId, TV value) { + return SetForPlayer(wrapper.Steam, statId, value); + } #endregion #region Remove - Task RemoveFromPlayer(ulong steam, IStat stat) - => RemoveFromPlayer(steam, stat.StatId); + Task RemoveFromPlayer(ulong steam, IStat stat) { + return RemoveFromPlayer(steam, stat.StatId); + } - Task RemoveFromPlayer(PlayerWrapper wrapper, string statId) - => RemoveFromPlayer(wrapper.Steam, statId); + Task RemoveFromPlayer(PlayerWrapper wrapper, string statId) { + return RemoveFromPlayer(wrapper.Steam, statId); + } - Task RemoveFromPlayer(PlayerWrapper wrapper, IStat stat) - => RemoveFromPlayer(wrapper, stat.StatId); + Task RemoveFromPlayer(PlayerWrapper wrapper, IStat stat) { + return RemoveFromPlayer(wrapper, stat.StatId); + } #endregion diff --git a/GangsImpl/AbstractDB/AbstractDBGangManager.cs b/GangsImpl/AbstractDB/AbstractDBGangManager.cs index 3180d77..45db5fc 100644 --- a/GangsImpl/AbstractDB/AbstractDBGangManager.cs +++ b/GangsImpl/AbstractDB/AbstractDBGangManager.cs @@ -4,12 +4,12 @@ using GangsAPI.Data.Gang; using GangsAPI.Services; using Mock; -using Xunit; namespace GenericDB; -public abstract class AbstractDBGangManager(IPlayerManager playerMgr, string connectionString, - string table = "gang_gangs", bool testing = false) : MockGangManager(playerMgr) { +public abstract class AbstractDBGangManager(IPlayerManager playerMgr, + string connectionString, string table = "gang_gangs", bool testing = false) + : MockGangManager(playerMgr) { protected DbConnection Connection = null!; protected DbTransaction? Transaction; public override void ClearCache() { CachedGangs.Clear(); } @@ -49,7 +49,7 @@ public override async Task UpdateGang(IGang gang) { var result = await base.UpdateGang(gang); var query = $"UPDATE {table} SET Name = @Name WHERE GangId = @GangId"; await Connection.ExecuteAsync(query, new { gang.Name, gang.GangId }, - transaction: Transaction); + Transaction); return result; } diff --git a/GangsImpl/AbstractDB/DBGang.cs b/GangsImpl/AbstractDB/DBGang.cs index f299284..d4d2aff 100644 --- a/GangsImpl/AbstractDB/DBGang.cs +++ b/GangsImpl/AbstractDB/DBGang.cs @@ -1,5 +1,4 @@ using GangsAPI.Data.Gang; -using GangsAPI.Permissions; using Mock; namespace GenericDB; diff --git a/GangsImpl/Mock/MockCommandManager.cs b/GangsImpl/Mock/MockCommandManager.cs index 99e2bd0..5571a42 100644 --- a/GangsImpl/Mock/MockCommandManager.cs +++ b/GangsImpl/Mock/MockCommandManager.cs @@ -16,6 +16,12 @@ public bool UnregisterCommand(ICommand command) { return command.Aliases.All(alias => commands.Remove(alias)); } + public async Task ProcessCommand(PlayerWrapper? executor, + params string[] args) { + var info = new CommandInfoWrapper(executor, 0, args); + return await ProcessCommand(executor, info); + } + public async Task ProcessCommand(PlayerWrapper? executor, CommandInfo sourceInfo) { var info = new CommandInfoWrapper(sourceInfo); @@ -44,10 +50,4 @@ await Task.Run(async () => { return result; } - - public async Task ProcessCommand(PlayerWrapper? executor, - params string[] args) { - var info = new CommandInfoWrapper(executor, 0, args); - return await ProcessCommand(executor, info); - } } \ No newline at end of file diff --git a/GangsImpl/Mock/MockGang.cs b/GangsImpl/Mock/MockGang.cs index 8571c28..a22a6eb 100644 --- a/GangsImpl/Mock/MockGang.cs +++ b/GangsImpl/Mock/MockGang.cs @@ -1,6 +1,4 @@ using GangsAPI.Data.Gang; -using GangsAPI.Data.Stat; -using GangsAPI.Permissions; namespace Mock; diff --git a/GangsImpl/Mock/MockInstanceStatManager.cs b/GangsImpl/Mock/MockInstanceStatManager.cs index c7a173b..45adc02 100644 --- a/GangsImpl/Mock/MockInstanceStatManager.cs +++ b/GangsImpl/Mock/MockInstanceStatManager.cs @@ -1,15 +1,30 @@ -using GangsAPI.Data.Stat; -using GangsAPI.Services; +using GangsAPI.Services; namespace Mock; public class MockInstanceStatManager : IPlayerStatManager, IGangStatManager { + public void ClearCache() { + cachedGangValues.Clear(); + cachedPlayerValues.Clear(); + } + + public Task Load() { + cachedGangValues.Clear(); + cachedPlayerValues.Clear(); + foreach (var (gangId, gangStatMap) in backendGangValues) + cachedGangValues[gangId] = new Dictionary(gangStatMap); + foreach (var (steam, playerStatMap) in backendPlayerValues) + cachedPlayerValues[steam] = new Dictionary(playerStatMap); + return Task.CompletedTask; + } + #region Player private readonly Dictionary> cachedPlayerValues = [], backendPlayerValues = []; - public Task GetForPlayer(ulong steam, string statId, out TV? result) { + public Task + GetForPlayer(ulong steam, string statId, out TV? result) { result = default; if (!cachedPlayerValues.TryGetValue(steam, out var playerStatMap)) return Task.FromResult(false); @@ -79,19 +94,4 @@ public Task RemoveFromGang(int gangId, string statId) { } #endregion - - public void ClearCache() { - cachedGangValues.Clear(); - cachedPlayerValues.Clear(); - } - - public Task Load() { - cachedGangValues.Clear(); - cachedPlayerValues.Clear(); - foreach (var (gangId, gangStatMap) in backendGangValues) - cachedGangValues[gangId] = new Dictionary(gangStatMap); - foreach (var (steam, playerStatMap) in backendPlayerValues) - cachedPlayerValues[steam] = new Dictionary(playerStatMap); - return Task.CompletedTask; - } } \ No newline at end of file diff --git a/GangsImpl/Mock/MockPlayer.cs b/GangsImpl/Mock/MockPlayer.cs index 43c23a9..b9a3eba 100644 --- a/GangsImpl/Mock/MockPlayer.cs +++ b/GangsImpl/Mock/MockPlayer.cs @@ -1,6 +1,4 @@ using GangsAPI.Data.Gang; -using GangsAPI.Data.Stat; -using GangsAPI.Permissions; namespace Mock; diff --git a/GangsImpl/Mock/MockStat.cs b/GangsImpl/Mock/MockStat.cs index e595036..03e2bfd 100644 --- a/GangsImpl/Mock/MockStat.cs +++ b/GangsImpl/Mock/MockStat.cs @@ -3,10 +3,6 @@ namespace Mock; public class MockStat(string statId, string name, string? desc = null) : IStat { - public bool Equals(MockStat? other) { - return other is not null && ((IStat)this).Equals(other); - } - public string StatId { get; } = statId; public string Name { get; } = name; public string? Description { get; } = desc; @@ -14,6 +10,11 @@ public bool Equals(MockStat? other) { public bool Equals(IStat? other) { return other is not null && StatId == other.StatId; } + + public bool Equals(MockStat? other) { + return other is not null && ((IStat)this).Equals(other); + } + public override bool Equals(object? obj) { return Equals(obj as MockStat); } public override int GetHashCode() { return HashCode.Combine(StatId); } diff --git a/GangsImpl/SQLite/SQLiteGangManager.cs b/GangsImpl/SQLite/SQLiteGangManager.cs index 9d7c2fb..9ff7d0b 100644 --- a/GangsImpl/SQLite/SQLiteGangManager.cs +++ b/GangsImpl/SQLite/SQLiteGangManager.cs @@ -8,23 +8,27 @@ namespace SQLite; -public class SQLiteGangManager(IPlayerManager playerMgr, string connectionString, - string table = "gang_gangs", bool testing = false) +public class SQLiteGangManager(IPlayerManager playerMgr, + string connectionString, string table = "gang_gangs", bool testing = false) : AbstractDBGangManager(playerMgr, connectionString, table, testing) { + private readonly bool myTesting = testing; + private readonly string myTable = table; + private readonly string myConnectionString = connectionString; + public override void Start(BasePlugin? plugin, bool hotReload) { - Connection = CreateDbConnection(connectionString); + Connection = CreateDbConnection(myConnectionString); Connection.Open(); - if (testing) Transaction = Connection.BeginTransaction(); + if (myTesting) Transaction = Connection.BeginTransaction(); try { var command = Connection.CreateCommand(); command.Transaction = Transaction; - command.CommandText = testing ? - $"CREATE TEMPORARY TABLE IF NOT EXISTS {table} (GangId INT PRIMARY KEY, Name VARCHAR(255) NOT NULL)" : - $"CREATE TABLE IF NOT EXISTS {table} (GangId INT PRIMARY KEY, Name VARCHAR(255) NOT NULL)"; + command.CommandText = myTesting ? + $"CREATE TEMPORARY TABLE IF NOT EXISTS {myTable} (GangId INT PRIMARY KEY, Name VARCHAR(255) NOT NULL)" : + $"CREATE TABLE IF NOT EXISTS {myTable} (GangId INT PRIMARY KEY, Name VARCHAR(255) NOT NULL)"; command.ExecuteNonQuery(); } catch (Exception e) { @@ -36,7 +40,7 @@ public override void Start(BasePlugin? plugin, bool hotReload) { public override async Task CreateGang(string name, ulong owner) { if (CachedGangs.Any(g => g.Name == name)) return null; - var query = $"INSERT INTO {table} (Name) VALUES (@name)"; + var query = $"INSERT INTO {myTable} (Name) VALUES (@name)"; var result = await Connection.ExecuteAsync(query, new { name }, Transaction); if (result == 0) return null; @@ -50,10 +54,9 @@ await Connection.ExecuteScalarAsync("SELECT last_insert_rowid()", public override async Task UpdateGang(IGang gang) { var result = await base.UpdateGang(gang); - var query = - $"UPDATE {table} SET Name = @Name WHERE GangId = @GangId"; + var query = $"UPDATE {myTable} SET Name = @Name WHERE GangId = @GangId"; await Connection.ExecuteAsync(query, new { gang.Name, gang.GangId }, - transaction: Transaction); + Transaction); return result; } diff --git a/GangsImpl/Stats/GangBankStat.cs b/GangsImpl/Stats/GangBankStat.cs index 7094e83..94444f7 100644 --- a/GangsImpl/Stats/GangBankStat.cs +++ b/GangsImpl/Stats/GangBankStat.cs @@ -5,7 +5,7 @@ namespace Stats; public class GangBankStat : IStat { public string StatId => "gang_native_bank"; public string Name => "Gang Bank"; - public string? Description => "The amount of money in the gang's bank."; + public string Description => "The amount of money in the gang's bank."; public int Value { get; set; } public IStat Clone() { return new GangBankStat { Value = Value }; } diff --git a/GangsTest/Commands/CommandTestData.cs b/GangsTest/Commands/CommandTestData.cs index 21cb962..6efb633 100644 --- a/GangsTest/Commands/CommandTestData.cs +++ b/GangsTest/Commands/CommandTestData.cs @@ -12,8 +12,7 @@ public class CommandTestData : IEnumerable { private static readonly IGangManager manager = new MockGangManager(playerMgr); private readonly IBehavior[] behaviors = [ - new CreateCommand(manager), new HelpCommand(), - new GangCommand(manager, playerMgr) + new CreateCommand(manager), new HelpCommand(), new GangCommand(manager) ]; public CommandTestData() { diff --git a/GangsTest/Commands/CreateTests.cs b/GangsTest/Commands/CreateTests.cs index d135080..efca8c1 100644 --- a/GangsTest/Commands/CreateTests.cs +++ b/GangsTest/Commands/CreateTests.cs @@ -6,8 +6,7 @@ namespace GangsTest.Commands; -public class CreateTests(ICommandManager commands, IGangManager gangMgr, - IPlayerManager playerMgr) +public class CreateTests(ICommandManager commands, IGangManager gangMgr) : CommandTests(commands, new CreateCommand(gangMgr)) { private readonly PlayerWrapper player = new((ulong)new Random().NextInt64(), "Test Player"); diff --git a/GangsTest/Commands/GangCommandTests.cs b/GangsTest/Commands/GangCommandTests.cs index 2eacf9f..bcf09e6 100644 --- a/GangsTest/Commands/GangCommandTests.cs +++ b/GangsTest/Commands/GangCommandTests.cs @@ -5,9 +5,8 @@ namespace GangsTest.Commands; -public class GangCommandTests(ICommandManager commands, IGangManager gangMgr, - IPlayerManager playerMgr) - : CommandTests(commands, new GangCommand(gangMgr, playerMgr)) { +public class GangCommandTests(ICommandManager commands, IGangManager gangMgr) + : CommandTests(commands, new GangCommand(gangMgr)) { [Fact] public async Task Gang_TestBase() { Assert.Equal("css_gang", Command.Name); diff --git a/GangsTest/Commands/ManagerTests/CommandTestData.cs b/GangsTest/Commands/ManagerTests/CommandTestData.cs index b01486e..5a5f197 100644 --- a/GangsTest/Commands/ManagerTests/CommandTestData.cs +++ b/GangsTest/Commands/ManagerTests/CommandTestData.cs @@ -11,7 +11,7 @@ public class CommandTestData : IEnumerable { private readonly IBehavior[] behaviors = [ new MockCommandManager(), - new CommandManager(new MockGangManager(playerMgr), playerMgr) + new CommandManager(new MockGangManager(playerMgr)) ]; public CommandTestData() { diff --git a/GangsTest/Commands/ManagerTests/ManagerTests.cs b/GangsTest/Commands/ManagerTests/ManagerTests.cs index 00c30e4..a321952 100644 --- a/GangsTest/Commands/ManagerTests/ManagerTests.cs +++ b/GangsTest/Commands/ManagerTests/ManagerTests.cs @@ -12,7 +12,7 @@ public class ManagerTests { private class DummyCommand : ICommand { public string Name => "css_dummy"; - public string? Description => "Dummy command for testing"; + public string Description => "Dummy command for testing"; public string[] RequiredFlags { get; } = []; public string[] RequiredGroups { get; } = []; diff --git a/GangsTest/Commands/PermissionTests.cs b/GangsTest/Commands/PermissionTests.cs index 05f83a5..d12b9d5 100644 --- a/GangsTest/Commands/PermissionTests.cs +++ b/GangsTest/Commands/PermissionTests.cs @@ -91,7 +91,7 @@ public async Task Permission_Pass_Both(ICommandManager mgr) { private class ElevatedCommand(string[] flags, string[] groups) : ICommand { public string Name => "css_elevated"; - public string? Description => "Elevated command for testing"; + public string Description => "Elevated command for testing"; public string[] RequiredFlags { get; } = flags; public string[] RequiredGroups { get; } = groups; diff --git a/GangsTest/GangTests/GangFetchTests.cs b/GangsTest/GangTests/GangFetchTests.cs index 89dbf72..510358d 100644 --- a/GangsTest/GangTests/GangFetchTests.cs +++ b/GangsTest/GangTests/GangFetchTests.cs @@ -35,7 +35,9 @@ public async Task Gang_Clone(IGangManager mgr) { var dummy = await mgr.CreateGang("foobar", 0); Assert.NotNull(dummy); var clone = dummy.Clone() as IGang; - Assert.Single(await mgr.GetGangs()); + Assert.NotNull(clone); + Assert.NotSame(dummy, clone); + Assert.Equal(dummy, clone); } [Theory] diff --git a/GangsTest/GangTests/GangMutabilityTests.cs b/GangsTest/GangTests/GangMutabilityTests.cs index 5b12af0..4fb46a2 100644 --- a/GangsTest/GangTests/GangMutabilityTests.cs +++ b/GangsTest/GangTests/GangMutabilityTests.cs @@ -1,5 +1,4 @@ using GangsAPI.Services; -using Mock; namespace GangsTest.GangTests; diff --git a/GangsTest/Startup.cs b/GangsTest/Startup.cs index 86167b3..782009d 100644 --- a/GangsTest/Startup.cs +++ b/GangsTest/Startup.cs @@ -1,6 +1,5 @@ using GangsAPI.Services; using GangsAPI.Services.Commands; -using MartinCostello.Logging.XUnit; using Microsoft.Extensions.DependencyInjection; using Mock;