diff --git a/src/EvoSC.CLI/CliManager.cs b/src/EvoSC.CLI/CliManager.cs index dc9cc0e99..f2febb08e 100644 --- a/src/EvoSC.CLI/CliManager.cs +++ b/src/EvoSC.CLI/CliManager.cs @@ -94,6 +94,7 @@ private async Task ExecuteHandlerAsync(ICliCommandInfo command, InvocationContex var startupPipeline = new StartupPipeline(config); startupPipeline.ServiceContainer.ConfigureServiceContainerForEvoSc(); startupPipeline.SetupBasePipeline(config); + startupPipeline.Services("CliContext", s => s.RegisterInstance(new CliContext(context))); startupPipeline.Services("Application", s => s.RegisterInstance(this)); await startupPipeline.ExecuteAsync(command.RequiredFeatures diff --git a/src/EvoSC.CLI/CliStartup.cs b/src/EvoSC.CLI/CliStartup.cs index 04f710473..042b7673a 100644 --- a/src/EvoSC.CLI/CliStartup.cs +++ b/src/EvoSC.CLI/CliStartup.cs @@ -25,8 +25,10 @@ public static class CliStartup public static void SetupBasePipeline(this IStartupPipeline pipeline, IEvoScBaseConfig config) { pipeline - // Set up service container - .Services(AppFeature.Config, s => s.RegisterInstance(config)) + // Set up service container + .Services(AppFeature.Config, s => + s.RegisterInstance(config) + , "CliContext") .Services(AppFeature.Logging, s => s.AddEvoScLogging(config.Logging)) @@ -93,11 +95,12 @@ public static void SetupBasePipeline(this IStartupPipeline pipeline, IEvoScBaseC .Services(AppFeature.Manialinks, s => s .AddEvoScManialinks() - , "Logging", "Events", "PlayerManager", "ControllerManager", "ActionPipelines", "GbxRemoteClient", "ActionInitializeTemplates") + , "Logging", "Events", "PlayerManager", "ControllerManager", "ActionPipelines", "GbxRemoteClient", + "ActionInitializeTemplates") .Services(AppFeature.Themes, s => s.AddEvoScThemes()) - - // initialization of features + + // initialization of features .Action("ActionMigrateDatabase", MigrateDatabase) .Action("ActionInitializeEventManager", s => s @@ -113,7 +116,8 @@ public static void SetupBasePipeline(this IStartupPipeline pipeline, IEvoScBaseC , "ActionInitializeEventManager", "ActionInitializePlayerCache") .AsyncAction("InitializeGbxRemoteConnection", SetupGbxRemoteConnectionAsync - , "ActionInitializeEventManager", "ActionInitializePlayerCache", "ActionInitializeManialinkInteractionHandler") + , "ActionInitializeEventManager", "ActionInitializePlayerCache", + "ActionInitializeManialinkInteractionHandler") .AsyncAction("ActionInitializeTemplates", InitializeTemplatesAsync); } diff --git a/src/EvoSC.CLI/Interfaces/ICliContext.cs b/src/EvoSC.CLI/Interfaces/ICliContext.cs new file mode 100644 index 000000000..bc37ee0bd --- /dev/null +++ b/src/EvoSC.CLI/Interfaces/ICliContext.cs @@ -0,0 +1,8 @@ +using System.CommandLine.Invocation; + +namespace EvoSC.CLI.Interfaces; + +public interface ICliContext +{ + public InvocationContext Context { get; } +} diff --git a/src/EvoSC.CLI/Models/CliContext.cs b/src/EvoSC.CLI/Models/CliContext.cs new file mode 100644 index 000000000..69650f978 --- /dev/null +++ b/src/EvoSC.CLI/Models/CliContext.cs @@ -0,0 +1,9 @@ +using System.CommandLine.Invocation; +using EvoSC.CLI.Interfaces; + +namespace EvoSC.CLI.Models; + +public class CliContext(InvocationContext context) : ICliContext +{ + public InvocationContext Context { get; } = context; +} diff --git a/src/EvoSC.Common/Application/AppFeature.cs b/src/EvoSC.Common/Application/AppFeature.cs index 20e8a45fc..4677c6a25 100644 --- a/src/EvoSC.Common/Application/AppFeature.cs +++ b/src/EvoSC.Common/Application/AppFeature.cs @@ -121,5 +121,5 @@ public enum AppFeature /// Add, remove and manage themes using the theme manager. /// [Identifier(NoPrefix = true)] - Themes + Themes, } diff --git a/src/EvoSC.Common/Config/Configuration.cs b/src/EvoSC.Common/Config/Configuration.cs index dc834026c..a82ab4773 100644 --- a/src/EvoSC.Common/Config/Configuration.cs +++ b/src/EvoSC.Common/Config/Configuration.cs @@ -20,7 +20,7 @@ public static IEvoScBaseConfig GetBaseConfig(string configFile, Dictionary() - .UseEvoScConfig(MainConfigFile, cliOptions) + .UseEvoScConfig(configFile, cliOptions) .UseTypeParser(new TextColorTypeParser()) .UseTypeParser(new VersionParser()) .UseTypeParser(new ThemeOptionsParser()) diff --git a/src/EvoSC.Common/Database/Models/Player/DbPlayer.cs b/src/EvoSC.Common/Database/Models/Player/DbPlayer.cs index 69213ae11..04bbdd65e 100644 --- a/src/EvoSC.Common/Database/Models/Player/DbPlayer.cs +++ b/src/EvoSC.Common/Database/Models/Player/DbPlayer.cs @@ -43,6 +43,8 @@ public class DbPlayer : IPlayer public string? Zone { get; set; } public IPlayerSettings Settings => DbSettings; + public IEnumerable Groups { get; set; } + public IGroup? DisplayGroup { get; set; } [Association(ThisKey = nameof(Id), OtherKey = nameof(DbPlayerSettings.PlayerId))] public DbPlayerSettings DbSettings { get; set; } @@ -64,6 +66,8 @@ public DbPlayer(IPlayer? player) NickName = player.NickName; UbisoftName = player.UbisoftName; Zone = player.Zone; + Groups = player.Groups; + DisplayGroup = player.DisplayGroup; } public bool Equals(IPlayer? other) => other != null && AccountId.Equals(other.AccountId, StringComparison.Ordinal); diff --git a/src/EvoSC.Common/Database/Repository/Players/PlayerRepository.cs b/src/EvoSC.Common/Database/Repository/Players/PlayerRepository.cs index e3d974f91..be55951bf 100644 --- a/src/EvoSC.Common/Database/Repository/Players/PlayerRepository.cs +++ b/src/EvoSC.Common/Database/Repository/Players/PlayerRepository.cs @@ -1,4 +1,5 @@ using System.Globalization; +using EvoSC.Common.Database.Models.Permissions; using EvoSC.Common.Database.Models.Player; using EvoSC.Common.Interfaces.Database; using EvoSC.Common.Interfaces.Database.Repository; @@ -8,11 +9,33 @@ namespace EvoSC.Common.Database.Repository.Players; -public class PlayerRepository(IDbConnectionFactory dbConnFactory) : DbRepository(dbConnFactory), IPlayerRepository +public class PlayerRepository(IDbConnectionFactory dbConnFactory, IPermissionRepository permissionRepository) : DbRepository(dbConnFactory), IPlayerRepository { - public async Task GetPlayerByAccountIdAsync(string accountId) => await Table() - .LoadWith(p => p.DbSettings) - .SingleOrDefaultAsync(t => t.AccountId == accountId); + public async Task GetPlayerByAccountIdAsync(string accountId) + { + var player = await Table() + .LoadWith(p => p.DbSettings) + .SingleOrDefaultAsync(t => t.AccountId == accountId); + + if (player == null) + { + return null; + } + + var groups = await permissionRepository.GetGroupsAsync(player.Id); + player.Groups = groups; + + var displayGroup = await ( + from g in Table() + join ug in Table() on g.Id equals ug.GroupId + where ug.UserId == player.Id && ug.Display + select g + ).FirstOrDefaultAsync(); + + player.DisplayGroup = displayGroup; + + return player; + } public async Task AddPlayerAsync(string accountId, TmPlayerDetailedInfo playerInfo) { @@ -23,7 +46,8 @@ public async Task AddPlayerAsync(string accountId, TmPlayerDetailedInfo AccountId = accountId.ToLower(CultureInfo.InvariantCulture), NickName = playerInfo.NickName ?? accountId, UbisoftName = playerInfo.NickName ?? accountId, - Zone = playerInfo.Path ?? "World" + Zone = playerInfo.Path ?? "World", + Groups = Array.Empty() }; var id = await Database.InsertWithIdentityAsync(player); @@ -33,7 +57,6 @@ public async Task AddPlayerAsync(string accountId, TmPlayerDetailedInfo { PlayerId = player.Id, DisplayLanguage = "en" - }; await Database.InsertAsync(playerSettings); diff --git a/src/EvoSC.Common/Interfaces/Database/Repository/IPlayerRepository.cs b/src/EvoSC.Common/Interfaces/Database/Repository/IPlayerRepository.cs index 24a619071..5dd5cd510 100644 --- a/src/EvoSC.Common/Interfaces/Database/Repository/IPlayerRepository.cs +++ b/src/EvoSC.Common/Interfaces/Database/Repository/IPlayerRepository.cs @@ -1,4 +1,5 @@ -using EvoSC.Common.Interfaces.Models; +using EvoSC.Common.Database.Models.Player; +using EvoSC.Common.Interfaces.Models; using GbxRemoteNet.Structs; namespace EvoSC.Common.Interfaces.Database.Repository; @@ -10,7 +11,7 @@ public interface IPlayerRepository /// /// The account ID of the player. /// - public Task GetPlayerByAccountIdAsync(string accountId); + public Task GetPlayerByAccountIdAsync(string accountId); /// /// Add a new player to the database. diff --git a/src/EvoSC.Common/Interfaces/Models/IPlayer.cs b/src/EvoSC.Common/Interfaces/Models/IPlayer.cs index 99ac22e63..293b90544 100644 --- a/src/EvoSC.Common/Interfaces/Models/IPlayer.cs +++ b/src/EvoSC.Common/Interfaces/Models/IPlayer.cs @@ -38,4 +38,7 @@ public interface IPlayer : IEquatable public string? Zone { get; } public IPlayerSettings Settings { get; } + + public IEnumerable Groups { get; } + public IGroup? DisplayGroup { get; } } diff --git a/src/EvoSC.Common/Interfaces/Services/IPlayerCacheService.cs b/src/EvoSC.Common/Interfaces/Services/IPlayerCacheService.cs index 5a886ba66..cecee370d 100644 --- a/src/EvoSC.Common/Interfaces/Services/IPlayerCacheService.cs +++ b/src/EvoSC.Common/Interfaces/Services/IPlayerCacheService.cs @@ -31,4 +31,5 @@ public interface IPlayerCacheService public Task UpdatePlayerListAsync(); public Task UpdatePlayerAsync(IPlayer player); + public Task InvalidatePlayerStateAsync(IPlayer player); } diff --git a/src/EvoSC.Common/Models/Players/OnlinePlayer.cs b/src/EvoSC.Common/Models/Players/OnlinePlayer.cs index 5ddb33748..210f47c7c 100644 --- a/src/EvoSC.Common/Models/Players/OnlinePlayer.cs +++ b/src/EvoSC.Common/Models/Players/OnlinePlayer.cs @@ -11,6 +11,8 @@ public class OnlinePlayer : IOnlinePlayer public string UbisoftName { get; set; } public string Zone { get; set; } public IPlayerSettings Settings { get; set; } + public IEnumerable Groups { get; set; } + public IGroup? DisplayGroup { get; set; } public required PlayerState State { get; set; } public IPlayerFlags Flags { get; set; } public PlayerTeam Team { get; set; } @@ -25,6 +27,8 @@ public OnlinePlayer(IPlayer player) UbisoftName = player.UbisoftName; Zone = player.Zone; Settings = player.Settings; + Groups = player.Groups; + DisplayGroup = player.DisplayGroup; } public bool Equals(IPlayer? other) => other != null && AccountId.Equals(other.AccountId, StringComparison.Ordinal); diff --git a/src/EvoSC.Common/Models/Players/Player.cs b/src/EvoSC.Common/Models/Players/Player.cs index 01f25a58a..cb912f818 100644 --- a/src/EvoSC.Common/Models/Players/Player.cs +++ b/src/EvoSC.Common/Models/Players/Player.cs @@ -11,6 +11,8 @@ public class Player : IPlayer public string UbisoftName { get; init; } public string? Zone { get; init; } public IPlayerSettings Settings { get; set; } + public IEnumerable Groups { get; set; } + public IGroup? DisplayGroup { get; set; } public Player() { @@ -24,6 +26,8 @@ public Player(DbPlayer dbPlayer) : this() UbisoftName = dbPlayer.UbisoftName; Zone = dbPlayer.Zone; Settings = dbPlayer.Settings; + Groups = dbPlayer.Groups; + DisplayGroup = dbPlayer.DisplayGroup; } public bool Equals(IPlayer? other) => other != null && AccountId.Equals(other.AccountId, StringComparison.Ordinal); diff --git a/src/EvoSC.Common/Permissions/PermissionManager.cs b/src/EvoSC.Common/Permissions/PermissionManager.cs index 42fa00f2b..16327c947 100644 --- a/src/EvoSC.Common/Permissions/PermissionManager.cs +++ b/src/EvoSC.Common/Permissions/PermissionManager.cs @@ -4,7 +4,7 @@ namespace EvoSC.Common.Permissions; -public class PermissionManager(IPermissionRepository permissionRepository) : IPermissionManager +public class PermissionManager(IPermissionRepository permissionRepository, IPlayerCacheService playerCache) : IPermissionManager { public async Task HasPermissionAsync(IPlayer player, string permission) { @@ -73,11 +73,17 @@ public async Task RemoveGroupAsync(int id) public async Task GetGroupAsync(int id) => await permissionRepository.GetGroupAsync(id); - public async Task AddPlayerToGroupAsync(IPlayer player, IGroup group) => + public async Task AddPlayerToGroupAsync(IPlayer player, IGroup group) + { await permissionRepository.AddPlayerToGroupAsync(player.Id, group.Id); + await playerCache.InvalidatePlayerStateAsync(player); + } - public async Task RemovePlayerFromGroupAsync(IPlayer player, IGroup group) => + public async Task RemovePlayerFromGroupAsync(IPlayer player, IGroup group) + { await permissionRepository.RemovePlayerFromGroupAsync(player.Id, group.Id); + await playerCache.InvalidatePlayerStateAsync(player); + } public async Task AddPermissionToGroupAsync(IGroup group, IPermission permission) => await permissionRepository.AddPermissionToGroupAsync(group.Id, permission.Id); diff --git a/src/EvoSC.Common/Remote/ChatRouter/RemoteChatRouter.cs b/src/EvoSC.Common/Remote/ChatRouter/RemoteChatRouter.cs index 46e6b3904..d7850995e 100644 --- a/src/EvoSC.Common/Remote/ChatRouter/RemoteChatRouter.cs +++ b/src/EvoSC.Common/Remote/ChatRouter/RemoteChatRouter.cs @@ -53,7 +53,7 @@ private async Task HandlePlayerChatRoutingAsync(object sender, PlayerChatGbxEven { Task.Run(async () => { - var formatted = FormattingUtils.FormatPlayerChatMessage(chatContext.Player.NickName, + var formatted = FormattingUtils.FormatPlayerChatMessage(chatContext.Player, chatContext.MessageText); await _server.SendChatMessageAsync(formatted); }); diff --git a/src/EvoSC.Common/Services/PlayerCacheService.cs b/src/EvoSC.Common/Services/PlayerCacheService.cs index 9035e6d06..53f8cdf58 100644 --- a/src/EvoSC.Common/Services/PlayerCacheService.cs +++ b/src/EvoSC.Common/Services/PlayerCacheService.cs @@ -20,7 +20,6 @@ public class PlayerCacheService : IPlayerCacheService private readonly ILogger _logger; private readonly IPlayerRepository _playerRepository; - private readonly Dictionary _onlinePlayers = new(); private readonly object _onlinePlayersMutex = new(); @@ -259,4 +258,17 @@ public async Task UpdatePlayerListAsync() } public Task UpdatePlayerAsync(IPlayer player) => ForceUpdatePlayerInternalAsync(player.AccountId); + + public Task InvalidatePlayerStateAsync(IPlayer player) + { + lock (_onlinePlayersMutex) + { + if (_onlinePlayers.ContainsKey(player.AccountId)) + { + _onlinePlayers.Remove(player.AccountId); + } + } + + return Task.CompletedTask; + } } diff --git a/src/EvoSC.Common/Themes/ThemeManager.cs b/src/EvoSC.Common/Themes/ThemeManager.cs index 8e4699573..bc69ac428 100644 --- a/src/EvoSC.Common/Themes/ThemeManager.cs +++ b/src/EvoSC.Common/Themes/ThemeManager.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Reflection; using EvoSC.Common.Config.Models; using EvoSC.Common.Interfaces; @@ -137,6 +138,26 @@ private dynamic GetCurrentThemeOptions() themeOptions[option.Key] = option.Value; } + // override any options set as an envi + foreach (DictionaryEntry enviObject in Environment.GetEnvironmentVariables()) + { + var key = enviObject.Key as string; + if (key == null || enviObject.Value == null || !key.StartsWith("EVOSC_THEME_", StringComparison.Ordinal)) + { + continue; + } + + foreach (var option in themeOptions) + { + var enviKey = $"EVOSC_THEME_{option.Key.Replace('.', '_').ToUpper()}"; + + if (enviKey == key) + { + themeOptions[option.Key] = enviObject.Value; + } + } + } + _themeOptionsCache = themeOptions; return themeOptions; } @@ -158,7 +179,7 @@ private Dictionary GetConfigOverrideOptions() var key = defaultOption.Key.StartsWith("Theme.", StringComparison.Ordinal) ? defaultOption.Key[6..] : defaultOption.Key; - + themeOptions[key] = defaultOption.Value; } diff --git a/src/EvoSC.Common/Util/FormattingUtils.cs b/src/EvoSC.Common/Util/FormattingUtils.cs index 475c4113f..46c5ce607 100644 --- a/src/EvoSC.Common/Util/FormattingUtils.cs +++ b/src/EvoSC.Common/Util/FormattingUtils.cs @@ -1,4 +1,5 @@ using System.Text.RegularExpressions; +using EvoSC.Common.Interfaces.Models; using EvoSC.Common.Util.TextFormatting; namespace EvoSC.Common.Util; @@ -45,11 +46,17 @@ public static string FormatTimeAsDelta(int milliseconds) return $"+ {s:0}.{ms:000}"; } - public static TextFormatter FormatPlayerChatMessage(string nickname, string message) + public static TextFormatter FormatPlayerChatMessage(IPlayer player, string message) { - var formattedMessage = new TextFormatter() - .AddText("[") - .AddText(text => text.AddText(nickname)) + var formattedMessage = new TextFormatter(); + + if (player.DisplayGroup?.Icon != null) + { + formattedMessage.AddText(player.DisplayGroup.Icon, s => s.WithColor(player.DisplayGroup.Color ?? "FFF")); + } + + formattedMessage.AddText("[") + .AddText(text => text.AddText(player.NickName)) .AddText("] ") .AddText(text => text.AddText(message)); diff --git a/src/EvoSC.Testing/Database/DbTestHelper.cs b/src/EvoSC.Testing/Database/DbTestHelper.cs index 27ac9a081..1f3d86bc7 100644 --- a/src/EvoSC.Testing/Database/DbTestHelper.cs +++ b/src/EvoSC.Testing/Database/DbTestHelper.cs @@ -1,4 +1,5 @@ -using EvoSC.Common.Database.Repository.Players; +using EvoSC.Common.Database.Repository.Permissions; +using EvoSC.Common.Database.Repository.Players; using EvoSC.Common.Interfaces.Database; using EvoSC.Common.Interfaces.Models; using GbxRemoteNet.Structs; @@ -9,7 +10,9 @@ public static class DbTestHelper { public static async Task AddTestPlayer(IDbConnectionFactory factory, string accountId) { - var playerRepo = new PlayerRepository(factory); + var logger = TestLoggerSetup.CreateLogger(); + var permissionRepo = new PermissionRepository(factory, logger); + var playerRepo = new PlayerRepository(factory, permissionRepo); return await playerRepo.AddPlayerAsync(accountId, new TmPlayerDetailedInfo { diff --git a/tests/EvoSC.Common.Tests/LoggerSetup.cs b/src/EvoSC.Testing/TestLoggerSetup.cs similarity index 83% rename from tests/EvoSC.Common.Tests/LoggerSetup.cs rename to src/EvoSC.Testing/TestLoggerSetup.cs index 213853456..cd14d2660 100644 --- a/tests/EvoSC.Common.Tests/LoggerSetup.cs +++ b/src/EvoSC.Testing/TestLoggerSetup.cs @@ -1,8 +1,8 @@ using Microsoft.Extensions.Logging; -namespace EvoSC.Common.Tests; +namespace EvoSC.Testing; -public static class LoggerSetup +public static class TestLoggerSetup { /// /// Create a new logger. diff --git a/src/EvoSC/Application.cs b/src/EvoSC/Application.cs index 29e5bd659..4c515afcd 100644 --- a/src/EvoSC/Application.cs +++ b/src/EvoSC/Application.cs @@ -1,4 +1,5 @@ -using EvoSC.Common.Application; +using EvoSC.CLI.Interfaces; +using EvoSC.Common.Application; using EvoSC.Common.Config.Models; using EvoSC.Common.Interfaces; using EvoSC.Common.Services; @@ -20,13 +21,14 @@ public sealed class Application : IEvoSCApplication, IDisposable public CancellationToken MainCancellationToken => _runningToken.Token; public Container Services => StartupPipeline.ServiceContainer; - public Application(IEvoScBaseConfig config) + public Application(IEvoScBaseConfig config, ICliContext cliContext) { _config = config; _isDebug = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") == "Development"; StartupPipeline = new StartupPipeline(_config); StartupPipeline.ServiceContainer.ConfigureServiceContainerForEvoSc(); + StartupPipeline.Services("CliContext", s => s.RegisterInstance(cliContext)); StartupPipeline.Services("Application", s => s.RegisterInstance(this)); } diff --git a/src/EvoSC/CliCommands/RunCommand.cs b/src/EvoSC/CliCommands/RunCommand.cs index 9395ae3f6..335b4ac57 100644 --- a/src/EvoSC/CliCommands/RunCommand.cs +++ b/src/EvoSC/CliCommands/RunCommand.cs @@ -1,17 +1,17 @@ using EvoSC.CLI.Attributes; +using EvoSC.CLI.Interfaces; using EvoSC.Common.Application; using EvoSC.Common.Config.Models; -using EvoSC.Common.Util.EnumIdentifier; namespace EvoSC.CliCommands; [CliCommand(Name = "run", Description = "Start the server controller.")] [RequiredFeatures(AppFeature.Config)] -public class RunCommand(IEvoScBaseConfig config) +public class RunCommand(IEvoScBaseConfig config, ICliContext cliContext) { - public async Task ExecuteAsync([Alias(Name = "-s")]int something) + public async Task ExecuteAsync() { - var app = new Application(config); + var app = new Application(config, cliContext); await app.RunAsync(); app.Dispose(); } diff --git a/tests/EvoSC.Common.Tests/Database/MapRepositoryTests.cs b/tests/EvoSC.Common.Tests/Database/MapRepositoryTests.cs index 809458cdf..eb1d5349b 100644 --- a/tests/EvoSC.Common.Tests/Database/MapRepositoryTests.cs +++ b/tests/EvoSC.Common.Tests/Database/MapRepositoryTests.cs @@ -6,6 +6,7 @@ using EvoSC.Common.Interfaces.Database; using EvoSC.Common.Interfaces.Models; using EvoSC.Common.Models.Maps; +using EvoSC.Testing; using EvoSC.Testing.Database; using LinqToDB; using Xunit; @@ -17,13 +18,13 @@ public class MapRepositoryTests private static (MapRepository, IDbConnectionFactory) CreateNewRepository() { var factory = TestDbSetup.CreateDb(typeof(AddPlayersTable).Assembly); - return (new MapRepository(factory, LoggerSetup.CreateLogger()), factory); + return (new MapRepository(factory, TestLoggerSetup.CreateLogger()), factory); } private static async Task AddTestMap(IDbConnectionFactory dbFactory) { var player = await DbTestHelper.AddTestPlayer(dbFactory); - var mapRepo = new MapRepository(dbFactory, LoggerSetup.CreateLogger()); + var mapRepo = new MapRepository(dbFactory, TestLoggerSetup.CreateLogger()); return await mapRepo.AddMapAsync( new MapMetadata { diff --git a/tests/EvoSC.Common.Tests/Database/PermissionRepositoryTests.cs b/tests/EvoSC.Common.Tests/Database/PermissionRepositoryTests.cs index 2842928b8..a887c5d73 100644 --- a/tests/EvoSC.Common.Tests/Database/PermissionRepositoryTests.cs +++ b/tests/EvoSC.Common.Tests/Database/PermissionRepositoryTests.cs @@ -6,6 +6,7 @@ using EvoSC.Common.Interfaces.Database; using EvoSC.Common.Interfaces.Models; using EvoSC.Common.Permissions.Models; +using EvoSC.Testing; using EvoSC.Testing.Database; using LinqToDB; using Xunit; @@ -17,7 +18,7 @@ public class PermissionRepositoryTests private static (PermissionRepository, IDbConnectionFactory) CreateNewRepository() { var factory = TestDbSetup.CreateDb(typeof(AddPlayersTable).Assembly); - return (new PermissionRepository(factory, LoggerSetup.CreateLogger()), factory); + return (new PermissionRepository(factory, TestLoggerSetup.CreateLogger()), factory); } [Fact] diff --git a/tests/EvoSC.Common.Tests/Database/PlayerRepositoryTests.cs b/tests/EvoSC.Common.Tests/Database/PlayerRepositoryTests.cs index f9fbb6a51..94690f6ed 100644 --- a/tests/EvoSC.Common.Tests/Database/PlayerRepositoryTests.cs +++ b/tests/EvoSC.Common.Tests/Database/PlayerRepositoryTests.cs @@ -1,7 +1,9 @@ using System.Threading.Tasks; using EvoSC.Common.Database.Migrations; using EvoSC.Common.Database.Models.Player; +using EvoSC.Common.Database.Repository.Permissions; using EvoSC.Common.Database.Repository.Players; +using EvoSC.Testing; using EvoSC.Testing.Database; using GbxRemoteNet.Structs; using LinqToDB; @@ -16,7 +18,9 @@ public async Task Player_Added_To_Database() { var factory = TestDbSetup.CreateDb(typeof(AddPlayersTable).Assembly); var db = factory.GetConnection(); - var playerRepo = new PlayerRepository(factory); + var logger = TestLoggerSetup.CreateLogger(); + var permissionRepo = new PermissionRepository(factory, logger); + var playerRepo = new PlayerRepository(factory, permissionRepo); await playerRepo.AddPlayerAsync("TestAccountId", new TmPlayerDetailedInfo { @@ -36,7 +40,9 @@ public async Task Player_Added_To_Database() public void Player_With_Same_Account_ID_Fails() { var factory = TestDbSetup.CreateDb(typeof(AddPlayersTable).Assembly); - var playerRepo = new PlayerRepository(factory); + var logger = TestLoggerSetup.CreateLogger(); + var permissionRepo = new PermissionRepository(factory, logger); + var playerRepo = new PlayerRepository(factory, permissionRepo); Assert.Throws(() => { @@ -58,7 +64,9 @@ public void Player_With_Same_Account_ID_Fails() public async Task Get_Player_By_Account_ID_Returns_Correct() { var factory = TestDbSetup.CreateDb(typeof(AddPlayersTable).Assembly); - var playerRepo = new PlayerRepository(factory); + var logger = TestLoggerSetup.CreateLogger(); + var permissionRepo = new PermissionRepository(factory, logger); + var playerRepo = new PlayerRepository(factory, permissionRepo); await playerRepo.AddPlayerAsync("TestAccountId", new TmPlayerDetailedInfo { @@ -76,7 +84,9 @@ public async Task Player_Last_Visit_Updated() { var factory = TestDbSetup.CreateDb(typeof(AddPlayersTable).Assembly); var db = factory.GetConnection(); - var playerRepo = new PlayerRepository(factory); + var logger = TestLoggerSetup.CreateLogger(); + var permissionRepo = new PermissionRepository(factory, logger); + var playerRepo = new PlayerRepository(factory, permissionRepo); var player = await playerRepo.AddPlayerAsync("TestAccountId", new TmPlayerDetailedInfo { diff --git a/tests/Modules/LocalRecordsModule.Tests/Services/LocalRecordsServiceTests.cs b/tests/Modules/LocalRecordsModule.Tests/Services/LocalRecordsServiceTests.cs index 36085949f..e96008945 100644 --- a/tests/Modules/LocalRecordsModule.Tests/Services/LocalRecordsServiceTests.cs +++ b/tests/Modules/LocalRecordsModule.Tests/Services/LocalRecordsServiceTests.cs @@ -48,7 +48,7 @@ private MockData NewLocalRecordsServiceMock() var localRecordRepository = new Mock(); var playerManager = new Mock(); var manialinkManager = new Mock(); - var logger = LoggerSetup.CreateLogger(); + var logger = TestLoggerSetup.CreateLogger(); var settings = new Mock(); var server = Mocking.NewServerClientMock(); var themeManager = new Mock(); diff --git a/tests/Modules/MapListModule.Tests/Services/MapListServiceTests.cs b/tests/Modules/MapListModule.Tests/Services/MapListServiceTests.cs index 7b3e78c8b..85124b8dc 100644 --- a/tests/Modules/MapListModule.Tests/Services/MapListServiceTests.cs +++ b/tests/Modules/MapListModule.Tests/Services/MapListServiceTests.cs @@ -40,7 +40,7 @@ Mock PermissionManager var playerRecordsService = new Mock(); var context = Mocking.NewGenericServiceMock(); var mapService = new Mock(); - var logger = LoggerSetup.CreateLogger(); + var logger = TestLoggerSetup.CreateLogger(); var server = Mocking.NewServerClientMock(); var manialinkManagerService = new Mock(); var permissionManagerService = new Mock(); diff --git a/tests/Modules/MapQueueModuleTests/Controllers/QueueControllerTests.cs b/tests/Modules/MapQueueModuleTests/Controllers/QueueControllerTests.cs index 47b5b961b..2932a3669 100644 --- a/tests/Modules/MapQueueModuleTests/Controllers/QueueControllerTests.cs +++ b/tests/Modules/MapQueueModuleTests/Controllers/QueueControllerTests.cs @@ -23,7 +23,7 @@ public class QueueControllerTests : EventControllerTestBase public QueueControllerTests() { - InitMock(_mapQueueServiceMock, _server.Client, _mapServiceMock, LoggerSetup.CreateLogger()); + InitMock(_mapQueueServiceMock, _server.Client, _mapServiceMock, TestLoggerSetup.CreateLogger()); } [Fact]