From 9425801bafecd7f8e426141f342d09838f4afd39 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 08:19:23 +0000 Subject: [PATCH 01/71] Bump the actions-deps group with 2 updates Bumps the actions-deps group with 2 updates: [actions/upload-artifact](https://github.com/actions/upload-artifact) and [actions/download-artifact](https://github.com/actions/download-artifact). Updates `actions/upload-artifact` from 5 to 6 - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v5...v6) Updates `actions/download-artifact` from 6 to 7 - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v6...v7) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions-deps - dependency-name: actions/download-artifact dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions-deps ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d075d55..11ac349f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: - name: Create packages run: dotnet pack --configuration Release --output ./packages - name: Upload a Build Artifact - uses: actions/upload-artifact@v5 + uses: actions/upload-artifact@v6 with: name: NuGet packages path: packages/*.* @@ -45,7 +45,7 @@ jobs: fetch-depth: 0 - name: Setup .NET uses: actions/setup-dotnet@v5 - - uses: actions/download-artifact@v6 + - uses: actions/download-artifact@v7 with: name: NuGet packages path: packages From 65faceabc9cd2595a9f660167b6bd9ec4a5e902c Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 16:54:40 +0100 Subject: [PATCH 02/71] start creating a public testing framework --- .../AET.SteamAbstraction.csproj | 4 +- .../Library/SteamLibrary.cs | 12 +-- .../Linux/LinuxSteamRegistry.cs | 5 + .../Registry/ISteamRegistry.cs | 9 +- .../Windows/WindowsSteamRegistry.cs | 12 +-- .../AET.SteamAbstraction.Test.csproj | 7 +- .../SteamAppManifestTest.cs | 25 +++-- .../SteamLibraryFinderTest.cs | 61 +++++------ .../SteamLibraryTest.cs | 28 +++-- .../SteamVdfReaderTest.cs | 45 +++++--- .../SteamWrapperTestBase.cs | 79 +++++++------- .../AET.SteamAbstraction.Testing.csproj | 21 ++-- .../AssemblyInfo.cs | 2 +- .../ISteamFakeProcess.cs | 6 ++ .../ITestingSteamInstallation.cs | 28 +++++ .../ITestingSteamLibrary.cs | 25 +++++ .../ITestingSteamRegistry.cs | 28 +++++ .../Installation/SteamInstallation.Game.cs | 101 ------------------ .../SteamInstallation.Registry.Linux.cs | 16 --- .../SteamInstallation.Registry.Windows.cs | 32 ------ .../SteamInstallation.Registry.cs | 31 ------ .../Installation/SteamInstallation.cs | 92 ---------------- .../SteamFakeProcessImpl.cs | 20 ++++ .../SteamInstallationExtensions.cs | 23 ++++ .../TestProcessHelper.cs | 27 ++--- .../TestingSteamConstants.cs | 8 ++ ...> TestingSteamInstallationImpl.Library.cs} | 50 ++++----- .../TestingSteamInstallationImpl.User.cs | 74 +++++++++++++ .../TestingSteamInstallationImpl.cs | 39 +++++++ .../TestingSteamLibrary.cs | 99 +++++++++++++++++ .../TestingSteamRegistryImpl.cs | 83 ++++++++++++++ .../TestingSteamUserLoginMetadata.cs | 19 ++++ .../IGameClientFactoryTest.cs | 5 +- .../SteamPetroglyphStarWarsGameClientTest.cs | 38 +++---- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 15 ++- .../Arguments/ArgumentCollectionTest.cs | 4 + .../Arguments/GameArgumentsBuilderTest.cs | 2 +- .../Clients/GameClientFactoryTest.cs | 2 +- .../PetroglyphStarWarsGameClientTest.cs | 22 ++-- .../Processes/GameProcessLauncherTest.cs | 2 +- .../Clients/Processes/GameProcessTest.cs | 2 +- .../GameExecutableFileUtilitiesTest.cs | 8 +- .../GameLocalizationUtilitiesTest.cs | 2 +- .../Detection/CompositeDetectorTest.cs | 25 +++-- .../Detection/DirectoryGameDetectorTest.cs | 8 +- .../Detection/GameDetectionResultTest.cs | 2 +- .../Detection/RegistryGameDetectorTest.cs | 2 +- .../EnglishGameNameResolverTest.cs | 2 +- .../GameServices/GameFactoryTest.cs | 10 +- .../GameServices/SteamGameHelpersTest.cs | 2 +- .../ModBaseTest.cs | 2 +- .../ModEqualityComparerTest.cs | 2 +- .../ModDependencyGraphBuilderTest.cs | 2 +- .../Dependencies/ModDependencyResolverTest.cs | 2 +- .../ModDependencyTraverserTest.cs | 2 +- .../DirectoryModNameResolverTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 18 ++-- .../ModServices/ModFinderTest.cs | 30 +++--- .../ModGameTypeResolverTestBase.cs | 2 +- ...oglyphGameInfrastructureIntegrationTest.cs | 20 ++-- .../PetroglyphStarWarsGameTest.cs | 2 +- .../PlayableObjectTest.cs | 7 +- .../Services/IconFinderTest.cs | 2 +- .../Services/LanguageFinderTestBase.cs | 2 +- .../GITestUtilities.cs | 38 ++++++- .../Registry/GameRegistryTestExtensions.cs | 11 +- .../TestBases/GameDetectorTestBase.cs | 2 +- .../TestBases/GameDetectorTestBase_Tests.cs | 20 ++-- ...tBase.cs => GameInfrastructureTestBase.cs} | 36 +------ ...meInfrastructureTestBaseWithRandomGame.cs} | 4 +- 70 files changed, 845 insertions(+), 625 deletions(-) create mode 100644 test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs create mode 100644 test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs create mode 100644 test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs create mode 100644 test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs delete mode 100644 test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Game.cs delete mode 100644 test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Linux.cs delete mode 100644 test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Windows.cs delete mode 100644 test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.cs delete mode 100644 test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.cs create mode 100644 test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs create mode 100644 test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs create mode 100644 test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs rename test/AET.SteamAbstraction.Testing/{Installation/SteamInstallation.Library.cs => TestingSteamInstallationImpl.Library.cs} (57%) create mode 100644 test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs create mode 100644 test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs create mode 100644 test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs create mode 100644 test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs create mode 100644 test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs rename test/PG.StarWarsGame.Infrastructure.Testing/TestBases/{CommonTestBase.cs => GameInfrastructureTestBase.cs} (63%) rename test/PG.StarWarsGame.Infrastructure.Testing/TestBases/{CommonTestBaseWithRandomGame.cs => GameInfrastructureTestBaseWithRandomGame.cs} (84%) diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj index 35deee25..b7cae14e 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj @@ -1,6 +1,6 @@ - netstandard2.0 + netstandard2.0;netstandard2.1 AET.SteamAbstraction @@ -27,7 +27,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/AET.SteamAbstraction/Library/SteamLibrary.cs b/src/AET.SteamAbstraction/Library/SteamLibrary.cs index 8be9d434..dbcbdfa8 100644 --- a/src/AET.SteamAbstraction/Library/SteamLibrary.cs +++ b/src/AET.SteamAbstraction/Library/SteamLibrary.cs @@ -19,9 +19,12 @@ internal class SteamLibrary : ISteamLibrary TrailingDirectorySeparatorBehavior = TrailingDirectorySeparatorBehavior.Trim }; + private readonly string _normalizedLocation; private readonly ILogger? _logger; private readonly ConcurrentDictionary _locations = new(); + private protected readonly IFileSystem FileSystem; + private readonly Dictionary _locationsNames = new() { { KnownLibraryLocations.SteamApps, ["steamapps"] }, @@ -29,9 +32,6 @@ internal class SteamLibrary : ISteamLibrary { KnownLibraryLocations.Workshops, ["steamapps", "workshop"] } }; - private readonly string _normalizedLocation; - private readonly IFileSystem _fileSystem; - public IDirectoryInfo LibraryLocation { get; } public IDirectoryInfo SteamAppsLocation => GetKnownLibraryLocation(KnownLibraryLocations.SteamApps); @@ -46,9 +46,9 @@ public SteamLibrary(IDirectoryInfo libraryLocation, IServiceProvider serviceProv throw new ArgumentNullException(nameof(libraryLocation)); if (serviceProvider == null) throw new ArgumentNullException(nameof(serviceProvider)); - _fileSystem = serviceProvider.GetRequiredService(); + FileSystem = serviceProvider.GetRequiredService(); _logger = serviceProvider.GetService()?.CreateLogger(GetType()); - _normalizedLocation = PathNormalizer.Normalize(_fileSystem.Path.GetFullPath(libraryLocation.FullName), SteamLibraryPathNormalizeOptions); + _normalizedLocation = PathNormalizer.Normalize(FileSystem.Path.GetFullPath(libraryLocation.FullName), SteamLibraryPathNormalizeOptions); LibraryLocation = libraryLocation; } @@ -91,7 +91,7 @@ public bool Equals(ISteamLibrary? other) if (ReferenceEquals(this, other)) return true; - var normalizedOtherPath = PathNormalizer.Normalize(_fileSystem.Path.GetFullPath(other.LibraryLocation.FullName), SteamLibraryPathNormalizeOptions); + var normalizedOtherPath = PathNormalizer.Normalize(FileSystem.Path.GetFullPath(other.LibraryLocation.FullName), SteamLibraryPathNormalizeOptions); return _normalizedLocation.Equals(normalizedOtherPath); } diff --git a/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs b/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs index 2cf0585d..e8c040ad 100644 --- a/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs +++ b/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using AET.SteamAbstraction.Registry; using AnakinRaW.CommonUtilities; +using AnakinRaW.CommonUtilities.Registry; namespace AET.SteamAbstraction; @@ -16,4 +17,8 @@ internal class LinuxSteamRegistry(IServiceProvider serviceProvider) : Disposable public IDirectoryInfo? InstallationDirectory { get; } public int? ProcessId { get; } + public IRegistryKey? OpenSteamRegistryKey() + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/Registry/ISteamRegistry.cs b/src/AET.SteamAbstraction/Registry/ISteamRegistry.cs index b640d4ca..d03dba69 100644 --- a/src/AET.SteamAbstraction/Registry/ISteamRegistry.cs +++ b/src/AET.SteamAbstraction/Registry/ISteamRegistry.cs @@ -1,4 +1,5 @@ -using System; +using AnakinRaW.CommonUtilities.Registry; +using System; using System.IO.Abstractions; namespace AET.SteamAbstraction.Registry; @@ -22,4 +23,10 @@ internal interface ISteamRegistry : IDisposable /// The PID of the current Steam Process. 0 or if Steam is not running. /// int? ProcessId { get; } + + /// + /// Opens the Steam registry and returns a writeable key. + /// + /// The steam registry key. + IRegistryKey? OpenSteamRegistryKey(); } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs b/src/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs index 7f707d4b..3a4559e2 100644 --- a/src/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs +++ b/src/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs @@ -74,6 +74,12 @@ public IDirectoryInfo? InstallationDirectory } } + public IRegistryKey? OpenSteamRegistryKey() + { + ThrowIfDisposed(); + return _registryKey!.OpenSubKey(string.Empty, true); + } + protected override void DisposeResources() { _registryKey?.Dispose(); @@ -95,10 +101,4 @@ private void WriteToSubKey(string subKeyName, Action keyAction) if (subKey is not null) keyAction(subKey); } - - internal IRegistryKey GetSteamRegistryKey() - { - ThrowIfDisposed(); - return _registryKey!.OpenSubKey(string.Empty, true)!; - } } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index d3d787e4..7af86b95 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -1,4 +1,4 @@ - + AET.SteamAbstraction.Test @@ -28,6 +28,11 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index e191113d..4a8b06d2 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -2,7 +2,8 @@ using System.Collections.Generic; using System.IO.Abstractions; using AET.SteamAbstraction.Games; -using AET.SteamAbstraction.Testing.Installation; +using AET.SteamAbstraction.Testing; +using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using PG.TestingUtilities; using Testably.Abstractions.Testing; @@ -10,17 +11,25 @@ namespace AET.SteamAbstraction.Test; -public class SteamAppManifestTest +public class SteamAppManifestTest : IDisposable { private readonly MockFileSystem _fileSystem = new(); - private readonly IServiceProvider _serviceProvider; + private readonly ITestingSteamInstallation _steam; public SteamAppManifestTest() { var sc = new ServiceCollection(); sc.AddSingleton(_fileSystem); SteamAbstractionLayer.InitializeServices(sc); - _serviceProvider = sc.BuildServiceProvider(); + sc.AddSingleton(new InMemoryRegistry()); + var sp = sc.BuildServiceProvider(); + _steam = _fileSystem.Steam(sp); + _steam.InstallSteamFilesOnly(); + } + + public void Dispose() + { + _steam.Dispose(); } [Fact] @@ -29,7 +38,7 @@ public void Ctor_NullArgs_Throws() Assert.Throws(() => new SteamAppManifest(null!, _fileSystem.FileInfo.New("file.acf"), 0, "name", _fileSystem.DirectoryInfo.New("path"), SteamAppState.StateFullyInstalled, new HashSet())); - var lib = _fileSystem.InstallSteamLibrary("path", _serviceProvider, false); + var lib = _steam.InstallLibrary("path", false); Assert.Throws(() => new SteamAppManifest(lib, null!, 0, "name", _fileSystem.DirectoryInfo.New("path"), SteamAppState.StateFullyInstalled, new HashSet())); @@ -49,7 +58,7 @@ public void Ctor_NullArgs_Throws() [Fact] public void Ctor_SetsProperties() { - var lib = _fileSystem.InstallSteamLibrary("path", _serviceProvider, false); + var lib = _steam.InstallLibrary("path", false); var appManifest = new SteamAppManifest(lib, _fileSystem.FileInfo.New("file.acf"), 123, "name", _fileSystem.DirectoryInfo.New("path"), SteamAppState.StateFullyInstalled, new HashSet {987, 654}); @@ -66,8 +75,8 @@ public void Ctor_SetsProperties() [Fact] public void Equality() { - var lib = _fileSystem.InstallSteamLibrary("path", _serviceProvider, false); - var otherLib = _fileSystem.InstallSteamLibrary("other", _serviceProvider, false); + var lib = _steam.InstallLibrary("path", false); + var otherLib = _steam.InstallLibrary("other", false); const uint aId = 123; const uint bId = 456; diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index 3dd8ba3c..b9dd518d 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -5,7 +5,7 @@ using System.Runtime.InteropServices; using AET.SteamAbstraction.Library; using AET.SteamAbstraction.Registry; -using AET.SteamAbstraction.Testing.Installation; +using AET.SteamAbstraction.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using PG.TestingUtilities; @@ -14,11 +14,12 @@ namespace AET.SteamAbstraction.Test; -public class SteamLibraryFinderTest +public class SteamLibraryFinderTest : IDisposable { private readonly SteamLibraryFinder _libraryFinder; private readonly MockFileSystem _fileSystem = new(); private readonly IServiceProvider _serviceProvider; + private readonly ITestingSteamInstallation _steam; public SteamLibraryFinderTest() { @@ -29,12 +30,20 @@ public SteamLibraryFinderTest() SteamAbstractionLayer.InitializeServices(sc); _serviceProvider = sc.BuildServiceProvider(); _libraryFinder = new SteamLibraryFinder(_serviceProvider); + + _steam = _fileSystem.Steam(_serviceProvider); + _steam.Install(); + } + + public void Dispose() + { + _steam.Dispose(); } [Fact] public void FindLibraries_SteamNotFound_ReturnsEmpty() { - Assert.Empty(_libraryFinder.FindLibraries(_fileSystem.DirectoryInfo.New("does not exist"))); + Assert.Empty(_libraryFinder.FindLibraries(_fileSystem.DirectoryInfo.New("not steam"))); } // TODO: Target all platforms @@ -42,7 +51,7 @@ public void FindLibraries_SteamNotFound_ReturnsEmpty() public void FindLibraries_NoLibrariesInstalled() { using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); + _fileSystem.Steam(_serviceProvider).Install(); var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); Assert.Empty(libs); } @@ -52,8 +61,8 @@ public void FindLibraries_NoLibrariesInstalled() public void FindLibraries_DefaultLibraryInstalled() { using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); - var lib = _fileSystem.InstallDefaultLibrary(_serviceProvider, addToConfig: true); + _fileSystem.Steam(_serviceProvider).Install(); + var lib = _steam.InstallDefaultLibrary(addToConfig: true); var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); @@ -64,12 +73,8 @@ public void FindLibraries_DefaultLibraryInstalled() [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryInstalledButNotInConfig_NotFound() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); - _fileSystem.InstallDefaultLibrary(_serviceProvider, addToConfig: false); - - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); - + _steam.InstallDefaultLibrary(addToConfig: false); + var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); Assert.Empty(libs); } @@ -77,12 +82,10 @@ public void FindLibraries_DefaultLibraryInstalledButNotInConfig_NotFound() [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryAndExternalLibInstalled() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); - var defaultLib = _fileSystem.InstallDefaultLibrary(_serviceProvider, addToConfig: true); - var externalLib = _fileSystem.InstallSteamLibrary("externalLib", _serviceProvider); + var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = _steam.InstallLibrary("externalLib"); - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); Assert.Equal( new List { defaultLib, externalLib }.OrderBy(x => x.LibraryLocation.FullName), @@ -92,14 +95,12 @@ public void FindLibraries_DefaultLibraryAndExternalLibInstalled() [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_Windows_DefaultLibraryAndExternalLibInstalled_ExternalDoesNotHaveSteamDll_Skip() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); - var defaultLib = _fileSystem.InstallDefaultLibrary(_serviceProvider, addToConfig: true); - var externalLib = _fileSystem.InstallSteamLibrary("externalLib", _serviceProvider); + var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = _steam.InstallLibrary("externalLib"); _fileSystem.File.Delete(_fileSystem.Path.Combine(externalLib.LibraryLocation.FullName, "steam.dll")); - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); Assert.Equal([defaultLib], libs.OrderBy(x => x.LibraryLocation.FullName)); } @@ -108,14 +109,12 @@ public void FindLibraries_Windows_DefaultLibraryAndExternalLibInstalled_External [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryAndExternalLibInstalled_ExternalDoesNotHaveVdf_Skip() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); - var defaultLib = _fileSystem.InstallDefaultLibrary(_serviceProvider, addToConfig: true); - var externalLib = _fileSystem.InstallSteamLibrary("externalLib", _serviceProvider); + var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = _steam.InstallLibrary("externalLib"); _fileSystem.File.Delete(_fileSystem.Path.Combine(externalLib.LibraryLocation.FullName, "libraryfolder.vdf")); - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); Assert.Equal([defaultLib], libs.OrderBy(x => x.LibraryLocation.FullName)); } @@ -124,14 +123,12 @@ public void FindLibraries_DefaultLibraryAndExternalLibInstalled_ExternalDoesNotH [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryAndExternalLibInstalled_ExternalFolderDoesNotExist() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.InstallSteam(registry); - var defaultLib = _fileSystem.InstallDefaultLibrary(_serviceProvider, addToConfig: true); - var externalLib = _fileSystem.InstallSteamLibrary("externalLib", _serviceProvider); + var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = _steam.InstallLibrary("externalLib"); _fileSystem.Directory.Delete(externalLib.LibraryLocation.FullName, true); - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); Assert.Equal([defaultLib], libs.OrderBy(x => x.LibraryLocation.FullName)); } diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs index cf5e885a..daea596a 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs @@ -3,26 +3,36 @@ using System.Linq; using System.Runtime.InteropServices; using AET.SteamAbstraction.Library; -using AET.SteamAbstraction.Testing.Installation; +using AET.SteamAbstraction.Testing; +using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; using Xunit; namespace AET.SteamAbstraction.Test; -public class SteamLibraryTest +public class SteamLibraryTest : IDisposable { private readonly IServiceProvider _serviceProvider; private readonly MockFileSystem _fileSystem = new(); + private readonly IRegistry _registry = new InMemoryRegistry(); + private readonly ITestingSteamInstallation _steam; public SteamLibraryTest() { var sc = new ServiceCollection(); sc.AddSingleton(_ => _fileSystem); SteamAbstractionLayer.InitializeServices(sc); + sc.AddSingleton(_registry); _serviceProvider = sc.BuildServiceProvider(); - _fileSystem.InstallSteamFiles(); + _steam = _fileSystem.Steam(_serviceProvider); + _steam.InstallSteamFilesOnly(); + } + + public void Dispose() + { + _steam.Dispose(); } [Fact] @@ -77,7 +87,7 @@ public void Locations() [Fact] public void GetApps_NoAppsInstalled_Empty() { - var library = _fileSystem.InstallSteamLibrary("Library", _serviceProvider); + var library = _steam.InstallLibrary("Library"); var apps = library.GetApps(); @@ -87,7 +97,7 @@ public void GetApps_NoAppsInstalled_Empty() [Fact] public void GetApps_NoSteamAppsDirectoryDoesNotExists_Empty() { - var library = _fileSystem.InstallSteamLibrary("Library", _serviceProvider); + var library = _steam.InstallLibrary("Library"); library.SteamAppsLocation.Delete(true); var apps = library.GetApps(); @@ -98,8 +108,8 @@ public void GetApps_NoSteamAppsDirectoryDoesNotExists_Empty() [Fact] public void GetApps_InvalidAcfFile_Skipped() { - var library = _fileSystem.InstallSteamLibrary("Library", _serviceProvider); - library.InstallCorruptApp(_fileSystem); + var library = _steam.InstallLibrary("Library"); + library.InstallCorruptApp(); var apps = library.GetApps(); @@ -109,9 +119,9 @@ public void GetApps_InvalidAcfFile_Skipped() [Fact] public void TestApps() { - var library = _fileSystem.InstallSteamLibrary("Library", _serviceProvider); + var library = _steam.InstallLibrary("Library"); - library.InstallCorruptApp(_fileSystem); + library.InstallCorruptApp(); library.InstallGame(123, "Game1", "manifest1.acf"); var expectedGame2 = library.InstallGame(456, "Game2"); library.InstallGame(123, "NotGame1", "manifest2.acf"); diff --git a/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs b/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs index 6e3eb335..8ad112d2 100644 --- a/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs @@ -1,27 +1,37 @@ -using System; +using AET.SteamAbstraction.Games; +using AET.SteamAbstraction.Testing; +using AnakinRaW.CommonUtilities.Registry; +using Microsoft.Extensions.DependencyInjection; +using System; using System.Collections.Generic; using System.IO; using System.IO.Abstractions; using System.Linq; -using AET.SteamAbstraction.Games; -using AET.SteamAbstraction.Testing.Installation; -using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; using Xunit; using VdfException = AET.SteamAbstraction.Vdf.VdfException; namespace AET.SteamAbstraction.Test; -public class SteamVdfReaderTest +public class SteamVdfReaderTest : IDisposable { - private readonly IServiceProvider _serviceProvider; private readonly MockFileSystem _fileSystem = new(); + private readonly IRegistry _registry = new InMemoryRegistry(); + private readonly ITestingSteamInstallation _steam; public SteamVdfReaderTest() { var sc = new ServiceCollection(); sc.AddSingleton(_ => _fileSystem); - _serviceProvider = sc.BuildServiceProvider(); + sc.AddSingleton(_registry); + SteamAbstractionLayer.InitializeServices(sc); + _steam = _fileSystem.Steam(sc.BuildServiceProvider()); + _steam.InstallSteamFilesOnly(); + } + + public void Dispose() + { + _steam.Dispose(); } #region ReadLibraryLocationsFromConfig @@ -137,7 +147,7 @@ public void ReadLibraryLocationsFromConfig_EmptyContent_EmptyEnumerable() [Fact] public void ReadManifest_NullArgs_Throws() { - var lib = _fileSystem.InstallSteamLibrary("steamLib", _serviceProvider, false); + var lib = _steam.InstallLibrary("steamLib", false); Assert.Throws(() => SteamVdfReader.ReadManifest(null!, lib)); Assert.Throws(() => SteamVdfReader.ReadManifest(_fileSystem.FileInfo.New("path"), null!)); } @@ -145,7 +155,7 @@ public void ReadManifest_NullArgs_Throws() [Fact] public void ReadManifest_CorrectManifest() { - var lib = _fileSystem.InstallSteamLibrary("steamLib", _serviceProvider, false); + var lib = _steam.InstallLibrary("steamLib", false); var expectedManifest = lib.InstallGame( 1230, @@ -295,7 +305,7 @@ public static IEnumerable GetInvalidAppManifestContent() [MemberData(nameof(GetInvalidAppManifestContent))] public void ReadManifest_InvalidAppManifest_Throws(string content) { - var lib = _fileSystem.InstallSteamLibrary("steamLib", _serviceProvider, false); + var lib = _steam.InstallLibrary("steamLib", false); var manifestFile = _fileSystem.Path.Combine(lib.SteamAppsLocation.FullName, "manifest.acf"); _fileSystem.File.WriteAllText(manifestFile, content); @@ -306,8 +316,8 @@ public void ReadManifest_InvalidAppManifest_Throws(string content) [Fact] public void ReadManifest_ManifestNotPartOfLibrary_Throws() { - var lib = _fileSystem.InstallSteamLibrary("steamLib", _serviceProvider, false); - var otherLib = _fileSystem.InstallSteamLibrary("otherLib", _serviceProvider, false); + var lib = _steam.InstallLibrary("steamLib", false); + var otherLib = _steam.InstallLibrary("otherLib", false); var manifestFile = otherLib.InstallGame(1230, "MyGame").ManifestFile; @@ -473,9 +483,7 @@ public void ReadLoginUsers_EmptyFile() [Fact] public void ReadLoginUsers() { - _fileSystem.InstallSteamFiles(); - - var expectedUsers = new List + var expectedUsers = new List { new(1, true, false), new(2, false, false), @@ -483,11 +491,14 @@ public void ReadLoginUsers() new(4, true, true), }; - var file = _fileSystem.WriteLoginUsers(expectedUsers); + var file = _steam.WriteLoginUsers(expectedUsers); var users = SteamVdfReader.ReadLoginUsers(file); - Assert.Equal(expectedUsers, users.Users.OrderBy(x => x.UserId).ToList(), new SteamUserLoginMetadataEqualityComparer()); + Assert.Equal( + expectedUsers.Select(x => new SteamUserLoginMetadata(x.UserId, x.MostRecent, x.UserWantsOffline)), + users.Users.OrderBy(x => x.UserId).ToList(), + new SteamUserLoginMetadataEqualityComparer()); } private class SteamUserLoginMetadataEqualityComparer : IEqualityComparer diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 68140391..9d5f7065 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using System.Linq; using System.Threading; using System.Threading.Tasks; using AET.SteamAbstraction.Library; -using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Testing; -using AET.SteamAbstraction.Testing.Installation; using AET.SteamAbstraction.Utilities; using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; @@ -23,6 +22,8 @@ public abstract class SteamWrapperTestBase : IDisposable protected readonly MockFileSystem FileSystem = new(); protected readonly IServiceProvider ServiceProvider; + + protected ITestingSteamInstallation? Steam; internal TestProcessHelper? ProcessHelper; protected SteamWrapperTestBase() @@ -30,24 +31,31 @@ protected SteamWrapperTestBase() var sc = new ServiceCollection(); sc.AddSingleton(FileSystem); SteamAbstractionLayer.InitializeServices(sc); - sc.AddSingleton(sp => + sc.AddSingleton(sp => { return ProcessHelper = new TestProcessHelper(sp); }); + sc.AddSingleton(sp => sp.GetRequiredService()); // ReSharper disable once VirtualMemberCallInConstructor BuildServiceCollection(sc); ServiceProvider = sc.BuildServiceProvider(); _wrapperFactory = ServiceProvider.GetRequiredService(); } + public void Dispose() + { + ProcessHelper?.KillCurrent(); + } + protected virtual void BuildServiceCollection(IServiceCollection serviceCollection) { } + [MemberNotNull(nameof(Steam))] protected void InstallSteam() { - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - FileSystem.InstallSteam(registry); + Steam = FileSystem.Steam(ServiceProvider); + Steam.Install(); } private protected SteamWrapper CreateWrapper() @@ -121,8 +129,7 @@ public void IsRunning_RegistryHasPidSetButProcessNotRunning() var wrapper = CreateWrapper(); var expectedPid = new Random().Next(0, int.MaxValue); - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - registry.SetPid(expectedPid); + Steam.Registry.SetPid(expectedPid); Assert.False(wrapper.IsRunning); Assert.False(wrapper.IsUserLoggedIn); @@ -137,11 +144,11 @@ public void Libraries() Assert.Empty(wrapper.Libraries); - var expectedLib = FileSystem.InstallDefaultLibrary(ServiceProvider); + var expectedLib = Steam.InstallDefaultLibrary(); var lib = Assert.Single(wrapper.Libraries); Assert.Equal(expectedLib, lib); - var otherExpectedLib = FileSystem.InstallSteamLibrary("externalLib", ServiceProvider); + var otherExpectedLib = Steam.InstallLibrary("externalLib"); Assert.Equal( new List{ expectedLib, otherExpectedLib }.OrderBy(x => x.LibraryLocation.FullName), wrapper.Libraries.OrderBy(x => x.LibraryLocation.FullName)); @@ -159,7 +166,7 @@ public void IsGameInstalled() Assert.Null(game); - var lib = FileSystem.InstallDefaultLibrary(ServiceProvider); + var lib = Steam.InstallDefaultLibrary(); // One Lib with no games Assert.False(wrapper.IsGameInstalled(123, out game)); Assert.Null(game); @@ -174,8 +181,8 @@ public void IsGameInstalled() Assert.Null(otherGame); - var otherLib = FileSystem.InstallSteamLibrary("externalLib", ServiceProvider); - otherLib.InstallCorruptApp(FileSystem); + var otherLib = Steam.InstallLibrary("externalLib"); + otherLib.InstallCorruptApp(); var otherExpectedGame = otherLib.InstallGame(456, "OtherGame"); Assert.True(wrapper.IsGameInstalled(456, out otherGame)); Assert.NotNull(otherGame); @@ -211,27 +218,31 @@ public void UserWantsOfflineMode() InstallSteam(); var wrapper = CreateWrapper(); - FileSystem.DeleteLoginUsersFile(); + Steam.DeleteLoginUsersFile(); Assert.Null(wrapper.UserWantsOfflineMode); - FileSystem.WriteLoginUsers(new SteamUserLoginMetadata(ulong.MaxValue, false, false)); + Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(ulong.MaxValue, false, false)); Assert.False(wrapper.UserWantsOfflineMode); // Not most recent - FileSystem.WriteLoginUsers(new SteamUserLoginMetadata(ulong.MaxValue, false, true)); + Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(ulong.MaxValue, false, true)); Assert.False(wrapper.UserWantsOfflineMode); - FileSystem.WriteLoginUsers(new SteamUserLoginMetadata(ulong.MaxValue, true, true)); + Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(ulong.MaxValue, true, true)); Assert.True(wrapper.UserWantsOfflineMode); - FileSystem.WriteLoginUsers(new SteamUserLoginMetadata(ulong.MaxValue, false, true), new SteamUserLoginMetadata(456, true, true)); + Steam.WriteLoginUsers( + new TestingSteamUserLoginMetadata(ulong.MaxValue, false, true), + new TestingSteamUserLoginMetadata(456, true, true)); Assert.True(wrapper.UserWantsOfflineMode); // Not most recent - FileSystem.WriteLoginUsers(new SteamUserLoginMetadata(ulong.MaxValue, false, true), new SteamUserLoginMetadata(456, true, false)); + Steam.WriteLoginUsers( + new TestingSteamUserLoginMetadata(ulong.MaxValue, false, true), + new TestingSteamUserLoginMetadata(456, true, false)); Assert.False(wrapper.UserWantsOfflineMode); - FileSystem.WriteCorruptLoginUsers(); + Steam.WriteCorruptLoginUsers(); Assert.Null(wrapper.UserWantsOfflineMode); } @@ -361,39 +372,27 @@ public async Task WaitSteamRunningAndLoggedInAsync_UserDoesNotLoginBeforeCancell private void StopSteam() { - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - registry.SetPid(null); + Steam?.Registry.SetPid(null); ProcessHelper!.SetRunningPid(null); } - private void FakeStartSteam(int pid) - { - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - registry.SetPid(pid); - ProcessHelper!.SetRunningPid(pid); - } - private void FakeStartSteam() { - FakeStartSteam(new Random().Next(100, 10000)); + Assert.NotNull(Steam); + Steam.FakeStart(new Random().Next(100, 10000)); } protected virtual void LogoutUser() { - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - registry.SetUserId(0); - FileSystem.WriteLoginUsers(null); + Assert.NotNull(Steam); + Steam.Registry.SetUserId(0); + Steam.WriteLoginUsers(null); } protected virtual void LoginUser(uint userId) { - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - registry.SetUserId(userId); - FileSystem.WriteLoginUsers(new SteamUserLoginMetadata(userId, true, false)); - } - - public void Dispose() - { - ProcessHelper?.KillCurrent(); + Assert.NotNull(Steam); + Steam.Registry.SetUserId(userId); + Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(userId, true, false)); } } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 90660bc1..7f32d61f 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -1,12 +1,13 @@ - + AET.SteamAbstraction.TestingUtilities - net10.0 - $(TargetFrameworks);net481 + + netstandard2.0 false false @@ -25,22 +26,22 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + - - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs b/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs index 1957ee0b..41944430 100644 --- a/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs +++ b/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs @@ -1,4 +1,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("AET.SteamAbstraction.Test")] -[assembly: InternalsVisibleTo("PG.StarWarsGame.Infrastructure.Clients.Steam.Test")] +//[assembly: InternalsVisibleTo("PG.StarWarsGame.Infrastructure.Clients.Steam.Test")] diff --git a/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs b/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs new file mode 100644 index 00000000..239ad43f --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs @@ -0,0 +1,6 @@ +namespace AET.SteamAbstraction.Testing; + +public interface ISteamFakeProcess +{ + void Kill(); +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs new file mode 100644 index 00000000..9e5d7476 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.IO.Abstractions; + +namespace AET.SteamAbstraction.Testing; + +public interface ITestingSteamInstallation : IDisposable +{ + IDirectoryInfo? InstallationDirectory { get; } + + ITestingSteamRegistry Registry { get; } + + void Install(); + + void InstallSteamFilesOnly(); + + ISteamFakeProcess FakeStart(int pid); + + ITestingSteamLibrary InstallDefaultLibrary(bool addToConfig = true); + + ITestingSteamLibrary InstallLibrary(string path, bool addToConfig = true); + + void WriteCorruptLoginUsers(); + + void DeleteLoginUsersFile(); + + IFileInfo WriteLoginUsers(params IEnumerable? users); +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs new file mode 100644 index 00000000..d0e8cbad --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs @@ -0,0 +1,25 @@ +using AET.SteamAbstraction.Games; +using AET.SteamAbstraction.Library; +using System.Collections.Generic; + +namespace AET.SteamAbstraction.Testing; + +public interface ITestingSteamLibrary : ISteamLibrary +{ + SteamAppManifest InstallGame(uint id, string gameName, string appManifestName); + + SteamAppManifest InstallGame( + uint id, + string gameName, + uint numberDepots = 1, + SteamAppState appState = SteamAppState.StateFullyInstalled); + + SteamAppManifest InstallGame( + uint id, + string gameName, + IList depots, + SteamAppState appState = SteamAppState.StateFullyInstalled); + + + void InstallCorruptApp(); +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs new file mode 100644 index 00000000..8205b543 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs @@ -0,0 +1,28 @@ +using System; +using System.IO.Abstractions; + +namespace AET.SteamAbstraction.Testing; + +public interface ITestingSteamRegistry : IDisposable +{ + /// + /// Gets the executable of the Steam client. + /// + IFileInfo? ExecutableFile { get; } + + /// + /// Gets the installation directory of the Steam client + /// + IDirectoryInfo? InstallationDirectory { get; } + + /// + /// The PID of the current Steam Process. 0 or if Steam is not running. + /// + int? ProcessId { get; } + + void InstallSteam(); + + void SetPid(int? pid); + + void SetUserId(uint userId); +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Game.cs b/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Game.cs deleted file mode 100644 index 3e0fb259..00000000 --- a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Game.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Collections.Generic; -using System.IO.Abstractions; -using System.Text; -using AET.SteamAbstraction.Games; -using AET.SteamAbstraction.Library; -using Xunit; - -namespace AET.SteamAbstraction.Testing.Installation; - -internal static partial class SteamInstallation -{ - public static void InstallCorruptApp(this ISteamLibrary library, IFileSystem fileSystem) - { - var randomAcfName = fileSystem.Path.GetRandomFileName() + ".acf"; - library.SteamAppsLocation.Create(); - - fileSystem.File.WriteAllText(fileSystem.Path.Combine(library.SteamAppsLocation.FullName, randomAcfName), "\0"); - } - - public static SteamAppManifest InstallGame( - this ISteamLibrary library, - uint id, - string gameName, - string appManifestName) - { - return InstallGameCore(library, id, appManifestName, gameName, [id+1]); - } - - public static SteamAppManifest InstallGame( - this ISteamLibrary library, - uint id, - string gameName, - uint numberDepots = 1, - SteamAppState appState = SteamAppState.StateFullyInstalled) - { - var manifestFileName = $"appmanifest_{id}.acf"; - var depots = new List(); - for (uint i = 1; i < numberDepots + 1; i++) - depots.Add(i); - return InstallGameCore(library, id, manifestFileName, gameName, depots, appState); - } - - public static SteamAppManifest InstallGame( - this ISteamLibrary library, - uint id, - string gameName, - IList depots, - SteamAppState appState = SteamAppState.StateFullyInstalled) - { - var manifestFileName = $"appmanifest_{id}.acf"; - return InstallGameCore(library, id, manifestFileName, gameName, depots, appState); - } - - private static SteamAppManifest InstallGameCore( - this ISteamLibrary library, - uint id, - string appManifestName, - string gameName, - IList depots, - SteamAppState appState = SteamAppState.StateFullyInstalled) - { - var fs = library.SteamAppsLocation.FileSystem; - - - var depotSb = new StringBuilder(); - foreach (var depot in depots) - { - depotSb.Append($@" - ""{depot}"" - {{ - }} -"); - } - - var manifestContent = $@" -""AppState"" -{{ - ""appid"" ""{id}"" - ""name"" ""{gameName}"" - ""StateFlags"" ""{(int)appState}"" - ""installdir"" ""{gameName}"" - ""InstalledDepots"" - {{ - {depotSb} - }} - ""someProperty"" ""someValue"" -}} -"; - - var manifestFilePath = fs.Path.Combine(library.SteamAppsLocation.FullName, appManifestName); - fs.File.WriteAllText(manifestFilePath, manifestContent); - - Assert.True(fs.File.Exists(manifestFilePath)); - - var gamePath = fs.Path.Combine(library.CommonLocation.FullName, gameName); - var gameDir = fs.Directory.CreateDirectory(gamePath); - - return new SteamAppManifest(library, fs.FileInfo.New(manifestFilePath), id, gameName, gameDir, - SteamAppState.StateFullyInstalled, new HashSet()); - } -} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Linux.cs b/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Linux.cs deleted file mode 100644 index 2b42d713..00000000 --- a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Linux.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.IO.Abstractions; - -namespace AET.SteamAbstraction.Testing.Installation; - -internal static partial class SteamInstallation -{ - private static void InstallLinuxRegistry(LinuxSteamRegistry registry, IFileSystem fs) - { - // TODO - } - - private static void SetPidLinuxRegistry(LinuxSteamRegistry linuxRegistry, int? pid) - { - // TODO - } -} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Windows.cs b/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Windows.cs deleted file mode 100644 index 90a80bd5..00000000 --- a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.Windows.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.IO.Abstractions; - -namespace AET.SteamAbstraction.Testing.Installation; - -internal static partial class SteamInstallation -{ - private static void InstallWindowsRegistry(WindowsSteamRegistry registry, IFileSystem fs) - { - using var key = registry.GetSteamRegistryKey(); - - key.SetValue("SteamExe", fs.Path.GetFullPath(SteamExePath)); - key.SetValue("SteamPath", fs.Path.GetFullPath(SteamInstallPath)); - } - - private static void SetPidWindowsRegistry(WindowsSteamRegistry registry, int? pid) - { - if (pid is null) - return; - using var key = registry.GetSteamRegistryKey(); - using var activeProcessKey = key.CreateSubKey("ActiveProcess"); - - activeProcessKey!.SetValue("pid", pid); - } - - private static void SetUserIdWindowsRegistry(WindowsSteamRegistry registry, uint userId) - { - using var key = registry.GetSteamRegistryKey(); - using var activeProcessKey = key.CreateSubKey("ActiveProcess"); - - activeProcessKey!.SetValue("ActiveUser", userId); - } -} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.cs b/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.cs deleted file mode 100644 index bf7c600c..00000000 --- a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Registry.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.IO.Abstractions; -using AET.SteamAbstraction.Registry; - -namespace AET.SteamAbstraction.Testing.Installation; - -internal static partial class SteamInstallation -{ - public static void InstallSteam(this ISteamRegistry registry, IFileSystem fs) - { - if (registry is WindowsSteamRegistry windowsRegistry) - InstallWindowsRegistry(windowsRegistry, fs); - else if (registry is LinuxSteamRegistry linuxRegistry) - InstallLinuxRegistry(linuxRegistry, fs); - } - - - public static void SetPid(this ISteamRegistry registry, int? pid) - { - if (registry is WindowsSteamRegistry windowsRegistry) - SetPidWindowsRegistry(windowsRegistry, pid); - else if (registry is LinuxSteamRegistry linuxRegistry) - SetPidLinuxRegistry(linuxRegistry, pid); - } - - public static void SetUserId(this ISteamRegistry registry, uint userId) - { - if (registry is WindowsSteamRegistry windowsRegistry) - SetUserIdWindowsRegistry(windowsRegistry, userId); - // Does not exist for Linux - } -} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.cs b/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.cs deleted file mode 100644 index 16c04a49..00000000 --- a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.Collections.Generic; -using System.IO.Abstractions; -using System.Text; -using AET.SteamAbstraction.Registry; - -namespace AET.SteamAbstraction.Testing.Installation; - -internal static partial class SteamInstallation -{ - // Ensure starts on path 'steam'. See GameInstallation.cs - private const string SteamInstallPath = "steam"; - private const string SteamExePath = "steam/steam.exe"; - - public static void InstallSteam(this IFileSystem fs, ISteamRegistry registry) - { - registry.InstallSteam(fs); - fs.InstallSteamFiles(); - } - - public static void InstallSteamFiles(this IFileSystem fs) - { - var configPath = fs.Path.GetFullPath(fs.Path.Combine(SteamInstallPath, "config")); - var exePath = fs.Path.GetFullPath(SteamExePath); - - fs.Directory.CreateDirectory(configPath); - using var _ = fs.File.Create(exePath); - } - - public static void DeleteLoginUsersFile(this IFileSystem fs) - { - var configPath = fs.Path.GetFullPath(fs.Path.Combine(SteamInstallPath, "config")); - var loginUsersPath = fs.Path.Combine(configPath, "loginusers.vdf"); - fs.File.Delete(loginUsersPath); - } - - public static void WriteCorruptLoginUsers(this IFileSystem fs) - { - var configPath = fs.Path.GetFullPath(fs.Path.Combine(SteamInstallPath, "config")); - var loginUsersPath = fs.Path.Combine(configPath, "loginusers.vdf"); - fs.File.WriteAllText(loginUsersPath, "\0"); - } - - public static IFileInfo WriteLoginUsers(this IFileSystem fs, params IEnumerable? users) - { - var configPath = fs.Path.GetFullPath(fs.Path.Combine(SteamInstallPath, "config")); - var loginUsersPath = fs.Path.Combine(configPath, "loginusers.vdf"); - - var content = $@" -""users"" -{{ - {SerializeUsers(users)} -}} -"; - fs.File.WriteAllText(loginUsersPath, content); - return fs.FileInfo.New(loginUsersPath); - } - - private static string SerializeUsers(IEnumerable? users) - { - var sb = new StringBuilder(); - - if (users is null) - return string.Empty; - - foreach (var metadata in users) - { - var content = $@" - ""{metadata.UserId}"" - {{ - ""AccountName"" ""someName"" - ""PersonaName"" ""some Name"" - ""RememberPassword"" ""1"" - ""WantsOfflineMode"" ""{BoolToNumber(metadata.UserWantsOffline)}"" - ""SkipOfflineModeWarning"" ""0"" - ""AllowAutoLogin"" ""1"" - ""MostRecent"" ""{BoolToNumber(metadata.MostRecent)}"" - ""Timestamp"" ""0000000000"" - }}"; - - sb.AppendLine(content); - - } - - return sb.ToString(); - } - - - private static int BoolToNumber(bool value) - { - return value ? 1 : 0; - } -} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs b/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs new file mode 100644 index 00000000..d8dca256 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.Extensions.DependencyInjection; + +namespace AET.SteamAbstraction.Testing; + +internal sealed class SteamFakeProcessImpl : ISteamFakeProcess +{ + private readonly TestProcessHelper _processHelper; + + public SteamFakeProcessImpl(IServiceProvider serviceProvider, int pid) + { + _processHelper = serviceProvider.GetRequiredService(); + _processHelper.SetRunningPid(pid); + } + + public void Kill() + { + _processHelper.KillCurrent(); + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs new file mode 100644 index 00000000..c893f82f --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs @@ -0,0 +1,23 @@ +using AET.SteamAbstraction.Testing.Installation; +using System; +using System.IO.Abstractions; +using Testably.Abstractions.Testing; + +namespace AET.SteamAbstraction.Testing; + +public static class SteamInstallationExtensions +{ + public static ITestingSteamInstallation Steam(this MockFileSystem fs, IServiceProvider serviceProvider) + { + return new TestingSteamInstallationImpl(fs, serviceProvider); + } + + + extension(ITestingSteamRegistry) + { + public static ITestingSteamRegistry Create(IFileSystem fileSystem, IServiceProvider serviceProvider) + { + return new TestingSteamRegistryImpl(fileSystem, serviceProvider); + } + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index 7773e9cf..cef9815b 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -1,23 +1,27 @@ -using System; +using AET.SteamAbstraction.Utilities; +using Microsoft.Extensions.DependencyInjection; +using System; using System.Diagnostics; using System.IO.Abstractions; using System.Runtime.InteropServices; using System.Threading.Tasks; -using AET.SteamAbstraction.Registry; -using AET.SteamAbstraction.Testing.Installation; -using AET.SteamAbstraction.Utilities; -using Microsoft.Extensions.DependencyInjection; using Xunit; namespace AET.SteamAbstraction.Testing; -public class TestProcessHelper(IServiceProvider sp) : IProcessHelper +public sealed class TestProcessHelper : IProcessHelper { - private readonly ISteamRegistryFactory _registryFactory = sp.GetRequiredService(); - private readonly IFileSystem _fileSystem = sp.GetRequiredService(); + private readonly IFileSystem _fileSystem; + private readonly ITestingSteamRegistry _registry; private int? _pid; + public TestProcessHelper(IServiceProvider sp) + { + _fileSystem = sp.GetRequiredService(); + _registry = ITestingSteamRegistry.Create(_fileSystem, sp); + } + public Process? CurrentProcess { get; private set; } public bool DelayStart { get; set; } @@ -34,8 +38,7 @@ public bool IsProcessRunning(int pid) public Process StartProcess(ProcessStartInfo startInfo) { - var registry = _registryFactory.CreateRegistry(); - var expectedFileName = registry.ExecutableFile?.FullName; + var expectedFileName = _registry.ExecutableFile?.FullName; Assert.Equal(expectedFileName, _fileSystem.Path.GetFullPath(startInfo.FileName)); var processName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "cmd.exe" : "/bin/bash"; @@ -47,7 +50,7 @@ public Process StartProcess(ProcessStartInfo startInfo) var pid = p.Id; SetRunningPid(pid); - registry.SetPid(pid); + _registry.SetPid(pid); CurrentProcess = p; return p; @@ -60,7 +63,7 @@ internal void KillCurrent() CurrentProcess?.Kill(); CurrentProcess = null; SetRunningPid(null); - _registryFactory.CreateRegistry().SetPid(null); + _registry.SetPid(null); } catch { diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs b/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs new file mode 100644 index 00000000..25525d48 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs @@ -0,0 +1,8 @@ +namespace AET.SteamAbstraction.Testing; + +internal static class TestingSteamConstants +{ + // Ensure starts on path 'steam'. See GameInstallation.cs + public const string SteamInstallPath = "steam"; + public const string SteamExePath = "steam/steam.exe"; +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs similarity index 57% rename from test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Library.cs rename to test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index d37253ba..438dcc17 100644 --- a/test/AET.SteamAbstraction.Testing/Installation/SteamInstallation.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -1,48 +1,36 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using AET.SteamAbstraction.Library; using AnakinRaW.CommonUtilities.FileSystem; using PG.TestingUtilities; using Xunit; namespace AET.SteamAbstraction.Testing.Installation; -internal static partial class SteamInstallation +internal sealed partial class TestingSteamInstallationImpl { - public static ISteamLibrary InstallDefaultLibrary(this IFileSystem fs, IServiceProvider serviceProvider, bool addToConfig = true) + public ITestingSteamLibrary InstallDefaultLibrary(bool addToConfig = true) { - var steamPath = fs.Path.GetFullPath(SteamInstallPath); - return InstallSteamLibrary(fs, steamPath, true, serviceProvider, addToConfig); - + var steamPath = _fileSystem.Path.GetFullPath(TestingSteamConstants.SteamInstallPath); + return InstallSteamLibrary(steamPath, true, addToConfig); } - public static ISteamLibrary InstallSteamLibrary( - this IFileSystem fs, - string path, - IServiceProvider serviceProvider, - bool addToConfig = true) + public ITestingSteamLibrary InstallLibrary(string path, bool addToConfig = true) { - return InstallSteamLibrary(fs, path, false, serviceProvider, addToConfig); + return InstallSteamLibrary(path, false, addToConfig); } - private static ISteamLibrary InstallSteamLibrary( - this IFileSystem fs, - string path, - bool isDefault, - IServiceProvider serviceProvider, - bool addToConfig = true) + private ITestingSteamLibrary InstallSteamLibrary(string path, bool isDefault, bool addToConfig = true) { - var commonPath = fs.Path.Combine(path, "steamapps", "common"); - var workshopPath = fs.Path.Combine(path, "steamapps", "workshop"); + var commonPath = _fileSystem.Path.Combine(path, "steamapps", "common"); + var workshopPath = _fileSystem.Path.Combine(path, "steamapps", "workshop"); - fs.Directory.CreateDirectory(commonPath); - fs.Directory.CreateDirectory(workshopPath); + _fileSystem.Directory.CreateDirectory(commonPath); + _fileSystem.Directory.CreateDirectory(workshopPath); - var libDir = fs.DirectoryInfo.New(path); + var libDir = _fileSystem.DirectoryInfo.New(path); Assert.True(libDir.Exists); var contentId = TestHelpers.RandomLong(); @@ -62,23 +50,23 @@ private static ISteamLibrary InstallSteamLibrary( libraryVdfSubPath = "steamapps"; } - fs.File.WriteAllText(fs.Path.Combine(libDir.FullName, libraryVdfSubPath, libraryVdfName), libraryVdf); + _fileSystem.File.WriteAllText(_fileSystem.Path.Combine(libDir.FullName, libraryVdfSubPath, libraryVdfName), libraryVdf); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - using var _ = fs.File.Create(fs.Path.Combine(libDir.FullName, "steam.dll")); + using var _ = _fileSystem.File.Create(_fileSystem.Path.Combine(libDir.FullName, "steam.dll")); } - var lib = new SteamLibrary(libDir, serviceProvider); + var lib = new TestingSteamLibrary(libDir, serviceProvider); if (addToConfig) - AddToConfig(lib, fs); + AddToConfig(lib, _fileSystem); return lib; } - private static void AddToConfig(ISteamLibrary lib, IFileSystem fs) + private static void AddToConfig(TestingSteamLibrary lib, IFileSystem fs) { - var steamPath = fs.Path.GetFullPath(SteamInstallPath); + var steamPath = fs.Path.GetFullPath(TestingSteamConstants.SteamInstallPath); if (!fs.Directory.Exists(steamPath)) Assert.Fail("Steam not installed."); diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs new file mode 100644 index 00000000..9d7a5430 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.IO.Abstractions; +using System.Linq; +using System.Text; + +namespace AET.SteamAbstraction.Testing.Installation; +internal sealed partial class TestingSteamInstallationImpl +{ + public void DeleteLoginUsersFile() + { + var configPath = + _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(TestingSteamConstants.SteamInstallPath, "config")); + var loginUsersPath = _fileSystem.Path.Combine(configPath, "loginusers.vdf"); + _fileSystem.File.Delete(loginUsersPath); + } + + public void WriteCorruptLoginUsers() + { + var configPath = + _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(TestingSteamConstants.SteamInstallPath, "config")); + var loginUsersPath = _fileSystem.Path.Combine(configPath, "loginusers.vdf"); + _fileSystem.File.WriteAllText(loginUsersPath, "\0"); + } + + public IFileInfo WriteLoginUsers(params IEnumerable? users) + { + var configPath = + _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(TestingSteamConstants.SteamInstallPath, "config")); + var loginUsersPath = _fileSystem.Path.Combine(configPath, "loginusers.vdf"); + + var content = $@" +""users"" +{{ + {SerializeUsers(users?.Select(x => new SteamUserLoginMetadata(x.UserId, x.MostRecent, x.UserWantsOffline)))} +}} +"; + _fileSystem.File.WriteAllText(loginUsersPath, content); + return _fileSystem.FileInfo.New(loginUsersPath); + } + + private static string SerializeUsers(IEnumerable? users) + { + var sb = new StringBuilder(); + + if (users is null) + return string.Empty; + + foreach (var metadata in users) + { + var content = $@" + ""{metadata.UserId}"" + {{ + ""AccountName"" ""someName"" + ""PersonaName"" ""some Name"" + ""RememberPassword"" ""1"" + ""WantsOfflineMode"" ""{BoolToNumber(metadata.UserWantsOffline)}"" + ""SkipOfflineModeWarning"" ""0"" + ""AllowAutoLogin"" ""1"" + ""MostRecent"" ""{BoolToNumber(metadata.MostRecent)}"" + ""Timestamp"" ""0000000000"" + }}"; + + sb.AppendLine(content); + } + + return sb.ToString(); + } + + + private static int BoolToNumber(bool value) + { + return value ? 1 : 0; + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs new file mode 100644 index 00000000..b6efb65c --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs @@ -0,0 +1,39 @@ +using System; +using System.IO.Abstractions; + +namespace AET.SteamAbstraction.Testing.Installation; + +internal sealed partial class TestingSteamInstallationImpl(IFileSystem fileSystem, IServiceProvider serviceProvider) : ITestingSteamInstallation +{ + private readonly IFileSystem _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); + private readonly IServiceProvider _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); + + public IDirectoryInfo? InstallationDirectory => Registry.InstallationDirectory; + public ITestingSteamRegistry Registry { get; } = new TestingSteamRegistryImpl(fileSystem, serviceProvider); + + public void Install() + { + Registry.InstallSteam(); + InstallSteamFilesOnly(); + } + + public void InstallSteamFilesOnly() + { + var configPath = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(TestingSteamConstants.SteamInstallPath, "config")); + var exePath = _fileSystem.Path.GetFullPath(TestingSteamConstants.SteamExePath); + + _fileSystem.Directory.CreateDirectory(configPath); + using var _ = _fileSystem.File.Create(exePath); + } + + public ISteamFakeProcess FakeStart(int pid) + { + Registry.SetPid(pid); + return new SteamFakeProcessImpl(_serviceProvider, pid); + } + + public void Dispose() + { + Registry.Dispose(); + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs b/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs new file mode 100644 index 00000000..8ce5e898 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.IO.Abstractions; +using System.Text; +using AET.SteamAbstraction.Games; +using AET.SteamAbstraction.Library; +using Xunit; + +namespace AET.SteamAbstraction.Testing; + +internal sealed class TestingSteamLibrary(IDirectoryInfo libraryLocation, IServiceProvider serviceProvider) + : SteamLibrary(libraryLocation, serviceProvider), ITestingSteamLibrary +{ + public SteamAppManifest InstallGame(uint id, string gameName, string appManifestName) + { + return InstallGameCore(id, appManifestName, gameName, [id + 1]); + } + + public SteamAppManifest InstallGame( + uint id, + string gameName, + uint numberDepots = 1, + SteamAppState appState = SteamAppState.StateFullyInstalled) + { + var manifestFileName = $"appmanifest_{id}.acf"; + var depots = new List(); + for (uint i = 1; i < numberDepots + 1; i++) + depots.Add(i); + return InstallGameCore(id, manifestFileName, gameName, depots, appState); + } + + public SteamAppManifest InstallGame( + uint id, + string gameName, + IList depots, + SteamAppState appState = SteamAppState.StateFullyInstalled) + { + var manifestFileName = $"appmanifest_{id}.acf"; + return InstallGameCore(id, manifestFileName, gameName, depots, appState); + } + + public void InstallCorruptApp() + { + var randomAcfName = FileSystem.Path.GetRandomFileName() + ".acf"; + SteamAppsLocation.Create(); + + FileSystem.File.WriteAllText(FileSystem.Path.Combine(SteamAppsLocation.FullName, randomAcfName), "\0"); + } + + private SteamAppManifest InstallGameCore( + uint id, + string appManifestName, + string gameName, + IList depots, + SteamAppState appState = SteamAppState.StateFullyInstalled) + { + var depotSb = new StringBuilder(); + foreach (var depot in depots) + { + depotSb.Append($@" + ""{depot}"" + {{ + }} +"); + } + + var manifestContent = $@" +""AppState"" +{{ + ""appid"" ""{id}"" + ""name"" ""{gameName}"" + ""StateFlags"" ""{(int)appState}"" + ""installdir"" ""{gameName}"" + ""InstalledDepots"" + {{ + {depotSb} + }} + ""someProperty"" ""someValue"" +}} +"; + + var manifestFilePath = FileSystem.Path.Combine(SteamAppsLocation.FullName, appManifestName); + FileSystem.File.WriteAllText(manifestFilePath, manifestContent); + + Assert.True(FileSystem.File.Exists(manifestFilePath)); + + var gamePath = FileSystem.Path.Combine(CommonLocation.FullName, gameName); + var gameDir = FileSystem.Directory.CreateDirectory(gamePath); + + return new SteamAppManifest( + this, + FileSystem.FileInfo.New(manifestFilePath), + id, + gameName, + gameDir, + SteamAppState.StateFullyInstalled, + new HashSet()); + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs new file mode 100644 index 00000000..ae69a6d6 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs @@ -0,0 +1,83 @@ +using System; +using System.IO.Abstractions; +using AET.SteamAbstraction.Registry; +using Microsoft.Extensions.DependencyInjection; +using Xunit; + +namespace AET.SteamAbstraction.Testing; + +internal class TestingSteamRegistryImpl(IFileSystem fileSystem, IServiceProvider serviceProvider) : ITestingSteamRegistry +{ + private readonly ISteamRegistry _registry = serviceProvider.GetRequiredService().CreateRegistry(); + + public IFileInfo? ExecutableFile => _registry.ExecutableFile; + public IDirectoryInfo? InstallationDirectory => _registry.InstallationDirectory; + public int? ProcessId => _registry.ProcessId; + + public void InstallSteam() + { + if (_registry is WindowsSteamRegistry) + InstallWindowsRegistry(); + else if (_registry is LinuxSteamRegistry) + InstallLinuxRegistry(); + } + + + public void SetPid(int? pid) + { + if (_registry is WindowsSteamRegistry) + SetPidWindowsRegistry(pid); + else if (_registry is LinuxSteamRegistry) + SetPidLinuxRegistry(pid); + } + + public void SetUserId(uint userId) + { + if (_registry is WindowsSteamRegistry) + SetUserIdWindowsRegistry(userId); + // Does not exist for Linux + } + + private void InstallWindowsRegistry() + { + using var key = _registry.OpenSteamRegistryKey(); + Assert.NotNull(key); + key.SetValue("SteamExe", fileSystem.Path.GetFullPath(TestingSteamConstants.SteamExePath)); + key.SetValue("SteamPath", fileSystem.Path.GetFullPath(TestingSteamConstants.SteamInstallPath)); + } + + private void SetPidWindowsRegistry(int? pid) + { + if (pid is null) + return; + using var key = _registry.OpenSteamRegistryKey(); + Assert.NotNull(key); + using var activeProcessKey = key.CreateSubKey("ActiveProcess"); + + activeProcessKey!.SetValue("pid", pid); + } + + private void SetUserIdWindowsRegistry(uint userId) + { + using var key = _registry.OpenSteamRegistryKey(); + Assert.NotNull(key); + using var activeProcessKey = key.CreateSubKey("ActiveProcess"); + + activeProcessKey!.SetValue("ActiveUser", userId); + } + + private void InstallLinuxRegistry() + { + throw new NotImplementedException("Linux is currently not supported"); + } + + private void SetPidLinuxRegistry(int? pid) + { + throw new NotImplementedException("Linux is currently not supported"); + } + + public void Dispose() + { + _registry.Dispose(); + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs b/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs new file mode 100644 index 00000000..090b7aee --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs @@ -0,0 +1,19 @@ +namespace AET.SteamAbstraction.Testing; + +public sealed class TestingSteamUserLoginMetadata +{ + public ulong UserId { get; init; } + public bool UserWantsOffline { get; init; } + public bool MostRecent { get; init; } + + public TestingSteamUserLoginMetadata() + { + } + + public TestingSteamUserLoginMetadata(ulong userId, bool mostRecent = false, bool userWantsOffline = false) + { + UserId = userId; + MostRecent = mostRecent; + UserWantsOffline = userWantsOffline; + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs index 5784774d..144e5e8a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs @@ -4,13 +4,14 @@ using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; -public class IGameClientFactoryTest : CommonTestBase +public class IGameClientFactoryTest : GameInfrastructureTestBase { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); @@ -24,7 +25,7 @@ protected override void SetupServiceProvider(IServiceCollection sc) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateClient_CreatesCorrectClientType(GameIdentity identity) { var game = FileSystem.InstallGame(identity, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index db607eb8..2205c025 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -1,11 +1,7 @@ #if Windows // TODO: Enable for linux -using System; -using System.Collections.Generic; using AET.SteamAbstraction; -using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Testing; -using AET.SteamAbstraction.Testing.Installation; using AET.SteamAbstraction.Utilities; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; @@ -13,7 +9,10 @@ using PG.StarWarsGame.Infrastructure.Clients.Processes; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Test.Clients; +using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using System; +using System.Collections.Generic; using Xunit; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; @@ -22,16 +21,17 @@ public class SteamPetroglyphStarWarsGameClientTest : PetroglyphStarWarsGameClien { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); private readonly PetroglyphStarWarsGame _game; - private TestProcessHelper? _processHelper; + + private ISteamFakeProcess? _steamProcess; protected override ICollection SupportedPlatforms { get; } = [GamePlatform.SteamGold]; protected override void BeforePlay() { // Install Steam (regardless whether the identity is supported) - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - FileSystem.InstallSteam(registry); - FakeStartSteam(12345); + var steam = FileSystem.Steam(ServiceProvider); + steam.Install(); + _steamProcess = steam.FakeStart(12345); base.BeforePlay(); } @@ -47,10 +47,9 @@ protected override void SetupServiceProvider(IServiceCollection sc) SteamAbstractionLayer.InitializeServices(sc); SteamPetroglyphStarWarsGameClients.InitializeServices(sc); - sc.AddSingleton(sp => - { - return _processHelper = new TestProcessHelper(sp); - }); + sc.AddSingleton(sp => new TestProcessHelper(sp)); + sc.AddSingleton(sp => sp.GetRequiredService()); + } [Fact] @@ -72,7 +71,7 @@ public void SteamPetroglyphStarWarsGameClient_Lifecycle() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Ctor_NonSteamGameThrows(GameIdentity identity) { if (identity.Platform is GamePlatform.SteamGold) @@ -96,26 +95,17 @@ public void Play_SteamNotInstalled_Throws() public void Play_SteamNotRunning_Throws() { // Install Steam (regardless whether the identity is supported) - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - FileSystem.InstallSteam(registry); + FileSystem.Steam(ServiceProvider).Install(); var expected = new GameProcessInfo(_game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay(_game, expected, gameClient => gameClient.Play(), shallThrowGameStartException: true); } - - private void FakeStartSteam(int pid) - { - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - registry.SetPid(pid); - _processHelper!.SetRunningPid(pid); - } - public override void Dispose() { base.Dispose(); - _processHelper?.KillCurrent(); + _steamProcess?.Kill(); } } diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index f11848f5..4a38f749 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -4,8 +4,7 @@ using System.Collections.Generic; using AET.SteamAbstraction; using AET.SteamAbstraction.Games; -using AET.SteamAbstraction.Registry; -using AET.SteamAbstraction.Testing.Installation; +using AET.SteamAbstraction.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; @@ -45,7 +44,7 @@ protected override GameDetectorTestInfo SetupGame(GameIdentity game { return SetupGame(gameIdentity, (game, otherGameType) => { - TestGameRegistrySetupData.Installed(game.Type, game.Directory).Create(ServiceProvider); + _registry.InstallGame(game, ServiceProvider); otherGameType.CreateNonExistingRegistry(ServiceProvider); }); } @@ -115,7 +114,7 @@ public void Detect_SteamInstalledButGameNotFullyInstalled_ShouldReturnNotInstall var info = SetupGame(gameId, (game, otherGameType) => { - TestGameRegistrySetupData.Installed(game.Type, game.Directory).Create(ServiceProvider); + _registry.InstallGame(game, ServiceProvider); otherGameType.CreateNonExistingRegistry(ServiceProvider); }, SteamAppState.StateUpdateRequired); @@ -131,17 +130,17 @@ private GameDetectorTestInfo SetupGame( SteamAppState appState = SteamAppState.StateFullyInstalled) { // Install Steam (regardless whether the identity is supported) - var registry = ServiceProvider.GetRequiredService().CreateRegistry(); - FileSystem.InstallSteam(registry); + var steam = FileSystem.Steam(ServiceProvider); + steam.Install(); if (gameIdentity.Platform != GamePlatform.SteamGold) return new GameDetectorTestInfo(gameIdentity.Type, null, default); - + // Install Game var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); // Register Game to Steam - var lib = FileSystem.InstallDefaultLibrary(ServiceProvider); + var lib = steam.InstallDefaultLibrary(); IList depots = gameIdentity.Type == GameType.Foc ? [32472] : []; lib.InstallGame(32470, "Star Wars Empire at War", depots, appState); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentCollectionTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentCollectionTest.cs index d4f651d3..9e73128c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentCollectionTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentCollectionTest.cs @@ -13,7 +13,9 @@ public void TestEmpty() { var empty = ArgumentCollection.Empty; Assert.Empty(empty); +#pragma warning disable xUnit2013 Assert.Equal(0, empty.Count); +#pragma warning restore xUnit2013 } [Fact] @@ -24,7 +26,9 @@ public void TestImmutable() args.Add(new MapArgument("Map")); +#pragma warning disable xUnit2013 Assert.Equal(1, argList.Count); +#pragma warning restore xUnit2013 var a = Assert.Single(argList); var e = ((IEnumerable)argList).GetEnumerator(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index 1d800a96..76ee0458 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -14,7 +14,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; -public class GameArgumentsBuilderTest : CommonTestBase +public class GameArgumentsBuilderTest : GameInfrastructureTestBase { private readonly MockFileSystem _fileSystem = new(); private readonly GameArgumentsBuilder _builder = new(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs index 1061f845..c78411c8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs @@ -6,7 +6,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients; -public class GameClientFactoryTest : CommonTestBase +public class GameClientFactoryTest : GameInfrastructureTestBase { protected override void SetupServiceProvider(IServiceCollection sc) { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 077a59f2..7cad8c5f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -18,7 +18,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients; -public class PetroglyphStarWarsGameClientTest : CommonTestBase, IDisposable +public class PetroglyphStarWarsGameClientTest : GameInfrastructureTestBase, IDisposable { private readonly IGameClientFactory _clientFactory; private readonly TestGameProcessLauncher _processLauncher = new(); @@ -58,7 +58,7 @@ public void Ctor_SetsGame() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void IsDebugAvailable_NoDebugFilesAvailable(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -89,7 +89,7 @@ public void PlayDebug_NullArgs_Throws() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Play_CancelGameStart_Throws(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -123,7 +123,7 @@ void Cancel(GameStartingEventArgs args) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void PlayDebug_ProcessLauncherThrows(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -150,7 +150,7 @@ public void PlayDebug_ProcessLauncherThrows(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Play(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -163,7 +163,7 @@ public void Play(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Play_Args(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -178,7 +178,7 @@ public void Play_Args(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Play_Mod(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -210,7 +210,7 @@ public void Debug_DebugIsAvailable(GameType gameType) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Debug_FallbackToRelease(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -226,7 +226,7 @@ public void Debug_FallbackToRelease(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Debug_DoNotFallbackToRelease_Throws(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -243,7 +243,7 @@ public void Debug_DoNotFallbackToRelease_Throws(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void PlayDebug_GameExecutablesNotAvailable_Throws(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) @@ -269,7 +269,7 @@ public void PlayDebug_GameExecutablesNotAvailable_Throws(GameIdentity gameIdenti } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void PlayDebug_Derived_OnGameStarting_ThrowsCustom(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs index 89423dc6..09842c81 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs @@ -13,7 +13,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients.Processes; -public class GameProcessLauncherTest : CommonTestBaseWithRandomGame, IDisposable +public class GameProcessLauncherTest : GameInfrastructureTestBaseWithRandomGame, IDisposable { private readonly GameProcessLauncher _launcher; private readonly IFileInfo _executable; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs index 3acdd5e8..ee39f1c0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs @@ -11,7 +11,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients.Processes; -public class GameProcessTest : CommonTestBaseWithRandomGame, IDisposable +public class GameProcessTest : GameInfrastructureTestBaseWithRandomGame, IDisposable { private Process _testProcess = null!; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs index ed8f70de..bcea9e0f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs @@ -10,7 +10,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients.Utilities; -public class GameExecutableFileUtilitiesTest : CommonTestBase +public class GameExecutableFileUtilitiesTest : GameInfrastructureTestBase { public static IEnumerable GetGameExeNamesTestData() { @@ -38,7 +38,7 @@ public static IEnumerable GetGameExeNamesTestData() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetExecutableForGame_NullGame_ThrowsArgumentNullException(GameIdentity gameIdentity) { FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -48,7 +48,7 @@ public void GetExecutableForGame_NullGame_ThrowsArgumentNullException(GameIdenti } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetExecutableForGame_GameExeFilesNotInstalled_ReturnsNull(GameIdentity gameIdentity) { var gameDir = FileSystem.DirectoryInfo.New("Game"); @@ -95,7 +95,7 @@ public void GetExecutableForGame_SteamHasReleaseButNotDebugFiles(GameType gameTy } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetExecutableForGame_DebugFilesForOtherThanSteam_ShouldReturnNull(GameIdentity identity) { if (identity.Platform == GamePlatform.SteamGold) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameLocalizationUtilitiesTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameLocalizationUtilitiesTest.cs index 0b70a84a..bb555d61 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameLocalizationUtilitiesTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameLocalizationUtilitiesTest.cs @@ -9,7 +9,7 @@ namespace PG.StarWarsGame.Infrastructure.Test; -public class GameLocalizationUtilitiesTest : CommonTestBaseWithRandomGame +public class GameLocalizationUtilitiesTest : GameInfrastructureTestBaseWithRandomGame { [Fact] public void ArgumentNull_Throws() diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CompositeDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CompositeDetectorTest.cs index 4a5651cf..c8edd60f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CompositeDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CompositeDetectorTest.cs @@ -10,7 +10,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.GameServices.Detection; -public class CompositeDetectorTest : CommonTestBase +public class CompositeDetectorTest : GameInfrastructureTestBase { [Fact] public void Ctor_InvalidThrows() @@ -22,7 +22,7 @@ public void Ctor_InvalidThrows() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_InstalledGame_MultipleDetectorsRunInSpecifiedSequence(GameIdentity identity) { var expectedResult = GameDetectionResult.FromInstalled(identity, FileSystem.DirectoryInfo.New("installed")); @@ -67,7 +67,7 @@ public void Detect_TryDetect_InstalledGame_MultipleDetectorsRunInSpecifiedSequen } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_InstalledGame_SecondDetectorDoesNotRunBecauseFirstFoundGame(GameIdentity identity) { var expectedResult = GameDetectionResult.FromInstalled(identity, FileSystem.DirectoryInfo.New("installed")); @@ -104,7 +104,7 @@ public void Detect_TryDetect_InstalledGame_SecondDetectorDoesNotRunBecauseFirstF } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_InstalledGame_ShallNotThrowIfInstalled(GameIdentity identity) { var expectedResult = GameDetectionResult.FromInstalled(identity, FileSystem.DirectoryInfo.New("installed")); @@ -123,7 +123,7 @@ public void Detect_TryDetect_InstalledGame_ShallNotThrowIfInstalled(GameIdentity } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_NotInstalledGame_ShallNotThrowEvenIfNotInstalled(GameIdentity identity) { var expectedResult = GameDetectionResult.NotInstalled(identity.Type); @@ -142,7 +142,7 @@ public void Detect_TryDetect_NotInstalledGame_ShallNotThrowEvenIfNotInstalled(Ga } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_NotInstalledGame_WhenAllDetectorsReturnNull(GameIdentity identity) { var expectedResult = GameDetectionResult.NotInstalled(identity.Type); @@ -161,7 +161,7 @@ public void Detect_TryDetect_NotInstalledGame_WhenAllDetectorsReturnNull(GameIde } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_ShallThrowAggregateException_TryDetect_ReturnsNotInstalledGame_WhenAllDetectorsThrow(GameIdentity identity) { var expectedResult = GameDetectionResult.NotInstalled(identity.Type); @@ -179,7 +179,7 @@ public void Detect_ShallThrowAggregateException_TryDetect_ReturnsNotInstalledGam } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_ShallPropagateRequireInitializationEvent(GameIdentity identity) { var expectedResult = GameDetectionResult.RequiresInitialization(identity.Type); @@ -234,7 +234,7 @@ public void Detect_TryDetect_ShallPropagateRequireInitializationEvent(GameIdenti //} [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_ShallDisposeDetectors(GameIdentity identity) { var expectedResult = GameDetectionResult.FromInstalled(identity, FileSystem.DirectoryInfo.New("installed")); @@ -255,11 +255,16 @@ public void Detect_ShallDisposeDetectors(GameIdentity identity) Assert.True(thirdDetector.IsDisposed); } - private class EmptyDetector : IGameDetector + private sealed class EmptyDetector : IGameDetector { public event EventHandler? InitializationRequested; public GameDetectionResult Detect(GameType gameType, ICollection platforms) => throw new NotImplementedException(); public bool TryDetect(GameType gameType, ICollection platforms, out GameDetectionResult result) => throw new NotImplementedException(); + + private void OnInitializationRequested(GameInitializeRequestEventArgs e) + { + InitializationRequested?.Invoke(this, e); + } } private delegate GameDetectionResult DetectDelegate(IGameDetector detector, GameType gameType, ICollection platforms); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs index 3dac0eb0..e988ac86 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs @@ -38,14 +38,14 @@ public void InvalidArgs_Throws() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GamesNotInstalled_DirectoryNotFound(GameIdentity identity) { TestNotInstalledWithCustomSetup(identity, _ => FileSystem.DirectoryInfo.New("doesNotExist")); } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GamesNotInstalled_GameExeNotFound(GameIdentity identity) { FileSystem.Initialize().WithFile("Game/Data/megafiles.xml"); @@ -53,7 +53,7 @@ public void Detect_TryDetect_GamesNotInstalled_GameExeNotFound(GameIdentity iden } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GamesNotInstalled_GameDataWithMegaFilesNotFound(GameIdentity identity) { var exeName = identity.Type == GameType.Eaw @@ -68,7 +68,7 @@ public void Detect_TryDetect_GamesNotInstalled_GameDataWithMegaFilesNotFound(Gam } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GamesInstalled_WrongPathGiven(GameIdentity identity) { TestNotInstalledWithCustomSetup(identity, i => diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GameDetectionResultTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GameDetectionResultTest.cs index 75a19d23..f7f0e0b5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GameDetectionResultTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GameDetectionResultTest.cs @@ -6,7 +6,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.GameServices.Detection; -public class GameDetectionResultTest : CommonTestBase +public class GameDetectionResultTest : GameInfrastructureTestBase { [Fact] public void CreateInstance_Throws() diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs index 1bb63d10..b2316c2d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs @@ -106,7 +106,7 @@ public void TestInvalidArgs_Throws() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Dispose_ShallDisposeRegistries(GameIdentity identity) { var info = SetupGame(identity); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs index 534c0a83..f3469596 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs @@ -8,7 +8,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.GameServices; -public class EnglishGameNameResolverTest : CommonTestBase +public class EnglishGameNameResolverTest : GameInfrastructureTestBase { public static IEnumerable GetCultures() { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index f2c90a0f..42d88ab3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -14,7 +14,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.GameServices; -public class GameFactoryTest : CommonTestBase +public class GameFactoryTest : GameInfrastructureTestBase { private readonly GameFactory _factory; private readonly IGameNameResolver _nameResolver; @@ -239,7 +239,7 @@ private void AssertGame(IGame game, IGameIdentity expectedIdentity, string expec } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateGame_FromIdentity_GameCreated(GameIdentity gameIdentity) { var installedGame = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -257,7 +257,7 @@ public void CreateGame_FromIdentity_GameCreated(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateGame_FromDetectionResult_GameCreated(GameIdentity gameIdentity) { var installedGame = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -276,7 +276,7 @@ public void CreateGame_FromDetectionResult_GameCreated(GameIdentity gameIdentity AssertGame(tryGame, gameIdentity, installedGame.Directory.FullName, expectedName); } - public class GameFactoryWithNullNameResolver : CommonTestBaseWithRandomGame + public class GameFactoryWithNullNameResolver : GameInfrastructureTestBaseWithRandomGame { private readonly GameFactory _factory; @@ -306,7 +306,7 @@ public void CreateGame_NameResolverReturnNull_Throws() } } - public class GameFactoryWithCustomNameResolver : CommonTestBaseWithRandomGame + public class GameFactoryWithCustomNameResolver : GameInfrastructureTestBaseWithRandomGame { private readonly GameFactory _factory; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs index 9c55fe62..9b2f8bad 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs @@ -9,7 +9,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.GameServices; -public class SteamGameHelpersTest : CommonTestBase +public class SteamGameHelpersTest : GameInfrastructureTestBase { private readonly SteamGameHelpers _service; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 2922d0f4..5b40ecfc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -281,7 +281,7 @@ public void EqualsHashCode() Assert.True(mod.Equals((IModReference)custom)); } - public class ModBaseAbstractTest : CommonTestBaseWithRandomGame + public class ModBaseAbstractTest : GameInfrastructureTestBaseWithRandomGame { [Fact] public void ResolveDependencies_CalledTwice_Throws() diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index b0d887d2..e9e449eb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -12,7 +12,7 @@ namespace PG.StarWarsGame.Infrastructure.Test; -public class ModEqualityComparerTest : CommonTestBaseWithRandomGame +public class ModEqualityComparerTest : GameInfrastructureTestBaseWithRandomGame { [Theory] [InlineData(false, false)] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 1ee26001..5c7a1d94 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -13,7 +13,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices.Dependencies; -public class ModDependencyGraphBuilderTest : CommonTestBaseWithRandomGame +public class ModDependencyGraphBuilderTest : GameInfrastructureTestBaseWithRandomGame { private readonly ModDependencyGraphBuilder _graphBuilder = new(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs index 241f9f26..08312410 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs @@ -11,7 +11,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices.Dependencies; -public class ModDependencyResolverTest : CommonTestBaseWithRandomGame +public class ModDependencyResolverTest : GameInfrastructureTestBaseWithRandomGame { private readonly ModDependencyResolver _resolver; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 054fd1fe..5740e49c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -10,7 +10,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices.Dependencies; -public class ModDependencyTraverserTest : CommonTestBaseWithRandomGame +public class ModDependencyTraverserTest : GameInfrastructureTestBaseWithRandomGame { private readonly ModDependencyTraverser _traverser; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs index f6d54da7..fd99eb2f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs @@ -53,7 +53,7 @@ public void ResolveName_Steam_WithoutModinfo_FindNameOnline(string path, string } } -public abstract class ModNameResolverTestBase : CommonTestBase +public abstract class ModNameResolverTestBase : GameInfrastructureTestBase { public abstract ModNameResolverBase CreateResolver(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index b9f42c25..2a0c0022 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -23,7 +23,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices; -public class ModFactoryTest : CommonTestBase +public class ModFactoryTest : GameInfrastructureTestBase { private const string DefaultModName = "Default Mod Name"; private const string SteamModName = "Steam Mod Name"; @@ -75,7 +75,7 @@ public void CreatePhysicalMod_ModDirectoryNotFound_Throws() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -91,7 +91,7 @@ public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdenti } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -145,7 +145,7 @@ public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -160,7 +160,7 @@ public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -174,7 +174,7 @@ public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdenti } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -207,7 +207,7 @@ public void CreateVirtualMod_NullArgs_Throws() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -222,7 +222,7 @@ public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -236,7 +236,7 @@ public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity game } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 394d75a2..384adc95 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -22,7 +22,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices; -public class ModFinderTest : CommonTestBase +public class ModFinderTest : GameInfrastructureTestBase { private readonly ModFinder _modFinder; private readonly ISteamGameHelpers _steamGameHelpers; @@ -43,7 +43,7 @@ public void FindMods_NullArg_Throws() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_GameNotExists_Throws(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -53,7 +53,7 @@ public void FindMods_GameNotExists_Throws(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_NoModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -73,7 +73,7 @@ public void FindMods_NoModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -90,7 +90,7 @@ public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdent } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -104,7 +104,7 @@ public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -120,7 +120,7 @@ public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -139,7 +139,7 @@ public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdenti } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -156,7 +156,7 @@ public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -189,7 +189,7 @@ public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -222,7 +222,7 @@ public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -296,7 +296,7 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -310,7 +310,7 @@ public void FindMods_FromExternal(GameIdentity gameIdentity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -325,7 +325,7 @@ public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameI } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -423,7 +423,7 @@ public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameTyp } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_InvalidModinfoContentIsSkippedButModIsFound(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 76130879..977ba768 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -19,7 +19,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.ModServices; -public abstract class ModGameTypeResolverTestBase : CommonTestBase +public abstract class ModGameTypeResolverTestBase : GameInfrastructureTestBase { public abstract ModGameTypeResolver CreateResolver(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 0d28c712..99c70e8b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Modinfo.Spec.Equality; using AET.Modinfo.Utilities; @@ -15,16 +11,21 @@ using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; +using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; -public class PetroglyphGameInfrastructureIntegrationTest : CommonTestBase +public class PetroglyphGameInfrastructureIntegrationTest : GameInfrastructureTestBase { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); @@ -37,7 +38,7 @@ protected override void SetupServiceProvider(IServiceCollection sc) } [Theory] - [MemberData(nameof(RealPlatforms))] + [MemberData(nameof(GITestUtilities.GetRealPlatforms), MemberType = typeof(GITestUtilities))] public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(GamePlatform platform) { // Init Mods uninitialized @@ -58,10 +59,7 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga var initCount = 0; gameDetector.InitializationRequested += (_, args) => { - if (args.GameType == GameType.Eaw) - TestGameRegistrySetupData.Installed(GameType.Eaw, eaw.Directory).Create(ServiceProvider); - else - TestGameRegistrySetupData.Installed(GameType.Foc, foc.Directory).Create(ServiceProvider); + _registry.InstallGame(args.GameType == GameType.Eaw ? eaw : foc, ServiceProvider); args.Handled = true; initCount++; }; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index cd5b9248..a1f36a83 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -101,7 +101,7 @@ public void Equals_GetHashCode() } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetModDirTest(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs index 5fb0df25..e355aaeb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs @@ -2,12 +2,13 @@ using AET.Modinfo.Spec; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Services.Language; +using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; -public abstract class PlayableObjectTest : CommonTestBase +public abstract class PlayableObjectTest : GameInfrastructureTestBase { protected abstract IPlayableObject CreatePlayableObject( string? iconPath = null, @@ -40,14 +41,14 @@ public void InstalledLanguages_NoLanguagesFound() [Fact] public void InstalledLanguages() { - var expected = GetRandomLanguages(); + var expected = GITestUtilities.GetRandomLanguages(); var obj = CreatePlayableObject(languages: expected); Assert.Equivalent(expected, obj.InstalledLanguages, true); // Get a second time Assert.Equivalent(expected, obj.InstalledLanguages, true); } - public class PlayableObjectAbstractTest : CommonTestBaseWithRandomGame + public class PlayableObjectAbstractTest : GameInfrastructureTestBaseWithRandomGame { protected override void SetupServiceProvider(IServiceCollection sc) { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs index 28c1aecc..e9428f53 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs @@ -13,7 +13,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Services; -public class IconFinderTest : CommonTestBaseWithRandomGame +public class IconFinderTest : GameInfrastructureTestBaseWithRandomGame { private readonly IconFinder _iconFinder = new(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 04c3bfb0..01fae330 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -13,7 +13,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Services; -public class LanguageFinderTest : CommonTestBaseWithRandomGame +public class LanguageFinderTest : GameInfrastructureTestBaseWithRandomGame { private readonly InstalledLanguageFinder _languageFinder; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index c5ef6ac9..ed92bbd5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -1,7 +1,11 @@ -using System; -using System.Collections.Generic; +using AET.Modinfo.Model; +using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; +using PG.TestingUtilities; +using System; +using System.Collections.Generic; +using System.Linq; namespace PG.StarWarsGame.Infrastructure.Testing; @@ -11,6 +15,8 @@ public static class GITestUtilities public static ICollection RealPlatforms { get; } = [GamePlatform.Disk, GamePlatform.DiskGold, GamePlatform.SteamGold, GamePlatform.GoG, GamePlatform.Origin]; + private static readonly string[] PossibleLanguages = ["en", "de", "es", "it"]; + public static void AssertEqual(this GameDetectionResult expected, GameDetectionResult actual) { Assert.Equal(expected.Installed, actual.Installed); @@ -25,4 +31,32 @@ public static bool GetRandomWorkshopFlag(IGame game) return false; return new Random().NextDouble() >= 0.5; } + + public static IEnumerable GetRealPlatforms() + { + return RealPlatforms.Select(platform => (object[])[platform]); + } + + public static IEnumerable RealGameIdentities() + { + foreach (var platform in RealPlatforms) + { + yield return [new GameIdentity(GameType.Eaw, platform)]; + yield return [new GameIdentity(GameType.Foc, platform)]; + } + } + + public static ICollection GetRandomLanguages() + { + var languages = new HashSet(PossibleLanguages.Length); + + foreach (var _ in PossibleLanguages) + { + var code = TestHelpers.GetRandom(PossibleLanguages); + var support = TestHelpers.GetRandomEnum(); + languages.Add(new LanguageInfo(code, support)); + } + + return languages; + } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs index b0e18e4d..bbe585bf 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs @@ -11,10 +11,15 @@ public static class GameRegistryTestExtensions { public static IGameRegistry CreateNonExistingRegistry(this GameType gameType, IServiceProvider serviceProvider) { - var factory = new GameRegistryFactory(serviceProvider); - return factory.CreateRegistry(gameType); + return serviceProvider.GetRequiredService().CreateRegistry(gameType); } - + + public static IGameRegistry InstallGame(this IRegistry registry, IGame game, IServiceProvider serviceProvider) + { + InitializeRegistry(registry, TestGameRegistrySetupData.Installed(game.Type, game.Directory), null, serviceProvider); + return serviceProvider.GetRequiredService().CreateRegistry(game.Type); + } + public static IGameRegistry Create(this TestGameRegistrySetupData registrySetupData, IServiceProvider serviceProvider) { var gameRegistry = CreateNonExistingRegistry(registrySetupData.GameType, serviceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs index eeae83b2..271e6d1d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs @@ -6,7 +6,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; -public abstract partial class GameDetectorTestBase : CommonTestBase +public abstract partial class GameDetectorTestBase : GameInfrastructureTestBase { protected abstract bool SupportInitialization { get; } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs index b251cf97..30dd1084 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs @@ -17,35 +17,35 @@ private void TestDetectorGameInstalled(GameIdentity identity, params GamePlatfor } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GameInstalled_DetectWithSinglePlatform(GameIdentity identity) { TestDetectorGameInstalled(identity, identity.Platform); } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GameInstalled_NoQueryPlatformSearchesAll(GameIdentity identity) { TestDetectorGameInstalled(identity, queryPlatforms: []); } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GameInstalled_UndefinedPlatformPlatformSearchesAll(GameIdentity identity) { TestDetectorGameInstalled(identity, queryPlatforms: [GamePlatform.Undefined]); } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GameInstalled_QueryContainsUndefinedSearchesAll(GameIdentity identity) { TestDetectorGameInstalled(identity, queryPlatforms: [GamePlatform.Disk, GamePlatform.Undefined]); } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_GameNotInstalled(GameIdentity identity) { var expected = GameDetectionResult.NotInstalled(identity.Type); @@ -57,7 +57,7 @@ public void Detect_TryDetect_GameNotInstalled(GameIdentity identity) } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_TypeOfDesiredPlatformNotFound(GameIdentity identity) { // Install the opposite of the desired game type. @@ -90,7 +90,7 @@ public void Detect_TryDetect_GoG_PlatformDoesNotMatch(GameType gameType, params } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_TestRequiresGameInitialization_DetectorDoesNotHandle(GameIdentity identity) { if (!SupportInitialization) @@ -109,7 +109,7 @@ public void Detect_TryDetect_TestRequiresGameInitialization_DetectorDoesNotHandl } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_TestRequiresGameInitialization_DetectorCanHandle_ButDoesNotHandle(GameIdentity identity) { if (!SupportInitialization) @@ -127,7 +127,7 @@ public void Detect_TryDetect_TestRequiresGameInitialization_DetectorCanHandle_Bu } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_TestRequiresGameInitialization_DetectorCanHandle_DoesHandleAndGameIsInitialized(GameIdentity identity) { if (!SupportInitialization) @@ -155,7 +155,7 @@ public void Detect_TryDetect_TestRequiresGameInitialization_DetectorCanHandle_Do } [Theory] - [MemberData(nameof(RealGameIdentities))] + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_TestRequiresGameInitialization_DetectorCanHandle_DoesHandleButGameIsNotInitialized(GameIdentity identity) { if (!SupportInitialization) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/CommonTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs similarity index 63% rename from test/PG.StarWarsGame.Infrastructure.Testing/TestBases/CommonTestBase.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index e8f57b9a..e653012e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/CommonTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; -using System.Linq; using AET.Modinfo.Model; using AET.Modinfo.Spec; using Microsoft.Extensions.DependencyInjection; @@ -15,13 +13,13 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; -public abstract class CommonTestBase +public abstract class GameInfrastructureTestBase { protected readonly IServiceProvider ServiceProvider; protected readonly MockFileSystem FileSystem = new(); [SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")] - protected CommonTestBase() + protected GameInfrastructureTestBase() { var sc = new ServiceCollection(); SetupServiceProvider(sc); @@ -34,20 +32,6 @@ protected virtual void SetupServiceProvider(IServiceCollection sc) PetroglyphGameInfrastructure.InitializeServices(sc); } - public static IEnumerable RealPlatforms() - { - return GITestUtilities.RealPlatforms.Select(platform => (object[])[platform]); - } - - public static IEnumerable RealGameIdentities() - { - foreach (var platform in GITestUtilities.RealPlatforms) - { - yield return [new GameIdentity(GameType.Eaw, platform)]; - yield return [new GameIdentity(GameType.Foc, platform)]; - } - } - protected static GameIdentity CreateRandomGameIdentity() { return new GameIdentity(TestHelpers.GetRandomEnum(), TestHelpers.GetRandom(GITestUtilities.RealPlatforms)); @@ -58,22 +42,6 @@ protected PetroglyphStarWarsGame CreateRandomGame() return FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); } - private static readonly string[] PossibleLanguages = ["en", "de", "es", "it"]; - - protected static ICollection GetRandomLanguages() - { - var languages = new HashSet(PossibleLanguages.Length); - - foreach (var _ in PossibleLanguages) - { - var code = TestHelpers.GetRandom(PossibleLanguages); - var support = TestHelpers.GetRandomEnum(); - languages.Add(new LanguageInfo(code, support)); - } - - return languages; - } - protected IMod CreateAndAddMod(IGame game, bool isWorkshop, string name, IModDependencyList dependencies) { if (dependencies.Count == 0) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/CommonTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs similarity index 84% rename from test/PG.StarWarsGame.Infrastructure.Testing/TestBases/CommonTestBaseWithRandomGame.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 7c994c41..a6663b63 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/CommonTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -6,11 +6,11 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; -public abstract class CommonTestBaseWithRandomGame : CommonTestBase +public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastructureTestBase { protected readonly IGame Game; - protected CommonTestBaseWithRandomGame() + protected GameInfrastructureTestBaseWithRandomGame() { Game = CreateRandomGame(); } From 80c2b3235e52a41587432b3bdc7b6dd59b4f47e9 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 17:09:31 +0100 Subject: [PATCH 03/71] allow all FS --- test/AET.SteamAbstraction.Testing/AssemblyInfo.cs | 3 +-- .../SteamInstallationExtensions.cs | 5 ++--- .../TestingSteamInstallationImpl.Library.cs | 2 +- .../TestingSteamInstallationImpl.User.cs | 2 +- .../TestingSteamInstallationImpl.cs | 2 +- .../Game/Installation/GameInstallation.Eaw.cs | 12 ++++++------ .../Game/Installation/GameInstallation.Foc.cs | 12 ++++++------ .../Game/Installation/GameInstallation.cs | 14 +++++++------- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs b/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs index 41944430..81d8889c 100644 --- a/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs +++ b/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs @@ -1,4 +1,3 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("AET.SteamAbstraction.Test")] -//[assembly: InternalsVisibleTo("PG.StarWarsGame.Infrastructure.Clients.Steam.Test")] +[assembly: InternalsVisibleTo("AET.SteamAbstraction.Test")] \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs index c893f82f..6b0bbb89 100644 --- a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs +++ b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs @@ -1,5 +1,4 @@ -using AET.SteamAbstraction.Testing.Installation; -using System; +using System; using System.IO.Abstractions; using Testably.Abstractions.Testing; @@ -7,7 +6,7 @@ namespace AET.SteamAbstraction.Testing; public static class SteamInstallationExtensions { - public static ITestingSteamInstallation Steam(this MockFileSystem fs, IServiceProvider serviceProvider) + public static ITestingSteamInstallation Steam(this IFileSystem fs, IServiceProvider serviceProvider) { return new TestingSteamInstallationImpl(fs, serviceProvider); } diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index 438dcc17..ced27154 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -7,7 +7,7 @@ using PG.TestingUtilities; using Xunit; -namespace AET.SteamAbstraction.Testing.Installation; +namespace AET.SteamAbstraction.Testing; internal sealed partial class TestingSteamInstallationImpl { diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs index 9d7a5430..e581fb07 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace AET.SteamAbstraction.Testing.Installation; +namespace AET.SteamAbstraction.Testing; internal sealed partial class TestingSteamInstallationImpl { public void DeleteLoginUsersFile() diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs index b6efb65c..3c40336e 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs @@ -1,7 +1,7 @@ using System; using System.IO.Abstractions; -namespace AET.SteamAbstraction.Testing.Installation; +namespace AET.SteamAbstraction.Testing; internal sealed partial class TestingSteamInstallationImpl(IFileSystem fileSystem, IServiceProvider serviceProvider) : ITestingSteamInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs index bcce128d..5351e917 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs @@ -11,7 +11,7 @@ public static partial class GameInstallation private const string EawGoldPath = "games/gold/eaw"; private const string EawGameDataSubPath = "GameData"; - private static IDirectoryInfo InstallEaw(this MockFileSystem fs, GamePlatform platform) + private static IDirectoryInfo InstallEaw(this IFileSystem fs, GamePlatform platform) { IDirectoryInfo gameDirectory; switch (platform) @@ -39,7 +39,7 @@ private static IDirectoryInfo InstallEaw(this MockFileSystem fs, GamePlatform pl return gameDirectory; } - private static IDirectoryInfo InstallEawDisk(this MockFileSystem fs) + private static IDirectoryInfo InstallEawDisk(this IFileSystem fs) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(EawNormalPath, "sweaw.exe")); @@ -47,7 +47,7 @@ private static IDirectoryInfo InstallEawDisk(this MockFileSystem fs) return gameDir; } - private static IDirectoryInfo InstallEawOrigin(this MockFileSystem fs) + private static IDirectoryInfo InstallEawOrigin(this IFileSystem fs) { var basePath = fs.Path.Combine(OriginBasePath, EawGameDataSubPath); @@ -58,7 +58,7 @@ private static IDirectoryInfo InstallEawOrigin(this MockFileSystem fs) return fs.DirectoryInfo.New(basePath); } - private static IDirectoryInfo InstallEawGog(this MockFileSystem fs) + private static IDirectoryInfo InstallEawGog(this IFileSystem fs) { var basePath = fs.Path.Combine(GogBasePath, EawGameDataSubPath); @@ -70,7 +70,7 @@ private static IDirectoryInfo InstallEawGog(this MockFileSystem fs) return fs.DirectoryInfo.New(basePath); } - private static IDirectoryInfo InstallEawSteam(this MockFileSystem fs) + private static IDirectoryInfo InstallEawSteam(this IFileSystem fs) { var basePath = fs.Path.Combine(SteamBasePath, EawGameDataSubPath); @@ -82,7 +82,7 @@ private static IDirectoryInfo InstallEawSteam(this MockFileSystem fs) return fs.DirectoryInfo.New(fs.Path.Combine(basePath)); } - private static IDirectoryInfo InstallEawDiskGold(this MockFileSystem fs) + private static IDirectoryInfo InstallEawDiskGold(this IFileSystem fs) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(EawGoldPath, EawGameDataSubPath, "sweaw.exe")); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs index 24eaa91e..1dbe963a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs @@ -18,7 +18,7 @@ public static IDirectoryInfo GetWrongOriginFocRegistryLocation(this IFileSystem return fs.DirectoryInfo.New(fs.Path.Combine(OriginBasePath, "corruption")); } - public static IDirectoryInfo InstallFoc(MockFileSystem fs, GamePlatform platform) + public static IDirectoryInfo InstallFoc(IFileSystem fs, GamePlatform platform) { IDirectoryInfo gameDirectory; switch (platform) @@ -46,7 +46,7 @@ public static IDirectoryInfo InstallFoc(MockFileSystem fs, GamePlatform platform return gameDirectory; } - private static IDirectoryInfo InstallFocDisk(this MockFileSystem fs) + private static IDirectoryInfo InstallFocDisk(this IFileSystem fs) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(FocNormalPath, "swfoc.exe")); @@ -54,7 +54,7 @@ private static IDirectoryInfo InstallFocDisk(this MockFileSystem fs) return gameDir; } - private static IDirectoryInfo InstallFocOrigin(this MockFileSystem fs) + private static IDirectoryInfo InstallFocOrigin(this IFileSystem fs) { var basePath = fs.Path.Combine(OriginBasePath, FocOriginSubPath); @@ -66,7 +66,7 @@ private static IDirectoryInfo InstallFocOrigin(this MockFileSystem fs) return fs.DirectoryInfo.New(basePath); } - private static IDirectoryInfo InstallFocGog(this MockFileSystem fs) + private static IDirectoryInfo InstallFocGog(this IFileSystem fs) { var basePath = fs.Path.Combine(GogBasePath, FocGogSubPath); @@ -77,7 +77,7 @@ private static IDirectoryInfo InstallFocGog(this MockFileSystem fs) return fs.DirectoryInfo.New(basePath); } - private static IDirectoryInfo InstallFocSteam(this MockFileSystem fs) + private static IDirectoryInfo InstallFocSteam(this IFileSystem fs) { var basePath = fs.Path.Combine(SteamBasePath, FocSteamSubPath); @@ -89,7 +89,7 @@ private static IDirectoryInfo InstallFocSteam(this MockFileSystem fs) return fs.DirectoryInfo.New(basePath); } - private static IDirectoryInfo InstallFocDiskGold(this MockFileSystem fs) + private static IDirectoryInfo InstallFocDiskGold(this IFileSystem fs) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(FocGoldPath, "swfoc.exe")); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs index f17b0f9d..3f442cd7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs @@ -12,9 +12,9 @@ public static partial class GameInstallation private const string GogBasePath = "games/gog"; private const string OriginBasePath = "games/origin"; - public static PetroglyphStarWarsGame InstallGame(this MockFileSystem fs, GameIdentity gameIdentity, IServiceProvider sp) + public static PetroglyphStarWarsGame InstallGame(this IFileSystem fs, GameIdentity gameIdentity, IServiceProvider sp) { - Func installFunc; + Func installFunc; if (gameIdentity.Type == GameType.Foc) installFunc = InstallFoc; @@ -39,13 +39,13 @@ public static void InstallDebug(this IGame game) CreateFile(fs, fs.Path.Combine(game.Directory.FullName, "StarWarsI.exe")); } - private static void InstallDataAndMegaFilesXml(this MockFileSystem fs, IDirectoryInfo directory) + private static void InstallDataAndMegaFilesXml(this IFileSystem fs, IDirectoryInfo directory) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(directory.FullName, "Data", "megafiles.xml")); } - private static void InstallSteamFiles(this MockFileSystem fs, Action initAction) + private static void InstallSteamFiles(this IFileSystem fs, Action initAction) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(SteamBasePath, "32470_install.vdf")); @@ -59,7 +59,7 @@ private static void InstallSteamFiles(this MockFileSystem fs, Action initAction) initAction(); } - private static void InstallGoGFiles(this MockFileSystem fs, Action initAction) + private static void InstallGoGFiles(this IFileSystem fs, Action initAction) { fs.Initialize(); CreateFile(fs, fs.Path.Combine(GogBasePath, "goggame.sdb")); @@ -69,7 +69,7 @@ private static void InstallGoGFiles(this MockFileSystem fs, Action initAction) initAction(); } - private static void InstallOriginFiles(this MockFileSystem fs, Action initAction) + private static void InstallOriginFiles(this IFileSystem fs, Action initAction) { fs.Initialize(); fs.Directory.CreateDirectory(fs.Path.Combine(OriginBasePath, "Manuals")); @@ -77,7 +77,7 @@ private static void InstallOriginFiles(this MockFileSystem fs, Action initAction initAction(); } - private static void InstallModsLocations(this MockFileSystem fileSystem, IDirectoryInfo directory) + private static void InstallModsLocations(this IFileSystem fileSystem, IDirectoryInfo directory) { fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(directory.FullName, "Mods")); } From 170804a8543880df430abfec674ea328eea6a507 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 17:38:48 +0100 Subject: [PATCH 04/71] reorganize solution --- PetroGlyphGameInfrastructure.slnx | 4 ++- .../Properties/AssemblyInfo.cs | 2 +- .../AET.SteamAbstraction.Testing.csproj | 27 +++++++++++++------ ...StarWarsGame.Infrastructure.Testing.csproj | 27 +++++++++++++------ .../PG.TestingUtilities.csproj | 11 ++++---- 5 files changed, 48 insertions(+), 23 deletions(-) diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index c29d09ef..d96e3df2 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -6,9 +6,11 @@ - + + + diff --git a/src/AET.SteamAbstraction/Properties/AssemblyInfo.cs b/src/AET.SteamAbstraction/Properties/AssemblyInfo.cs index 372482c9..333fabca 100644 --- a/src/AET.SteamAbstraction/Properties/AssemblyInfo.cs +++ b/src/AET.SteamAbstraction/Properties/AssemblyInfo.cs @@ -1,7 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("AET.SteamAbstraction.Test")] -[assembly: InternalsVisibleTo("AET.SteamAbstraction.TestingUtilities")] +[assembly: InternalsVisibleTo("AET.SteamAbstraction.Testing")] [assembly: InternalsVisibleTo("PG.StarWarsGame.Infrastructure.Clients.Steam.Test")] diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 7f32d61f..6e567a61 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -1,21 +1,32 @@  - AET.SteamAbstraction.TestingUtilities - - - + AET.SteamAbstraction.Testing netstandard2.0 - false + true false - - - + + AET.SteamAbstraction.Testing + Provides a testing layer that allowes to virtualize Steam, so that it does not need to be physically installed. + AlamoEngineTools.SteamAbstraction.Testing + alamo,petroglyph,glyphx + en + + + + true + true + + + true + snupkg + + all diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 72f1d12e..abd59c77 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -1,19 +1,30 @@ - + PG.StarWarsGame.Infrastructure.TestingUtilities - - - net10.0 $(TargetFrameworks);net481 - false + true false - - - + + PG.StarWarsGame.Infrastructure.Testing + Provides a testing layer that allowes to virtualize PG Star Wars game installations, so that they do not need to be physically installed. + AlamoEngineTools.PG.StarWarsGame.Infrastructure.Testing + alamo,petroglyph,glyphx + en + + + + + true + true + + + true + snupkg + diff --git a/test/PG.TestingUtilities/PG.TestingUtilities.csproj b/test/PG.TestingUtilities/PG.TestingUtilities.csproj index 16fc0df1..afa2749d 100644 --- a/test/PG.TestingUtilities/PG.TestingUtilities.csproj +++ b/test/PG.TestingUtilities/PG.TestingUtilities.csproj @@ -1,8 +1,9 @@ - net10.0 - $(TargetFrameworks);net481 + netstandard2.0 + false false @@ -12,12 +13,12 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + From a819d7055548f9930d7350ff51dc3ad55eb89ba2 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 17:43:53 +0100 Subject: [PATCH 05/71] disable on linux atm --- test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index b9dd518d..8d803355 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -40,7 +40,8 @@ public void Dispose() _steam.Dispose(); } - [Fact] + // TODO: Target all platforms + [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_SteamNotFound_ReturnsEmpty() { Assert.Empty(_libraryFinder.FindLibraries(_fileSystem.DirectoryInfo.New("not steam"))); From 65e9d9b20abccec85aa35adcd3e79dff03605da5 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 17:52:31 +0100 Subject: [PATCH 06/71] try make test more stable --- .../Clients/Processes/GameProcessLauncherTest.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs index 09842c81..31686c6b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs @@ -34,7 +34,9 @@ public GameProcessLauncherTest() _executable = _realFileSystem.FileInfo.New(_realFileSystem.Path.Combine(tempDir, executableName)); var scriptContent = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) - ? "@echo off\nexit 0" + ? "@echo off\r\n" + + "timeout /t 5 /nobreak >nul\r\n" + + "exit 0" : "#!/bin/bash\nsleep 5\nexit 0"; _realFileSystem.File.WriteAllText(_executable.FullName,scriptContent); From 85ddd21a9370b918c1d785cc4afa1d75e3e4fdac Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 17:52:41 +0100 Subject: [PATCH 07/71] to netstandard --- .../AET.SteamAbstraction.Testing.csproj | 24 ++++++++----------- .../GITestUtilities.cs | 2 +- ...StarWarsGame.Infrastructure.Testing.csproj | 21 +++++++--------- .../PG.TestingUtilities.csproj | 11 +-------- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 6e567a61..b839973c 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -2,8 +2,6 @@ AET.SteamAbstraction.Testing - netstandard2.0 true false @@ -27,28 +25,26 @@ snupkg + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - all + runtime; build; native; contentfiles; analyzers; buildtransitive + all - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index ed92bbd5..2c3aed68 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -48,7 +48,7 @@ public static IEnumerable RealGameIdentities() public static ICollection GetRandomLanguages() { - var languages = new HashSet(PossibleLanguages.Length); + var languages = new HashSet(); foreach (var _ in PossibleLanguages) { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index abd59c77..64c10e18 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -2,8 +2,7 @@ PG.StarWarsGame.Infrastructure.TestingUtilities - net10.0 - $(TargetFrameworks);net481 + netstandard2.0 true false @@ -26,28 +25,26 @@ snupkg + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - runtime; build; native; contentfiles; analyzers; buildtransitive all + runtime; build; native; contentfiles; analyzers; buildtransitive runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - diff --git a/test/PG.TestingUtilities/PG.TestingUtilities.csproj b/test/PG.TestingUtilities/PG.TestingUtilities.csproj index afa2749d..bb29ecce 100644 --- a/test/PG.TestingUtilities/PG.TestingUtilities.csproj +++ b/test/PG.TestingUtilities/PG.TestingUtilities.csproj @@ -2,28 +2,19 @@ netstandard2.0 - false false + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - From dc7349c8071086ecd26fa661d6631ec9211e3cca Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 19:28:08 +0100 Subject: [PATCH 08/71] remove empty struct --- .../SteamPetroglyphStarWarsGameDetectorTest.cs | 17 ++++++++--------- .../Detection/DirectoryGameDetectorTest.cs | 13 ++++++------- test/PG.TestingUtilities/EmptyStruct.cs | 6 ------ 3 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 test/PG.TestingUtilities/EmptyStruct.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 4a38f749..762bc691 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -13,12 +13,11 @@ using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; -public class SteamPetroglyphStarWarsGameDetectorTest : GameDetectorTestBase +public class SteamPetroglyphStarWarsGameDetectorTest : GameDetectorTestBase { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); @@ -35,12 +34,12 @@ protected override void SetupServiceProvider(IServiceCollection sc) SteamPetroglyphStarWarsGameClients.InitializeServices(sc); } - protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) + protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) { return new SteamPetroglyphStarWarsGameDetector(ServiceProvider); } - protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) + protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { return SetupGame(gameIdentity, (game, otherGameType) => { @@ -49,7 +48,7 @@ protected override GameDetectorTestInfo SetupGame(GameIdentity game }); } - protected override GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity) + protected override GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity) { return SetupGame(gameIdentity, (game, otherGameType) => { @@ -58,7 +57,7 @@ protected override GameDetectorTestInfo SetupForRequiredInitializat }); } - protected override void HandleInitialization(bool shallInitSuccessfully, GameDetectorTestInfo info) + protected override void HandleInitialization(bool shallInitSuccessfully, GameDetectorTestInfo info) { if (!shallInitSuccessfully) return; @@ -124,7 +123,7 @@ public void Detect_SteamInstalledButGameNotFullyInstalled_ShouldReturnNotInstall expected.AssertEqual(result); } - private GameDetectorTestInfo SetupGame( + private GameDetectorTestInfo SetupGame( GameIdentity gameIdentity, Action registrySetup, SteamAppState appState = SteamAppState.StateFullyInstalled) @@ -134,7 +133,7 @@ private GameDetectorTestInfo SetupGame( steam.Install(); if (gameIdentity.Platform != GamePlatform.SteamGold) - return new GameDetectorTestInfo(gameIdentity.Type, null, default); + return new GameDetectorTestInfo(gameIdentity.Type, null, null); // Install Game var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); @@ -148,7 +147,7 @@ private GameDetectorTestInfo SetupGame( var otherGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; registrySetup(game, otherGameType); - return new GameDetectorTestInfo(gameIdentity.Type, game.Directory, default); + return new GameDetectorTestInfo(gameIdentity.Type, game.Directory, null); } } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs index e988ac86..04c85242 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs @@ -6,24 +6,23 @@ using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.GameServices.Detection; -public class DirectoryGameDetectorTest : GameDetectorTestBase +public class DirectoryGameDetectorTest : GameDetectorTestBase { protected override bool SupportInitialization => false; protected override ICollection SupportedPlatforms => GITestUtilities.RealPlatforms; protected override bool CanDisableInitRequest => false; - protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) + protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) { return new DirectoryGameDetector(gameInfo.GameDirectory ?? FileSystem.DirectoryInfo.New("doesNotExist"), ServiceProvider); } - protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) + protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); return new(gameIdentity.Type, game.Directory, default); @@ -84,15 +83,15 @@ private void TestNotInstalledWithCustomSetup(GameIdentity identity, Func new GameDetectorTestInfo(identity.Type, customSetup(identity), default), + _ => new GameDetectorTestInfo(identity.Type, customSetup(identity), default), _ => expected, null, queryPlatforms: []); } - protected override GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity) + protected override GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity) => throw new NotSupportedException(); - protected override void HandleInitialization(bool shallInitSuccessfully, GameDetectorTestInfo info) + protected override void HandleInitialization(bool shallInitSuccessfully, GameDetectorTestInfo info) => throw new NotSupportedException(); } \ No newline at end of file diff --git a/test/PG.TestingUtilities/EmptyStruct.cs b/test/PG.TestingUtilities/EmptyStruct.cs deleted file mode 100644 index 826f4a15..00000000 --- a/test/PG.TestingUtilities/EmptyStruct.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System.Runtime.InteropServices; - -namespace PG.TestingUtilities; - -[StructLayout(LayoutKind.Explicit)] -public struct EmptyStruct; \ No newline at end of file From 6a16791fd7a317dced0303eac139524432d0e35e Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 15 Dec 2025 19:49:26 +0100 Subject: [PATCH 09/71] start extracting to shared proj --- PetroGlyphGameInfrastructure.slnx | 1 + .../AET.SteamAbstraction.Test.csproj | 6 ++++++ .../AET.SteamAbstraction.Testing.csproj | 6 ++++++ test/AET.Testing/AET.Testing.projitems | 14 ++++++++++++++ test/AET.Testing/AET.Testing.shproj | 13 +++++++++++++ .../TestHelpers.cs | 2 +- .../PG.StarWarsGame.Infrastructure.Test.csproj | 6 ++++++ .../PG.StarWarsGame.Infrastructure.Testing.csproj | 6 ++++++ 8 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 test/AET.Testing/AET.Testing.projitems create mode 100644 test/AET.Testing/AET.Testing.shproj rename test/{PG.TestingUtilities => AET.Testing}/TestHelpers.cs (98%) diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index d96e3df2..3f91aecf 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -10,6 +10,7 @@ + diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 7af86b95..dfeedee1 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -40,6 +40,12 @@ + + + ..\AET.SteamAbstraction.Testing\bin\Debug\netstandard2.0\PG.TestingUtilities.dll + + + true true diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index b839973c..bf25ae1d 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -56,4 +56,10 @@ + + + bin\Debug\netstandard2.0\PG.TestingUtilities.dll + + + diff --git a/test/AET.Testing/AET.Testing.projitems b/test/AET.Testing/AET.Testing.projitems new file mode 100644 index 00000000..fa671674 --- /dev/null +++ b/test/AET.Testing/AET.Testing.projitems @@ -0,0 +1,14 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + f52e1de8-1a9f-41c0-aae4-935c35783026 + + + AET.Testing + + + + + \ No newline at end of file diff --git a/test/AET.Testing/AET.Testing.shproj b/test/AET.Testing/AET.Testing.shproj new file mode 100644 index 00000000..65189b1d --- /dev/null +++ b/test/AET.Testing/AET.Testing.shproj @@ -0,0 +1,13 @@ + + + + f52e1de8-1a9f-41c0-aae4-935c35783026 + 14.0 + + + + + + + + diff --git a/test/PG.TestingUtilities/TestHelpers.cs b/test/AET.Testing/TestHelpers.cs similarity index 98% rename from test/PG.TestingUtilities/TestHelpers.cs rename to test/AET.Testing/TestHelpers.cs index 3960f1a6..3cbb4e23 100644 --- a/test/PG.TestingUtilities/TestHelpers.cs +++ b/test/AET.Testing/TestHelpers.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; -namespace PG.TestingUtilities; +namespace AET.Testing; public static class TestHelpers { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index 29c43ac0..5667e8bb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -37,4 +37,10 @@ + + + ..\AET.SteamAbstraction.Testing\bin\Debug\netstandard2.0\PG.TestingUtilities.dll + + + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 64c10e18..f12307a2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -52,6 +52,12 @@ + + + ..\AET.SteamAbstraction.Testing\bin\Debug\netstandard2.0\PG.TestingUtilities.dll + + + From f9f48e79ed473dac8c0ce89f0fae890de0f852b9 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 11:11:05 +0100 Subject: [PATCH 10/71] try use shared proj --- .../AET.SteamAbstraction.Test.csproj | 6 ------ test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs | 2 +- test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs | 2 +- .../AET.SteamAbstraction.Testing.csproj | 7 +------ .../SteamInstallationExtensions.cs | 1 - .../TestingSteamInstallationImpl.Library.cs | 2 +- .../Clients/Arguments/FlagArgumentTest.cs | 2 +- .../Clients/Arguments/GameArgumentTest.cs | 4 ++-- .../Clients/Arguments/GameArgumentTestBase.cs | 2 +- .../Clients/Arguments/GameArgumentTestClasses.cs | 4 ++-- .../Clients/Arguments/NamedArgumentTest.cs | 2 +- .../GameIdentityTest.cs | 4 ++-- .../GameServices/GameFactoryTest.cs | 2 +- .../GameServices/SteamGameHelpersTest.cs | 2 +- .../PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs | 2 +- .../ModEqualityComparerTest.cs | 2 +- .../Dependencies/ModDependencyGraphBuilderTest.cs | 2 +- .../Dependencies/ModDependencyTraverserTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 2 +- .../ModServices/ModFinderTest.cs | 2 +- .../ModServices/ModGameTypeResolverTestBase.cs | 2 +- .../ModServices/OnlineModGameTypeResolverTest.cs | 2 +- .../PG.StarWarsGame.Infrastructure.Test.csproj | 6 ------ .../PetroglyphStarWarsGameTest.cs | 2 +- .../GITestUtilities.cs | 2 +- .../PG.StarWarsGame.Infrastructure.Testing.csproj | 10 +--------- .../TestBases/GameInfrastructureTestBase.cs | 2 +- 27 files changed, 27 insertions(+), 53 deletions(-) diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index dfeedee1..7af86b95 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -40,12 +40,6 @@ - - - ..\AET.SteamAbstraction.Testing\bin\Debug\netstandard2.0\PG.TestingUtilities.dll - - - true true diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index 4a8b06d2..159a5a48 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -3,9 +3,9 @@ using System.IO.Abstractions; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing; +using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 9d5f7065..52d28e95 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -8,9 +8,9 @@ using AET.SteamAbstraction.Library; using AET.SteamAbstraction.Testing; using AET.SteamAbstraction.Utilities; +using AET.Testing; using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index bf25ae1d..2c9d054e 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -56,10 +56,5 @@ - - - bin\Debug\netstandard2.0\PG.TestingUtilities.dll - - - + diff --git a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs index 6b0bbb89..01624f5c 100644 --- a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs +++ b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs @@ -1,6 +1,5 @@ using System; using System.IO.Abstractions; -using Testably.Abstractions.Testing; namespace AET.SteamAbstraction.Testing; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index ced27154..4bd227d1 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -3,8 +3,8 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; +using AET.Testing; using AnakinRaW.CommonUtilities.FileSystem; -using PG.TestingUtilities; using Xunit; namespace AET.SteamAbstraction.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs index f78e7858..c69bebe1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs @@ -1,6 +1,6 @@ using System; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Clients.Arguments; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs index c90e2e04..3037a842 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs @@ -1,5 +1,5 @@ -using PG.StarWarsGame.Infrastructure.Clients.Arguments; -using PG.TestingUtilities; +using AET.Testing; +using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs index 25458c52..27d9cb4f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs @@ -4,9 +4,9 @@ using System.Runtime.InteropServices; using AET.Modinfo.Model; using AET.Modinfo.Spec; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; -using PG.TestingUtilities; using Testably.Abstractions.Testing; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs index 10dbb8b4..7b41fd72 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs @@ -1,6 +1,6 @@ -using PG.StarWarsGame.Infrastructure.Clients.Arguments; +using AET.Testing; +using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.CommandLine; -using PG.TestingUtilities; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs index 50a8ce29..fda23b63 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs @@ -1,7 +1,7 @@ using System; +using AET.Testing; using AnakinRaW.CommonUtilities.FileSystem.Normalization; using PG.StarWarsGame.Infrastructure.Clients.Arguments; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs index 7049a017..68ee1374 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs @@ -1,5 +1,5 @@ -using PG.StarWarsGame.Infrastructure.Games; -using PG.TestingUtilities; +using AET.Testing; +using PG.StarWarsGame.Infrastructure.Games; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index 42d88ab3..dfdf503d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services; @@ -9,7 +10,6 @@ using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.GameServices; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs index 9b2f8bad..704329d0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs @@ -1,10 +1,10 @@ using System; +using AET.Testing; using AnakinRaW.CommonUtilities.FileSystem.Normalization; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.GameServices; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 5b40ecfc..845a1c90 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -3,10 +3,10 @@ using System.Linq; using AET.Modinfo.Model; using AET.Modinfo.Spec; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Mods; -using PG.TestingUtilities; using Xunit; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index e9e449eb..dcb11764 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using AET.Modinfo.Model; using AET.Modinfo.Spec; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 5c7a1d94..30ffa089 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using AET.Modinfo.Model; using AET.Modinfo.Spec; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 5740e49c..1ae2f20b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -1,11 +1,11 @@ using System; using AET.Modinfo.Spec; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.ModServices.Dependencies; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 2a0c0022..734af8fd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -8,6 +8,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; @@ -17,7 +18,6 @@ using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 384adc95..41a345b7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -7,6 +7,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; @@ -16,7 +17,6 @@ using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 977ba768..df2ed0a9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -6,6 +6,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; @@ -14,7 +15,6 @@ using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.ModServices; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs index 57854c23..844e9e84 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; using AET.Modinfo.Spec; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.ModServices; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index 5667e8bb..29c43ac0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -37,10 +37,4 @@ - - - ..\AET.SteamAbstraction.Testing\bin\Debug\netstandard2.0\PG.TestingUtilities.dll - - - diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index a1f36a83..da7d6f24 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using AET.Modinfo.Spec; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index 2c3aed68..c55a56a3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -2,10 +2,10 @@ using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; -using PG.TestingUtilities; using System; using System.Collections.Generic; using System.Linq; +using AET.Testing; namespace PG.StarWarsGame.Infrastructure.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index f12307a2..941db4f6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -52,14 +52,6 @@ - - - ..\AET.SteamAbstraction.Testing\bin\Debug\netstandard2.0\PG.TestingUtilities.dll - - - - - - + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index e653012e..1488ab0e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -3,12 +3,12 @@ using System.IO.Abstractions; using AET.Modinfo.Model; using AET.Modinfo.Spec; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; -using PG.TestingUtilities; using Testably.Abstractions.Testing; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; From a8126035d091aa933d70b651acacf2d557430bf4 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 11:15:06 +0100 Subject: [PATCH 11/71] explicit usings --- .../Clients/TestGameProcessLauncher.cs | 1 + test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs | 1 + .../Game/Installation/GameInstallation.cs | 1 + .../Game/Registry/GameRegistryTestExtensions.cs | 1 + .../Mods/ModInstallations.cs | 1 + .../PlayableObjectTestingExtensions.cs | 1 + .../TestBases/GameDetectorTestBase.cs | 1 + .../TestBases/GameDetectorTestBase_Tests.cs | 1 + 8 files changed, 8 insertions(+) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs index 24781aed..c2fb3d94 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs @@ -4,6 +4,7 @@ using System.Runtime.InteropServices; using PG.StarWarsGame.Infrastructure.Clients; using PG.StarWarsGame.Infrastructure.Clients.Processes; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Clients; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index c55a56a3..9e3f1046 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using AET.Testing; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs index 3f442cd7..04d78e78 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs @@ -2,6 +2,7 @@ using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs index bbe585bf..4b7634a6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs index 7037d205..8410d975 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs @@ -6,6 +6,7 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Utilities; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs index b6a88ffe..3de6f41c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs @@ -1,6 +1,7 @@ using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Services.Language; using PG.StarWarsGame.Infrastructure.Utilities; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs index 271e6d1d..af63094d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs index 30dd1084..c85f49bd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs @@ -1,5 +1,6 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; +using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; From 6e8cd98deeab5e606897a49ffb43753b276ad68a Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 11:24:35 +0100 Subject: [PATCH 12/71] move private project ref --- .../AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj | 1 + .../AET.SteamAbstraction.Testing.csproj | 1 - .../PG.StarWarsGame.Infrastructure.Test.csproj | 3 ++- .../PG.StarWarsGame.Infrastructure.Testing.csproj | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 7af86b95..3c3706ce 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -38,6 +38,7 @@ + diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 2c9d054e..c8298891 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -53,7 +53,6 @@ - diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index 29c43ac0..fd14bafc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -1,4 +1,4 @@ - + PG.StarWarsGame.Infrastructure.Test @@ -35,6 +35,7 @@ + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 941db4f6..1c6a46a1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -49,7 +49,6 @@ - From 57fdda501b04b6b020a7c7e538ef6334cb098073 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 12:51:38 +0100 Subject: [PATCH 13/71] to own project --- PetroGlyphGameInfrastructure.slnx | 3 +- .../ThrowHelper.cs | 1 + .../CallerArgumentExpressionAttribute.cs | 6 ++-- .../AET.SteamAbstraction.Test.csproj | 2 +- .../SteamLibraryFinderTest.cs | 2 +- .../SteamWrapperFactoryTest.cs | 2 +- .../AET.SteamAbstraction.Testing.csproj | 11 +----- test/AET.Testing/AET.Testing.csproj | 36 +++++++++++++++++++ test/AET.Testing/AET.Testing.projitems | 14 -------- test/AET.Testing/AET.Testing.shproj | 13 ------- .../PlatformSpecificFactAttribute.cs | 3 +- .../PlatformSpecificTheoryAttribute.cs | 3 +- .../Attributes}/TestPlatformIdentifier.cs | 2 +- test/AET.Testing/ExceptionHelpers.cs | 29 +++++++++++++++ .../ReferenceEqualityComparer.cs | 2 +- .../Arguments/ArgumentValueSerializerTest.cs | 2 +- .../GameExceptionTest.cs | 8 ++--- .../Registry/GameRegistryIntegrationTest.cs | 2 +- ...PG.StarWarsGame.Infrastructure.Test.csproj | 2 +- .../PlayableModContainerTest.cs | 2 +- ...StarWarsGame.Infrastructure.Testing.csproj | 12 +------ test/PG.TestingUtilities/ExceptionTest.cs | 20 ----------- .../PG.TestingUtilities.csproj | 20 ----------- 23 files changed, 90 insertions(+), 107 deletions(-) create mode 100644 test/AET.Testing/AET.Testing.csproj delete mode 100644 test/AET.Testing/AET.Testing.projitems delete mode 100644 test/AET.Testing/AET.Testing.shproj rename test/{PG.TestingUtilities => AET.Testing/Attributes}/PlatformSpecificFactAttribute.cs (92%) rename test/{PG.TestingUtilities => AET.Testing/Attributes}/PlatformSpecificTheoryAttribute.cs (92%) rename test/{PG.TestingUtilities => AET.Testing/Attributes}/TestPlatformIdentifier.cs (74%) create mode 100644 test/AET.Testing/ExceptionHelpers.cs rename test/{PG.TestingUtilities => AET.Testing}/ReferenceEqualityComparer.cs (94%) delete mode 100644 test/PG.TestingUtilities/ExceptionTest.cs delete mode 100644 test/PG.TestingUtilities/PG.TestingUtilities.csproj diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index 3f91aecf..6a3d4a42 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -10,10 +10,9 @@ - + - diff --git a/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs b/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs index 401eb717..07bab13c 100644 --- a/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs +++ b/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; +using PG.StarWarsGame.Infrastructure.Utilities.CompilerServices; namespace PG.StarWarsGame.Infrastructure; diff --git a/src/PG.StarWarsGame.Infrastructure/Utilities/CompilerServices/CallerArgumentExpressionAttribute.cs b/src/PG.StarWarsGame.Infrastructure/Utilities/CompilerServices/CallerArgumentExpressionAttribute.cs index 093da83f..91d5d562 100644 --- a/src/PG.StarWarsGame.Infrastructure/Utilities/CompilerServices/CallerArgumentExpressionAttribute.cs +++ b/src/PG.StarWarsGame.Infrastructure/Utilities/CompilerServices/CallerArgumentExpressionAttribute.cs @@ -1,6 +1,8 @@ -#if !NET +using System; + +#if !NET #pragma warning disable IDE0130 -namespace System.Runtime.CompilerServices; +namespace PG.StarWarsGame.Infrastructure.Utilities.CompilerServices; #pragma warning restore IDE0130 [AttributeUsage(AttributeTargets.Parameter)] diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 3c3706ce..3914c501 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -38,7 +38,7 @@ - + diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index 8d803355..5784128a 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -6,9 +6,9 @@ using AET.SteamAbstraction.Library; using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Testing; +using AET.Testing.Attributes; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs b/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs index 5d104d6f..8861a44f 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs @@ -1,8 +1,8 @@ using System; using System.IO.Abstractions; +using AET.Testing.Attributes; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index c8298891..99a90cfd 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -33,14 +33,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -53,7 +45,6 @@ + - - diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj new file mode 100644 index 00000000..8714df1e --- /dev/null +++ b/test/AET.Testing/AET.Testing.csproj @@ -0,0 +1,36 @@ + + + + AET.Testing + netstandard2.0;net10.0 + true + false + + + + AET.Testing + Provides common utilities for testing projects, used by Alamo Engine Tools. + AlamoEngineTools.Testing + alamo,petroglyph,glyphx,testing + en + + + + + true + true + + + true + snupkg + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/test/AET.Testing/AET.Testing.projitems b/test/AET.Testing/AET.Testing.projitems deleted file mode 100644 index fa671674..00000000 --- a/test/AET.Testing/AET.Testing.projitems +++ /dev/null @@ -1,14 +0,0 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - f52e1de8-1a9f-41c0-aae4-935c35783026 - - - AET.Testing - - - - - \ No newline at end of file diff --git a/test/AET.Testing/AET.Testing.shproj b/test/AET.Testing/AET.Testing.shproj deleted file mode 100644 index 65189b1d..00000000 --- a/test/AET.Testing/AET.Testing.shproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - f52e1de8-1a9f-41c0-aae4-935c35783026 - 14.0 - - - - - - - - diff --git a/test/PG.TestingUtilities/PlatformSpecificFactAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs similarity index 92% rename from test/PG.TestingUtilities/PlatformSpecificFactAttribute.cs rename to test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs index e2d545d7..02ab035d 100644 --- a/test/PG.TestingUtilities/PlatformSpecificFactAttribute.cs +++ b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs @@ -1,8 +1,9 @@ using System; using System.Linq; using System.Runtime.InteropServices; +using Xunit; -namespace PG.TestingUtilities; +namespace AET.Testing.Attributes; public sealed class PlatformSpecificFactAttribute : FactAttribute { diff --git a/test/PG.TestingUtilities/PlatformSpecificTheoryAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs similarity index 92% rename from test/PG.TestingUtilities/PlatformSpecificTheoryAttribute.cs rename to test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs index 0ea85b11..0724c67c 100644 --- a/test/PG.TestingUtilities/PlatformSpecificTheoryAttribute.cs +++ b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs @@ -1,8 +1,9 @@ using System; using System.Linq; using System.Runtime.InteropServices; +using Xunit; -namespace PG.TestingUtilities; +namespace AET.Testing.Attributes; public sealed class PlatformSpecificTheoryAttribute : TheoryAttribute { diff --git a/test/PG.TestingUtilities/TestPlatformIdentifier.cs b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs similarity index 74% rename from test/PG.TestingUtilities/TestPlatformIdentifier.cs rename to test/AET.Testing/Attributes/TestPlatformIdentifier.cs index da1529a9..7c45e26e 100644 --- a/test/PG.TestingUtilities/TestPlatformIdentifier.cs +++ b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs @@ -1,6 +1,6 @@ using System; -namespace PG.TestingUtilities; +namespace AET.Testing.Attributes; [Flags] public enum TestPlatformIdentifier diff --git a/test/AET.Testing/ExceptionHelpers.cs b/test/AET.Testing/ExceptionHelpers.cs new file mode 100644 index 00000000..8d0ccb98 --- /dev/null +++ b/test/AET.Testing/ExceptionHelpers.cs @@ -0,0 +1,29 @@ +using System; +using Xunit; + +namespace AET.Testing; + +// Based on https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Exception.Helpers.cs + +public class ExceptionHelpers +{ + public static void ValidateExceptionProperties(Exception e, + Exception innerException = null, + string message = null, + string source = null, + string stackTrace = null, + bool validateMessage = true) + { + Assert.Equal(innerException, e.InnerException); + if (validateMessage) + { + Assert.Equal(message, e.Message); + } + else + { + Assert.NotNull(e.Message); + } + Assert.Equal(source, e.Source); + Assert.Equal(stackTrace, e.StackTrace); + } +} \ No newline at end of file diff --git a/test/PG.TestingUtilities/ReferenceEqualityComparer.cs b/test/AET.Testing/ReferenceEqualityComparer.cs similarity index 94% rename from test/PG.TestingUtilities/ReferenceEqualityComparer.cs rename to test/AET.Testing/ReferenceEqualityComparer.cs index 58d0b3db..11eeac94 100644 --- a/test/PG.TestingUtilities/ReferenceEqualityComparer.cs +++ b/test/AET.Testing/ReferenceEqualityComparer.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; -namespace PG.TestingUtilities; +namespace AET.Testing; public sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs index 00a07e7e..a1afcdc6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs @@ -1,7 +1,7 @@ using System; +using AET.Testing.Attributes; using PG.StarWarsGame.Infrastructure.Clients.Arguments.CommandLine; using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs index 2cb2301c..87d0021e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs @@ -1,6 +1,6 @@ using System; +using AET.Testing; using PG.StarWarsGame.Infrastructure.Games; -using PG.TestingUtilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; @@ -11,7 +11,7 @@ public static class GameExceptionTest public static void Ctor() { var exception = new GameException(); - ExceptionTest.AssertException(exception, validateMessage: false); + ExceptionHelpers.ValidateExceptionProperties(exception, validateMessage: false); } [Fact] @@ -19,7 +19,7 @@ public static void Ctor_String() { var message = "game error"; var exception = new GameException(message); - ExceptionTest.AssertException(exception, message: message); + ExceptionHelpers.ValidateExceptionProperties(exception, message: message); } [Fact] @@ -28,6 +28,6 @@ public static void Ctor_String_Exception() var message = "game error"; var innerException = new Exception("Inner exception"); var exception = new GameException(message, innerException); - ExceptionTest.AssertException(exception, innerException: innerException, message: message); + ExceptionHelpers.ValidateExceptionProperties(exception, innerException: innerException, message: message); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs index a4a8a5f3..7ba3bed5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs @@ -1,11 +1,11 @@ using System; using System.IO.Abstractions; +using AET.Testing.Attributes; using AnakinRaW.CommonUtilities.Registry; using AnakinRaW.CommonUtilities.Registry.Windows; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; -using PG.TestingUtilities; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index fd14bafc..d5d6af2c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -34,8 +34,8 @@ + - diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs index 8e9669a8..d6fb1525 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs @@ -8,7 +8,7 @@ #if NET5_0_OR_GREATER using System.Collections.Generic; #else -using PG.TestingUtilities; +using AET.Testing; #endif namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 1c6a46a1..f7fa9639 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -33,24 +33,14 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + - - - diff --git a/test/PG.TestingUtilities/ExceptionTest.cs b/test/PG.TestingUtilities/ExceptionTest.cs deleted file mode 100644 index 610ca98d..00000000 --- a/test/PG.TestingUtilities/ExceptionTest.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace PG.TestingUtilities; - -public class ExceptionTest -{ - public static void AssertException(Exception e, - Exception? innerException = null, - string? message = null, - string? stackTrace = null, - bool validateMessage = true) - { - Assert.Equal(innerException, e.InnerException); - if (validateMessage) - Assert.Equal(message, e.Message); - else - Assert.NotNull(e.Message); - Assert.Equal(stackTrace, e.StackTrace); - } -} \ No newline at end of file diff --git a/test/PG.TestingUtilities/PG.TestingUtilities.csproj b/test/PG.TestingUtilities/PG.TestingUtilities.csproj deleted file mode 100644 index bb29ecce..00000000 --- a/test/PG.TestingUtilities/PG.TestingUtilities.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - netstandard2.0 - false - false - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - From 26fba8cbf79282f4755b8f92ab23948115bf2fb7 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 12:52:49 +0100 Subject: [PATCH 14/71] own version --- test/AET.Testing/version.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/AET.Testing/version.json diff --git a/test/AET.Testing/version.json b/test/AET.Testing/version.json new file mode 100644 index 00000000..6b36dbce --- /dev/null +++ b/test/AET.Testing/version.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", + "version": "1.0", + "publicReleaseRefSpec": [ + "^refs/heads/main" + ], + "cloudBuild": { + "buildNumber": { + "enabled": true + } + }, + "assemblyVersion": { + "precision": "major" + }, + "nugetPackageVersion": { + "semVer": 2 + } +} \ No newline at end of file From 4359b751973bc8e643ce48cbde603f8724de0abb Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 12:54:43 +0100 Subject: [PATCH 15/71] no own version --- test/AET.Testing/version.json | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 test/AET.Testing/version.json diff --git a/test/AET.Testing/version.json b/test/AET.Testing/version.json deleted file mode 100644 index 6b36dbce..00000000 --- a/test/AET.Testing/version.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.0", - "publicReleaseRefSpec": [ - "^refs/heads/main" - ], - "cloudBuild": { - "buildNumber": { - "enabled": true - } - }, - "assemblyVersion": { - "precision": "major" - }, - "nugetPackageVersion": { - "semVer": 2 - } -} \ No newline at end of file From 013bfa1a4c738fa9357917a88fa0fccbc81fcb3a Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 16 Dec 2025 14:04:52 +0100 Subject: [PATCH 16/71] to new namespace --- .../Services/Detection/Mods/ModFinder.cs | 4 +- .../ThrowHelper.cs | 1 - .../SteamAppManifestTest.cs | 4 +- .../SteamWrapperTestBase.cs | 6 +- .../TestingSteamInstallationImpl.Library.cs | 7 +- test/AET.Testing/AET.Testing.csproj | 2 + .../Extensions/AssertExtensions.cs | 28 +++++ .../Extensions/RandomExtensions.cs | 106 ++++++++++++++++++ .../Extensions/StringExtensions.cs | 31 +++++ test/AET.Testing/TestHelpers.cs | 67 +++-------- .../Clients/Arguments/FlagArgumentTest.cs | 14 +-- .../Clients/Arguments/GameArgumentTest.cs | 5 +- .../Clients/Arguments/GameArgumentTestBase.cs | 47 ++++---- .../Arguments/GameArgumentTestClasses.cs | 11 +- .../Clients/Arguments/NamedArgumentTest.cs | 6 +- .../GameIdentityTest.cs | 9 +- .../Detection/DirectoryGameDetectorTest.cs | 4 +- .../GameServices/GameFactoryTest.cs | 38 +++---- .../GameServices/SteamGameHelpersTest.cs | 8 +- .../ModBaseTest.cs | 6 +- .../ModEqualityComparerTest.cs | 6 +- .../ModDependencyGraphBuilderTest.cs | 14 +-- .../ModDependencyTraverserTest.cs | 6 +- .../ModServices/ModFactoryTest.cs | 4 +- .../ModServices/ModFinderTest.cs | 8 +- .../ModGameTypeResolverTestBase.cs | 48 ++++---- .../OnlineModGameTypeResolverTest.cs | 9 +- .../PetroglyphStarWarsGameTest.cs | 4 +- .../GITestUtilities.cs | 6 +- .../TestBases/GameInfrastructureTestBase.cs | 4 +- 30 files changed, 321 insertions(+), 192 deletions(-) create mode 100644 test/AET.Testing/Extensions/AssertExtensions.cs create mode 100644 test/AET.Testing/Extensions/RandomExtensions.cs create mode 100644 test/AET.Testing/Extensions/StringExtensions.cs diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModFinder.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModFinder.cs index ba2cfbf0..3c159ef1 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModFinder.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModFinder.cs @@ -3,7 +3,6 @@ using System.IO.Abstractions; using System.Linq; using AET.Modinfo.File; -using AET.Modinfo.Spec; using AET.Modinfo.Utilities; using AnakinRaW.CommonUtilities.FileSystem; using Microsoft.Extensions.DependencyInjection; @@ -83,8 +82,7 @@ private IEnumerable GetModsFromDirectory( _logger?.LogTrace("Searching for mods at location '{Location}'", modDirectory.FullName); - ModinfoFinderCollection modinfoFiles; - modinfoFiles = ModinfoFileFinder.FindModinfoFiles(modDirectory); + var modinfoFiles = ModinfoFileFinder.FindModinfoFiles(modDirectory); foreach (var modRef in ModReferenceBuilder.CreateIdentifiers(modinfoFiles, locationKind)) { diff --git a/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs b/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs index 07bab13c..348c3a75 100644 --- a/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs +++ b/src/PG.StarWarsGame.Infrastructure/ThrowHelper.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Runtime.CompilerServices; using PG.StarWarsGame.Infrastructure.Utilities.CompilerServices; namespace PG.StarWarsGame.Infrastructure; diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index 159a5a48..5995f346 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -3,7 +3,7 @@ using System.IO.Abstractions; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing; -using AET.Testing; +using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; @@ -87,7 +87,7 @@ public void Equality() var appB = new SteamAppManifest(lib, _fileSystem.FileInfo.New(_fileSystem.Path.GetRandomFileName()), aId, _fileSystem.Path.GetRandomFileName(), _fileSystem.DirectoryInfo.New(_fileSystem.Path.GetRandomFileName()), - TestHelpers.GetRandomEnum(), new HashSet()); + Random.Enum(), new HashSet()); var appOtherLib = new SteamAppManifest(otherLib, _fileSystem.FileInfo.New("file.acf"), aId, "name", _fileSystem.DirectoryInfo.New("path"), diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 52d28e95..2e4df3d7 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -8,7 +8,7 @@ using AET.SteamAbstraction.Library; using AET.SteamAbstraction.Testing; using AET.SteamAbstraction.Utilities; -using AET.Testing; +using AET.Testing.Extensions; using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; @@ -77,7 +77,7 @@ public async Task TestInstalled() Assert.Throws(() => wrapper.IsGameInstalled(123, out _)); Assert.Throws(wrapper.StartSteam); - await Assert.ThrowsAsync(() => wrapper.WaitSteamRunningAndLoggedInAsync(TestHelpers.RandomBool(), CancellationToken.None)); + await Assert.ThrowsAsync(() => wrapper.WaitSteamRunningAndLoggedInAsync(Random.Bool(), CancellationToken.None)); // Install Steam InstallSteam(); @@ -105,7 +105,7 @@ public async Task TestDisposed() Assert.Throws(() => wrapper.UserWantsOfflineMode); Assert.Throws(wrapper.StartSteam); Assert.Throws(() => wrapper.IsGameInstalled(123, out _)); - await Assert.ThrowsAsync(() => wrapper.WaitSteamRunningAndLoggedInAsync(TestHelpers.RandomBool(), CancellationToken.None)); + await Assert.ThrowsAsync(() => wrapper.WaitSteamRunningAndLoggedInAsync(Random.Bool(), CancellationToken.None)); } [Fact] diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index 4bd227d1..e57ab11a 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -1,9 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using AET.Testing; +using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.FileSystem; using Xunit; @@ -33,7 +34,7 @@ private ITestingSteamLibrary InstallSteamLibrary(string path, bool isDefault, bo var libDir = _fileSystem.DirectoryInfo.New(path); Assert.True(libDir.Exists); - var contentId = TestHelpers.RandomLong(); + var contentId = Random.Long(); var libraryVdf = $@"""libraryfolder"" {{ diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index 8714df1e..5199ca73 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -23,9 +23,11 @@ true snupkg + true + all diff --git a/test/AET.Testing/Extensions/AssertExtensions.cs b/test/AET.Testing/Extensions/AssertExtensions.cs new file mode 100644 index 00000000..7e93fb1d --- /dev/null +++ b/test/AET.Testing/Extensions/AssertExtensions.cs @@ -0,0 +1,28 @@ +using System; +using Xunit; + +namespace AET.Testing.Extensions; + +public static class AssertExtensions +{ + extension(Assert) + { + public static T AssertDoesNotThrowException(Func action) + { + try + { + return action(); + } + catch (Exception e) + { + Assert.Fail($"Expected no exception to be thrown but got '{e.GetType().Name}' instead"); + return default; + } + } + + public static void AssertDoesNotThrowException(Action action) + { + AssertDoesNotThrowException(() => action); + } + } +} \ No newline at end of file diff --git a/test/AET.Testing/Extensions/RandomExtensions.cs b/test/AET.Testing/Extensions/RandomExtensions.cs new file mode 100644 index 00000000..cd2ca323 --- /dev/null +++ b/test/AET.Testing/Extensions/RandomExtensions.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; + +namespace AET.Testing.Extensions; + +public static class RandomExtensions +{ + private static readonly Random Random = new(); + private static readonly string AllowedChars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789!@$?_-"; + + extension(Random) + { + public static bool Bool() + { + return Random.Next() % 2 == 0; + } + + public static sbyte SByte() + { + return (sbyte)Random.Next(sbyte.MinValue, sbyte.MaxValue); + } + + public static byte Byte() + { + return (byte)Random.Next(byte.MinValue, byte.MaxValue); + } + + public static short Short() + { + return (short)Random.Next(short.MinValue, short.MaxValue); + } + + public static ushort UShort() + { + return (ushort)Random.Next(ushort.MinValue, ushort.MaxValue); + } + + public static int Int() + { + return Random.Next(int.MinValue, int.MaxValue); + } + + public static uint UInt() + { + return (uint)Random.Int(); + } + + public static long Long() + { +#if NET || NETSTANDARD2_1_OR_GREATER + Span buf = stackalloc byte[8]; + Random.NextBytes(buf); + return BitConverter.ToInt64(buf); +#else + var buf = new byte[8]; + Random.NextBytes(buf); + return BitConverter.ToInt64(buf, 0); +#endif + } + + public static ulong ULong() + { + return (ulong)Random.Long(); + } + + public static T Enum() where T : struct, Enum + { + var values = System.Enum.GetValues(typeof(T)); + return (T)values.GetValue(Random.Next(values.Length))!; + } + + + // From: https://stackoverflow.com/questions/648196/random-row-from-linq-to-sql/648240#648240 + public static T Item(IEnumerable items) + { + T current = default!; + var count = 0; + foreach (var element in items) + { + count++; + if (Random.Next(count) == 0) + current = element; + } + return count == 0 + ? throw new InvalidOperationException("Sequence was empty") + : current; + } + + public static unsafe string GetRandomStringOfLength(int length) + { + if (length < 0) + throw new ArgumentOutOfRangeException(nameof(length)); + + var result = new string('\0', length); + + fixed (char* p = result) + { + var span = new Span(p, length); + for (var i = 0; i < span.Length; i++) + span[i] = AllowedChars[Random.Next(0, AllowedChars.Length)]; + } + + return result; + } + } +} \ No newline at end of file diff --git a/test/AET.Testing/Extensions/StringExtensions.cs b/test/AET.Testing/Extensions/StringExtensions.cs new file mode 100644 index 00000000..fd769ac6 --- /dev/null +++ b/test/AET.Testing/Extensions/StringExtensions.cs @@ -0,0 +1,31 @@ +using System; + +namespace AET.Testing.Extensions; + +public static class StringExtensions +{ + private static readonly Random Random = new(); + + extension(string) + { + public static string ShuffleCasing(string input) + { + var characters = input.ToCharArray(); + + for (var i = 0; i < characters.Length; i++) + { + if (char.IsLetter(characters[i])) + { + if (Random.Next(2) == 0) + { + characters[i] = char.IsUpper(characters[i]) + ? char.ToLower(characters[i]) + : char.ToUpper(characters[i]); + } + } + } + + return new string(characters); + } + } +} \ No newline at end of file diff --git a/test/AET.Testing/TestHelpers.cs b/test/AET.Testing/TestHelpers.cs index 3cbb4e23..ef4b9471 100644 --- a/test/AET.Testing/TestHelpers.cs +++ b/test/AET.Testing/TestHelpers.cs @@ -1,65 +1,24 @@ using System; -using System.Collections.Generic; -using System.Linq; +using System.IO; namespace AET.Testing; -public static class TestHelpers +public class TestHelpers { - private static readonly Random Random = new(); - - public static bool RandomBool() - { - return Random.Next() % 2 == 0; - } - - public static long RandomLong() - { - var buf = new byte[8]; - Random.NextBytes(buf); - return BitConverter.ToInt64(buf, 0); - } - - public static uint RandomUInt() - { - return (uint)Random.Next(int.MinValue, int.MaxValue); - } - - public static ushort RandomUShort() + public static Stream GetEmbeddedResource(Type type, string path) { - return (ushort)Random.Next(ushort.MinValue, ushort.MaxValue); + var assembly = type.Assembly; + var resourcePath = $"{assembly.GetName().Name}.Resources.{path}"; + return assembly.GetManifestResourceStream(resourcePath) ?? + throw new IOException($"Could not find embedded resource: '{resourcePath}'"); } - public static T GetRandomEnum() where T : struct, Enum + public static byte[] GetEmbeddedResourceAsByteArray(Type type, string path) { - var values = Enum.GetValues(typeof(T)); - return (T)values.GetValue(Random.Next(values.Length))!; - } - - public static T GetRandom(IEnumerable items) - { - var list = items.ToList(); - var r = Random.Next(list.Count); - return list[r]; - } - - public static string ShuffleCasing(string input) - { - var characters = input.ToCharArray(); - - for (var i = 0; i < characters.Length; i++) - { - if (char.IsLetter(characters[i])) - { - if (Random.Next(2) == 0) - { - characters[i] = char.IsUpper(characters[i]) - ? char.ToLower(characters[i]) - : char.ToUpper(characters[i]); - } - } - } - - return new string(characters); + using var stream = GetEmbeddedResource(type, path); + using var ms = new MemoryStream(); + stream.CopyTo(ms); + ms.Position = 0; + return ms.ToArray(); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs index c69bebe1..049acd91 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs @@ -1,5 +1,5 @@ using System; -using AET.Testing; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Xunit; @@ -10,18 +10,18 @@ public class FlagArgumentTest [Fact] public void Ctor_InvalidArgs_Throws() { - Assert.Throws(() => new TestFlagArg(null!, TestHelpers.RandomBool(), TestHelpers.RandomBool())); - Assert.Throws(() => new TestFlagArg(string.Empty, TestHelpers.RandomBool(), TestHelpers.RandomBool())); + Assert.Throws(() => new TestFlagArg(null!, Random.Bool(), Random.Bool())); + Assert.Throws(() => new TestFlagArg(string.Empty, Random.Bool(), Random.Bool())); } [Fact] public void Ctor_SetProperty() { - var name = TestHelpers.GetRandom(GameArgumentNames.AllInternalSupportedArgumentNames); - var isDebug = TestHelpers.RandomBool(); - var value = TestHelpers.RandomBool(); + var name = Random.Item(GameArgumentNames.AllInternalSupportedArgumentNames); + var isDebug = Random.Bool(); + var value = Random.Bool(); - var a = new TestFlagArg(name, value, TestHelpers.RandomBool(), isDebug); + var a = new TestFlagArg(name, value, Random.Bool(), isDebug); Assert.Equal(name, a.Name); Assert.Equal(value, a.Value); Assert.Equal(value, ((GameArgument)a).Value); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs index 3037a842..8c954540 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs @@ -1,4 +1,5 @@ -using AET.Testing; +using System; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Xunit; @@ -52,7 +53,7 @@ public void IsValid_ArgumentNotValid(GameArgument arg, ArgumentValidityStatus ex } public class ValidatingTestArgument(bool isValueValid, string value) - : GameArgument(TestHelpers.GetRandom(GameArgumentNames.AllInternalSupportedArgumentNames), value) + : GameArgument(Random.Item(GameArgumentNames.AllInternalSupportedArgumentNames), value) { private protected override bool IsDataValid() { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs index 27d9cb4f..cdb76fa1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; -using System.IO.Abstractions; -using System.Linq; -using System.Runtime.InteropServices; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; +using System; +using System.Collections.Generic; +using System.IO.Abstractions; +using System.Linq; +using System.Runtime.InteropServices; +using AET.Testing.Extensions; using Testably.Abstractions.Testing; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; @@ -198,22 +199,22 @@ public static IEnumerable GetValidArguments() yield return [new LanguageArgument(new LanguageInfo("en", LanguageSupportLevel.Default))]; yield return [new LanguageArgument(new LanguageInfo("de", LanguageSupportLevel.SFX))]; - yield return [new LocalPortArgument(TestHelpers.RandomUInt())]; - yield return [new MonitorArgument(TestHelpers.RandomUInt())]; - yield return [new ScreenWidthArgument(TestHelpers.RandomUInt())]; - yield return [new ScreenHeightArgument(TestHelpers.RandomUInt())]; - yield return [new FPSCapArgument(TestHelpers.RandomUInt())]; - yield return [new RandomSeedArgument(TestHelpers.RandomUInt())]; - yield return [new ProfileArgument(TestHelpers.RandomUInt())]; - yield return [new BCast2Argument(TestHelpers.RandomUInt())]; - yield return [new BCast3Argument(TestHelpers.RandomUInt())]; - yield return [new BCast4Argument(TestHelpers.RandomUInt())]; - yield return [new AILogStyleArgument(TestHelpers.GetRandomEnum())]; - yield return [new SyncLogFilterArgument(TestHelpers.RandomUShort())]; - yield return [new ConnectPortArgument(TestHelpers.RandomUInt())]; - foreach (var nonPathArg in GetNonPathKeyValueArgs(TestHelpers.GetRandom(GetValidStringValues))) + yield return [new LocalPortArgument(Random.UInt())]; + yield return [new MonitorArgument(Random.UInt())]; + yield return [new ScreenWidthArgument(Random.UInt())]; + yield return [new ScreenHeightArgument(Random.UInt())]; + yield return [new FPSCapArgument(Random.UInt())]; + yield return [new RandomSeedArgument(Random.UInt())]; + yield return [new ProfileArgument(Random.UInt())]; + yield return [new BCast2Argument(Random.UInt())]; + yield return [new BCast3Argument(Random.UInt())]; + yield return [new BCast4Argument(Random.UInt())]; + yield return [new AILogStyleArgument(Random.Enum())]; + yield return [new SyncLogFilterArgument(Random.UShort())]; + yield return [new ConnectPortArgument(Random.UInt())]; + foreach (var nonPathArg in GetNonPathKeyValueArgs(Random.Item(GetValidStringValues))) yield return [nonPathArg]; - foreach (var pathArg in GetPathKeyValueArgs(TestHelpers.GetRandom(GetValidStringValues), gameDir.FullName, fs)) + foreach (var pathArg in GetPathKeyValueArgs(Random.Item(GetValidStringValues), gameDir.FullName, fs)) yield return [pathArg]; // Mod @@ -225,8 +226,8 @@ public static IEnumerable GetValidArguments() yield return [ new ModArgumentList([ - new ModArgument(fs.DirectoryInfo.New(TestHelpers.GetRandom(GetValidStringValues)), gameDir, false), - new ModArgument(fs.DirectoryInfo.New(TestHelpers.GetRandom(GetValidStringValues)), gameDir, false), + new ModArgument(fs.DirectoryInfo.New(Random.Item(GetValidStringValues)), gameDir, false), + new ModArgument(fs.DirectoryInfo.New(Random.Item(GetValidStringValues)), gameDir, false), ]) ]; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs index 7b41fd72..56661e57 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs @@ -1,6 +1,7 @@ -using AET.Testing; -using PG.StarWarsGame.Infrastructure.Clients.Arguments; +using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.CommandLine; +using System; +using AET.Testing.Extensions; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; @@ -12,7 +13,7 @@ public TestNamedArg(string name) : this(name, GameArgumentTestBase.ValidStringVa public static TestNamedArg FromValue(string value) { - var name = TestHelpers.GetRandom(GameArgumentNames.SupportedKeyValueArgumentNames); + var name = Random.Item(GameArgumentNames.SupportedKeyValueArgumentNames); return new TestNamedArg(name, value, false); } } @@ -21,7 +22,7 @@ public class TestFlagArg(string name, bool value, bool dashed = false, bool debu : FlagArgument(name, value, dashed, debug) { public TestFlagArg(bool value, bool dashed) : this( - TestHelpers.GetRandom(GameArgumentNames.SupportedFlagArgumentNames), value, dashed) + Random.Item(GameArgumentNames.SupportedFlagArgumentNames), value, dashed) { } @@ -31,7 +32,7 @@ public TestFlagArg(string name) : this(name, true) } public class LowerCaseNameArg() - : FlagArgument(TestHelpers.GetRandom(GameArgumentNames.AllInternalSupportedArgumentNames).ToLowerInvariant(), true); + : FlagArgument(Random.Item(GameArgumentNames.AllInternalSupportedArgumentNames).ToLowerInvariant(), true); [SerializeEnumValue] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs index fda23b63..4a9a5b5b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs @@ -1,5 +1,5 @@ using System; -using AET.Testing; +using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.FileSystem.Normalization; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Testably.Abstractions.Testing; @@ -21,8 +21,8 @@ public void Ctor_InvalidArgs_Throws() [Fact] public void Ctor_SetProperty() { - var name = TestHelpers.GetRandom(GameArgumentNames.AllInternalSupportedArgumentNames); - var isDebug = TestHelpers.RandomBool(); + var name = Random.Item(GameArgumentNames.AllInternalSupportedArgumentNames); + var isDebug = Random.Bool(); var a = new TestNamedArg(name, "value", isDebug); Assert.Equal(name, a.Name); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs index 68ee1374..3865e78d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs @@ -1,5 +1,6 @@ -using AET.Testing; -using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Games; +using System; +using AET.Testing.Extensions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; @@ -9,8 +10,8 @@ public class GameIdentityTest [Fact] public void Ctor() { - var type = TestHelpers.GetRandomEnum(); - var platform = TestHelpers.GetRandomEnum(); + var type = Random.Enum(); + var platform = Random.Enum(); var id = new GameIdentity(type, platform); Assert.Equal(type, id.Type); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs index 04c85242..8c589678 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs @@ -25,7 +25,7 @@ protected override IGameDetector CreateDetector(GameDetectorTestInfo gam protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); - return new(gameIdentity.Type, game.Directory, default); + return new(gameIdentity.Type, game.Directory, null); } [Fact] @@ -83,7 +83,7 @@ private void TestNotInstalledWithCustomSetup(GameIdentity identity, Func new GameDetectorTestInfo(identity.Type, customSetup(identity), default), + _ => new GameDetectorTestInfo(identity.Type, customSetup(identity), null), _ => expected, null, queryPlatforms: []); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index dfdf503d..53a3fea2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; -using AET.Testing; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services; @@ -36,23 +36,23 @@ public void CreateGame_NullArg_Throws() { Assert.Throws(() => _factory.CreateGame(null!, CultureInfo.CurrentCulture)); Assert.Throws(() => _factory.CreateGame( - GameDetectionResult.NotInstalled(TestHelpers.GetRandomEnum()), + GameDetectionResult.NotInstalled(Random.Enum()), null!)); Assert.Throws(() => _factory.CreateGame( null!, FileSystem.DirectoryInfo.New("path"), - TestHelpers.RandomBool(), + Random.Bool(), CultureInfo.CurrentCulture)); Assert.Throws(() => _factory.CreateGame( CreateRandomGameIdentity(), null!, - TestHelpers.RandomBool(), + Random.Bool(), CultureInfo.CurrentCulture)); Assert.Throws(() => _factory.CreateGame( CreateRandomGameIdentity(), FileSystem.DirectoryInfo.New("path"), - TestHelpers.RandomBool(), + Random.Bool(), null!)); } @@ -61,23 +61,23 @@ public void TryCreateGame_NullArg_Throws() { Assert.Throws(() => _factory.TryCreateGame(null!, CultureInfo.CurrentCulture, out _)); Assert.Throws(() => _factory.TryCreateGame( - GameDetectionResult.NotInstalled(TestHelpers.GetRandomEnum()), + GameDetectionResult.NotInstalled(Random.Enum()), null!, out _)); Assert.Throws(() => _factory.TryCreateGame( null!, FileSystem.DirectoryInfo.New("path"), - TestHelpers.RandomBool(), + Random.Bool(), CultureInfo.CurrentCulture, out _)); Assert.Throws(() => _factory.TryCreateGame( CreateRandomGameIdentity(), null!, - TestHelpers.RandomBool(), + Random.Bool(), CultureInfo.CurrentCulture, out _)); Assert.Throws(() => _factory.TryCreateGame( CreateRandomGameIdentity(), FileSystem.DirectoryInfo.New("path"), - TestHelpers.RandomBool(), + Random.Bool(), null!, out _)); } @@ -85,20 +85,20 @@ public void TryCreateGame_NullArg_Throws() public void CreateGame_NoGameInstalled_Throws() { Assert.Throws(() => - _factory.CreateGame(GameDetectionResult.NotInstalled(TestHelpers.GetRandomEnum()), + _factory.CreateGame(GameDetectionResult.NotInstalled(Random.Enum()), CultureInfo.CurrentCulture)); Assert.Throws(() => - _factory.CreateGame(GameDetectionResult.RequiresInitialization(TestHelpers.GetRandomEnum()), + _factory.CreateGame(GameDetectionResult.RequiresInitialization(Random.Enum()), CultureInfo.CurrentCulture)); } [Fact] public void TryCreateGame_NoGameInstalled_Throws() { - Assert.False(_factory.TryCreateGame(GameDetectionResult.NotInstalled(TestHelpers.GetRandomEnum()), + Assert.False(_factory.TryCreateGame(GameDetectionResult.NotInstalled(Random.Enum()), CultureInfo.CurrentCulture, out _)); Assert.False(_factory.TryCreateGame( - GameDetectionResult.RequiresInitialization(TestHelpers.GetRandomEnum()), + GameDetectionResult.RequiresInitialization(Random.Enum()), CultureInfo.CurrentCulture, out _)); } @@ -146,7 +146,7 @@ public void CreateGame_GameNotExists_Throws() [InlineData(GamePlatform.SteamGold, false)] public void CreateGame_WrongGameIdentityInstalled_WrongPlatform_Throws(GamePlatform platform, bool checkExists) { - var actualGameType = TestHelpers.GetRandomEnum(); + var actualGameType = Random.Enum(); // Use Disk so that we can check against more specific platforms var installedGame = @@ -170,7 +170,7 @@ public static IEnumerable GetWrongGameTypeTestData() [MemberData(nameof(GetWrongGameTypeTestData))] public void CreateGame_WrongGameIdentityInstalled_WrongType_Throws(GamePlatform platform, bool checkExists) { - var actualGameType = TestHelpers.GetRandomEnum(); + var actualGameType = Random.Enum(); // Use Disk so that we can check against more specific platforms var installedGame = FileSystem.InstallGame( @@ -187,15 +187,15 @@ public void CreateGame_UnidentifiedPlatform_Throws() { var installedGame = CreateRandomGame(); Assert.Throws(() => _factory.CreateGame( - new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.Undefined), + new GameIdentity(Random.Enum(), GamePlatform.Undefined), installedGame.Directory, - TestHelpers.RandomBool(), + Random.Bool(), CultureInfo.CurrentCulture)); Assert.False(_factory.TryCreateGame( - new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.Undefined), + new GameIdentity(Random.Enum(), GamePlatform.Undefined), installedGame.Directory, - TestHelpers.RandomBool(), + Random.Bool(), CultureInfo.CurrentCulture, out _)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs index 704329d0..fc7198ca 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs @@ -1,5 +1,5 @@ using System; -using AET.Testing; +using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.FileSystem.Normalization; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Steam; @@ -28,7 +28,7 @@ public void GetWorkshopsLocation_NullArgs_Throws() [Fact] public void GetWorkshopsLocation_Success() { - var game = FileSystem.InstallGame(new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.SteamGold), + var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); var wsDir = _service.GetWorkshopsLocation(game); @@ -46,7 +46,7 @@ public void GetWorkshopsLocation_CannotFindWorkshopPath() var gameDir = FileSystem.DirectoryInfo.New("SteamFakeFame"); gameDir.Create(); var game = new PetroglyphStarWarsGame( - new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.SteamGold), gameDir, "Game", + new GameIdentity(Random.Enum(), GamePlatform.SteamGold), gameDir, "Game", ServiceProvider); Assert.Throws(() => _service.GetWorkshopsLocation(game)); @@ -60,7 +60,7 @@ public void GetWorkshopsLocation_CannotFindWorkshopPath() [InlineData(GamePlatform.Origin)] public void GetWorkshopsLocation_FailNoSteam(GamePlatform platform) { - var game = FileSystem.InstallGame(new GameIdentity(TestHelpers.GetRandomEnum(), platform), + var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), platform), ServiceProvider); Assert.Throws(() => _service.GetWorkshopsLocation(game)); Assert.False(_service.TryGetWorkshopsLocation(game, out _)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 845a1c90..0090ba80 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -3,7 +3,7 @@ using System.Linq; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Mods; @@ -85,7 +85,7 @@ public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectl // Do not add mod to game var notAddedDep = Game.InstallMod("NotAddedMod", false, ServiceProvider); - var mod = CreateMod("Mod", TestHelpers.GetRandomEnum(), notAddedDep); + var mod = CreateMod("Mod", Random.Enum(), notAddedDep); Game.AddMod(mod); var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); @@ -107,7 +107,7 @@ public void ResolveDependencies_DepOfWrongGame_Throws() var otherGameReference = new PetroglyphStarWarsGame(Game, Game.Directory, Game.Name, ServiceProvider); var wrongGameDep = otherGameReference.InstallAndAddMod("WrongGameRefMod", GITestUtilities.GetRandomWorkshopFlag(otherGameReference), ServiceProvider); - var mod = CreateMod("Mod", TestHelpers.GetRandomEnum(), wrongGameDep); + var mod = CreateMod("Mod", Random.Enum(), wrongGameDep); var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index dcb11764..cf8689d5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; @@ -82,7 +82,7 @@ public void Equals_DependencyAware(bool depAware) var differentDep = new Mod(Game, modA.Identifier, modA.Directory, modA.Type == ModType.Workshops, "A", ServiceProvider); - var comparer = new ModEqualityComparer(depAware, TestHelpers.RandomBool()); + var comparer = new ModEqualityComparer(depAware, Random.Bool()); Assert.True(comparer.Equals(modA, modA)); Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(modA)); @@ -118,7 +118,7 @@ public void Equals_GameAware(bool gameAware) var diffGameMod = diffGame.InstallMod("A", modA.Type == ModType.Workshops, ServiceProvider); - var comparer = new ModEqualityComparer(TestHelpers.RandomBool(), gameAware); + var comparer = new ModEqualityComparer(Random.Bool(), gameAware); Assert.True(comparer.Equals(modA, modA)); Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(modA)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 30ffa089..c9993685 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; @@ -37,7 +37,7 @@ public void Build_NoDependencies() public void Build_OneDependency() { var b = CreateAndAddMod("B"); - var mod = CreateAndAddMod("A", TestHelpers.GetRandomEnum(), b); + var mod = CreateAndAddMod("A", Random.Enum(), b); var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -260,7 +260,7 @@ public void Build_DirectCycle() Dependencies = new DependencyList(new List { depA - }, TestHelpers.GetRandomEnum()) + }, Random.Enum()) }; var mod = Game.InstallAndAddMod(false, modinfo, ServiceProvider); @@ -273,7 +273,7 @@ public void Build_TransitiveCycle() { var depA = new ModReference("A", ModType.Default); - var b = CreateAndAddMod("B", TestHelpers.GetRandomEnum(), depA); + var b = CreateAndAddMod("B", Random.Enum(), depA); var modinfo = new ModinfoData("A") { @@ -301,7 +301,7 @@ public void Build_SelfNotFound_Throws() public void Build_DirectDependencyNotFound_Throws() { var b = Game.InstallMod("B", false, ServiceProvider); - var mod = CreateAndAddMod("A", TestHelpers.GetRandomEnum(), b); + var mod = CreateAndAddMod("A", Random.Enum(), b); var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(b, e.Mod); @@ -338,7 +338,7 @@ public void Build_OneDependency_VersionRangeMatches(SemVersion? version, SemVers var b = CreateAndAddMod(new ModinfoData("B") { Version = version }); Assert.Equal(version, b.Version); - var mod = CreateAndAddMod("A", TestHelpers.GetRandomEnum(), + var mod = CreateAndAddMod("A", Random.Enum(), new ModReference(b.Identifier, b.Type, ranges)); var graph = _graphBuilder.Build(mod); @@ -388,7 +388,7 @@ public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion ver }); Assert.Equal(version, b.Version); - var mod = CreateAndAddMod("A", TestHelpers.GetRandomEnum(), + var mod = CreateAndAddMod("A", Random.Enum(), new ModReference(b.Identifier, b.Type, range)); var e = Assert.Throws(() => _graphBuilder.Build(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 1ae2f20b..0216f557 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -1,6 +1,6 @@ using System; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; @@ -45,7 +45,7 @@ public void Traverse_FaultedResolvedMod_Throws() // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddMod("Mod", TestHelpers.GetRandomEnum(), dep); + var mod = CreateAndAddMod("Mod", Random.Enum(), dep); try { @@ -65,7 +65,7 @@ public void Traverse_NotResolvedMod_Throws() { // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddMod("Mod", TestHelpers.GetRandomEnum(), dep); + var mod = CreateAndAddMod("Mod", Random.Enum(), dep); Assert.Equal(DependencyResolveStatus.None, mod.DependencyResolveStatus); Assert.Throws(() => _traverser.Traverse(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 734af8fd..684cf0a3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -8,7 +8,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; -using AET.Testing; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; @@ -181,7 +181,7 @@ public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) var oppositeGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; var otherGame = FileSystem.InstallGame( - new GameIdentity(oppositeGameType, TestHelpers.GetRandom(GITestUtilities.RealPlatforms)), ServiceProvider); + new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); var modDir = otherGame.GetModDirectory("Mod_Name", false, ServiceProvider); var modData = CreateDetectedModReference(otherGame, modDir, false, null); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 41a345b7..1d5d1362 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -7,7 +7,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; -using AET.Testing; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; @@ -279,7 +279,7 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", [$"{oppositeGameType.ToString().ToUpper()}"]); var modinfo = new ModinfoData("Name") @@ -393,9 +393,9 @@ public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType t public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameType type) { var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; - var game = FileSystem.InstallGame(new GameIdentity(type, TestHelpers.GetRandom(GITestUtilities.RealPlatforms)), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); // Other, random platform to shuffle a bit more. - var otherTypeGame = FileSystem.InstallGame(new GameIdentity(oppositeGameType, TestHelpers.GetRandom(GITestUtilities.RealPlatforms)), ServiceProvider); + var otherTypeGame = FileSystem.InstallGame(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); var wrongMod = otherTypeGame.InstallMod("MyMod", false, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index df2ed0a9..e02a5569 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -6,7 +6,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; -using AET.Testing; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; @@ -32,7 +32,7 @@ protected static DetectedModReference CreateDetectedModReference(IDirectoryInfo public void NullArg_Throws() { Assert.Throws(() => CreateResolver().TryGetGameType((DetectedModReference)null!, out _)); - Assert.Throws(() => CreateResolver().IsDefinitelyNotCompatibleToGame((DetectedModReference)null!, TestHelpers.GetRandomEnum())); + Assert.Throws(() => CreateResolver().IsDefinitelyNotCompatibleToGame((DetectedModReference)null!, Random.Enum())); } [Fact] @@ -40,7 +40,7 @@ public void Modinfo_IsNull_CannotGetType() { var resolver = CreateResolver(); Assert.False(resolver.TryGetGameType((IModinfo?)null!, out _)); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame((IModinfo?)null!, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame((IModinfo?)null!, Random.Enum())); } [Fact] @@ -50,7 +50,7 @@ public void Modinfo_WithoutSteamData_CannotGetType() var resolver = CreateResolver(); Assert.False(resolver.TryGetGameType(modinfo, out _)); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(modinfo, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(modinfo, Random.Enum())); } [Theory] @@ -63,7 +63,7 @@ public void Modinfo_WithoutSteamGameTag_CannotGetType(params string[] tags) var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", tags); var modinfo = new ModinfoData("Name") @@ -73,7 +73,7 @@ public void Modinfo_WithoutSteamGameTag_CannotGetType(params string[] tags) var resolver = CreateResolver(); Assert.False(resolver.TryGetGameType(modinfo, out _)); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(modinfo, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(modinfo, Random.Enum())); } public static IEnumerable GetSteamTagsSuccessTestData() @@ -93,7 +93,7 @@ public void Modinfo_WithSteamDataAndSteamTag_CanDetermineGameType(IList var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", tags); var modinfo = new ModinfoData("Name") { @@ -104,7 +104,7 @@ public void Modinfo_WithSteamDataAndSteamTag_CanDetermineGameType(IList Assert.True(resolver.TryGetGameType(modinfo, out var types)); Assert.Equivalent(expectedTypes, types, true); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(modinfo, TestHelpers.GetRandom(expectedTypes))); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(modinfo, Random.Item(expectedTypes))); if (incompatibleWith is not null) Assert.True(resolver.IsDefinitelyNotCompatibleToGame(modinfo, incompatibleWith.Value)); @@ -116,7 +116,7 @@ public void Directory_WithModinfo_ModinfoIsAlwaysSuperiorForSteamTypes() var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", ["EAW"]); var modinfo = new ModinfoData("Name") @@ -147,7 +147,7 @@ public void Directory_SteamWithoutModinfoCannotDecide() // No SteamData here var modinfo = new ModinfoData("Name"); - var game = FileSystem.InstallGame(new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.SteamGold), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); var steamHelpers = ServiceProvider.GetRequiredService(); @@ -163,7 +163,7 @@ public void Directory_SteamWithoutModinfoCannotDecide() Assert.False(resolver.TryGetGameType(info, out var types)); Assert.Empty(types); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, Random.Enum())); } [Fact] @@ -172,7 +172,7 @@ public void Directory_SteamWithInvalidDirName() var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", ["FOC"]); var modinfo = new ModinfoData("Name") @@ -180,7 +180,7 @@ public void Directory_SteamWithInvalidDirName() SteamData = steamData }; - var game = FileSystem.InstallGame(new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.SteamGold), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); var steamHelpers = ServiceProvider.GetRequiredService(); var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("notASteamId"); @@ -194,7 +194,7 @@ public void Directory_SteamWithInvalidDirName() Assert.False(resolver.TryGetGameType(info, out var types)); Assert.Empty(types); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, Random.Enum())); } public static IEnumerable GetCachedModsTestData() @@ -218,7 +218,7 @@ public void Directory_SteamWithoutModinfoButKnownModID(string knownId, ICollecti // No SteamData here var modinfo = new ModinfoData("Name"); - var game = FileSystem.InstallGame(new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.SteamGold), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); var steamHelpers = ServiceProvider.GetRequiredService(); @@ -230,7 +230,7 @@ public void Directory_SteamWithoutModinfoButKnownModID(string knownId, ICollecti Assert.True(resolver.TryGetGameType(info, out var types)); Assert.Equivalent(expectedTypes, types, true); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, TestHelpers.GetRandom(expectedTypes))); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, Random.Item(expectedTypes))); if (incompatibleWith is not null) Assert.True(resolver.IsDefinitelyNotCompatibleToGame(info, incompatibleWith.Value)); } @@ -241,7 +241,7 @@ public void VirtualMods_VirtualModsAreAlwaysUndecidable() var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", ["FOC"]); var modinfo = new ModinfoData("Name") @@ -259,7 +259,7 @@ public void VirtualMods_VirtualModsAreAlwaysUndecidable() Assert.False(CreateResolver().TryGetGameType(info, out var types)); Assert.Empty(types); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, Random.Enum())); } [Fact] @@ -268,7 +268,7 @@ public void ExternalModsAreAlwaysUndecidable() var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", ["FOC"]); var modinfo = new ModinfoData("Name") @@ -285,7 +285,7 @@ public void ExternalModsAreAlwaysUndecidable() Assert.False(CreateResolver().TryGetGameType(info, out var types)); Assert.Empty(types); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, TestHelpers.GetRandomEnum())); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, Random.Enum())); } [Theory] @@ -296,7 +296,7 @@ public void ModsInModsDirUseGameType(GameType gameType) var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", ["FOC"]); var modinfo = new ModinfoData("Name") @@ -304,7 +304,7 @@ public void ModsInModsDirUseGameType(GameType gameType) SteamData = steamData }; - var game = FileSystem.InstallGame(new GameIdentity(gameType, TestHelpers.GetRandom(GITestUtilities.RealPlatforms)), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); var mod = game.InstallMod("Name", false, ServiceProvider); var info = CreateDetectedModReference(mod.Directory, ModType.Default, modinfo); @@ -326,7 +326,7 @@ public void ModsNotInModsDirButSomeOtherGameBasesDir_NotDecidable(GameType gameT var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", - TestHelpers.GetRandomEnum(), + Random.Enum(), "Title", ["FOC"]); var modinfo = new ModinfoData("Name") @@ -334,7 +334,7 @@ public void ModsNotInModsDirButSomeOtherGameBasesDir_NotDecidable(GameType gameT SteamData = steamData }; - var game = FileSystem.InstallGame(new GameIdentity(gameType, TestHelpers.GetRandom(GITestUtilities.RealPlatforms)), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); var modDir = game.Directory.CreateSubdirectory("ModsOther").CreateSubdirectory("MyMod"); var mod = game.InstallMod(modDir, false, modinfo, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs index 844e9e84..90a8b74e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs @@ -1,6 +1,7 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; @@ -27,7 +28,7 @@ public static IEnumerable GetOnlineModsData() [MemberData(nameof(GetOnlineModsData))] public void Online_GetTagsFromSteamOnline(string knownId, ICollection expectedTypes, GameType? incompatibleWith) { - var game = FileSystem.InstallGame(new GameIdentity(TestHelpers.GetRandomEnum(), GamePlatform.SteamGold), ServiceProvider); + var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); var steamHelpers = ServiceProvider.GetRequiredService(); var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory(knownId); @@ -39,7 +40,7 @@ public void Online_GetTagsFromSteamOnline(string knownId, ICollection Assert.True(CreateResolver().TryGetGameType(info, out var types)); Assert.Equivalent(expectedTypes, types, true); - Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, TestHelpers.GetRandom(expectedTypes))); + Assert.False(resolver.IsDefinitelyNotCompatibleToGame(info, Random.Item(expectedTypes))); if (incompatibleWith is not null) Assert.True(resolver.IsDefinitelyNotCompatibleToGame(info, incompatibleWith.Value)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index da7d6f24..89390e6c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; @@ -15,7 +15,7 @@ private PetroglyphStarWarsGame CreateGame( string? iconPath = null, ICollection? languages = null) { - var gameId = new GameIdentity(TestHelpers.GetRandomEnum(), TestHelpers.GetRandom(GITestUtilities.RealPlatforms)); + var gameId = new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); var game = FileSystem.InstallGame(gameId, ServiceProvider); if (languages is not null) { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index 9e3f1046..3dde43aa 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; -using AET.Testing; +using AET.Testing.Extensions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing; @@ -53,8 +53,8 @@ public static ICollection GetRandomLanguages() foreach (var _ in PossibleLanguages) { - var code = TestHelpers.GetRandom(PossibleLanguages); - var support = TestHelpers.GetRandomEnum(); + var code = Random.Item(PossibleLanguages); + var support = Random.Enum(); languages.Add(new LanguageInfo(code, support)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 1488ab0e..eb46447b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -3,7 +3,7 @@ using System.IO.Abstractions; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; @@ -34,7 +34,7 @@ protected virtual void SetupServiceProvider(IServiceCollection sc) protected static GameIdentity CreateRandomGameIdentity() { - return new GameIdentity(TestHelpers.GetRandomEnum(), TestHelpers.GetRandom(GITestUtilities.RealPlatforms)); + return new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); } protected PetroglyphStarWarsGame CreateRandomGame() From 745d65aa13b284eaf1905cf7ba79101a63932ab2 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 17 Dec 2025 15:20:47 +0100 Subject: [PATCH 17/71] start generalize tests --- .../ProcessHelperTest.cs | 13 ++- .../SteamAppManifestTest.cs | 18 ++-- .../SteamLibraryFinderTest.cs | 87 +++++++------------ .../SteamLibraryTest.cs | 2 +- .../SteamVdfReaderTest.cs | 2 +- .../SteamWrapperTestBase.cs | 2 +- .../AET.SteamAbstraction.Testing.csproj | 3 +- .../InMemorySteamTestBase.cs | 30 +++++++ .../SteamInstallationExtensions.cs | 17 ++-- .../SteamTestBase.cs | 25 ++++++ .../TestProcessHelper.cs | 2 +- .../TestingSteamInstallationImpl.Library.cs | 2 +- .../TestingSteamInstallationImpl.cs | 7 +- .../TestingSteamRegistryImpl.cs | 7 +- test/AET.Testing/AET.Testing.csproj | 3 +- .../TestBaseWithServiceProvider.cs | 21 +++++ 16 files changed, 151 insertions(+), 90 deletions(-) create mode 100644 test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs create mode 100644 test/AET.SteamAbstraction.Testing/SteamTestBase.cs create mode 100644 test/AET.Testing/TestBaseWithServiceProvider.cs diff --git a/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs b/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs index 9abf488e..5b836674 100644 --- a/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs +++ b/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs @@ -2,20 +2,25 @@ using System.Diagnostics; using System.Runtime.InteropServices; using AET.SteamAbstraction.Utilities; +using AET.Testing; using Microsoft.Extensions.DependencyInjection; using Xunit; namespace AET.SteamAbstraction.Test; -public class ProcessHelperTest +public class ProcessHelperTest : TestBaseWithServiceProvider { private readonly IProcessHelper _processHelper; public ProcessHelperTest() { - var sc = new ServiceCollection(); - SteamAbstractionLayer.InitializeServices(sc); - _processHelper = sc.BuildServiceProvider().GetRequiredService(); + _processHelper = ServiceProvider.GetRequiredService(); + } + + protected override void SetupServices(IServiceCollection serviceCollection) + { + base.SetupServices(serviceCollection); + SteamAbstractionLayer.InitializeServices(serviceCollection); } [Fact] diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index 5995f346..e278cd62 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing; +using AET.Testing; using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; @@ -11,22 +12,25 @@ namespace AET.SteamAbstraction.Test; -public class SteamAppManifestTest : IDisposable +public class SteamAppManifestTest : TestBaseWithServiceProvider, IDisposable { private readonly MockFileSystem _fileSystem = new(); private readonly ITestingSteamInstallation _steam; public SteamAppManifestTest() { - var sc = new ServiceCollection(); - sc.AddSingleton(_fileSystem); - SteamAbstractionLayer.InitializeServices(sc); - sc.AddSingleton(new InMemoryRegistry()); - var sp = sc.BuildServiceProvider(); - _steam = _fileSystem.Steam(sp); + _steam = SteamTesting.Steam(ServiceProvider); _steam.InstallSteamFilesOnly(); } + protected override void SetupServices(IServiceCollection serviceCollection) + { + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(_fileSystem); + SteamAbstractionLayer.InitializeServices(serviceCollection); + serviceCollection.AddSingleton(new InMemoryRegistry()); + } + public void Dispose() { _steam.Dispose(); diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index 5784128a..6e6a4684 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -1,59 +1,40 @@ -using System; -using System.Collections.Generic; -using System.IO.Abstractions; +using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using AET.SteamAbstraction.Library; -using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Testing; using AET.Testing.Attributes; -using AnakinRaW.CommonUtilities.Registry; -using Microsoft.Extensions.DependencyInjection; -using Testably.Abstractions.Testing; using Xunit; +#if NET5_0_OR_GREATER +using System.Runtime.Versioning; +#endif namespace AET.SteamAbstraction.Test; -public class SteamLibraryFinderTest : IDisposable +#if NET5_0_OR_GREATER +[SupportedOSPlatform("windows")] +#endif +public class SteamLibraryFinderTest : InMemorySteamTestBase { private readonly SteamLibraryFinder _libraryFinder; - private readonly MockFileSystem _fileSystem = new(); - private readonly IServiceProvider _serviceProvider; - private readonly ITestingSteamInstallation _steam; public SteamLibraryFinderTest() { - var sc = new ServiceCollection(); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - sc.AddSingleton(new InMemoryRegistry(InMemoryRegistryCreationFlags.Default)); - sc.AddSingleton(_fileSystem); - SteamAbstractionLayer.InitializeServices(sc); - _serviceProvider = sc.BuildServiceProvider(); - _libraryFinder = new SteamLibraryFinder(_serviceProvider); - - _steam = _fileSystem.Steam(_serviceProvider); - _steam.Install(); - } - - public void Dispose() - { - _steam.Dispose(); + _libraryFinder = new SteamLibraryFinder(ServiceProvider); + Steam.Install(); } // TODO: Target all platforms [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_SteamNotFound_ReturnsEmpty() { - Assert.Empty(_libraryFinder.FindLibraries(_fileSystem.DirectoryInfo.New("not steam"))); + Assert.Empty(_libraryFinder.FindLibraries(FileSystem.DirectoryInfo.New("not steam"))); } // TODO: Target all platforms [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_NoLibrariesInstalled() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.Steam(_serviceProvider).Install(); - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(Steam.Registry.InstallationDirectory!); Assert.Empty(libs); } @@ -61,11 +42,8 @@ public void FindLibraries_NoLibrariesInstalled() [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryInstalled() { - using var registry = _serviceProvider.GetRequiredService().CreateRegistry(); - _fileSystem.Steam(_serviceProvider).Install(); - var lib = _steam.InstallDefaultLibrary(addToConfig: true); - - var libs = _libraryFinder.FindLibraries(registry.InstallationDirectory!); + var lib = Steam.InstallDefaultLibrary(addToConfig: true); + var libs = _libraryFinder.FindLibraries(Steam.Registry.InstallationDirectory!); Assert.Equal([lib], libs); } @@ -74,8 +52,8 @@ public void FindLibraries_DefaultLibraryInstalled() [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryInstalledButNotInConfig_NotFound() { - _steam.InstallDefaultLibrary(addToConfig: false); - var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); + Steam.InstallDefaultLibrary(addToConfig: false); + var libs = _libraryFinder.FindLibraries(Steam.InstallationDirectory!); Assert.Empty(libs); } @@ -83,25 +61,26 @@ public void FindLibraries_DefaultLibraryInstalledButNotInConfig_NotFound() [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryAndExternalLibInstalled() { - var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); - var externalLib = _steam.InstallLibrary("externalLib"); + var defaultLib = Steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = Steam.InstallLibrary("externalLib"); - var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(Steam.InstallationDirectory!); Assert.Equal( new List { defaultLib, externalLib }.OrderBy(x => x.LibraryLocation.FullName), libs.OrderBy(x => x.LibraryLocation.FullName)); } + // TODO: Target all platforms [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_Windows_DefaultLibraryAndExternalLibInstalled_ExternalDoesNotHaveSteamDll_Skip() { - var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); - var externalLib = _steam.InstallLibrary("externalLib"); - - _fileSystem.File.Delete(_fileSystem.Path.Combine(externalLib.LibraryLocation.FullName, "steam.dll")); + var defaultLib = Steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = Steam.InstallLibrary("externalLib"); + + FileSystem.File.Delete(FileSystem.Path.Combine(externalLib.LibraryLocation.FullName, "steam.dll")); - var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(Steam.InstallationDirectory!); Assert.Equal([defaultLib], libs.OrderBy(x => x.LibraryLocation.FullName)); } @@ -110,12 +89,12 @@ public void FindLibraries_Windows_DefaultLibraryAndExternalLibInstalled_External [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryAndExternalLibInstalled_ExternalDoesNotHaveVdf_Skip() { - var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); - var externalLib = _steam.InstallLibrary("externalLib"); + var defaultLib = Steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = Steam.InstallLibrary("externalLib"); - _fileSystem.File.Delete(_fileSystem.Path.Combine(externalLib.LibraryLocation.FullName, "libraryfolder.vdf")); + FileSystem.File.Delete(FileSystem.Path.Combine(externalLib.LibraryLocation.FullName, "libraryfolder.vdf")); - var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(Steam.InstallationDirectory!); Assert.Equal([defaultLib], libs.OrderBy(x => x.LibraryLocation.FullName)); } @@ -124,12 +103,12 @@ public void FindLibraries_DefaultLibraryAndExternalLibInstalled_ExternalDoesNotH [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void FindLibraries_DefaultLibraryAndExternalLibInstalled_ExternalFolderDoesNotExist() { - var defaultLib = _steam.InstallDefaultLibrary(addToConfig: true); - var externalLib = _steam.InstallLibrary("externalLib"); + var defaultLib = Steam.InstallDefaultLibrary(addToConfig: true); + var externalLib = Steam.InstallLibrary("externalLib"); - _fileSystem.Directory.Delete(externalLib.LibraryLocation.FullName, true); + FileSystem.Directory.Delete(externalLib.LibraryLocation.FullName, true); - var libs = _libraryFinder.FindLibraries(_steam.InstallationDirectory!); + var libs = _libraryFinder.FindLibraries(Steam.InstallationDirectory!); Assert.Equal([defaultLib], libs.OrderBy(x => x.LibraryLocation.FullName)); } diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs index daea596a..24501519 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs @@ -26,7 +26,7 @@ public SteamLibraryTest() sc.AddSingleton(_registry); _serviceProvider = sc.BuildServiceProvider(); - _steam = _fileSystem.Steam(_serviceProvider); + _steam = SteamTesting.Steam(_serviceProvider); _steam.InstallSteamFilesOnly(); } diff --git a/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs b/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs index 8ad112d2..ff5bfd4e 100644 --- a/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs @@ -25,7 +25,7 @@ public SteamVdfReaderTest() sc.AddSingleton(_ => _fileSystem); sc.AddSingleton(_registry); SteamAbstractionLayer.InitializeServices(sc); - _steam = _fileSystem.Steam(sc.BuildServiceProvider()); + _steam = SteamTesting.Steam(sc.BuildServiceProvider()); _steam.InstallSteamFilesOnly(); } diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 2e4df3d7..0c05e16e 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -54,7 +54,7 @@ protected virtual void BuildServiceCollection(IServiceCollection serviceCollecti [MemberNotNull(nameof(Steam))] protected void InstallSteam() { - Steam = FileSystem.Steam(ServiceProvider); + Steam = SteamTesting.Steam(ServiceProvider); Steam.Install(); } diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 99a90cfd..a0fe0108 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -2,7 +2,7 @@ AET.SteamAbstraction.Testing - netstandard2.0 + netstandard2.0;net10.0 true false @@ -27,7 +27,6 @@ - diff --git a/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs b/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs new file mode 100644 index 00000000..6c585c34 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs @@ -0,0 +1,30 @@ +using System; +using System.IO.Abstractions; +using System.Runtime.InteropServices; +using AnakinRaW.CommonUtilities.Registry; +using Microsoft.Extensions.DependencyInjection; +using Testably.Abstractions.Testing; +#if NET5_0_OR_GREATER +using System.Runtime.Versioning; +#endif + +namespace AET.SteamAbstraction.Testing; + +#if NET5_0_OR_GREATER +[SupportedOSPlatform("windows")] +#endif +public abstract class InMemorySteamTestBase : SteamTestBase +{ + protected readonly MockFileSystem FileSystem = new(); + + protected override void SetupServices(IServiceCollection serviceCollection) + { + base.SetupServices(serviceCollection); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + serviceCollection.AddSingleton(new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike)); + else + throw new NotImplementedException("A system other than Windows is currently not supported"); + + serviceCollection.AddSingleton(FileSystem); + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs index 01624f5c..87c7202e 100644 --- a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs +++ b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs @@ -1,21 +1,16 @@ using System; -using System.IO.Abstractions; namespace AET.SteamAbstraction.Testing; -public static class SteamInstallationExtensions +public static class SteamTesting { - public static ITestingSteamInstallation Steam(this IFileSystem fs, IServiceProvider serviceProvider) + public static ITestingSteamInstallation Steam(IServiceProvider serviceProvider) { - return new TestingSteamInstallationImpl(fs, serviceProvider); + return new TestingSteamInstallationImpl(serviceProvider); } - - - extension(ITestingSteamRegistry) + + public static ITestingSteamRegistry SteamRegistry(IServiceProvider serviceProvider) { - public static ITestingSteamRegistry Create(IFileSystem fileSystem, IServiceProvider serviceProvider) - { - return new TestingSteamRegistryImpl(fileSystem, serviceProvider); - } + return new TestingSteamRegistryImpl(serviceProvider); } } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/SteamTestBase.cs b/test/AET.SteamAbstraction.Testing/SteamTestBase.cs new file mode 100644 index 00000000..3fc6edd7 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/SteamTestBase.cs @@ -0,0 +1,25 @@ +using System; +using AET.Testing; +using Microsoft.Extensions.DependencyInjection; + +namespace AET.SteamAbstraction.Testing; + +public abstract class SteamTestBase : TestBaseWithServiceProvider, IDisposable +{ + protected readonly ITestingSteamInstallation Steam; + protected SteamTestBase() + { + Steam = SteamTesting.Steam(ServiceProvider); + } + + protected override void SetupServices(IServiceCollection serviceCollection) + { + base.SetupServices(serviceCollection); + SteamAbstractionLayer.InitializeServices(serviceCollection); + } + + public virtual void Dispose() + { + Steam.Dispose(); + } +} \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index cef9815b..de43bc63 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -19,7 +19,7 @@ public sealed class TestProcessHelper : IProcessHelper public TestProcessHelper(IServiceProvider sp) { _fileSystem = sp.GetRequiredService(); - _registry = ITestingSteamRegistry.Create(_fileSystem, sp); + _registry = SteamTesting.SteamRegistry(sp); } public Process? CurrentProcess { get; private set; } diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index e57ab11a..01b10874 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -58,7 +58,7 @@ private ITestingSteamLibrary InstallSteamLibrary(string path, bool isDefault, bo using var _ = _fileSystem.File.Create(_fileSystem.Path.Combine(libDir.FullName, "steam.dll")); } - var lib = new TestingSteamLibrary(libDir, serviceProvider); + var lib = new TestingSteamLibrary(libDir, _serviceProvider); if (addToConfig) AddToConfig(lib, _fileSystem); diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs index 3c40336e..2034135a 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs @@ -1,15 +1,16 @@ using System; using System.IO.Abstractions; +using Microsoft.Extensions.DependencyInjection; namespace AET.SteamAbstraction.Testing; -internal sealed partial class TestingSteamInstallationImpl(IFileSystem fileSystem, IServiceProvider serviceProvider) : ITestingSteamInstallation +internal sealed partial class TestingSteamInstallationImpl(IServiceProvider serviceProvider) : ITestingSteamInstallation { - private readonly IFileSystem _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); + private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); private readonly IServiceProvider _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); public IDirectoryInfo? InstallationDirectory => Registry.InstallationDirectory; - public ITestingSteamRegistry Registry { get; } = new TestingSteamRegistryImpl(fileSystem, serviceProvider); + public ITestingSteamRegistry Registry { get; } = SteamTesting.SteamRegistry(serviceProvider); public void Install() { diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs index ae69a6d6..0742e343 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs @@ -6,9 +6,10 @@ namespace AET.SteamAbstraction.Testing; -internal class TestingSteamRegistryImpl(IFileSystem fileSystem, IServiceProvider serviceProvider) : ITestingSteamRegistry +internal class TestingSteamRegistryImpl(IServiceProvider serviceProvider) : ITestingSteamRegistry { private readonly ISteamRegistry _registry = serviceProvider.GetRequiredService().CreateRegistry(); + private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); public IFileInfo? ExecutableFile => _registry.ExecutableFile; public IDirectoryInfo? InstallationDirectory => _registry.InstallationDirectory; @@ -42,8 +43,8 @@ private void InstallWindowsRegistry() { using var key = _registry.OpenSteamRegistryKey(); Assert.NotNull(key); - key.SetValue("SteamExe", fileSystem.Path.GetFullPath(TestingSteamConstants.SteamExePath)); - key.SetValue("SteamPath", fileSystem.Path.GetFullPath(TestingSteamConstants.SteamInstallPath)); + key.SetValue("SteamExe", _fileSystem.Path.GetFullPath(TestingSteamConstants.SteamExePath)); + key.SetValue("SteamPath", _fileSystem.Path.GetFullPath(TestingSteamConstants.SteamInstallPath)); } private void SetPidWindowsRegistry(int? pid) diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index 5199ca73..81c5a783 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -27,7 +27,8 @@ - + + all diff --git a/test/AET.Testing/TestBaseWithServiceProvider.cs b/test/AET.Testing/TestBaseWithServiceProvider.cs new file mode 100644 index 00000000..7216d9da --- /dev/null +++ b/test/AET.Testing/TestBaseWithServiceProvider.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.Extensions.DependencyInjection; + +namespace AET.Testing; + +public abstract class TestBaseWithServiceProvider +{ + protected readonly IServiceProvider ServiceProvider; + + protected TestBaseWithServiceProvider() + { + var sc = new ServiceCollection(); + // ReSharper disable once VirtualMemberCallInConstructor + SetupServices(sc); + ServiceProvider = sc.BuildServiceProvider(); + } + + protected virtual void SetupServices(IServiceCollection serviceCollection) + { + } +} \ No newline at end of file From 3855950efe2dadf112d6bd8174f7e9304a6d4032 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 17 Dec 2025 15:55:29 +0100 Subject: [PATCH 18/71] containue refactor test bases --- .../AET.SteamAbstraction.Test.csproj | 5 --- .../SteamAppManifestTest.cs | 21 +++------- .../SteamRegistryTestBase.cs | 32 +++++++------- .../SteamWrapperTestBase.cs | 35 +++++----------- .../Windows/WindowsSteamRegistryTest.cs | 8 ---- .../Windows/WindowsSteamWrapperTest.cs | 10 ----- .../CompilerHelpers/Attributes.cs | 42 +++++++++++++++++++ .../ITestingSteamInstallation.cs | 7 +++- .../InMemorySteamTestBase.cs | 16 ++----- .../SteamPetroglyphStarWarsGameClientTest.cs | 4 +- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 2 +- 11 files changed, 87 insertions(+), 95 deletions(-) create mode 100644 test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 3914c501..b841e134 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -28,11 +28,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index e278cd62..fbb3d7aa 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -3,7 +3,6 @@ using System.IO.Abstractions; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing; -using AET.Testing; using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; @@ -12,37 +11,29 @@ namespace AET.SteamAbstraction.Test; -public class SteamAppManifestTest : TestBaseWithServiceProvider, IDisposable +public class SteamAppManifestTest : SteamTestBase { private readonly MockFileSystem _fileSystem = new(); - private readonly ITestingSteamInstallation _steam; public SteamAppManifestTest() { - _steam = SteamTesting.Steam(ServiceProvider); - _steam.InstallSteamFilesOnly(); + Steam.InstallSteamFilesOnly(); } protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); serviceCollection.AddSingleton(_fileSystem); - SteamAbstractionLayer.InitializeServices(serviceCollection); serviceCollection.AddSingleton(new InMemoryRegistry()); } - public void Dispose() - { - _steam.Dispose(); - } - [Fact] public void Ctor_NullArgs_Throws() { Assert.Throws(() => new SteamAppManifest(null!, _fileSystem.FileInfo.New("file.acf"), 0, "name", _fileSystem.DirectoryInfo.New("path"), SteamAppState.StateFullyInstalled, new HashSet())); - var lib = _steam.InstallLibrary("path", false); + var lib = Steam.InstallLibrary("path", false); Assert.Throws(() => new SteamAppManifest(lib, null!, 0, "name", _fileSystem.DirectoryInfo.New("path"), SteamAppState.StateFullyInstalled, new HashSet())); @@ -62,7 +53,7 @@ public void Ctor_NullArgs_Throws() [Fact] public void Ctor_SetsProperties() { - var lib = _steam.InstallLibrary("path", false); + var lib = Steam.InstallLibrary("path", false); var appManifest = new SteamAppManifest(lib, _fileSystem.FileInfo.New("file.acf"), 123, "name", _fileSystem.DirectoryInfo.New("path"), SteamAppState.StateFullyInstalled, new HashSet {987, 654}); @@ -79,8 +70,8 @@ public void Ctor_SetsProperties() [Fact] public void Equality() { - var lib = _steam.InstallLibrary("path", false); - var otherLib = _steam.InstallLibrary("other", false); + var lib = Steam.InstallLibrary("path", false); + var otherLib = Steam.InstallLibrary("other", false); const uint aId = 123; const uint bId = 456; diff --git a/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs b/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs index 9777a1f7..d250857a 100644 --- a/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs @@ -1,40 +1,38 @@ -using System; +using AET.SteamAbstraction.Registry; +using AET.Testing; +using AnakinRaW.CommonUtilities.Registry; +using Microsoft.Extensions.DependencyInjection; +using System; using System.IO.Abstractions; using System.Reflection; -using AET.SteamAbstraction.Registry; -using Microsoft.Extensions.DependencyInjection; +using System.Runtime.InteropServices; using Testably.Abstractions.Testing; using Xunit; namespace AET.SteamAbstraction.Test; -public abstract class SteamRegistryTestBase +public abstract class SteamRegistryTestBase : TestBaseWithServiceProvider { protected readonly MockFileSystem FileSystem = new(); + protected readonly IRegistry InternalRegistry = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike) + : new InMemoryRegistry(); protected readonly string SteamInstallPath = "steamDir"; protected readonly string SteamExePath = "steamDir/steam"; - protected readonly IServiceProvider ServiceProvider; - - protected SteamRegistryTestBase() + protected override void SetupServices(IServiceCollection serviceCollection) { - var sc = new ServiceCollection(); - sc.AddSingleton(FileSystem); - SteamAbstractionLayer.InitializeServices(sc); - // ReSharper disable once VirtualMemberCallInConstructor - BuildServiceCollection(sc); - ServiceProvider = sc.BuildServiceProvider(); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(FileSystem); + serviceCollection.AddSingleton(InternalRegistry); + SteamAbstractionLayer.InitializeServices(serviceCollection); } private protected abstract ISteamRegistry CreateRegistry(bool steamExists = true); protected abstract void SetSteamPid(int pid); - protected virtual void BuildServiceCollection(IServiceCollection serviceCollection) - { - } - [Fact] public void TestInstallationProperties_SteamNotInstalled() { diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 0c05e16e..a36508b7 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO.Abstractions; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -11,50 +9,39 @@ using AET.Testing.Extensions; using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; -using Testably.Abstractions.Testing; using Xunit; namespace AET.SteamAbstraction.Test; -public abstract class SteamWrapperTestBase : IDisposable +public abstract class SteamWrapperTestBase : InMemorySteamTestBase { private readonly ISteamWrapperFactory _wrapperFactory; - protected readonly MockFileSystem FileSystem = new(); - protected readonly IServiceProvider ServiceProvider; - - protected ITestingSteamInstallation? Steam; internal TestProcessHelper? ProcessHelper; protected SteamWrapperTestBase() { - var sc = new ServiceCollection(); - sc.AddSingleton(FileSystem); - SteamAbstractionLayer.InitializeServices(sc); - sc.AddSingleton(sp => - { - return ProcessHelper = new TestProcessHelper(sp); - }); - sc.AddSingleton(sp => sp.GetRequiredService()); - // ReSharper disable once VirtualMemberCallInConstructor - BuildServiceCollection(sc); - ServiceProvider = sc.BuildServiceProvider(); _wrapperFactory = ServiceProvider.GetRequiredService(); } - public void Dispose() + protected override void SetupServices(IServiceCollection serviceCollection) { - ProcessHelper?.KillCurrent(); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(sp => + { + return ProcessHelper = new TestProcessHelper(sp); + }); + serviceCollection.AddSingleton(sp => sp.GetRequiredService()); } - protected virtual void BuildServiceCollection(IServiceCollection serviceCollection) + public override void Dispose() { + base.Dispose(); + ProcessHelper?.KillCurrent(); } - [MemberNotNull(nameof(Steam))] protected void InstallSteam() { - Steam = SteamTesting.Steam(ServiceProvider); Steam.Install(); } diff --git a/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs b/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs index 5d2dd58f..6cd0fa0a 100644 --- a/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs +++ b/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs @@ -2,20 +2,12 @@ using AET.SteamAbstraction.Registry; using AnakinRaW.CommonUtilities.Registry; -using Microsoft.Extensions.DependencyInjection; using Xunit; namespace AET.SteamAbstraction.Test.Windows; public class WindowsSteamRegistryTest : SteamRegistryTestBase { - protected readonly IRegistry InternalRegistry = new InMemoryRegistry(); - - protected override void BuildServiceCollection(IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(InternalRegistry); - } - internal WindowsSteamRegistry CreateWindowsRegistry(bool steamExists = true) { var registry = new WindowsSteamRegistry(ServiceProvider); diff --git a/test/AET.SteamAbstraction.Test/Windows/WindowsSteamWrapperTest.cs b/test/AET.SteamAbstraction.Test/Windows/WindowsSteamWrapperTest.cs index f814648d..9986ba4c 100644 --- a/test/AET.SteamAbstraction.Test/Windows/WindowsSteamWrapperTest.cs +++ b/test/AET.SteamAbstraction.Test/Windows/WindowsSteamWrapperTest.cs @@ -1,21 +1,11 @@ #if Windows - using System; -using AnakinRaW.CommonUtilities.Registry; -using Microsoft.Extensions.DependencyInjection; using Xunit; namespace AET.SteamAbstraction.Test.Windows; public class WindowsSteamWrapperTest : SteamWrapperTestBase { - protected readonly IRegistry InternalRegistry = new InMemoryRegistry(); - - protected override void BuildServiceCollection(IServiceCollection serviceCollection) - { - serviceCollection.AddSingleton(InternalRegistry); - } - [Fact] public void TestInvalidArgs_Throws() { diff --git a/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs b/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs new file mode 100644 index 00000000..e20fb274 --- /dev/null +++ b/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs @@ -0,0 +1,42 @@ +#if !NET5_0_OR_GREATER +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +namespace System.Runtime.Versioning; + +/// +/// Base type for all platform-specific API attributes. +/// + +internal abstract class OSPlatformAttribute(string PlatformName) : Attribute; + +/// +/// Records the platform that the project targeted. +/// +[AttributeUsage(AttributeTargets.Assembly)] +internal sealed class TargetPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); + +/// +/// Records the operating system (and minimum version) that supports an API. Multiple attributes can be +/// applied to indicate support on multiple operating systems. +/// +/// +/// Callers can apply a +/// or use guards to prevent calls to APIs on unsupported operating systems. +/// +/// A given platform should only be specified once. +/// +[AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Interface | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +internal sealed class SupportedOSPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); +// ReSharper restore InconsistentNaming +#endif \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs index 9e5d7476..62b2c328 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs @@ -1,19 +1,24 @@ using System; using System.Collections.Generic; using System.IO.Abstractions; +using System.Runtime.Versioning; namespace AET.SteamAbstraction.Testing; public interface ITestingSteamInstallation : IDisposable { + [SupportedOSPlatform("windows")] IDirectoryInfo? InstallationDirectory { get; } + [SupportedOSPlatform("windows")] ITestingSteamRegistry Registry { get; } + [SupportedOSPlatform("windows")] void Install(); void InstallSteamFilesOnly(); - + + [SupportedOSPlatform("windows")] ISteamFakeProcess FakeStart(int pid); ITestingSteamLibrary InstallDefaultLibrary(bool addToConfig = true); diff --git a/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs b/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs index 6c585c34..bd3265d4 100644 --- a/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs @@ -1,18 +1,11 @@ -using System; -using System.IO.Abstractions; +using System.IO.Abstractions; using System.Runtime.InteropServices; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; -#if NET5_0_OR_GREATER -using System.Runtime.Versioning; -#endif namespace AET.SteamAbstraction.Testing; -#if NET5_0_OR_GREATER -[SupportedOSPlatform("windows")] -#endif public abstract class InMemorySteamTestBase : SteamTestBase { protected readonly MockFileSystem FileSystem = new(); @@ -20,10 +13,9 @@ public abstract class InMemorySteamTestBase : SteamTestBase protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - serviceCollection.AddSingleton(new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike)); - else - throw new NotImplementedException("A system other than Windows is currently not supported"); + serviceCollection.AddSingleton(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike) + : new InMemoryRegistry()); serviceCollection.AddSingleton(FileSystem); } diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index 2205c025..ede4efb6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -29,7 +29,7 @@ public class SteamPetroglyphStarWarsGameClientTest : PetroglyphStarWarsGameClien protected override void BeforePlay() { // Install Steam (regardless whether the identity is supported) - var steam = FileSystem.Steam(ServiceProvider); + var steam = SteamTesting.Steam(ServiceProvider); steam.Install(); _steamProcess = steam.FakeStart(12345); base.BeforePlay(); @@ -95,7 +95,7 @@ public void Play_SteamNotInstalled_Throws() public void Play_SteamNotRunning_Throws() { // Install Steam (regardless whether the identity is supported) - FileSystem.Steam(ServiceProvider).Install(); + SteamTesting.Steam(ServiceProvider).Install(); var expected = new GameProcessInfo(_game, GameBuildType.Release, ArgumentCollection.Empty); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 762bc691..5ff090dc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -129,7 +129,7 @@ private GameDetectorTestInfo SetupGame( SteamAppState appState = SteamAppState.StateFullyInstalled) { // Install Steam (regardless whether the identity is supported) - var steam = FileSystem.Steam(ServiceProvider); + var steam = SteamTesting.Steam(ServiceProvider); steam.Install(); if (gameIdentity.Platform != GamePlatform.SteamGold) From 549cb7cf67bf395490b8ecc1c50f373ce6cab856 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 17 Dec 2025 18:10:08 +0100 Subject: [PATCH 19/71] using test bases --- .../SteamAppManifestTest.cs | 2 +- .../SteamLibraryFinderTest.cs | 3 +- .../SteamLibraryTest.cs | 54 ++++------- .../SteamRegistryFactoryTest.cs | 27 +++--- .../SteamVdfReaderTest.cs | 94 ++++++++----------- .../SteamWrapperFactoryTest.cs | 25 ++--- .../SteamWrapperIntegrationTest.cs | 18 ++-- .../SteamWrapperTestBase.cs | 1 + .../ITestingSteamInstallation.cs | 2 - .../ITestingSteamRegistry.cs | 3 + .../{ => TestBases}/InMemorySteamTestBase.cs | 2 +- .../{ => TestBases}/SteamTestBase.cs | 2 +- .../TestingSteamInstallationImpl.cs | 8 +- 13 files changed, 102 insertions(+), 139 deletions(-) rename test/AET.SteamAbstraction.Testing/{ => TestBases}/InMemorySteamTestBase.cs (93%) rename test/AET.SteamAbstraction.Testing/{ => TestBases}/SteamTestBase.cs (92%) diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index fbb3d7aa..d32cc5b7 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO.Abstractions; using AET.SteamAbstraction.Games; -using AET.SteamAbstraction.Testing; +using AET.SteamAbstraction.Testing.TestBases; using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index 6e6a4684..760c6725 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -1,9 +1,10 @@ using System.Collections.Generic; using System.Linq; using AET.SteamAbstraction.Library; -using AET.SteamAbstraction.Testing; +using AET.SteamAbstraction.Testing.TestBases; using AET.Testing.Attributes; using Xunit; + #if NET5_0_OR_GREATER using System.Runtime.Versioning; #endif diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs index 24501519..3e39d97d 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryTest.cs @@ -1,45 +1,25 @@ using System; -using System.IO.Abstractions; using System.Linq; using System.Runtime.InteropServices; using AET.SteamAbstraction.Library; -using AET.SteamAbstraction.Testing; -using AnakinRaW.CommonUtilities.Registry; -using Microsoft.Extensions.DependencyInjection; -using Testably.Abstractions.Testing; +using AET.SteamAbstraction.Testing.TestBases; using Xunit; namespace AET.SteamAbstraction.Test; -public class SteamLibraryTest : IDisposable +public class SteamLibraryTest : InMemorySteamTestBase { - private readonly IServiceProvider _serviceProvider; - private readonly MockFileSystem _fileSystem = new(); - private readonly IRegistry _registry = new InMemoryRegistry(); - private readonly ITestingSteamInstallation _steam; - public SteamLibraryTest() { - var sc = new ServiceCollection(); - sc.AddSingleton(_ => _fileSystem); - SteamAbstractionLayer.InitializeServices(sc); - sc.AddSingleton(_registry); - _serviceProvider = sc.BuildServiceProvider(); - - _steam = SteamTesting.Steam(_serviceProvider); - _steam.InstallSteamFilesOnly(); + Steam.InstallSteamFilesOnly(); } - public void Dispose() - { - _steam.Dispose(); - } [Fact] public void Ctor_NullArgs_Throws() { - Assert.Throws(() => new SteamLibrary(null!, _serviceProvider)); - Assert.Throws(() => new SteamLibrary(_fileSystem.DirectoryInfo.New("Library"), null!)); + Assert.Throws(() => new SteamLibrary(null!, ServiceProvider)); + Assert.Throws(() => new SteamLibrary(FileSystem.DirectoryInfo.New("Library"), null!)); } [Theory] @@ -49,8 +29,8 @@ public void Ctor_NullArgs_Throws() [InlineData("other", false, false)] public void TestEquality(string path, bool equalWindows, bool equalLinux) { - var lib = new SteamLibrary(_fileSystem.DirectoryInfo.New("Library"), _serviceProvider); - var other = new SteamLibrary(_fileSystem.DirectoryInfo.New(path), _serviceProvider); + var lib = new SteamLibrary(FileSystem.DirectoryInfo.New("Library"), ServiceProvider); + var other = new SteamLibrary(FileSystem.DirectoryInfo.New(path), ServiceProvider); var equal = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? equalWindows : equalLinux; @@ -61,7 +41,7 @@ public void TestEquality(string path, bool equalWindows, bool equalLinux) [Fact] public void TestEquality_NullAndSame() { - var lib = new SteamLibrary(_fileSystem.DirectoryInfo.New("Library"), _serviceProvider); + var lib = new SteamLibrary(FileSystem.DirectoryInfo.New("Library"), ServiceProvider); Assert.False(lib.Equals((object)null!)); Assert.False(lib.Equals(null)); @@ -73,12 +53,12 @@ public void TestEquality_NullAndSame() [Fact] public void Locations() { - var libDirBasePath = _fileSystem.DirectoryInfo.New("Library"); - var expectedSteamApps = _fileSystem.Path.Combine(libDirBasePath.FullName, "steamapps"); - var expectedCommon = _fileSystem.Path.Combine(expectedSteamApps, "common"); - var expectedWorkshop = _fileSystem.Path.Combine(expectedSteamApps, "workshop"); + var libDirBasePath = FileSystem.DirectoryInfo.New("Library"); + var expectedSteamApps = FileSystem.Path.Combine(libDirBasePath.FullName, "steamapps"); + var expectedCommon = FileSystem.Path.Combine(expectedSteamApps, "common"); + var expectedWorkshop = FileSystem.Path.Combine(expectedSteamApps, "workshop"); - var lib = new SteamLibrary(_fileSystem.DirectoryInfo.New("Library"), _serviceProvider); + var lib = new SteamLibrary(FileSystem.DirectoryInfo.New("Library"), ServiceProvider); Assert.Equal(expectedSteamApps, lib.SteamAppsLocation.FullName); Assert.Equal(expectedCommon, lib.CommonLocation.FullName); Assert.Equal(expectedWorkshop, lib.WorkshopsLocation.FullName); @@ -87,7 +67,7 @@ public void Locations() [Fact] public void GetApps_NoAppsInstalled_Empty() { - var library = _steam.InstallLibrary("Library"); + var library = Steam.InstallLibrary("Library"); var apps = library.GetApps(); @@ -97,7 +77,7 @@ public void GetApps_NoAppsInstalled_Empty() [Fact] public void GetApps_NoSteamAppsDirectoryDoesNotExists_Empty() { - var library = _steam.InstallLibrary("Library"); + var library = Steam.InstallLibrary("Library"); library.SteamAppsLocation.Delete(true); var apps = library.GetApps(); @@ -108,7 +88,7 @@ public void GetApps_NoSteamAppsDirectoryDoesNotExists_Empty() [Fact] public void GetApps_InvalidAcfFile_Skipped() { - var library = _steam.InstallLibrary("Library"); + var library = Steam.InstallLibrary("Library"); library.InstallCorruptApp(); var apps = library.GetApps(); @@ -119,7 +99,7 @@ public void GetApps_InvalidAcfFile_Skipped() [Fact] public void TestApps() { - var library = _steam.InstallLibrary("Library"); + var library = Steam.InstallLibrary("Library"); library.InstallCorruptApp(); library.InstallGame(123, "Game1", "manifest1.acf"); diff --git a/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs b/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs index 6a1738b6..90515390 100644 --- a/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs @@ -1,32 +1,29 @@ -using System; -using System.IO.Abstractions; -using System.Runtime.InteropServices; -using AET.SteamAbstraction.Registry; +using AET.SteamAbstraction.Registry; +using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Win32; +using System; +using System.IO.Abstractions; +using System.Runtime.InteropServices; using Testably.Abstractions.Testing; using Xunit; namespace AET.SteamAbstraction.Test; -public class SteamRegistryFactoryTest +public class SteamRegistryFactoryTest : TestBaseWithServiceProvider { - private readonly IRegistry _registry = new InMemoryRegistry(); - private readonly MockFileSystem _fileSystem = new(); - private readonly IServiceProvider _serviceProvider; - - public SteamRegistryFactoryTest() + protected override void SetupServices(IServiceCollection serviceCollection) { - var sc = new ServiceCollection(); - sc.AddSingleton(_fileSystem); - sc.AddSingleton(_registry); - _serviceProvider = sc.BuildServiceProvider(); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(new MockFileSystem()); + serviceCollection.AddSingleton(new InMemoryRegistry()); } [Fact] public void Test_CreateWrapper() { - var factory = new SteamRegistryFactory(_serviceProvider); + var factory = new SteamRegistryFactory(ServiceProvider); var registry = factory.CreateRegistry(); diff --git a/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs b/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs index ff5bfd4e..e741d6ab 100644 --- a/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamVdfReaderTest.cs @@ -1,11 +1,9 @@ using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing; -using AnakinRaW.CommonUtilities.Registry; -using Microsoft.Extensions.DependencyInjection; +using AET.SteamAbstraction.Testing.TestBases; using System; using System.Collections.Generic; using System.IO; -using System.IO.Abstractions; using System.Linq; using Testably.Abstractions.Testing; using Xunit; @@ -13,25 +11,11 @@ namespace AET.SteamAbstraction.Test; -public class SteamVdfReaderTest : IDisposable +public class SteamVdfReaderTest : InMemorySteamTestBase { - private readonly MockFileSystem _fileSystem = new(); - private readonly IRegistry _registry = new InMemoryRegistry(); - private readonly ITestingSteamInstallation _steam; - public SteamVdfReaderTest() { - var sc = new ServiceCollection(); - sc.AddSingleton(_ => _fileSystem); - sc.AddSingleton(_registry); - SteamAbstractionLayer.InitializeServices(sc); - _steam = SteamTesting.Steam(sc.BuildServiceProvider()); - _steam.InstallSteamFilesOnly(); - } - - public void Dispose() - { - _steam.Dispose(); + Steam.InstallSteamFilesOnly(); } #region ReadLibraryLocationsFromConfig @@ -39,8 +23,8 @@ public void Dispose() [Fact] public void ReadLibraryLocationsFromConfig_EmptyFile_Throws() { - _fileSystem.Initialize().WithFile("input.vdf"); - var input = _fileSystem.FileInfo.New("input.vdf"); + FileSystem.Initialize().WithFile("input.vdf"); + var input = FileSystem.FileInfo.New("input.vdf"); Assert.Throws(() => SteamVdfReader.ReadLibraryLocationsFromConfig(input).ToList()); } @@ -52,9 +36,9 @@ public void ReadLibraryLocationsFromConfig_InvalidRootNodeName_Throws() ""0"" ""/Lib"" } "; - _fileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); + FileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); - var input = _fileSystem.FileInfo.New("input.vdf"); + var input = FileSystem.FileInfo.New("input.vdf"); Assert.Throws(() => SteamVdfReader.ReadLibraryLocationsFromConfig(input).ToList()); } @@ -62,9 +46,9 @@ public void ReadLibraryLocationsFromConfig_InvalidRootNodeName_Throws() public void ReadLibraryLocationsFromConfig_InvalidRootNodeKind_Throws() { var data = @"""libraryfolders"" ""someData"""; - _fileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); + FileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); - var input = _fileSystem.FileInfo.New("input.vdf"); + var input = FileSystem.FileInfo.New("input.vdf"); Assert.Throws(() => SteamVdfReader.ReadLibraryLocationsFromConfig(input).ToList()); } @@ -92,16 +76,16 @@ public void ReadLibraryLocationsFromConfig() } "; - var expected1 = _fileSystem.DirectoryInfo.New("/Lib1").FullName; - var expected2 = _fileSystem.DirectoryInfo.New("/Lib2").FullName; - var expected3 = _fileSystem.DirectoryInfo.New("/Lib3").FullName; + var expected1 = FileSystem.DirectoryInfo.New("/Lib1").FullName; + var expected2 = FileSystem.DirectoryInfo.New("/Lib2").FullName; + var expected3 = FileSystem.DirectoryInfo.New("/Lib3").FullName; - var notExpected1 = _fileSystem.DirectoryInfo.New("/LibA").FullName; - var notExpected2 = _fileSystem.DirectoryInfo.New("/LabelA").FullName; + var notExpected1 = FileSystem.DirectoryInfo.New("/LibA").FullName; + var notExpected2 = FileSystem.DirectoryInfo.New("/LabelA").FullName; - _fileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); + FileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); - var input = _fileSystem.FileInfo.New("input.vdf"); + var input = FileSystem.FileInfo.New("input.vdf"); var locations = SteamVdfReader.ReadLibraryLocationsFromConfig(input).Select(l => l.FullName).ToList(); Assert.Contains(expected1, locations); @@ -119,9 +103,9 @@ public void ReadLibraryLocationsFromConfig_NoLibrariesFound_EmptyEnumerable() ""NaN"" ""/Lib"" } "; - _fileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); + FileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); - var input = _fileSystem.FileInfo.New("input.vdf"); + var input = FileSystem.FileInfo.New("input.vdf"); var libs = SteamVdfReader.ReadLibraryLocationsFromConfig(input); Assert.Empty(libs); } @@ -133,9 +117,9 @@ public void ReadLibraryLocationsFromConfig_EmptyContent_EmptyEnumerable() { } "; - _fileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); + FileSystem.Initialize().WithFile("input.vdf").Which(d => d.HasStringContent(data)); - var input = _fileSystem.FileInfo.New("input.vdf"); + var input = FileSystem.FileInfo.New("input.vdf"); var libs = SteamVdfReader.ReadLibraryLocationsFromConfig(input); Assert.Empty(libs); } @@ -147,15 +131,15 @@ public void ReadLibraryLocationsFromConfig_EmptyContent_EmptyEnumerable() [Fact] public void ReadManifest_NullArgs_Throws() { - var lib = _steam.InstallLibrary("steamLib", false); + var lib = Steam.InstallLibrary("steamLib", false); Assert.Throws(() => SteamVdfReader.ReadManifest(null!, lib)); - Assert.Throws(() => SteamVdfReader.ReadManifest(_fileSystem.FileInfo.New("path"), null!)); + Assert.Throws(() => SteamVdfReader.ReadManifest(FileSystem.FileInfo.New("path"), null!)); } [Fact] public void ReadManifest_CorrectManifest() { - var lib = _steam.InstallLibrary("steamLib", false); + var lib = Steam.InstallLibrary("steamLib", false); var expectedManifest = lib.InstallGame( 1230, @@ -305,19 +289,19 @@ public static IEnumerable GetInvalidAppManifestContent() [MemberData(nameof(GetInvalidAppManifestContent))] public void ReadManifest_InvalidAppManifest_Throws(string content) { - var lib = _steam.InstallLibrary("steamLib", false); + var lib = Steam.InstallLibrary("steamLib", false); - var manifestFile = _fileSystem.Path.Combine(lib.SteamAppsLocation.FullName, "manifest.acf"); - _fileSystem.File.WriteAllText(manifestFile, content); + var manifestFile = FileSystem.Path.Combine(lib.SteamAppsLocation.FullName, "manifest.acf"); + FileSystem.File.WriteAllText(manifestFile, content); - Assert.ThrowsAny(() => SteamVdfReader.ReadManifest(_fileSystem.FileInfo.New(manifestFile), lib)); + Assert.ThrowsAny(() => SteamVdfReader.ReadManifest(FileSystem.FileInfo.New(manifestFile), lib)); } [Fact] public void ReadManifest_ManifestNotPartOfLibrary_Throws() { - var lib = _steam.InstallLibrary("steamLib", false); - var otherLib = _steam.InstallLibrary("otherLib", false); + var lib = Steam.InstallLibrary("steamLib", false); + var otherLib = Steam.InstallLibrary("otherLib", false); var manifestFile = otherLib.InstallGame(1230, "MyGame").ManifestFile; @@ -337,7 +321,7 @@ public void ReadLoginUsers_NullFile_Throws() [Fact] public void ReadLoginUsers_FileNotExists_Throws() { - var e = Assert.ThrowsAny(() => SteamVdfReader.ReadLoginUsers(_fileSystem.FileInfo.New("NotExists.vdf"))); + var e = Assert.ThrowsAny(() => SteamVdfReader.ReadLoginUsers(FileSystem.FileInfo.New("NotExists.vdf"))); Assert.IsType(e.InnerException); } @@ -402,8 +386,8 @@ public static IEnumerable GetInvalidLoginUserContent() [MemberData(nameof(GetInvalidLoginUserContent))] public void ReadLoginUsers_FileWithInvalidContent(string content) { - _fileSystem.File.WriteAllText("loginusers.vdf", content); - var file = _fileSystem.FileInfo.New("loginusers.vdf"); + FileSystem.File.WriteAllText("loginusers.vdf", content); + var file = FileSystem.FileInfo.New("loginusers.vdf"); Assert.ThrowsAny(() => SteamVdfReader.ReadLoginUsers(file)); } @@ -437,8 +421,8 @@ public void ReadLoginUsers_FileWithNotParsableUserIdIsSkipped() ""Timestamp"" ""00000000"" } }"; - _fileSystem.File.WriteAllText("loginusers.vdf", content); - var file = _fileSystem.FileInfo.New("loginusers.vdf"); + FileSystem.File.WriteAllText("loginusers.vdf", content); + var file = FileSystem.FileInfo.New("loginusers.vdf"); var user = Assert.Single(SteamVdfReader.ReadLoginUsers(file).Users); Assert.Equal(18446744073709551615u, user.UserId); @@ -457,8 +441,8 @@ public void ReadLoginUsers_UseDefaults() } } "; - _fileSystem.File.WriteAllText("loginusers.vdf", content); - var file = _fileSystem.FileInfo.New("loginusers.vdf"); + FileSystem.File.WriteAllText("loginusers.vdf", content); + var file = FileSystem.FileInfo.New("loginusers.vdf"); var user = Assert.Single(SteamVdfReader.ReadLoginUsers(file).Users); Assert.Equal(123456789u, user.UserId); @@ -474,8 +458,8 @@ public void ReadLoginUsers_EmptyFile() { } "; - _fileSystem.File.WriteAllText("loginusers.vdf", content); - var file = _fileSystem.FileInfo.New("loginusers.vdf"); + FileSystem.File.WriteAllText("loginusers.vdf", content); + var file = FileSystem.FileInfo.New("loginusers.vdf"); Assert.Empty(SteamVdfReader.ReadLoginUsers(file).Users); } @@ -491,7 +475,7 @@ public void ReadLoginUsers() new(4, true, true), }; - var file = _steam.WriteLoginUsers(expectedUsers); + var file = Steam.WriteLoginUsers(expectedUsers); var users = SteamVdfReader.ReadLoginUsers(file); diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs b/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs index 8861a44f..2d4fc260 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs @@ -1,5 +1,5 @@ -using System; -using System.IO.Abstractions; +using System.IO.Abstractions; +using AET.Testing; using AET.Testing.Attributes; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; @@ -8,27 +8,20 @@ namespace AET.SteamAbstraction.Test; -public class SteamWrapperFactoryTest +public class SteamWrapperFactoryTest : TestBaseWithServiceProvider { - private readonly IServiceProvider _serviceProvider; - - public SteamWrapperFactoryTest() + protected override void SetupServices(IServiceCollection serviceCollection) { - var sc = new ServiceCollection(); - var registry = new InMemoryRegistry(); - var fs = new MockFileSystem(); - - sc.AddSingleton(fs); - sc.AddSingleton(registry); - SteamAbstractionLayer.InitializeServices(sc); - - _serviceProvider = sc.BuildServiceProvider(); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(new MockFileSystem()); + serviceCollection.AddSingleton(new InMemoryRegistry()); + SteamAbstractionLayer.InitializeServices(serviceCollection); } [PlatformSpecificFact(TestPlatformIdentifier.Windows)] public void Test_CreateWrapper_Windows() { - var factory = new SteamWrapperFactory(_serviceProvider); + var factory = new SteamWrapperFactory(ServiceProvider); var wrapper = factory.CreateWrapper(); Assert.IsType(wrapper); } diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs b/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs index ac91aa74..639ea54c 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs @@ -1,6 +1,7 @@ using System.IO.Abstractions; using System.Runtime.InteropServices; using System.Threading.Tasks; +using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using AnakinRaW.CommonUtilities.Registry.Windows; using Microsoft.Extensions.DependencyInjection; @@ -9,21 +10,22 @@ namespace AET.SteamAbstraction.Test; -public class SteamWrapperIntegrationTest +public class SteamWrapperIntegrationTest : TestBaseWithServiceProvider { private readonly ISteamWrapper _service; public SteamWrapperIntegrationTest() { - var sc = new ServiceCollection(); - // Use actual FS - sc.AddSingleton(new RealFileSystem()); - SteamAbstractionLayer.InitializeServices(sc); + _service = ServiceProvider.GetRequiredService().CreateWrapper(); + } + protected override void SetupServices(IServiceCollection serviceCollection) + { + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(new RealFileSystem()); + SteamAbstractionLayer.InitializeServices(serviceCollection); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - sc.AddSingleton(new WindowsRegistry()); - - _service = sc.BuildServiceProvider().GetRequiredService().CreateWrapper(); + serviceCollection.AddSingleton(new WindowsRegistry()); } //[Fact] diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index a36508b7..125ec804 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using AET.SteamAbstraction.Library; using AET.SteamAbstraction.Testing; +using AET.SteamAbstraction.Testing.TestBases; using AET.SteamAbstraction.Utilities; using AET.Testing.Extensions; using AnakinRaW.CommonUtilities; diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs index 62b2c328..81532f0b 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs @@ -7,10 +7,8 @@ namespace AET.SteamAbstraction.Testing; public interface ITestingSteamInstallation : IDisposable { - [SupportedOSPlatform("windows")] IDirectoryInfo? InstallationDirectory { get; } - [SupportedOSPlatform("windows")] ITestingSteamRegistry Registry { get; } [SupportedOSPlatform("windows")] diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs index 8205b543..b771f3c5 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs @@ -1,5 +1,6 @@ using System; using System.IO.Abstractions; +using System.Runtime.Versioning; namespace AET.SteamAbstraction.Testing; @@ -20,8 +21,10 @@ public interface ITestingSteamRegistry : IDisposable /// int? ProcessId { get; } + [SupportedOSPlatform("windows")] void InstallSteam(); + [SupportedOSPlatform("windows")] void SetPid(int? pid); void SetUserId(uint userId); diff --git a/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs similarity index 93% rename from test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs rename to test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs index bd3265d4..81722ebf 100644 --- a/test/AET.SteamAbstraction.Testing/InMemorySteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; -namespace AET.SteamAbstraction.Testing; +namespace AET.SteamAbstraction.Testing.TestBases; public abstract class InMemorySteamTestBase : SteamTestBase { diff --git a/test/AET.SteamAbstraction.Testing/SteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs similarity index 92% rename from test/AET.SteamAbstraction.Testing/SteamTestBase.cs rename to test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs index 3fc6edd7..f976d963 100644 --- a/test/AET.SteamAbstraction.Testing/SteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs @@ -2,7 +2,7 @@ using AET.Testing; using Microsoft.Extensions.DependencyInjection; -namespace AET.SteamAbstraction.Testing; +namespace AET.SteamAbstraction.Testing.TestBases; public abstract class SteamTestBase : TestBaseWithServiceProvider, IDisposable { diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs index 2034135a..882e6f00 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs @@ -1,6 +1,7 @@ -using System; +using Microsoft.Extensions.DependencyInjection; +using System; using System.IO.Abstractions; -using Microsoft.Extensions.DependencyInjection; +using System.Runtime.Versioning; namespace AET.SteamAbstraction.Testing; @@ -10,8 +11,10 @@ internal sealed partial class TestingSteamInstallationImpl(IServiceProvider serv private readonly IServiceProvider _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); public IDirectoryInfo? InstallationDirectory => Registry.InstallationDirectory; + public ITestingSteamRegistry Registry { get; } = SteamTesting.SteamRegistry(serviceProvider); + [SupportedOSPlatform("windows")] public void Install() { Registry.InstallSteam(); @@ -27,6 +30,7 @@ public void InstallSteamFilesOnly() using var _ = _fileSystem.File.Create(exePath); } + [SupportedOSPlatform("windows")] public ISteamFakeProcess FakeStart(int pid) { Registry.SetPid(pid); From 7a767fc7be20505bbb93146639d412f8c68bea91 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 17 Dec 2025 19:41:48 +0100 Subject: [PATCH 20/71] use testing bases --- .../CompilerHelpers/Attributes.cs | 42 +++++++++++++++++++ .../IGameClientFactoryTest.cs | 12 +++--- .../SteamPetroglyphStarWarsGameClientTest.cs | 16 +++---- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 12 +++--- .../Clients/GameClientFactoryTest.cs | 6 +-- .../PetroglyphStarWarsGameClientTest.cs | 18 ++++---- .../Detection/RegistryGameDetectorTest.cs | 6 +-- .../GameServices/GameFactoryTest.cs | 12 +++--- .../ModServices/ModFactoryTest.cs | 6 +-- ...oglyphGameInfrastructureIntegrationTest.cs | 6 +-- .../PlayableObjectTest.cs | 6 +-- .../Clients/TestGameProcessLauncher.cs | 2 +- .../Registry/TestGameRegistrySetupData.cs | 2 +- .../TestBases/GameInfrastructureTestBase.cs | 24 +++++------ 14 files changed, 106 insertions(+), 64 deletions(-) create mode 100644 test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs new file mode 100644 index 00000000..e20fb274 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs @@ -0,0 +1,42 @@ +#if !NET5_0_OR_GREATER +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +namespace System.Runtime.Versioning; + +/// +/// Base type for all platform-specific API attributes. +/// + +internal abstract class OSPlatformAttribute(string PlatformName) : Attribute; + +/// +/// Records the platform that the project targeted. +/// +[AttributeUsage(AttributeTargets.Assembly)] +internal sealed class TargetPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); + +/// +/// Records the operating system (and minimum version) that supports an API. Multiple attributes can be +/// applied to indicate support on multiple operating systems. +/// +/// +/// Callers can apply a +/// or use guards to prevent calls to APIs on unsupported operating systems. +/// +/// A given platform should only be specified once. +/// +[AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Interface | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +internal sealed class SupportedOSPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); +// ReSharper restore InconsistentNaming +#endif \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs index 144e5e8a..8ff8ee11 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs @@ -15,13 +15,13 @@ public class IGameClientFactoryTest : GameInfrastructureTestBase { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(_registry); - SteamAbstractionLayer.InitializeServices(sc); - PetroglyphGameInfrastructure.InitializeServices(sc); - SteamPetroglyphStarWarsGameClients.InitializeServices(sc); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(_registry); + SteamAbstractionLayer.InitializeServices(serviceCollection); + PetroglyphGameInfrastructure.InitializeServices(serviceCollection); + SteamPetroglyphStarWarsGameClients.InitializeServices(serviceCollection); } [Theory] diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index ede4efb6..9c3b6187 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -13,10 +13,12 @@ using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using System; using System.Collections.Generic; +using System.Runtime.Versioning; using Xunit; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; +[SupportedOSPlatform("windows")] public class SteamPetroglyphStarWarsGameClientTest : PetroglyphStarWarsGameClientTest { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); @@ -40,15 +42,15 @@ public SteamPetroglyphStarWarsGameClientTest() _game = FileSystem.InstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); } - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - sc.AddSingleton(_registry); - base.SetupServiceProvider(sc); - SteamAbstractionLayer.InitializeServices(sc); - SteamPetroglyphStarWarsGameClients.InitializeServices(sc); + serviceCollection.AddSingleton(_registry); + base.SetupServices(serviceCollection); + SteamAbstractionLayer.InitializeServices(serviceCollection); + SteamPetroglyphStarWarsGameClients.InitializeServices(serviceCollection); - sc.AddSingleton(sp => new TestProcessHelper(sp)); - sc.AddSingleton(sp => sp.GetRequiredService()); + serviceCollection.AddSingleton(sp => new TestProcessHelper(sp)); + serviceCollection.AddSingleton(sp => sp.GetRequiredService()); } diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 5ff090dc..f932c1d4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -25,13 +25,13 @@ public class SteamPetroglyphStarWarsGameDetectorTest : GameDetectorTestBase SupportedPlatforms => [GamePlatform.SteamGold]; protected override bool CanDisableInitRequest => false; - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(_registry); - SteamAbstractionLayer.InitializeServices(sc); - PetroglyphGameInfrastructure.InitializeServices(sc); - SteamPetroglyphStarWarsGameClients.InitializeServices(sc); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(_registry); + SteamAbstractionLayer.InitializeServices(serviceCollection); + PetroglyphGameInfrastructure.InitializeServices(serviceCollection); + SteamPetroglyphStarWarsGameClients.InitializeServices(serviceCollection); } protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs index c78411c8..ed6ccd64 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs @@ -8,10 +8,10 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients; public class GameClientFactoryTest : GameInfrastructureTestBase { - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - PetroglyphGameInfrastructure.InitializeServices(sc); + base.SetupServices(serviceCollection); + PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 7cad8c5f..1031778a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -25,6 +25,11 @@ public class PetroglyphStarWarsGameClientTest : GameInfrastructureTestBase, IDis protected virtual ICollection SupportedPlatforms => GITestUtilities.RealPlatforms; + public virtual void Dispose() + { + _processLauncher.Dispose(); + } + protected virtual void BeforePlay() { } @@ -34,11 +39,11 @@ public PetroglyphStarWarsGameClientTest() _clientFactory = ServiceProvider.GetRequiredService(); } - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - PetroglyphGameInfrastructure.InitializeServices(sc); - sc.AddSingleton(_processLauncher); + base.SetupServices(serviceCollection); + PetroglyphGameInfrastructure.InitializeServices(serviceCollection); + serviceCollection.AddSingleton(_processLauncher); } [Fact] @@ -344,11 +349,6 @@ private void AssertProcessStartInfo(GameProcessInfo expected, GameProcessInfo ac Assert.Equal(expected.Arguments, actual.Arguments); } - public virtual void Dispose() - { - _processLauncher.Dispose(); - } - private delegate void OnGameStartingDelegate(ArgumentCollection arguments, GameBuildType type); private class MyTestClient(OnGameStartingDelegate action, IGame game, IServiceProvider serviceProvider) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs index b2316c2d..dc498ccb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs @@ -27,10 +27,10 @@ public class RegistryGameDetectorTest : GameDetectorTestBase true; protected override ICollection SupportedPlatforms => GITestUtilities.RealPlatforms; - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(_registry); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(_registry); } protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index 53a3fea2..3352b6ba 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -285,10 +285,10 @@ public GameFactoryWithNullNameResolver() _factory = new GameFactory(ServiceProvider); } - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(new NullGameNameResolver()); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(new NullGameNameResolver()); } [Fact] @@ -315,10 +315,10 @@ public GameFactoryWithCustomNameResolver() _factory = new GameFactory(ServiceProvider); } - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(new CultureAwareGameNameResolver()); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(new CultureAwareGameNameResolver()); } public static IEnumerable GetCultures() diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 684cf0a3..5396c245 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -36,10 +36,10 @@ public ModFactoryTest() _factory = new ModFactory(ServiceProvider); } - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(_ => _nameResolver); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(_ => _nameResolver); } #region CreatePhysicalMod diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 99c70e8b..2411a61a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -31,10 +31,10 @@ public class PetroglyphGameInfrastructureIntegrationTest : GameInfrastructureTes private const string ExternalModPath = "externalMods/MyExternalMod"; - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(_registry); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(_registry); } [Theory] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs index e355aaeb..819b74f7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs @@ -50,10 +50,10 @@ public void InstalledLanguages() public class PlayableObjectAbstractTest : GameInfrastructureTestBaseWithRandomGame { - protected override void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - base.SetupServiceProvider(sc); - sc.AddSingleton(new NullLanguageFinder()); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(new NullLanguageFinder()); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs index c2fb3d94..d976757e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs @@ -8,7 +8,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Clients; -public class TestGameProcessLauncher : IGameProcessLauncher, IDisposable +public sealed class TestGameProcessLauncher : IGameProcessLauncher, IDisposable { private Process? _process; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs index c7954677..8ed57642 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs @@ -3,7 +3,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; -public class TestGameRegistrySetupData +public sealed class TestGameRegistrySetupData { public required GameType GameType { get; init; } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index eb46447b..f5e4a8b4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,8 +1,9 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; +using System.Threading; using AET.Modinfo.Model; using AET.Modinfo.Spec; +using AET.Testing; using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; @@ -13,23 +14,20 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; -public abstract class GameInfrastructureTestBase +public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { - protected readonly IServiceProvider ServiceProvider; - protected readonly MockFileSystem FileSystem = new(); - - [SuppressMessage("ReSharper", "VirtualMemberCallInConstructor")] - protected GameInfrastructureTestBase() + public IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); + + protected virtual IFileSystem CreateFileSystem() { - var sc = new ServiceCollection(); - SetupServiceProvider(sc); - ServiceProvider = sc.BuildServiceProvider(); + return new MockFileSystem(); } - protected virtual void SetupServiceProvider(IServiceCollection sc) + protected override void SetupServices(IServiceCollection serviceCollection) { - sc.AddSingleton(FileSystem); - PetroglyphGameInfrastructure.InitializeServices(sc); + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(FileSystem); + PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } protected static GameIdentity CreateRandomGameIdentity() From 91576b0104a1a5a03a9d1a444fae1ebf1cda3337 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 17 Dec 2025 21:43:52 +0100 Subject: [PATCH 21/71] Refactor Steam HTML downloader to return non-nullable doc Removed nullable return from GetSteamWorkshopsPageHtmlAsync and shifted error handling to the caller. Now, exceptions are handled and logged in OnlineModGameTypeResolver, making error management more explicit and centralized. --- .../Mods/OnlineModGameTypeResolver.cs | 16 +++++++++++--- .../Steam/ISteamWorkshopWebpageDownloader.cs | 2 +- .../Steam/SteamWorkshopWebpageDownloader.cs | 21 +++++++------------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs index b0c6ffd2..0f0f1c3a 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs @@ -5,6 +5,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Utilities; using AnakinRaW.CommonUtilities.Collections; +using HtmlAgilityPack; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PG.StarWarsGame.Infrastructure.Games; @@ -39,10 +40,19 @@ private bool GetGameTypeFromSteamPage(string steamIdValue, out ReadOnlyFrugalLis Logger?.LogTrace("Getting steam tags from Steam's webpage for mod '{SteamId}'", steamId); - var webPage = _steamWebpageDownloader.GetSteamWorkshopsPageHtmlAsync(steamId, CultureInfo.InvariantCulture) - .GetAwaiter().GetResult(); - if (webPage is null) + HtmlDocument webPage; + try + { + webPage = _steamWebpageDownloader.GetSteamWorkshopsPageHtmlAsync(steamId, CultureInfo.InvariantCulture) + .GetAwaiter().GetResult(); + if (webPage is null) + return false; + } + catch (Exception e) + { + Logger?.LogTrace(e, "Failed to get steam tags from Steam's webpage for mod '{SteamId}'", steamId); return false; + } var tagNodes = webPage.DocumentNode.SelectNodes("//div[@class='workshopTags']/a/text()"); if (tagNodes is null || tagNodes.Count == 0) diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Steam/ISteamWorkshopWebpageDownloader.cs b/src/PG.StarWarsGame.Infrastructure/Services/Steam/ISteamWorkshopWebpageDownloader.cs index e6612195..664d8c79 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Steam/ISteamWorkshopWebpageDownloader.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Steam/ISteamWorkshopWebpageDownloader.cs @@ -6,5 +6,5 @@ namespace PG.StarWarsGame.Infrastructure.Services.Steam; internal interface ISteamWorkshopWebpageDownloader { - Task GetSteamWorkshopsPageHtmlAsync(ulong workshopId, CultureInfo? culture); + Task GetSteamWorkshopsPageHtmlAsync(ulong workshopId, CultureInfo? culture); } \ No newline at end of file diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Steam/SteamWorkshopWebpageDownloader.cs b/src/PG.StarWarsGame.Infrastructure/Services/Steam/SteamWorkshopWebpageDownloader.cs index eedeb552..2686742a 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Steam/SteamWorkshopWebpageDownloader.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Steam/SteamWorkshopWebpageDownloader.cs @@ -10,7 +10,7 @@ internal class SteamWorkshopWebpageDownloader : ISteamWorkshopWebpageDownloader { private const string SteamWorkshopsBaseUrl = "https://steamcommunity.com/sharedfiles/filedetails/?"; - public async Task GetSteamWorkshopsPageHtmlAsync(ulong workshopId, CultureInfo? culture) + public async Task GetSteamWorkshopsPageHtmlAsync(ulong workshopId, CultureInfo? culture) { var queryString = HttpUtility.ParseQueryString(string.Empty); queryString.Add("id", workshopId.ToString()); @@ -18,18 +18,11 @@ internal class SteamWorkshopWebpageDownloader : ISteamWorkshopWebpageDownloader if (culture != null && !Equals(culture, CultureInfo.InvariantCulture)) queryString.Add("l", culture.EnglishName.ToLower()); - try - { - var address = $"{SteamWorkshopsBaseUrl}{queryString}"; - using var client = new HttpClient(); - var reply = await client.GetStringAsync(address); - var htmlDocument = new HtmlDocument(); - htmlDocument.LoadHtml(reply); - return htmlDocument; - } - catch - { - return null; - } + var address = $"{SteamWorkshopsBaseUrl}{queryString}"; + using var client = new HttpClient(); + var reply = await client.GetStringAsync(address); + var htmlDocument = new HtmlDocument(); + htmlDocument.LoadHtml(reply); + return htmlDocument; } } \ No newline at end of file From 584c8acfb8520ea12d69ad41b55e0064ec85ec64 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 17 Dec 2025 21:44:14 +0100 Subject: [PATCH 22/71] start implementing new testing game installation api --- .../IGameClientFactoryTest.cs | 7 +- .../SteamPetroglyphStarWarsGameClientTest.cs | 18 +++-- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 9 ++- .../Arguments/GameArgumentsBuilderTest.cs | 4 +- .../Clients/GameClientFactoryTest.cs | 6 +- .../PetroglyphStarWarsGameClientTest.cs | 10 +-- .../Processes/GameProcessLauncherTest.cs | 13 +-- .../GameExecutableFileUtilitiesTest.cs | 8 +- .../GameServices/GameFactoryTest.cs | 6 +- .../ModBaseTest.cs | 7 +- ...oglyphGameInfrastructureIntegrationTest.cs | 2 +- .../PetroglyphStarWarsGameTest.cs | 10 +-- .../PlayableObjectTest.cs | 4 +- .../VirtualModTest.cs | 28 +++---- .../GITestUtilities.cs | 2 +- .../Game/Installation/GameInstallation.Eaw.cs | 2 +- .../Game/Installation/GameInstallation.cs | 81 +++++++++++++++---- .../TestBases/GameInfrastructureTestBase.cs | 26 +++--- ...ameInfrastructureTestBaseWithRandomGame.cs | 9 ++- 19 files changed, 155 insertions(+), 97 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs index 8ff8ee11..70279823 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -28,12 +27,12 @@ protected override void SetupServices(IServiceCollection serviceCollection) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateClient_CreatesCorrectClientType(GameIdentity identity) { - var game = FileSystem.InstallGame(identity, ServiceProvider); + GameInstallation.Install(identity); var factory = ServiceProvider.GetRequiredService(); - var client = factory.CreateClient(game); + var client = factory.CreateClient(GameInstallation.Game); var expectedClientType = typeof(PetroglyphStarWarsGameClient); - if (game.Platform is GamePlatform.SteamGold) + if (GameInstallation.Game.Platform is GamePlatform.SteamGold) expectedClientType = typeof(SteamPetroglyphStarWarsGameClient); Assert.IsType(expectedClientType, client); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index 9c3b6187..2bfed64f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -22,12 +22,18 @@ namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; public class SteamPetroglyphStarWarsGameClientTest : PetroglyphStarWarsGameClientTest { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); - private readonly PetroglyphStarWarsGame _game; + private readonly IGame _game; private ISteamFakeProcess? _steamProcess; protected override ICollection SupportedPlatforms { get; } = [GamePlatform.SteamGold]; + public SteamPetroglyphStarWarsGameClientTest() + { + GameInstallation.Install(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); + _game = GameInstallation.Game; + } + protected override void BeforePlay() { // Install Steam (regardless whether the identity is supported) @@ -37,11 +43,6 @@ protected override void BeforePlay() base.BeforePlay(); } - public SteamPetroglyphStarWarsGameClientTest() - { - _game = FileSystem.InstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); - } - protected override void SetupServices(IServiceCollection serviceCollection) { serviceCollection.AddSingleton(_registry); @@ -78,8 +79,9 @@ public void Ctor_NonSteamGameThrows(GameIdentity identity) { if (identity.Platform is GamePlatform.SteamGold) return; - var game = FileSystem.InstallGame(identity, ServiceProvider); - Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(game, ServiceProvider)); + var otherGameInstallation = GameTesting.Game(ServiceProvider); + otherGameInstallation.Install(identity); + Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(otherGameInstallation.Game, ServiceProvider)); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index f932c1d4..c57435f6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -79,7 +79,7 @@ public void Detect_SteamNotInstalled_ShouldReturnNotInstalled(GameType gameType) var gameId = new GameIdentity(gameType, GamePlatform.SteamGold); var expected = GameDetectionResult.NotInstalled(gameId.Type); - FileSystem.InstallGame(gameId, ServiceProvider); + GameInstallation.Install(gameId); var detector = new SteamPetroglyphStarWarsGameDetector(ServiceProvider); var result = detector.Detect(gameType, GamePlatform.SteamGold); @@ -95,7 +95,7 @@ public void Detect_SteamInstalledButGameNotRegisteredToSteam_ShouldReturnNotInst var gameId = new GameIdentity(gameType, GamePlatform.SteamGold); var expected = GameDetectionResult.NotInstalled(gameId.Type); - FileSystem.InstallGame(gameId, ServiceProvider); + GameInstallation.Install(gameId); var detector = new SteamPetroglyphStarWarsGameDetector(ServiceProvider); var result = detector.Detect(gameType, GamePlatform.SteamGold); @@ -134,9 +134,10 @@ private GameDetectorTestInfo SetupGame( if (gameIdentity.Platform != GamePlatform.SteamGold) return new GameDetectorTestInfo(gameIdentity.Type, null, null); - + // Install Game - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + GameInstallation.Install(gameIdentity); + var game = GameInstallation.Game; // Register Game to Steam var lib = steam.InstallDefaultLibrary(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index 76ee0458..309d4498 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -6,7 +6,6 @@ using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Testably.Abstractions.Testing; @@ -22,7 +21,8 @@ public class GameArgumentsBuilderTest : GameInfrastructureTestBase public GameArgumentsBuilderTest() { - _game = _fileSystem.InstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); + GameInstallation.Install(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); + _game = GameInstallation.Game; } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs index ed6ccd64..569d8636 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs @@ -25,10 +25,10 @@ public void CreateClient_NullArgs_Throws() public void CreateClient_CorrectTypeAndSetsProperty() { var factory = new GameClientFactory(ServiceProvider); - var game = CreateRandomGame(); + InstallRandomGame(); - var client = factory.CreateClient(game); + var client = factory.CreateClient(GameInstallation.Game); Assert.IsType(client); - Assert.Same(game, client.Game); + Assert.Same(GameInstallation.Game, client.Game); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 1031778a..8dc807fc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -50,16 +50,16 @@ protected override void SetupServices(IServiceCollection serviceCollection) public void Ctor_NullArgs_Throws() { Assert.Throws(() => new PetroglyphStarWarsGameClient(null!, ServiceProvider)); - var game = CreateRandomGame(); - Assert.Throws(() => new PetroglyphStarWarsGameClient(game, null!)); + InstallRandomGame(); + Assert.Throws(() => new PetroglyphStarWarsGameClient(GameInstallation.Game, null!)); } [Fact] public void Ctor_SetsGame() { - var game = CreateRandomGame(); - using var client = new PetroglyphStarWarsGameClient(game, ServiceProvider); - Assert.Same(game, client.Game); + InstallRandomGame(); + using var client = new PetroglyphStarWarsGameClient(GameInstallation.Game, ServiceProvider); + Assert.Same(GameInstallation.Game, client.Game); } [Theory] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs index 31686c6b..84473dfb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs @@ -1,13 +1,14 @@ -using System; -using System.Diagnostics; -using System.IO.Abstractions; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using PG.StarWarsGame.Infrastructure.Clients; +using PG.StarWarsGame.Infrastructure.Clients; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using PG.StarWarsGame.Infrastructure.Clients.Processes; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using System; +using System.Diagnostics; +using System.IO.Abstractions; +using System.Runtime.InteropServices; +using System.Threading.Tasks; using Testably.Abstractions; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs index bcea9e0f..68b0454a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs @@ -41,7 +41,7 @@ public static IEnumerable GetGameExeNamesTestData() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetExecutableForGame_NullGame_ThrowsArgumentNullException(GameIdentity gameIdentity) { - FileSystem.InstallGame(gameIdentity, ServiceProvider); + GameInstallation.Install(gameIdentity); var buildTypes = new List { GameBuildType.Release, GameBuildType.Debug }; foreach (var buildType in buildTypes) Assert.Throws(() => GameExecutableFileUtilities.GetExecutableForGame(null!, buildType)); @@ -71,11 +71,11 @@ public void GetExecutableForGame_GameExeFilesNotInstalled_ReturnsNull(GameIdenti [MemberData(nameof(GetGameExeNamesTestData))] public void GetExecutableForGame_ReturnsFileHandle(GameIdentity gameIdentity, GameBuildType buildType, string expectedName) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + GameInstallation.Install(gameIdentity); if (buildType == GameBuildType.Debug) - game.InstallDebug(); + GameInstallation.InstallDebug(); - var exeFile = GameExecutableFileUtilities.GetExecutableForGame(game, buildType); + var exeFile = GameExecutableFileUtilities.GetExecutableForGame(GameInstallation.Game, buildType); Assert.NotNull(exeFile); Assert.Equal(expectedName, exeFile.Name); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index 3352b6ba..de06898b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -185,16 +185,16 @@ public void CreateGame_WrongGameIdentityInstalled_WrongType_Throws(GamePlatform [Fact] public void CreateGame_UnidentifiedPlatform_Throws() { - var installedGame = CreateRandomGame(); + InstallRandomGame(); Assert.Throws(() => _factory.CreateGame( new GameIdentity(Random.Enum(), GamePlatform.Undefined), - installedGame.Directory, + GameInstallation.Game.Directory, Random.Bool(), CultureInfo.CurrentCulture)); Assert.False(_factory.TryCreateGame( new GameIdentity(Random.Enum(), GamePlatform.Undefined), - installedGame.Directory, + GameInstallation.Game.Directory, Random.Bool(), CultureInfo.CurrentCulture, out _)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 0090ba80..2ba5c8ad 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -17,11 +17,12 @@ namespace PG.StarWarsGame.Infrastructure.Test; public abstract class ModBaseTest : PlayableModContainerTest { - protected IGame Game; + protected readonly IGame Game; protected ModBaseTest() { - Game = CreateRandomGame(); + InstallRandomGame(); + Game = GameInstallation.Game; } protected abstract ModBase CreateMod( @@ -44,7 +45,7 @@ protected IMod CreateOtherMod( DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreateAndAddMod(Game, isWorkshop, name, new DependencyList(deps, layout)); + return CreateAndAddMod(isWorkshop, name, new DependencyList(deps, layout)); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 2411a61a..dced6dfd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -269,7 +269,7 @@ private void AssertTraversedDependencies(IMod mod, IList expectedDepList) Assert.Equal(expectedDepList, depList); } - private void AssertExpectedGame(PetroglyphStarWarsGame expected, IGame actual) + private void AssertExpectedGame(IGame expected, IGame actual) { Assert.Equal(expected.Directory.FullName, actual.Directory.FullName); Assert.Equal(expected.Type, actual.Type); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index 89390e6c..350f5b3f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -11,9 +11,7 @@ namespace PG.StarWarsGame.Infrastructure.Test; public class PetroglyphStarWarsGameTest : PlayableModContainerTest { - private PetroglyphStarWarsGame CreateGame( - string? iconPath = null, - ICollection? languages = null) + private IGame CreateGame(string? iconPath = null, ICollection? languages = null) { var gameId = new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); var game = FileSystem.InstallGame(gameId, ServiceProvider); @@ -32,16 +30,14 @@ private PetroglyphStarWarsGame CreateGame( return game; } - protected override IPlayableObject CreatePlayableObject( - string? iconPath = null, - ICollection? languages = null) + protected override IPlayableObject CreatePlayableObject(string? iconPath = null, ICollection? languages = null) { return CreateGame(iconPath, languages); } protected override PlayableModContainer CreateModContainer() { - return CreateGame(); + return CreateGame() as PlayableModContainer; } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs index 819b74f7..4ae165aa 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs @@ -10,9 +10,7 @@ namespace PG.StarWarsGame.Infrastructure.Test; public abstract class PlayableObjectTest : GameInfrastructureTestBase { - protected abstract IPlayableObject CreatePlayableObject( - string? iconPath = null, - ICollection? languages = null); + protected abstract IPlayableObject CreatePlayableObject(string? iconPath = null, ICollection? languages = null); [Fact] public void IconFile_NoIcon() diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 3e0ae39f..4e77c5ee 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -40,8 +40,8 @@ private VirtualMod CreateVirtualMod( Dependencies = depList }; - var mod = new VirtualMod(Game, "VirtualModId", modinfo, ServiceProvider); - Game.AddMod(mod); + var mod = new VirtualMod(GameInstallation.Game, "VirtualModId", modinfo, ServiceProvider); + GameInstallation.Game.AddMod(mod); return mod; } @@ -68,25 +68,25 @@ protected override PlayableModContainer CreateModContainer() [Fact] public void InvalidCtor_ArgumentNull_Throws() { - Game.InstallAndAddMod("Dep", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + GameInstallation.Game.InstallAndAddMod("Dep", GITestUtilities.GetRandomWorkshopFlag(GameInstallation.Game), ServiceProvider); Assert.Throws(() => new VirtualMod(null!, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); - Assert.Throws(() => new VirtualMod(Game, "VirtualModId", null!, ServiceProvider)); - Assert.Throws(() => new VirtualMod(Game, "name", null!, ServiceProvider)); + Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", null!, ServiceProvider)); + Assert.Throws(() => new VirtualMod(GameInstallation.Game, "name", null!, ServiceProvider)); - Assert.Throws(() => new VirtualMod(Game, "VirtualModId", new ModinfoData("Name"), null!)); - Assert.Throws(() => new VirtualMod(Game, null!, new ModinfoData("Name"), ServiceProvider)); + Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", new ModinfoData("Name"), null!)); + Assert.Throws(() => new VirtualMod(GameInstallation.Game, null!, new ModinfoData("Name"), ServiceProvider)); } [Fact] public void Ctor_EmptyDependencies_Throws() { - Assert.Throws(() => new VirtualMod(Game, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); + Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); var modInfo = new ModinfoData("Name") { Dependencies = new DependencyList(new List(), DependencyResolveLayout.FullResolved) }; - Assert.Throws(() => new VirtualMod(Game, "VirtualModId", modInfo, ServiceProvider)); + Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", modInfo, ServiceProvider)); } [Fact] @@ -105,7 +105,7 @@ public void Ctor_FromModinfo_Properties() }, DependencyResolveLayout.ResolveLastItem) }; - var mod = new VirtualMod(Game, "VirtualModId", modinfo, ServiceProvider); + var mod = new VirtualMod(GameInstallation.Game, "VirtualModId", modinfo, ServiceProvider); Assert.Empty(mod.Dependencies); Assert.Single(((IModIdentity)mod).Dependencies); @@ -123,8 +123,8 @@ public void Ctor_FromModinfo_Properties() [Fact] public void Ctor_NonPhysicalDependencies_Throws() { - var customDep = new CustomVirtualMod(Game, ServiceProvider); - Game.AddMod(customDep); + var customDep = new CustomVirtualMod(GameInstallation.Game, ServiceProvider); + GameInstallation.Game.AddMod(customDep); var modInfo = new ModinfoData("Name") { @@ -132,8 +132,8 @@ public void Ctor_NonPhysicalDependencies_Throws() DependencyResolveLayout.FullResolved) }; - var mod = new VirtualMod(Game, "VirtualModId", modInfo, ServiceProvider); - Game.AddMod(mod); + var mod = new VirtualMod(GameInstallation.Game, "VirtualModId", modInfo, ServiceProvider); + GameInstallation.Game.AddMod(mod); Assert.Throws(mod.ResolveDependencies); } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index 3dde43aa..c84d310c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -30,7 +30,7 @@ public static bool GetRandomWorkshopFlag(IGame game) { if (game.Platform is not GamePlatform.SteamGold) return false; - return new Random().NextDouble() >= 0.5; + return Random.Bool(); } public static IEnumerable GetRealPlatforms() diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs index 5351e917..0c665dd8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs @@ -11,7 +11,7 @@ public static partial class GameInstallation private const string EawGoldPath = "games/gold/eaw"; private const string EawGameDataSubPath = "GameData"; - private static IDirectoryInfo InstallEaw(this IFileSystem fs, GamePlatform platform) + internal static IDirectoryInfo InstallEaw(IFileSystem fs, GamePlatform platform) { IDirectoryInfo gameDirectory; switch (platform) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs index 04d78e78..d38382fe 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs @@ -1,11 +1,67 @@ -using System; -using System.IO.Abstractions; +using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO.Abstractions; using Testably.Abstractions.Testing; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +public static class GameTesting +{ + public static ITestingGameInstallation Game(IServiceProvider serviceProvider) + { + return new TestingGameImpl(serviceProvider); + } +} + +public interface ITestingGameInstallation +{ + IGame? Game { get; } + + [MemberNotNull(nameof(Game))] + void Install(GameIdentity gameIdentity); + + void InstallDebug(); +} + +internal class TestingGameImpl(IServiceProvider serviceProvider) : ITestingGameInstallation +{ + private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); + + public IGame? Game { get; private set; } + + [MemberNotNull(nameof(Game))] + public void Install(GameIdentity gameIdentity) + { + var gameDir = gameIdentity.Type == GameType.Foc + ? GameInstallation.InstallFoc(_fileSystem, gameIdentity.Platform) + : GameInstallation.InstallEaw(_fileSystem, gameIdentity.Platform); + + _fileSystem.InstallModsLocations(gameDir); + + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), serviceProvider); + Assert.True(game.Exists()); + Game = game; + } + + public void InstallDebug() + { + ThrowIfNotInstalled(); + Game.InstallDebug(); + } + + + [MemberNotNull(nameof(Game))] + private void ThrowIfNotInstalled() + { + if (Game is null) + throw new InvalidOperationException("Game not installed"); + } +} + + public static partial class GameInstallation { // Ensure starts on path 'steam'. See SteamInstallation.cs @@ -13,20 +69,15 @@ public static partial class GameInstallation private const string GogBasePath = "games/gog"; private const string OriginBasePath = "games/origin"; - public static PetroglyphStarWarsGame InstallGame(this IFileSystem fs, GameIdentity gameIdentity, IServiceProvider sp) - { - Func installFunc; - - if (gameIdentity.Type == GameType.Foc) - installFunc = InstallFoc; - else - installFunc = InstallEaw; - - var gameDir = installFunc(fs, gameIdentity.Platform); + public static IGame InstallGame(this IFileSystem fileSystem, GameIdentity gameIdentity, IServiceProvider serviceProvider) + { + var gameDir = gameIdentity.Type == GameType.Foc + ? InstallFoc(fileSystem, gameIdentity.Platform) + : InstallEaw(fileSystem, gameIdentity.Platform); - fs.InstallModsLocations(gameDir); + fileSystem.InstallModsLocations(gameDir); - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), sp); + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), serviceProvider); Assert.True(game.Exists()); return game; } @@ -78,7 +129,7 @@ private static void InstallOriginFiles(this IFileSystem fs, Action initAction) initAction(); } - private static void InstallModsLocations(this IFileSystem fileSystem, IDirectoryInfo directory) + internal static void InstallModsLocations(this IFileSystem fileSystem, IDirectoryInfo directory) { fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(directory.FullName, "Mods")); } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index f5e4a8b4..9a61a2d6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using System.Threading; using AET.Modinfo.Model; @@ -16,7 +17,14 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { - public IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); + protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); + + protected ITestingGameInstallation GameInstallation; + + protected GameInfrastructureTestBase() + { + GameInstallation = GameTesting.Game(ServiceProvider); + } protected virtual IFileSystem CreateFileSystem() { @@ -26,7 +34,7 @@ protected virtual IFileSystem CreateFileSystem() protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); - serviceCollection.AddSingleton(FileSystem); + serviceCollection.AddSingleton(FileSystem); PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } @@ -35,25 +43,25 @@ protected static GameIdentity CreateRandomGameIdentity() return new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); } - protected PetroglyphStarWarsGame CreateRandomGame() + protected void InstallRandomGame() { - return FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + GameInstallation.Install(CreateRandomGameIdentity()); } - protected IMod CreateAndAddMod(IGame game, bool isWorkshop, string name, IModDependencyList dependencies) + protected IMod CreateAndAddMod(bool isWorkshop, string name, IModDependencyList dependencies) { if (dependencies.Count == 0) - return game.InstallAndAddMod(name, isWorkshop, ServiceProvider); + return GameInstallation.Game.InstallAndAddMod(name, isWorkshop, ServiceProvider); var modinfo = new ModinfoData(name) { Dependencies = dependencies }; - return CreateAndAddMod(game, isWorkshop, modinfo); + return CreateAndAddMod(isWorkshop, modinfo); } - protected IMod CreateAndAddMod(IGame game, bool isWorkshop, IModinfo modinfo) + protected IMod CreateAndAddMod(bool isWorkshop, IModinfo modinfo) { - return game.InstallAndAddMod(isWorkshop, modinfo, ServiceProvider); + return GameInstallation.Game.InstallAndAddMod(isWorkshop, modinfo, ServiceProvider); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index a6663b63..075c9146 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -11,8 +11,9 @@ public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastruct protected readonly IGame Game; protected GameInfrastructureTestBaseWithRandomGame() - { - Game = CreateRandomGame(); + { + InstallRandomGame(); + Game = GameInstallation.Game; } protected IMod CreateAndAddMod( @@ -20,11 +21,11 @@ protected IMod CreateAndAddMod( DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreateAndAddMod(Game, GITestUtilities.GetRandomWorkshopFlag(Game), name, new DependencyList(deps, layout)); + return CreateAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), name, new DependencyList(deps, layout)); } protected IMod CreateAndAddMod(IModinfo modinfo) { - return CreateAndAddMod(Game, GITestUtilities.GetRandomWorkshopFlag(Game), modinfo); + return CreateAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modinfo); } } \ No newline at end of file From 0eec09aaca0a256e4c743d47b1f40b39778d57e0 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Thu, 18 Dec 2025 15:38:50 +0100 Subject: [PATCH 23/71] testing classes for game and registry --- .../Name/Mods/OnlineWorkshopNameResolver.cs | 18 +- .../IGameClientFactoryTest.cs | 6 +- .../SteamPetroglyphStarWarsGameClientTest.cs | 37 ++-- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 24 ++- .../Arguments/GameArgumentsBuilderTest.cs | 5 +- .../Clients/GameClientFactoryTest.cs | 6 +- .../PetroglyphStarWarsGameClientTest.cs | 64 ++++--- .../Processes/GameProcessLauncherTest.cs | 1 - .../GameExecutableFileUtilitiesTest.cs | 11 +- .../Detection/CustomGameDetectorTest.cs | 178 ++++++++---------- .../Detection/DirectoryGameDetectorTest.cs | 5 +- .../Detection/GamePlatformIdentifierTest.cs | 59 +++--- .../Detection/RegistryGameDetectorTest.cs | 25 +-- .../EnglishGameNameResolverTest.cs | 3 +- .../GameServices/GameFactoryTest.cs | 33 ++-- .../GameServices/SteamGameHelpersTest.cs | 35 ++-- .../ModBaseTest.cs | 3 +- .../ModEqualityComparerTest.cs | 6 +- .../DirectoryModNameResolverTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 34 ++-- .../ModServices/ModFinderTest.cs | 47 ++--- .../ModGameTypeResolverTestBase.cs | 15 +- .../OnlineModGameTypeResolverTest.cs | 6 +- ...oglyphGameInfrastructureIntegrationTest.cs | 13 +- .../PetroglyphStarWarsGameTest.cs | 18 +- .../Services/LanguageFinderTestBase.cs | 10 +- .../VirtualModTest.cs | 28 +-- .../GITestUtilities.cs | 6 + .../Game/GameInfrastructureTesting.cs | 18 ++ .../Game/Installation/GameInstallation.Eaw.cs | 2 +- .../Game/Installation/GameInstallation.Foc.cs | 7 +- .../Game/Installation/GameInstallation.cs | 92 +-------- .../Installation/ITestingGameInstallation.cs | 20 ++ .../Game/Installation/TestingGameImpl.cs | 62 ++++++ .../Game/Registry/ITestingGameRegistry.cs | 13 ++ ...tensions.cs => TestingGameRegistryImpl.cs} | 38 ++-- .../TestBases/GameInfrastructureTestBase.cs | 23 +-- ...ameInfrastructureTestBaseWithRandomGame.cs | 8 +- 38 files changed, 494 insertions(+), 487 deletions(-) create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs rename test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/{GameRegistryTestExtensions.cs => TestingGameRegistryImpl.cs} (52%) diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Name/Mods/OnlineWorkshopNameResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Name/Mods/OnlineWorkshopNameResolver.cs index 91514eba..bc3d7628 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Name/Mods/OnlineWorkshopNameResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Name/Mods/OnlineWorkshopNameResolver.cs @@ -3,6 +3,7 @@ using System.Globalization; using AET.Modinfo.Spec; using AET.Modinfo.Utilities; +using HtmlAgilityPack; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PG.StarWarsGame.Infrastructure.Services.Steam; @@ -50,12 +51,21 @@ protected internal override string ResolveCore(DetectedModReference detectedMod, private string? GetNameFromOnline(ulong modId, CultureInfo culture) { - var modsWorkshopWebpage = _steamWebpageDownloader.GetSteamWorkshopsPageHtmlAsync(modId, culture) - .GetAwaiter().GetResult(); + HtmlDocument modsWorkshopWebpage; + try + { + modsWorkshopWebpage = _steamWebpageDownloader.GetSteamWorkshopsPageHtmlAsync(modId, culture) + .GetAwaiter().GetResult(); - if (modsWorkshopWebpage == null) + if (modsWorkshopWebpage == null) + { + Logger?.LogTrace("Unable to download website for Steam ID '{ModId}'.", modId); + return null; + } + } + catch (Exception e) { - Logger?.LogTrace("Unable to download website for Steam ID '{ModId}'.", modId); + Logger?.LogTrace(e, "Unable to download website for Steam ID '{ModId}'.", modId); return null; } diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs index 70279823..a4e30480 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs @@ -27,12 +27,12 @@ protected override void SetupServices(IServiceCollection serviceCollection) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateClient_CreatesCorrectClientType(GameIdentity identity) { - GameInstallation.Install(identity); + var game = GetOrÍnstallGame(identity); var factory = ServiceProvider.GetRequiredService(); - var client = factory.CreateClient(GameInstallation.Game); + var client = factory.CreateClient(game); var expectedClientType = typeof(PetroglyphStarWarsGameClient); - if (GameInstallation.Game.Platform is GamePlatform.SteamGold) + if (game.Platform is GamePlatform.SteamGold) expectedClientType = typeof(SteamPetroglyphStarWarsGameClient); Assert.IsType(expectedClientType, client); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index 2bfed64f..70d5fcba 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -10,11 +10,12 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Test.Clients; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using System; using System.Collections.Generic; using System.Runtime.Versioning; +using AET.Testing.Extensions; using Xunit; +using PG.StarWarsGame.Infrastructure.Testing.Game; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; @@ -22,16 +23,18 @@ namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; public class SteamPetroglyphStarWarsGameClientTest : PetroglyphStarWarsGameClientTest { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); - private readonly IGame _game; private ISteamFakeProcess? _steamProcess; protected override ICollection SupportedPlatforms { get; } = [GamePlatform.SteamGold]; - public SteamPetroglyphStarWarsGameClientTest() - { - GameInstallation.Install(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); - _game = GameInstallation.Game; + protected override IGame GetOrÍnstallGame(IGameIdentity? identity = null) + { + if (GameInstallation.Game is not null) + return GameInstallation.Game; + var type = identity?.Type ?? Random.Enum(); + var steamIdentity = new GameIdentity(type, GamePlatform.SteamGold); + return GameInstallation.Install(steamIdentity); } protected override void BeforePlay() @@ -59,13 +62,13 @@ protected override void SetupServices(IServiceCollection serviceCollection) public void Ctor_SteamClient_NullArgs_Throws() { Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(null!, ServiceProvider)); - Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(_game, null!)); + Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(GetOrÍnstallGame(), null!)); } [Fact] public void SteamPetroglyphStarWarsGameClient_Lifecycle() { - var client = new SteamPetroglyphStarWarsGameClient(_game, ServiceProvider); + var client = new SteamPetroglyphStarWarsGameClient(GetOrÍnstallGame(), ServiceProvider); Assert.NotNull(client.SteamWrapper); client.Dispose(); @@ -79,20 +82,21 @@ public void Ctor_NonSteamGameThrows(GameIdentity identity) { if (identity.Platform is GamePlatform.SteamGold) return; - var otherGameInstallation = GameTesting.Game(ServiceProvider); - otherGameInstallation.Install(identity); - Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(otherGameInstallation.Game, ServiceProvider)); + var otherGameInstallation = GameInfrastructureTesting.Game(ServiceProvider); + var otherGame = otherGameInstallation.Install(identity); + Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(otherGame, ServiceProvider)); } [Fact] public void Play_SteamNotInstalled_Throws() { - var client = new SteamPetroglyphStarWarsGameClient(_game, ServiceProvider); + var game = GetOrÍnstallGame(); + var client = new SteamPetroglyphStarWarsGameClient(game, ServiceProvider); Assert.Throws(client.Play); - var expected = new GameProcessInfo(_game, GameBuildType.Release, ArgumentCollection.Empty); + var expected = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); - TestPlay(_game, expected, gameClient => gameClient.Play(), shallThrowGameStartException: true); + TestPlay(game, expected, gameClient => gameClient.Play(), shallThrowGameStartException: true); } [Fact] @@ -101,9 +105,10 @@ public void Play_SteamNotRunning_Throws() // Install Steam (regardless whether the identity is supported) SteamTesting.Steam(ServiceProvider).Install(); - var expected = new GameProcessInfo(_game, GameBuildType.Release, ArgumentCollection.Empty); + var game = GetOrÍnstallGame(); + var expected = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); - TestPlay(_game, expected, gameClient => gameClient.Play(), shallThrowGameStartException: true); + TestPlay(game, expected, gameClient => gameClient.Play(), shallThrowGameStartException: true); } public override void Dispose() diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index c57435f6..058c4758 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -10,7 +10,7 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -30,7 +30,6 @@ protected override void SetupServices(IServiceCollection serviceCollection) base.SetupServices(serviceCollection); serviceCollection.AddSingleton(_registry); SteamAbstractionLayer.InitializeServices(serviceCollection); - PetroglyphGameInfrastructure.InitializeServices(serviceCollection); SteamPetroglyphStarWarsGameClients.InitializeServices(serviceCollection); } @@ -43,8 +42,8 @@ protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdent { return SetupGame(gameIdentity, (game, otherGameType) => { - _registry.InstallGame(game, ServiceProvider); - otherGameType.CreateNonExistingRegistry(ServiceProvider); + GameInfrastructureTesting.Registry(ServiceProvider).CreateInstlled(game); + GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); }); } @@ -52,8 +51,8 @@ protected override GameDetectorTestInfo SetupForRequiredInitialization(G { return SetupGame(gameIdentity, (game, otherGameType) => { - TestGameRegistrySetupData.Uninitialized(game.Type).Create(ServiceProvider); - otherGameType.CreateNonExistingRegistry(ServiceProvider); + GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(game.Type)); + GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); }); } @@ -62,7 +61,7 @@ protected override void HandleInitialization(bool shallInitSuccessfully, GameDet if (!shallInitSuccessfully) return; var registrySetupData = TestGameRegistrySetupData.Installed(info.GameType, info.GameDirectory!); - registrySetupData.Create(ServiceProvider); + GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(registrySetupData); } [Fact] @@ -79,7 +78,7 @@ public void Detect_SteamNotInstalled_ShouldReturnNotInstalled(GameType gameType) var gameId = new GameIdentity(gameType, GamePlatform.SteamGold); var expected = GameDetectionResult.NotInstalled(gameId.Type); - GameInstallation.Install(gameId); + GetOrÍnstallGame(gameId); var detector = new SteamPetroglyphStarWarsGameDetector(ServiceProvider); var result = detector.Detect(gameType, GamePlatform.SteamGold); @@ -95,7 +94,7 @@ public void Detect_SteamInstalledButGameNotRegisteredToSteam_ShouldReturnNotInst var gameId = new GameIdentity(gameType, GamePlatform.SteamGold); var expected = GameDetectionResult.NotInstalled(gameId.Type); - GameInstallation.Install(gameId); + GetOrÍnstallGame(gameId); var detector = new SteamPetroglyphStarWarsGameDetector(ServiceProvider); var result = detector.Detect(gameType, GamePlatform.SteamGold); @@ -113,8 +112,8 @@ public void Detect_SteamInstalledButGameNotFullyInstalled_ShouldReturnNotInstall var info = SetupGame(gameId, (game, otherGameType) => { - _registry.InstallGame(game, ServiceProvider); - otherGameType.CreateNonExistingRegistry(ServiceProvider); + GameInfrastructureTesting.Registry(ServiceProvider).CreateInstlled(game); + GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); }, SteamAppState.StateUpdateRequired); var detector = CreateDetector(info, true); @@ -136,8 +135,7 @@ private GameDetectorTestInfo SetupGame( return new GameDetectorTestInfo(gameIdentity.Type, null, null); // Install Game - GameInstallation.Install(gameIdentity); - var game = GameInstallation.Game; + var game = GetOrÍnstallGame(gameIdentity); // Register Game to Steam var lib = steam.InstallDefaultLibrary(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index 309d4498..1070518d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -13,7 +13,7 @@ namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; -public class GameArgumentsBuilderTest : GameInfrastructureTestBase +public sealed class GameArgumentsBuilderTest : GameInfrastructureTestBase { private readonly MockFileSystem _fileSystem = new(); private readonly GameArgumentsBuilder _builder = new(); @@ -21,8 +21,7 @@ public class GameArgumentsBuilderTest : GameInfrastructureTestBase public GameArgumentsBuilderTest() { - GameInstallation.Install(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); - _game = GameInstallation.Game; + _game = GetOrÍnstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs index 569d8636..ddc6d6d7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs @@ -25,10 +25,10 @@ public void CreateClient_NullArgs_Throws() public void CreateClient_CorrectTypeAndSetsProperty() { var factory = new GameClientFactory(ServiceProvider); - InstallRandomGame(); + var game = GetOrÍnstallGame(); - var client = factory.CreateClient(GameInstallation.Game); + var client = factory.CreateClient(game); Assert.IsType(client); - Assert.Same(GameInstallation.Game, client.Game); + Assert.Same(game, client.Game); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 8dc807fc..33df9651 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using AET.Modinfo.Spec; +using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Clients; using PG.StarWarsGame.Infrastructure.Clients.Arguments; @@ -11,7 +12,6 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Clients; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -34,6 +34,22 @@ protected virtual void BeforePlay() { } + protected override IGame GetOrÍnstallGame(IGameIdentity? identity = null) + { + if (GameInstallation.Game is not null) + return GameInstallation.Game; + + if (identity is not null) + { + if (!SupportedPlatforms.Contains(identity.Platform)) + throw new NotSupportedException($"The requested game platform '{identity.Platform}' is not supported by this client test"); + return GameInstallation.Install(identity); + } + + var newIdentity = new GameIdentity(Random.Enum(), Random.Item(SupportedPlatforms)); + return GameInstallation.Install(newIdentity); + } + public PetroglyphStarWarsGameClientTest() { _clientFactory = ServiceProvider.GetRequiredService(); @@ -50,15 +66,15 @@ protected override void SetupServices(IServiceCollection serviceCollection) public void Ctor_NullArgs_Throws() { Assert.Throws(() => new PetroglyphStarWarsGameClient(null!, ServiceProvider)); - InstallRandomGame(); - Assert.Throws(() => new PetroglyphStarWarsGameClient(GameInstallation.Game, null!)); + var game = GetOrÍnstallGame(); + Assert.Throws(() => new PetroglyphStarWarsGameClient(game, null!)); } [Fact] public void Ctor_SetsGame() { - InstallRandomGame(); - using var client = new PetroglyphStarWarsGameClient(GameInstallation.Game, ServiceProvider); + var game = GetOrÍnstallGame(); + using var client = new PetroglyphStarWarsGameClient(game, ServiceProvider); Assert.Same(GameInstallation.Game, client.Game); } @@ -66,7 +82,7 @@ public void Ctor_SetsGame() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void IsDebugAvailable_NoDebugFilesAvailable(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); using var client = _clientFactory.CreateClient(game); Assert.False(client.IsDebugAvailable()); } @@ -76,8 +92,8 @@ public void IsDebugAvailable_NoDebugFilesAvailable(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void IsDebugAvailable_DebugFilesAvailable(GameType gameType) { - var game = FileSystem.InstallGame(new GameIdentity(gameType, GamePlatform.SteamGold), ServiceProvider); - game.InstallDebug(); + var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); + GameInstallation.InstallDebug(); using var client = _clientFactory.CreateClient(game); Assert.True(client.IsDebugAvailable()); } @@ -85,7 +101,7 @@ public void IsDebugAvailable_DebugFilesAvailable(GameType gameType) [Fact] public void PlayDebug_NullArgs_Throws() { - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); var client = _clientFactory.CreateClient(game); Assert.Throws(() => client.Play((IPhysicalMod)null!)); @@ -99,10 +115,10 @@ public void Play_CancelGameStart_Throws(GameIdentity gameIdentity) { if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + + var game = GetOrÍnstallGame(gameIdentity); if (gameIdentity.Platform == GamePlatform.SteamGold) - game.InstallDebug(); + GameInstallation.InstallDebug(); var mod = game.InstallMod("MyMod", false, ServiceProvider); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -134,9 +150,9 @@ public void PlayDebug_ProcessLauncherThrows(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); if (gameIdentity.Platform == GamePlatform.SteamGold) - game.InstallDebug(); + GameInstallation.InstallDebug(); var mod = game.InstallMod("MyMod", false, ServiceProvider); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -161,7 +177,7 @@ public void Play(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay(game, expectedProcessInfo, client => client.Play()); @@ -174,7 +190,7 @@ public void Play_Args(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var arg = new WindowedArgument(); @@ -189,7 +205,7 @@ public void Play_Mod(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var mod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var expectedArguments = new ArgumentCollection([new ModArgumentList([ @@ -204,8 +220,8 @@ public void Play_Mod(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void Debug_DebugIsAvailable(GameType gameType) { - var game = FileSystem.InstallGame(new GameIdentity(gameType, GamePlatform.SteamGold), ServiceProvider); - game.InstallDebug(); + var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); + GameInstallation.InstallDebug(); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Debug, ArgumentCollection.Empty); TestPlay( @@ -221,7 +237,7 @@ public void Debug_FallbackToRelease(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay( @@ -237,7 +253,7 @@ public void Debug_DoNotFallbackToRelease_Throws(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay( @@ -254,7 +270,7 @@ public void PlayDebug_GameExecutablesNotAvailable_Throws(GameIdentity gameIdenti if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -280,7 +296,7 @@ public void PlayDebug_Derived_OnGameStarting_ThrowsCustom(GameIdentity gameIdent if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var derivedClient = new MyTestClient((_, type) => { @@ -342,7 +358,7 @@ protected void TestPlay( } } - private void AssertProcessStartInfo(GameProcessInfo expected, GameProcessInfo actual) + private static void AssertProcessStartInfo(GameProcessInfo expected, GameProcessInfo actual) { Assert.Equal(expected.Game, actual.Game); Assert.Equal(expected.BuildType, actual.BuildType); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs index 84473dfb..cd2d8ea9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs @@ -2,7 +2,6 @@ using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using PG.StarWarsGame.Infrastructure.Clients.Processes; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System; using System.Diagnostics; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs index 68b0454a..6639cfff 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs @@ -4,7 +4,6 @@ using PG.StarWarsGame.Infrastructure.Clients.Utilities; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -41,7 +40,7 @@ public static IEnumerable GetGameExeNamesTestData() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetExecutableForGame_NullGame_ThrowsArgumentNullException(GameIdentity gameIdentity) { - GameInstallation.Install(gameIdentity); + GetOrÍnstallGame(gameIdentity); var buildTypes = new List { GameBuildType.Release, GameBuildType.Debug }; foreach (var buildType in buildTypes) Assert.Throws(() => GameExecutableFileUtilities.GetExecutableForGame(null!, buildType)); @@ -71,11 +70,11 @@ public void GetExecutableForGame_GameExeFilesNotInstalled_ReturnsNull(GameIdenti [MemberData(nameof(GetGameExeNamesTestData))] public void GetExecutableForGame_ReturnsFileHandle(GameIdentity gameIdentity, GameBuildType buildType, string expectedName) { - GameInstallation.Install(gameIdentity); + var game = GetOrÍnstallGame(gameIdentity); if (buildType == GameBuildType.Debug) GameInstallation.InstallDebug(); - var exeFile = GameExecutableFileUtilities.GetExecutableForGame(GameInstallation.Game, buildType); + var exeFile = GameExecutableFileUtilities.GetExecutableForGame(game, buildType); Assert.NotNull(exeFile); Assert.Equal(expectedName, exeFile.Name); } @@ -85,7 +84,7 @@ public void GetExecutableForGame_ReturnsFileHandle(GameIdentity gameIdentity, Ga [InlineData(GameType.Foc)] public void GetExecutableForGame_SteamHasReleaseButNotDebugFiles(GameType gameType) { - var game = FileSystem.InstallGame(new GameIdentity(gameType, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); var releaseExe = GameExecutableFileUtilities.GetExecutableForGame(game, GameBuildType.Release); Assert.NotNull(releaseExe); @@ -101,7 +100,7 @@ public void GetExecutableForGame_DebugFilesForOtherThanSteam_ShouldReturnNull(Ga if (identity.Platform == GamePlatform.SteamGold) return; - var game = FileSystem.InstallGame(identity, ServiceProvider); + var game = GetOrÍnstallGame(identity); using var _ = FileSystem.File.Create(FileSystem.Path.Combine(game.Directory.FullName, "StarWarsG.exe")); Assert.Null(GameExecutableFileUtilities.GetExecutableForGame(game, GameBuildType.Debug)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs index 6499fbf3..25f21d29 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs @@ -1,46 +1,28 @@ -using System; -using System.IO.Abstractions; -using Microsoft.Extensions.DependencyInjection; -using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using Testably.Abstractions.Testing; +using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using System; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.GameServices.Detection; -public class CustomGameDetectorTest +public class CustomGameDetectorTest : GameInfrastructureTestBase { - private readonly IServiceProvider _serviceProvider; - private readonly MockFileSystem _fileSystem = new(); - - public CustomGameDetectorTest() - { - var sc = new ServiceCollection(); - sc.AddSingleton(_fileSystem); - PetroglyphGameInfrastructure.InitializeServices(sc); - _serviceProvider = sc.BuildServiceProvider(); - } - [Theory] - [InlineData(GameType.Eaw)] - [InlineData(GameType.Foc)] - public void Detect_TryDetect_FindGameLocationThrowsException(GameType gameType) + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] + public void Detect_TryDetect_FindGameLocationThrowsException(GameIdentity identity) { - var expected = GameDetectionResult.NotInstalled(gameType); - foreach (var platform in GITestUtilities.RealPlatforms) - { - var gameInfo = _fileSystem.InstallGame(new GameIdentity(gameType, platform), _serviceProvider); - Assert.NotNull(gameInfo); + var expected = GameDetectionResult.NotInstalled(identity.Type); + var game = GetOrÍnstallGame(identity); + Assert.NotNull(game); - var detector = new CallbackGameDetectorBase(FindGameThrowsException, _serviceProvider, false); + var detector = new CallbackGameDetectorBase(FindGameThrowsException, ServiceProvider, false); - Assert.Throws(() => detector.Detect(gameType)); + Assert.Throws(() => detector.Detect(identity.Type)); - Assert.False(detector.TryDetect(gameType, [], out var result)); - expected.AssertEqual(result); - } + Assert.False(detector.TryDetect(identity.Type, [], out var result)); + expected.AssertEqual(result); } [Theory] @@ -49,7 +31,7 @@ public void Detect_TryDetect_FindGameLocationThrowsException(GameType gameType) public void Detect_TryDetect_FindGameLocationReturnsGameWhenItDoesNotExistsOnDisk(GameType gameType) { var expected = GameDetectionResult.NotInstalled(gameType); - var detector = new CallbackGameDetectorBase(ReturnsGame, _serviceProvider, false); + var detector = new CallbackGameDetectorBase(ReturnsGame, ServiceProvider, false); var result = detector.Detect(gameType); expected.AssertEqual(result); @@ -59,87 +41,83 @@ public void Detect_TryDetect_FindGameLocationReturnsGameWhenItDoesNotExistsOnDis } [Theory] - [InlineData(GameType.Eaw, true)] - [InlineData(GameType.Eaw, false)] - [InlineData(GameType.Foc, true)] - [InlineData(GameType.Foc, false)] - public void Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_DoNotHandle(GameType gameType, bool supportInitialization) + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] + public void Detect_TryDetect_InitializationRequestedIsNotTriggeredWhenSupported_DoNotHandle(GameIdentity identity) { - var requiredInit = GameDetectionResult.RequiresInitialization(gameType); - foreach (var platform in GITestUtilities.RealPlatforms) - { - var gameInfo = _fileSystem.InstallGame(new GameIdentity(gameType, platform), _serviceProvider); - Assert.NotNull(gameInfo); - - var state = new DetectorState(); - var detector = new CallbackWithStateGameDetectorBase(state, HandleRequiredInitialization, _serviceProvider, supportInitialization); - - var eventRaised = false; - - detector.InitializationRequested += (_, e) => - { - state.Value = "some Value"; - eventRaised = true; - // Do not handle - e.Handled = false; - }; + var game = GetOrÍnstallGame(identity); + Assert.NotNull(game); + Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_DoNotHandle(game, false); + Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_DoNotHandle(game, true); + } + + private void Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_DoNotHandle(IGame game, bool supportInitialization) + { + var requiredInit = GameDetectionResult.RequiresInitialization(game.Type); - var result = detector.Detect(gameType, platform); - requiredInit.AssertEqual(result); - Assert.Equal(supportInitialization, eventRaised); + var state = new DetectorState(); + var detector = new CallbackWithStateGameDetectorBase(state, HandleRequiredInitialization, ServiceProvider, supportInitialization); - // Reset - eventRaised = false; - state.Value = null; + var eventRaised = false; - Assert.False(detector.TryDetect(gameType, [platform], out result)); - requiredInit.AssertEqual(result); - Assert.Equal(supportInitialization, eventRaised); - } + detector.InitializationRequested += (_, e) => + { + state.Value = "some Value"; + eventRaised = true; + // Do not handle + e.Handled = false; + }; + + var result = detector.Detect(game.Type, game.Platform); + requiredInit.AssertEqual(result); + Assert.Equal(supportInitialization, eventRaised); + + // Reset + eventRaised = false; + state.Value = null; + + Assert.False(detector.TryDetect(game.Type, [game.Platform], out result)); + requiredInit.AssertEqual(result); + Assert.Equal(supportInitialization, eventRaised); } [Theory] - [InlineData(GameType.Eaw)] - [InlineData(GameType.Foc)] - public void Detect_TryDetect_InitializationRequestedIsTriggeredAndHandled(GameType gameType) + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] + public void Detect_TryDetect_InitializationRequestedIsTriggeredAndHandled(GameIdentity identity) { - foreach (var platform in GITestUtilities.RealPlatforms) - { - var gameInfo = _fileSystem.InstallGame(new GameIdentity(gameType, platform), _serviceProvider); - Assert.NotNull(gameInfo); - - var installed = GameDetectionResult.FromInstalled(new GameIdentity(gameType, platform), gameInfo.Directory); - - var state = new DetectorState(); - var detector = new CallbackWithStateGameDetectorBase(state, HandleRequiredInitialization, _serviceProvider, true); - - var eventRaised = false; - - detector.InitializationRequested += (_, e) => - { - state.Value = gameInfo.Directory.FullName; - e.Handled = true; - eventRaised = true; - }; - var result = detector.Detect(gameType, platform); - installed.AssertEqual(result); - Assert.True(eventRaised); - - // Reset - eventRaised = false; - state.Value = null; - - Assert.True(detector.TryDetect(gameType, [platform], out result)); - installed.AssertEqual(result); - Assert.True(eventRaised); - } + var game = GetOrÍnstallGame(identity); + Assert.NotNull(game); + + var installed = GameDetectionResult.FromInstalled(identity, game.Directory); + + var state = new DetectorState(); + var detector = new CallbackWithStateGameDetectorBase(state, HandleRequiredInitialization, ServiceProvider, true); + + var eventRaised = false; + + detector.InitializationRequested += (_, e) => + { + state.Value = game.Directory.FullName; + e.Handled = true; + eventRaised = true; + }; + var result = detector.Detect(identity.Type, identity.Platform); + installed.AssertEqual(result); + Assert.True(eventRaised); + + // Reset + eventRaised = false; + state.Value = null; + + Assert.True(detector.TryDetect(identity.Type, [identity.Platform], out result)); + installed.AssertEqual(result); + Assert.True(eventRaised); } private GameDetectorBase.GameLocationData HandleRequiredInitialization(GameType type, DetectorState state) { return state.Value is null ? GameDetectorBase.GameLocationData.RequiresInitialization - : new GameDetectorBase.GameLocationData(_fileSystem.DirectoryInfo.New(state.Value.ToString()!)); + : new GameDetectorBase.GameLocationData(FileSystem.DirectoryInfo.New(state.Value.ToString()!)); } private static GameDetectorBase.GameLocationData FindGameThrowsException(GameType arg) @@ -149,7 +127,7 @@ private static GameDetectorBase.GameLocationData FindGameThrowsException(GameTyp private GameDetectorBase.GameLocationData ReturnsGame(GameType arg) { - return new GameDetectorBase.GameLocationData(_fileSystem.DirectoryInfo.New($"games/{arg}")); + return new GameDetectorBase.GameLocationData(FileSystem.DirectoryInfo.New($"games/{arg}")); } public class CallbackGameDetectorBase( diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs index 8c589678..12d4b409 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs @@ -4,7 +4,6 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Testably.Abstractions.Testing; using Xunit; @@ -24,7 +23,7 @@ protected override IGameDetector CreateDetector(GameDetectorTestInfo gam protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); return new(gameIdentity.Type, game.Directory, null); } @@ -72,7 +71,7 @@ public void Detect_TryDetect_GamesInstalled_WrongPathGiven(GameIdentity identity { TestNotInstalledWithCustomSetup(identity, i => { - FileSystem.InstallGame(i, ServiceProvider); + if (i != null) GetOrÍnstallGame(i); return FileSystem.DirectoryInfo.New("other"); }); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs index 99489e01..5ddf84d5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs @@ -1,29 +1,22 @@ -using System; -using System.Collections.Generic; -using System.IO.Abstractions; -using Microsoft.Extensions.DependencyInjection; -using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection.Platform; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using System; +using System.Collections.Generic; +using System.IO.Abstractions; using Testably.Abstractions.Testing; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.GameServices.Detection; -public class GamePlatformIdentifierTest +public class GamePlatformIdentifierTest : GameInfrastructureTestBase { - private readonly MockFileSystem _fileSystem = new(); private readonly GamePlatformIdentifier _platformIdentifier; - private readonly IServiceProvider _serviceProvider; public GamePlatformIdentifierTest() { - var sc = new ServiceCollection(); - sc.AddSingleton(_fileSystem); - PetroglyphGameInfrastructure.InitializeServices(sc); - _serviceProvider = sc.BuildServiceProvider(); - _platformIdentifier = new GamePlatformIdentifier(_serviceProvider); + _platformIdentifier = new GamePlatformIdentifier(ServiceProvider); } [Fact] @@ -36,20 +29,16 @@ public void NullArgs_ThrowsArgumentNullException() } [Theory] - [InlineData(GameType.Eaw)] - [InlineData(GameType.Foc)] - public void GetGamePlatform_WrongGameInstalledReturnsUndefined(GameType queryGameType) + [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] + public void GetGamePlatform_WrongGameInstalledReturnsUndefined(GameIdentity identity) { - foreach (var platform in GITestUtilities.RealPlatforms) - { - var installType = queryGameType == GameType.Foc ? GameType.Eaw : GameType.Foc; - var game = _fileSystem.InstallGame(new GameIdentity(installType, platform), _serviceProvider); - var gameLocation = game.Directory; - - var actual = _platformIdentifier.GetGamePlatform(queryGameType, ref gameLocation); - Assert.True(GamePlatform.Undefined == actual, $"Expected value to be Undefined for platform {platform}"); - Assert.Equal(game.Directory.FullName, gameLocation.FullName); - } + var oppositeGameType = identity.Type == GameType.Foc ? GameType.Eaw : GameType.Foc; + var game = GetOrÍnstallGame(new GameIdentity(oppositeGameType, identity.Platform)); + var gameLocation = game.Directory; + + var actual = _platformIdentifier.GetGamePlatform(identity.Type, ref gameLocation); + Assert.True(GamePlatform.Undefined == actual, $"Expected value to be Undefined for platform {identity.Platform}"); + Assert.Equal(game.Directory.FullName, gameLocation.FullName); } @@ -58,7 +47,7 @@ public void GetGamePlatform_WrongGameInstalledReturnsUndefined(GameType queryGam [InlineData(GameType.Foc)] public void GetGamePlatform_NoGameInstalledReturnsUndefined(GameType queryGameType) { - var gameLocation = _fileSystem.DirectoryInfo.New("noGameDir"); + var gameLocation = FileSystem.DirectoryInfo.New("noGameDir"); var locRef = gameLocation; var actual = _platformIdentifier.GetGamePlatform(queryGameType, ref locRef); Assert.Equal(GamePlatform.Undefined, actual); @@ -68,9 +57,9 @@ public void GetGamePlatform_NoGameInstalledReturnsUndefined(GameType queryGameTy [Fact] public void GetGamePlatform_FocOriginWithSanitization() { - _fileSystem.InstallGame(new GameIdentity(GameType.Foc, GamePlatform.Origin), _serviceProvider); + GetOrÍnstallGame(new GameIdentity(GameType.Foc, GamePlatform.Origin)); - var locRef = _fileSystem.GetWrongOriginFocRegistryLocation(); + var locRef = GameInstallation.GetWrongOriginFocRegistryLocation(); var locStore = locRef; var actual = _platformIdentifier.GetGamePlatform(GameType.Foc, ref locRef); @@ -94,9 +83,9 @@ public void GetGamePlatform_CannotGetPlatform_GameExeNotFound_Eaw(string subPath private void GetGamePlatform_CannotGetPlatform_GameExeNotFound(GameType gameType, string gamePath) { - _fileSystem.Initialize().WithFile(_fileSystem.Path.Combine(gamePath, "Data", "megafiles.xml")); + FileSystem.Initialize().WithFile(FileSystem.Path.Combine(gamePath, "Data", "megafiles.xml")); - var loc = _fileSystem.DirectoryInfo.New(gamePath); + var loc = FileSystem.DirectoryInfo.New(gamePath); var actual = _platformIdentifier.GetGamePlatform(gameType, ref loc); Assert.Equal(GamePlatform.Undefined, actual); @@ -119,14 +108,14 @@ public void GetGamePlatform_CannotGetPlatform_DataAndMegafilesXmlNotFound_Eaw(st private void GetGamePlatform_CannotGetPlatform_DataAndMegafilesXmlNotFound(GameType gameType, string gamePath) { - _fileSystem.Initialize().WithFile(_fileSystem.Path.Combine(gamePath, PetroglyphStarWarsGameConstants.ForcesOfCorruptionExeFileName)); - var loc = _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(gamePath)); + FileSystem.Initialize().WithFile(FileSystem.Path.Combine(gamePath, PetroglyphStarWarsGameConstants.ForcesOfCorruptionExeFileName)); + var loc = FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(gamePath)); var actual = _platformIdentifier.GetGamePlatform(gameType, ref loc); Assert.Equal(GamePlatform.Undefined, actual); Assert.Equal(loc, loc); - _fileSystem.Directory.CreateDirectory(_fileSystem.Path.Combine(gamePath, "Data")); + FileSystem.Directory.CreateDirectory(FileSystem.Path.Combine(gamePath, "Data")); actual = _platformIdentifier.GetGamePlatform(gameType, ref loc); Assert.Equal(GamePlatform.Undefined, actual); Assert.Equal(loc, loc); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs index dc498ccb..5a62cec7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs @@ -6,7 +6,7 @@ using PG.StarWarsGame.Infrastructure.Games.Registry; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -36,27 +36,22 @@ protected override void SetupServices(IServiceCollection serviceCollection) protected override IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization) { var eawRegistry = gameInfo.DetectorSetupInfo?.EawRegistry - ?? GameType.Eaw.CreateNonExistingRegistry(ServiceProvider); + ?? GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(GameType.Eaw); var focRegistry = gameInfo.DetectorSetupInfo?.FocRegistry - ?? GameType.Foc.CreateNonExistingRegistry(ServiceProvider); + ?? GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(GameType.Foc); return new RegistryGameDetector(eawRegistry, focRegistry, shallHandleInitialization, ServiceProvider); } - private IGame InstallGame(GameIdentity gameIdentity) - { - return FileSystem.InstallGame(gameIdentity, ServiceProvider); - } - protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { - var game = InstallGame(gameIdentity); + var game = GetOrÍnstallGame(gameIdentity); var registryContainer = SetupRegistry(game.Type, TestGameRegistrySetupData.Installed(game.Type, game.Directory)); return new GameDetectorTestInfo(game.Type, game.Directory, registryContainer); } protected override GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity) { - var game = InstallGame(gameIdentity); + var game = GetOrÍnstallGame(gameIdentity); var registryContainer = SetupRegistry(game.Type, TestGameRegistrySetupData.Uninitialized(gameIdentity.Type)); return new GameDetectorTestInfo(game.Type, game.Directory, registryContainer); } @@ -65,8 +60,8 @@ private GameRegistryContainer SetupRegistry(GameType gameType, TestGameRegistryS { var otherGameType = gameType == GameType.Eaw ? GameType.Foc : GameType.Eaw; - var gameRegistry = registrySetup.Create(ServiceProvider); - var defaultRegistry = otherGameType.CreateNonExistingRegistry(ServiceProvider); + var gameRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(registrySetup); + var defaultRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); IGameRegistry eawRegistry; IGameRegistry focRegistry; @@ -90,14 +85,14 @@ protected override void HandleInitialization(bool shallInitSuccessfully, GameDet if (!shallInitSuccessfully) return; var registrySetupData = TestGameRegistrySetupData.Installed(info.GameType, info.GameDirectory!); - registrySetupData.Create(ServiceProvider); + GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(registrySetupData); } [Fact] public void TestInvalidArgs_Throws() { - var eawRegistry = GameType.Eaw.CreateNonExistingRegistry(ServiceProvider); - var focRegistry = GameType.Foc.CreateNonExistingRegistry(ServiceProvider); + var eawRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(GameType.Eaw); + var focRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(GameType.Foc); Assert.Throws(() => new RegistryGameDetector(null!, focRegistry, false, ServiceProvider)); Assert.Throws(() => new RegistryGameDetector(eawRegistry, null!, false, ServiceProvider)); Assert.Throws(() => new RegistryGameDetector(eawRegistry, focRegistry, false, null!)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs index f3469596..12cad4cc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/EnglishGameNameResolverTest.cs @@ -3,6 +3,7 @@ using System.Globalization; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Name; +using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -25,7 +26,7 @@ public static IEnumerable GetCultures() public void ResolveName_IgnoreCulture(CultureInfo culture) { var resolver = new EnglishGameNameResolver(); - var id = CreateRandomGameIdentity(); + var id = GITestUtilities.GetRandomGameIdentity(); resolver.ResolveName(id, culture); var name = resolver.ResolveName(id, CultureInfo.CurrentCulture); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index de06898b..ab15bdd9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -8,7 +8,6 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Name; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -45,12 +44,12 @@ public void CreateGame_NullArg_Throws() Random.Bool(), CultureInfo.CurrentCulture)); Assert.Throws(() => _factory.CreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), null!, Random.Bool(), CultureInfo.CurrentCulture)); Assert.Throws(() => _factory.CreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), FileSystem.DirectoryInfo.New("path"), Random.Bool(), null!)); @@ -70,12 +69,12 @@ public void TryCreateGame_NullArg_Throws() Random.Bool(), CultureInfo.CurrentCulture, out _)); Assert.Throws(() => _factory.TryCreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), null!, Random.Bool(), CultureInfo.CurrentCulture, out _)); Assert.Throws(() => _factory.TryCreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), FileSystem.DirectoryInfo.New("path"), Random.Bool(), null!, out _)); @@ -107,12 +106,12 @@ public void CreateGame_GameNotExists_Throws() { Assert.Throws(() => _factory.CreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), FileSystem.DirectoryInfo.New("gamePath"), true, CultureInfo.CurrentCulture)); Assert.False(_factory.TryCreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), FileSystem.DirectoryInfo.New("gamePath"), true, CultureInfo.CurrentCulture, @@ -123,12 +122,12 @@ public void CreateGame_GameNotExists_Throws() Assert.Throws(() => _factory.CreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), FileSystem.DirectoryInfo.New("gamePath"), true, CultureInfo.CurrentCulture)); Assert.False(_factory.TryCreateGame( - CreateRandomGameIdentity(), + GITestUtilities.GetRandomGameIdentity(), FileSystem.DirectoryInfo.New("gamePath"), true, CultureInfo.CurrentCulture, @@ -149,8 +148,7 @@ public void CreateGame_WrongGameIdentityInstalled_WrongPlatform_Throws(GamePlatf var actualGameType = Random.Enum(); // Use Disk so that we can check against more specific platforms - var installedGame = - FileSystem.InstallGame(new GameIdentity(actualGameType, GamePlatform.Disk), ServiceProvider); + var installedGame = GetOrÍnstallGame(new GameIdentity(actualGameType, GamePlatform.Disk)); var createIdentity = new GameIdentity(actualGameType, platform); @@ -173,8 +171,7 @@ public void CreateGame_WrongGameIdentityInstalled_WrongType_Throws(GamePlatform var actualGameType = Random.Enum(); // Use Disk so that we can check against more specific platforms - var installedGame = FileSystem.InstallGame( - new GameIdentity(actualGameType, platform), ServiceProvider); + var installedGame = GetOrÍnstallGame(new GameIdentity(actualGameType, platform)); var createGameType = actualGameType == GameType.Eaw ? GameType.Foc : GameType.Eaw; var createIdentity = new GameIdentity(createGameType, platform); @@ -185,16 +182,16 @@ public void CreateGame_WrongGameIdentityInstalled_WrongType_Throws(GamePlatform [Fact] public void CreateGame_UnidentifiedPlatform_Throws() { - InstallRandomGame(); + var game = GetOrÍnstallGame(); Assert.Throws(() => _factory.CreateGame( new GameIdentity(Random.Enum(), GamePlatform.Undefined), - GameInstallation.Game.Directory, + game.Directory, Random.Bool(), CultureInfo.CurrentCulture)); Assert.False(_factory.TryCreateGame( new GameIdentity(Random.Enum(), GamePlatform.Undefined), - GameInstallation.Game.Directory, + game.Directory, Random.Bool(), CultureInfo.CurrentCulture, out _)); } @@ -242,7 +239,7 @@ private void AssertGame(IGame game, IGameIdentity expectedIdentity, string expec [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateGame_FromIdentity_GameCreated(GameIdentity gameIdentity) { - var installedGame = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var installedGame = GetOrÍnstallGame(gameIdentity); var expectedName = _nameResolver.ResolveName(gameIdentity, CultureInfo.CurrentCulture); @@ -260,7 +257,7 @@ public void CreateGame_FromIdentity_GameCreated(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateGame_FromDetectionResult_GameCreated(GameIdentity gameIdentity) { - var installedGame = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var installedGame = GetOrÍnstallGame(gameIdentity); var detector = new DirectoryGameDetector(installedGame.Directory, ServiceProvider); var detectionResult = detector.Detect(gameIdentity.Type, gameIdentity.Platform); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs index fc7198ca..af6d20d7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs @@ -3,7 +3,6 @@ using AnakinRaW.CommonUtilities.FileSystem.Normalization; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Steam; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -11,32 +10,31 @@ namespace PG.StarWarsGame.Infrastructure.Test.GameServices; public class SteamGameHelpersTest : GameInfrastructureTestBase { - private readonly SteamGameHelpers _service; + private readonly SteamGameHelpers _steamGameHelpers; public SteamGameHelpersTest() { - _service = new SteamGameHelpers(ServiceProvider); + _steamGameHelpers = new SteamGameHelpers(ServiceProvider); } [Fact] public void GetWorkshopsLocation_NullArgs_Throws() { - Assert.Throws(() => _service.GetWorkshopsLocation(null!)); - Assert.Throws(() => _service.TryGetWorkshopsLocation(null!, out _)); + Assert.Throws(() => _steamGameHelpers.GetWorkshopsLocation(null!)); + Assert.Throws(() => _steamGameHelpers.TryGetWorkshopsLocation(null!, out _)); } [Fact] public void GetWorkshopsLocation_Success() { - var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), - ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); - var wsDir = _service.GetWorkshopsLocation(game); + var wsDir = _steamGameHelpers.GetWorkshopsLocation(game); var expectedEnd = PathNormalizer.Normalize("/workshop/content/32470", PathNormalizeOptions.UnifySeparators); Assert.EndsWith(expectedEnd, wsDir.FullName); - Assert.True(_service.TryGetWorkshopsLocation(game, out var directoryInfo)); + Assert.True(_steamGameHelpers.TryGetWorkshopsLocation(game, out var directoryInfo)); Assert.EndsWith(expectedEnd, directoryInfo.FullName); } @@ -49,8 +47,8 @@ public void GetWorkshopsLocation_CannotFindWorkshopPath() new GameIdentity(Random.Enum(), GamePlatform.SteamGold), gameDir, "Game", ServiceProvider); - Assert.Throws(() => _service.GetWorkshopsLocation(game)); - Assert.False(_service.TryGetWorkshopsLocation(game, out _)); + Assert.Throws(() => _steamGameHelpers.GetWorkshopsLocation(game)); + Assert.False(_steamGameHelpers.TryGetWorkshopsLocation(game, out _)); } [Theory] @@ -60,10 +58,9 @@ public void GetWorkshopsLocation_CannotFindWorkshopPath() [InlineData(GamePlatform.Origin)] public void GetWorkshopsLocation_FailNoSteam(GamePlatform platform) { - var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), platform), - ServiceProvider); - Assert.Throws(() => _service.GetWorkshopsLocation(game)); - Assert.False(_service.TryGetWorkshopsLocation(game, out _)); + var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), platform)); + Assert.Throws(() => _steamGameHelpers.GetWorkshopsLocation(game)); + Assert.False(_steamGameHelpers.TryGetWorkshopsLocation(game, out _)); } [Fact] @@ -73,7 +70,7 @@ public void ToSteamWorkshopsId() new Random().NextBytes(buf); var steamId = (ulong)BitConverter.ToInt64(buf, 0); - Assert.True(_service.ToSteamWorkshopsId(steamId.ToString(), out var result)); + Assert.True(_steamGameHelpers.ToSteamWorkshopsId(steamId.ToString(), out var result)); Assert.Equal(steamId, result); Assert.True(SteamGameHelpers.IstValidSteamWorkshopsDir(steamId.ToString(), out result)); @@ -96,7 +93,7 @@ public void ToSteamWorkshopsId() [InlineData("1 ")] public void ToSteamWorkshopsId_InvalidFormats(string input) { - Assert.False(_service.ToSteamWorkshopsId(input, out _)); + Assert.False(_steamGameHelpers.ToSteamWorkshopsId(input, out _)); Assert.False(SteamGameHelpers.IstValidSteamWorkshopsDir(input, out _)); Assert.False(SteamGameHelpers.IstValidSteamWorkshopsDir(input)); } @@ -104,8 +101,8 @@ public void ToSteamWorkshopsId_InvalidFormats(string input) [Fact] public void ToSteamWorkshopsId_InvalidArgs_Throws() { - Assert.Throws(() => _service.ToSteamWorkshopsId(null!, out _)); - Assert.Throws(() => _service.ToSteamWorkshopsId(string.Empty, out _)); + Assert.Throws(() => _steamGameHelpers.ToSteamWorkshopsId(null!, out _)); + Assert.Throws(() => _steamGameHelpers.ToSteamWorkshopsId(string.Empty, out _)); Assert.Throws(() => SteamGameHelpers.IstValidSteamWorkshopsDir(null!, out _)); Assert.Throws(() => SteamGameHelpers.IstValidSteamWorkshopsDir(string.Empty, out _)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 2ba5c8ad..9a5a10f6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -21,8 +21,7 @@ public abstract class ModBaseTest : PlayableModContainerTest protected ModBaseTest() { - InstallRandomGame(); - Game = GameInstallation.Game; + Game = GetOrÍnstallGame(); } protected abstract ModBase CreateMod( diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index cf8689d5..c4a45dea 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -5,7 +5,7 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -113,8 +113,8 @@ public void Equals_GameAware(bool gameAware) var sameishGame = new PetroglyphStarWarsGame(Game, Game.Directory, Game.Name, ServiceProvider); var modSamish = sameishGame.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops, ServiceProvider); - var diffGame = FileSystem.InstallGame( - new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform), ServiceProvider); + var diffGame = GameInfrastructureTesting.Game(ServiceProvider) + .Install(new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform)); var diffGameMod = diffGame.InstallMod("A", modA.Type == ModType.Workshops, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs index fd99eb2f..01eedd59 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/DirectoryModNameResolverTest.cs @@ -38,7 +38,7 @@ public void Ctor_NullArgs_Throws() [Theory] [InlineData("path/1125718579", "z3r0x's mod version 3.5")] - [InlineData("path/2508288191", "Empire at War Expanded: Deep Core 3.1")] + [InlineData("path/2978074984", "EAWFOC Mod Template")] public void ResolveName_Steam_WithoutModinfo_FindNameOnline(string path, string containsExpected) { var modRef = CreateDetectedModReference(path, ModType.Workshops, null); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 5396c245..e9cadca1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -15,7 +15,7 @@ using PG.StarWarsGame.Infrastructure.Services; using PG.StarWarsGame.Infrastructure.Services.Name; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; @@ -47,7 +47,7 @@ protected override void SetupServices(IServiceCollection serviceCollection) [Fact] public void CreatePhysicalMod_NullArgs_Throws() { - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); var modData = CreateDetectedModReference(game, "path", null, null); Assert.Throws(() => _factory.CreatePhysicalMod(null!, modData, CultureInfo.CurrentCulture)); @@ -58,7 +58,7 @@ public void CreatePhysicalMod_NullArgs_Throws() [Fact] public void CreatePhysicalMod_VirtualMod_Throws() { - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); var modDir = FileSystem.DirectoryInfo.New("path"); modDir.Create(); var modData = new DetectedModReference(new ModReference("SOME_ID", ModType.Virtual), modDir, null); @@ -68,7 +68,7 @@ public void CreatePhysicalMod_VirtualMod_Throws() [Fact] public void CreatePhysicalMod_ModDirectoryNotFound_Throws() { - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); var modData = CreateDetectedModReference(game, "path", null, null); modData.Directory.Delete(true); Assert.Throws(() => _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture)); @@ -78,7 +78,7 @@ public void CreatePhysicalMod_ModDirectoryNotFound_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var modDir = game.GetModDirectory("Mod_Name", false, ServiceProvider); var modData = CreateDetectedModReference(game, modDir, false, null); @@ -94,7 +94,7 @@ public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var modDir = game.GetModDirectory("Mod_Name", false, ServiceProvider); var modinfo = new ModinfoData("MyMod"); @@ -113,7 +113,7 @@ public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void CreatePhysicalMod_Steam_WithoutModinfo(GameType gameType) { - var game = FileSystem.InstallGame(new GameIdentity(gameType, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); var modDir = game.GetModDirectory("Mod_Name", true, ServiceProvider); var modinfo = new ModinfoData("MyMod"); @@ -132,7 +132,7 @@ public void CreatePhysicalMod_Steam_WithoutModinfo(GameType gameType) [InlineData(GameType.Foc)] public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) { - var game = FileSystem.InstallGame(new GameIdentity(gameType, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); var modDir = game.GetModDirectory("Mod_Name", true, ServiceProvider); var modRef = CreateDetectedModReference(game, modDir, true, null); @@ -148,7 +148,7 @@ public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var ws = GITestUtilities.GetRandomWorkshopFlag(game); var modDir = game.GetModDirectory("Mod_Name", ws, ServiceProvider); @@ -163,7 +163,7 @@ public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var ws = GITestUtilities.GetRandomWorkshopFlag(game); var modDir = game.GetModDirectory("Mod_Name", ws, ServiceProvider); @@ -177,11 +177,11 @@ public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var oppositeGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; - var otherGame = FileSystem.InstallGame( - new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + var otherGame = GameInfrastructureTesting.Game(ServiceProvider) + .Install(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms))); var modDir = otherGame.GetModDirectory("Mod_Name", false, ServiceProvider); var modData = CreateDetectedModReference(otherGame, modDir, false, null); @@ -196,7 +196,7 @@ public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) [Fact] public void CreateVirtualMod_NullArgs_Throws() { - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); var dep = game.InstallMod("dep", false, ServiceProvider); Assert.Throws(() => _factory.CreateVirtualMod(null!, new ModinfoData("Name") @@ -210,7 +210,7 @@ public void CreateVirtualMod_NullArgs_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var dep = game.InstallMod("dep", false, ServiceProvider); var invalidModinfo = new CustomModInfo(string.Empty) @@ -225,7 +225,7 @@ public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var invalidModinfo = new CustomModInfo("MyVirtualMod") { @@ -239,7 +239,7 @@ public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity game [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var dep = game.InstallMod("dep", false, ServiceProvider); var modinfo = new CustomModInfo("VirtualModName") diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 1d5d1362..875d9b81 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -14,7 +14,7 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; @@ -38,7 +38,7 @@ public void FindMods_NullArg_Throws() { Assert.Throws(() => _modFinder.FindMods(null!)); Assert.Throws(() => _modFinder.FindMods(null!, FileSystem.Directory.CreateDirectory("path"))); - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); Assert.Throws(() => _modFinder.FindMods(game, null!)); } @@ -46,7 +46,7 @@ public void FindMods_NullArg_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_GameNotExists_Throws(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); game.Directory.Delete(true); Assert.Throws(() => _modFinder.FindMods(game)); Assert.Throws(() => _modFinder.FindMods(game, FileSystem.DirectoryInfo.New("path"))); @@ -56,7 +56,7 @@ public void FindMods_GameNotExists_Throws(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_NoModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); game.ModsLocation.Delete(true); if (game.Platform is GamePlatform.SteamGold) @@ -76,7 +76,7 @@ public void FindMods_NoModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); game.ModsLocation.Create(); if (game.Platform is GamePlatform.SteamGold) @@ -93,7 +93,7 @@ public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdent [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var installedMods = _modFinder.FindMods(game); @@ -107,7 +107,7 @@ public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); expectedMod.InstallInvalidModinfoFile(); @@ -123,7 +123,7 @@ public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var expectedModinfo = new ModinfoData("Variant1"); @@ -142,7 +142,7 @@ public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var modinfoData = new ModinfoData("MyMod"); var expectedMod = game.InstallMod(GITestUtilities.GetRandomWorkshopFlag(game), modinfoData, ServiceProvider); @@ -159,7 +159,7 @@ public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); @@ -192,7 +192,7 @@ public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var main = new ModinfoData("Main"); var info1 = new ModinfoData("MyName1"); @@ -225,7 +225,7 @@ public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var mod1 = game.InstallMod("Mod1", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var mod2 = game.InstallMod("Mod2", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -244,7 +244,7 @@ public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) { - var game = FileSystem.InstallGame(new GameIdentity(type, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); var steamMod = game.InstallMod("SteamMod", true, ServiceProvider); @@ -272,7 +272,7 @@ public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) [InlineData(GameType.Foc)] public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) { - var game = FileSystem.InstallGame(new GameIdentity(type, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; @@ -299,7 +299,7 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var modPath = FileSystem.DirectoryInfo.New("external/myMod"); modPath.Create(); @@ -313,7 +313,7 @@ public void FindMods_FromExternal(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var modPath = FileSystem.DirectoryInfo.New("external/myMod"); modPath.Create(); @@ -328,7 +328,7 @@ public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameI [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var modPath = FileSystem.DirectoryInfo.New("external/123456"); // Use a number so it may look like a Steam WS ID modPath.Create(); @@ -353,7 +353,7 @@ public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIden [InlineData(GameType.Foc)] public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) { - var game = FileSystem.InstallGame(new GameIdentity(type, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Create(); @@ -373,7 +373,7 @@ public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) [InlineData(GameType.Foc)] public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType type) { - var game = FileSystem.InstallGame(new GameIdentity(type, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Create(); @@ -393,9 +393,10 @@ public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType t public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameType type) { var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; - var game = FileSystem.InstallGame(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms))); // Other, random platform to shuffle a bit more. - var otherTypeGame = FileSystem.InstallGame(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + var otherTypeGame = GameInfrastructureTesting.Game(ServiceProvider) + .Install(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms))); var wrongMod = otherTypeGame.InstallMod("MyMod", false, ServiceProvider); @@ -408,7 +409,7 @@ public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameTyp [InlineData(GameType.Foc)] public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameType type) { - var game = FileSystem.InstallGame(new GameIdentity(type, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Delete(true); @@ -426,7 +427,7 @@ public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameTyp [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_InvalidModinfoContentIsSkippedButModIsFound(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GetOrÍnstallGame(gameIdentity); var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); expectedMod.InstallModinfoFile(new CustomModinfo(string.Empty)); // string.Empty is not valid diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index e02a5569..475582d5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -12,7 +12,6 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -125,7 +124,7 @@ public void Directory_WithModinfo_ModinfoIsAlwaysSuperiorForSteamTypes() }; // Installing FOC, while tags has EAW. So technically, EAW does not even exist. - var game = FileSystem.InstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); // Using a known MODID (RaW), which is FOC, to implicitly assert cache is not used. var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("1129810972"); @@ -147,7 +146,7 @@ public void Directory_SteamWithoutModinfoCannotDecide() // No SteamData here var modinfo = new ModinfoData("Name"); - var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); @@ -180,7 +179,7 @@ public void Directory_SteamWithInvalidDirName() SteamData = steamData }; - var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("notASteamId"); @@ -218,7 +217,7 @@ public void Directory_SteamWithoutModinfoButKnownModID(string knownId, ICollecti // No SteamData here var modinfo = new ModinfoData("Name"); - var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); @@ -249,7 +248,7 @@ public void VirtualMods_VirtualModsAreAlwaysUndecidable() SteamData = steamData }; - var game = FileSystem.InstallGame(CreateRandomGameIdentity(), ServiceProvider); + var game = GetOrÍnstallGame(); var mod = game.InstallMod("Name", false, ServiceProvider); var info = CreateDetectedModReference(mod.Directory, ModType.Virtual, modinfo); @@ -304,7 +303,7 @@ public void ModsInModsDirUseGameType(GameType gameType) SteamData = steamData }; - var game = FileSystem.InstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))); var mod = game.InstallMod("Name", false, ServiceProvider); var info = CreateDetectedModReference(mod.Directory, ModType.Default, modinfo); @@ -334,7 +333,7 @@ public void ModsNotInModsDirButSomeOtherGameBasesDir_NotDecidable(GameType gameT SteamData = steamData }; - var game = FileSystem.InstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))); var modDir = game.Directory.CreateSubdirectory("ModsOther").CreateSubdirectory("MyMod"); var mod = game.InstallMod(modDir, false, modinfo, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs index 90a8b74e..aaa8441c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; +using System.Threading; using AET.Modinfo.Spec; using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test.ModServices; @@ -21,14 +21,14 @@ public override ModGameTypeResolver CreateResolver() public static IEnumerable GetOnlineModsData() { yield return ["1125718579", new[] {GameType.Foc}, GameType.Eaw]; //z3r0x's Mod (3.5) - yield return ["2508288191", new[] {GameType.Foc, GameType.Eaw}, null!]; //Deep Core SDK + yield return ["2508288191", new[] {GameType.Foc, GameType.Eaw}, null!]; //Mod Template } [Theory] [MemberData(nameof(GetOnlineModsData))] public void Online_GetTagsFromSteamOnline(string knownId, ICollection expectedTypes, GameType? incompatibleWith) { - var game = FileSystem.InstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold), ServiceProvider); + var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory(knownId); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index dced6dfd..d1e0f510 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -12,7 +12,7 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; @@ -43,11 +43,11 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga { // Init Mods uninitialized - var eaw = FileSystem.InstallGame(new GameIdentity(GameType.Eaw, platform), ServiceProvider); - var foc = FileSystem.InstallGame(new GameIdentity(GameType.Foc, platform), ServiceProvider); + var eaw = GameInfrastructureTesting.Game(ServiceProvider).Install(new GameIdentity(GameType.Eaw, platform)); + var foc = GameInfrastructureTesting.Game(ServiceProvider).Install(new GameIdentity(GameType.Foc, platform)); - TestGameRegistrySetupData.Uninitialized(GameType.Eaw).Create(ServiceProvider); - TestGameRegistrySetupData.Uninitialized(GameType.Foc).Create(ServiceProvider); + GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(GameType.Eaw)); + GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(GameType.Foc)); var registryFactory = ServiceProvider.GetRequiredService(); var eawRegistry = registryFactory.CreateRegistry(GameType.Eaw); @@ -59,7 +59,8 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga var initCount = 0; gameDetector.InitializationRequested += (_, args) => { - _registry.InstallGame(args.GameType == GameType.Eaw ? eaw : foc, ServiceProvider); + var game = args.GameType == GameType.Eaw ? eaw : foc; + GameInfrastructureTesting.Registry(ServiceProvider).CreateInstlled(game); args.Handled = true; initCount++; }; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index 350f5b3f..c0ee0843 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -4,17 +4,17 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; public class PetroglyphStarWarsGameTest : PlayableModContainerTest { - private IGame CreateGame(string? iconPath = null, ICollection? languages = null) + private PetroglyphStarWarsGame CreateGame(string? iconPath = null, ICollection? languages = null) { var gameId = new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); - var game = FileSystem.InstallGame(gameId, ServiceProvider); + var game = GetOrÍnstallGame(gameId); if (languages is not null) { foreach (var languageInfo in languages) @@ -27,7 +27,7 @@ private IGame CreateGame(string? iconPath = null, ICollection? la FileSystem.File.Create(FileSystem.Path.Combine(game.Directory.FullName, iconPath)); } - return game; + return game as PetroglyphStarWarsGame; } protected override IPlayableObject CreatePlayableObject(string? iconPath = null, ICollection? languages = null) @@ -37,7 +37,7 @@ protected override IPlayableObject CreatePlayableObject(string? iconPath = null, protected override PlayableModContainer CreateModContainer() { - return CreateGame() as PlayableModContainer; + return CreateGame(); } [Fact] @@ -63,9 +63,9 @@ public void Equals_GetHashCode() var focSteamId = new GameIdentity(GameType.Foc, GamePlatform.SteamGold); var eawDiskId = new GameIdentity(GameType.Eaw, GamePlatform.Disk); - var eawSteam = FileSystem.InstallGame(eawSteamId, ServiceProvider); - var focSteam = FileSystem.InstallGame(focSteamId, ServiceProvider); - var eawDisc = FileSystem.InstallGame(eawDiskId, ServiceProvider); + var eawSteam = GameInfrastructureTesting.Game(ServiceProvider).Install(eawSteamId); + var focSteam = GameInfrastructureTesting.Game(ServiceProvider).Install(focSteamId); + var eawDisc = GameInfrastructureTesting.Game(ServiceProvider).Install(eawDiskId); Assert.False(eawSteam.Equals(null)); Assert.False(eawSteam.Equals((object)null!)); @@ -100,7 +100,7 @@ public void Equals_GetHashCode() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetModDirTest(GameIdentity gameIdentity) { - var game = FileSystem.InstallGame(gameIdentity, ServiceProvider); + var game = GameInstallation.Install(gameIdentity); var dataLocation = game.ModsLocation; Assert.Equal(FileSystem.Path.GetFullPath(FileSystem.Path.Combine(game.Directory.FullName, "Mods")), dataLocation.FullName); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 01fae330..8c8fe3ee 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -1,15 +1,15 @@ -using System; -using System.Collections.Generic; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Language; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using System; +using System.Collections.Generic; using Xunit; +using PG.StarWarsGame.Infrastructure.Testing.Game; namespace PG.StarWarsGame.Infrastructure.Test.Services; @@ -71,7 +71,7 @@ public void FindLanguages_Mod_WithNoLanguages_UsesGame() [Fact] public void FindLanguages_Mod_WithLanguages_En_De_Steam() { - var game = FileSystem.InstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); + var game = GameInfrastructureTesting.Game(ServiceProvider).Install(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); var mod = game.InstallMod("myMod", true, ServiceProvider); InstallModLanguage(mod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(mod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 4e77c5ee..3e0ae39f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -40,8 +40,8 @@ private VirtualMod CreateVirtualMod( Dependencies = depList }; - var mod = new VirtualMod(GameInstallation.Game, "VirtualModId", modinfo, ServiceProvider); - GameInstallation.Game.AddMod(mod); + var mod = new VirtualMod(Game, "VirtualModId", modinfo, ServiceProvider); + Game.AddMod(mod); return mod; } @@ -68,25 +68,25 @@ protected override PlayableModContainer CreateModContainer() [Fact] public void InvalidCtor_ArgumentNull_Throws() { - GameInstallation.Game.InstallAndAddMod("Dep", GITestUtilities.GetRandomWorkshopFlag(GameInstallation.Game), ServiceProvider); + Game.InstallAndAddMod("Dep", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); Assert.Throws(() => new VirtualMod(null!, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); - Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", null!, ServiceProvider)); - Assert.Throws(() => new VirtualMod(GameInstallation.Game, "name", null!, ServiceProvider)); + Assert.Throws(() => new VirtualMod(Game, "VirtualModId", null!, ServiceProvider)); + Assert.Throws(() => new VirtualMod(Game, "name", null!, ServiceProvider)); - Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", new ModinfoData("Name"), null!)); - Assert.Throws(() => new VirtualMod(GameInstallation.Game, null!, new ModinfoData("Name"), ServiceProvider)); + Assert.Throws(() => new VirtualMod(Game, "VirtualModId", new ModinfoData("Name"), null!)); + Assert.Throws(() => new VirtualMod(Game, null!, new ModinfoData("Name"), ServiceProvider)); } [Fact] public void Ctor_EmptyDependencies_Throws() { - Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); + Assert.Throws(() => new VirtualMod(Game, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); var modInfo = new ModinfoData("Name") { Dependencies = new DependencyList(new List(), DependencyResolveLayout.FullResolved) }; - Assert.Throws(() => new VirtualMod(GameInstallation.Game, "VirtualModId", modInfo, ServiceProvider)); + Assert.Throws(() => new VirtualMod(Game, "VirtualModId", modInfo, ServiceProvider)); } [Fact] @@ -105,7 +105,7 @@ public void Ctor_FromModinfo_Properties() }, DependencyResolveLayout.ResolveLastItem) }; - var mod = new VirtualMod(GameInstallation.Game, "VirtualModId", modinfo, ServiceProvider); + var mod = new VirtualMod(Game, "VirtualModId", modinfo, ServiceProvider); Assert.Empty(mod.Dependencies); Assert.Single(((IModIdentity)mod).Dependencies); @@ -123,8 +123,8 @@ public void Ctor_FromModinfo_Properties() [Fact] public void Ctor_NonPhysicalDependencies_Throws() { - var customDep = new CustomVirtualMod(GameInstallation.Game, ServiceProvider); - GameInstallation.Game.AddMod(customDep); + var customDep = new CustomVirtualMod(Game, ServiceProvider); + Game.AddMod(customDep); var modInfo = new ModinfoData("Name") { @@ -132,8 +132,8 @@ public void Ctor_NonPhysicalDependencies_Throws() DependencyResolveLayout.FullResolved) }; - var mod = new VirtualMod(GameInstallation.Game, "VirtualModId", modInfo, ServiceProvider); - GameInstallation.Game.AddMod(mod); + var mod = new VirtualMod(Game, "VirtualModId", modInfo, ServiceProvider); + Game.AddMod(mod); Assert.Throws(mod.ResolveDependencies); } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index c84d310c..ded9ade8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -60,4 +60,10 @@ public static ICollection GetRandomLanguages() return languages; } + + public static GameIdentity GetRandomGameIdentity(bool realOnly = true) + { + var platforms = realOnly ? RealPlatforms : (GamePlatform[])Enum.GetValues(typeof(GamePlatform)); + return new GameIdentity(Random.Enum(), Random.Item(platforms)); + } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs new file mode 100644 index 00000000..83a8adb9 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs @@ -0,0 +1,18 @@ +using System; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; + +namespace PG.StarWarsGame.Infrastructure.Testing.Game; + +public static class GameInfrastructureTesting +{ + public static ITestingGameInstallation Game(IServiceProvider serviceProvider) + { + return new TestingGameImpl(serviceProvider); + } + + public static ITestingGameRegistry Registry(IServiceProvider serviceProvider) + { + return new TestingGameRegistryImpl(serviceProvider); + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs index 0c665dd8..48d803e2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs @@ -5,7 +5,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -public static partial class GameInstallation +internal static partial class GameInstallation { private const string EawNormalPath = "games/eaw"; private const string EawGoldPath = "games/gold/eaw"; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs index 1dbe963a..a14e0687 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs @@ -5,7 +5,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -public static partial class GameInstallation +internal static partial class GameInstallation { private const string FocNormalPath = "games/foc"; private const string FocGoldPath = "games/gold/foc"; @@ -13,11 +13,6 @@ public static partial class GameInstallation private const string FocGogSubPath = "EAWX"; private const string FocOriginSubPath = "EAWX"; - public static IDirectoryInfo GetWrongOriginFocRegistryLocation(this IFileSystem fs) - { - return fs.DirectoryInfo.New(fs.Path.Combine(OriginBasePath, "corruption")); - } - public static IDirectoryInfo InstallFoc(IFileSystem fs, GamePlatform platform) { IDirectoryInfo gameDirectory; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs index d38382fe..f8630fa1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs @@ -1,95 +1,15 @@ -using Microsoft.Extensions.DependencyInjection; -using PG.StarWarsGame.Infrastructure.Games; -using System; -using System.Diagnostics.CodeAnalysis; +using System; using System.IO.Abstractions; using Testably.Abstractions.Testing; -using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -public static class GameTesting -{ - public static ITestingGameInstallation Game(IServiceProvider serviceProvider) - { - return new TestingGameImpl(serviceProvider); - } -} - -public interface ITestingGameInstallation -{ - IGame? Game { get; } - - [MemberNotNull(nameof(Game))] - void Install(GameIdentity gameIdentity); - - void InstallDebug(); -} - -internal class TestingGameImpl(IServiceProvider serviceProvider) : ITestingGameInstallation -{ - private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); - - public IGame? Game { get; private set; } - - [MemberNotNull(nameof(Game))] - public void Install(GameIdentity gameIdentity) - { - var gameDir = gameIdentity.Type == GameType.Foc - ? GameInstallation.InstallFoc(_fileSystem, gameIdentity.Platform) - : GameInstallation.InstallEaw(_fileSystem, gameIdentity.Platform); - - _fileSystem.InstallModsLocations(gameDir); - - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), serviceProvider); - Assert.True(game.Exists()); - Game = game; - } - - public void InstallDebug() - { - ThrowIfNotInstalled(); - Game.InstallDebug(); - } - - - [MemberNotNull(nameof(Game))] - private void ThrowIfNotInstalled() - { - if (Game is null) - throw new InvalidOperationException("Game not installed"); - } -} - - -public static partial class GameInstallation +internal static partial class GameInstallation { // Ensure starts on path 'steam'. See SteamInstallation.cs - private const string SteamBasePath = "steam/steamapps/common/Star Wars Empire at War"; - private const string GogBasePath = "games/gog"; - private const string OriginBasePath = "games/origin"; - - public static IGame InstallGame(this IFileSystem fileSystem, GameIdentity gameIdentity, IServiceProvider serviceProvider) - { - var gameDir = gameIdentity.Type == GameType.Foc - ? InstallFoc(fileSystem, gameIdentity.Platform) - : InstallEaw(fileSystem, gameIdentity.Platform); - - fileSystem.InstallModsLocations(gameDir); - - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), serviceProvider); - Assert.True(game.Exists()); - return game; - } - - public static void InstallDebug(this IGame game) - { - if (game.Platform is not GamePlatform.SteamGold) - Assert.Fail($"Cannot install Debug files for non-Steam game '{game}'"); - - var fs = game.Directory.FileSystem; - CreateFile(fs, fs.Path.Combine(game.Directory.FullName, "StarWarsI.exe")); - } + internal const string SteamBasePath = "steam/steamapps/common/Star Wars Empire at War"; + internal const string GogBasePath = "games/gog"; + internal const string OriginBasePath = "games/origin"; private static void InstallDataAndMegaFilesXml(this IFileSystem fs, IDirectoryInfo directory) { @@ -134,7 +54,7 @@ internal static void InstallModsLocations(this IFileSystem fileSystem, IDirector fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(directory.FullName, "Mods")); } - private static void CreateFile(IFileSystem fs, string path) + internal static void CreateFile(IFileSystem fs, string path) { var dir = fs.Path.GetDirectoryName(path)!; fs.Directory.CreateDirectory(dir); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs new file mode 100644 index 00000000..b446a9d9 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs @@ -0,0 +1,20 @@ +using System.Diagnostics.CodeAnalysis; +using System.IO.Abstractions; +using PG.StarWarsGame.Infrastructure.Games; + +namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +public interface ITestingGameInstallation +{ + IGame? Game { get; } + + [MemberNotNull(nameof(Game))] + IGame Install(IGameIdentity gameIdentity); + + [MemberNotNull(nameof(Game))] + IGame InstallRandom(); + + void InstallDebug(); + + IDirectoryInfo GetWrongOriginFocRegistryLocation(); +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs new file mode 100644 index 00000000..d5046935 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs @@ -0,0 +1,62 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO.Abstractions; +using Microsoft.Extensions.DependencyInjection; +using PG.StarWarsGame.Infrastructure.Games; +using Xunit; + +namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +internal class TestingGameImpl(IServiceProvider serviceProvider) : ITestingGameInstallation +{ + private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); + + public IGame? Game { get; private set; } + + [MemberNotNull(nameof(Game))] + public IGame Install(IGameIdentity gameIdentity) + { + ThrowIfInstalled(); + var gameDir = gameIdentity.Type == GameType.Foc + ? GameInstallation.InstallFoc(_fileSystem, gameIdentity.Platform) + : GameInstallation.InstallEaw(_fileSystem, gameIdentity.Platform); + + _fileSystem.InstallModsLocations(gameDir); + + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), serviceProvider); + Assert.True(game.Exists()); + return Game = game; + } + + public IGame InstallRandom() + { + return Install(GITestUtilities.GetRandomGameIdentity(realOnly: true)); + } + + public void InstallDebug() + { + ThrowIfNotInstalled(); + if (Game.Platform is not GamePlatform.SteamGold) + Assert.Fail($"Cannot install Debug files for non-Steam game '{Game}'"); + GameInstallation.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); + } + + public IDirectoryInfo GetWrongOriginFocRegistryLocation() + { + return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallation.OriginBasePath, "corruption")); + } + + + [MemberNotNull(nameof(Game))] + private void ThrowIfNotInstalled() + { + if (Game is null) + throw new InvalidOperationException("Game not installed"); + } + + private void ThrowIfInstalled() + { + if (Game is not null) + throw new InvalidOperationException("Game already installed for this testing instance. Create a new one."); + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs new file mode 100644 index 00000000..9ff12e34 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs @@ -0,0 +1,13 @@ +using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Games.Registry; + +namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; + +public interface ITestingGameRegistry +{ + IGameRegistry CreateNonExistingRegistry(GameType gameType); + + IGameRegistry CreateInstlled(IGame game); + + IGameRegistry CreateFrom(TestGameRegistrySetupData registrySetupData); +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestingGameRegistryImpl.cs similarity index 52% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestingGameRegistryImpl.cs index 4b7634a6..6f82d1c6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/GameRegistryTestExtensions.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestingGameRegistryImpl.cs @@ -1,47 +1,47 @@ -using System; -using System.IO.Abstractions; -using AnakinRaW.CommonUtilities.Registry; +using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; +using System; +using System.IO.Abstractions; using Xunit; +using RegistryHive = AnakinRaW.CommonUtilities.Registry.RegistryHive; +using RegistryView = AnakinRaW.CommonUtilities.Registry.RegistryView; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; -public static class GameRegistryTestExtensions +internal sealed class TestingGameRegistryImpl(IServiceProvider serviceProvider) : ITestingGameRegistry { - public static IGameRegistry CreateNonExistingRegistry(this GameType gameType, IServiceProvider serviceProvider) + private readonly IGameRegistryFactory _registryFactory = serviceProvider.GetRequiredService(); + private readonly IRegistry _registry = serviceProvider.GetRequiredService(); + + public IGameRegistry CreateNonExistingRegistry(GameType gameType) { - return serviceProvider.GetRequiredService().CreateRegistry(gameType); + return _registryFactory.CreateRegistry(gameType); } - public static IGameRegistry InstallGame(this IRegistry registry, IGame game, IServiceProvider serviceProvider) + public IGameRegistry CreateInstlled(IGame game) { - InitializeRegistry(registry, TestGameRegistrySetupData.Installed(game.Type, game.Directory), null, serviceProvider); - return serviceProvider.GetRequiredService().CreateRegistry(game.Type); + return CreateFrom(TestGameRegistrySetupData.Installed(game.Type, game.Directory)); } - public static IGameRegistry Create(this TestGameRegistrySetupData registrySetupData, IServiceProvider serviceProvider) + public IGameRegistry CreateFrom(TestGameRegistrySetupData registrySetupData) { - var gameRegistry = CreateNonExistingRegistry(registrySetupData.GameType, serviceProvider); - var registry = serviceProvider.GetRequiredService(); - InitializeRegistry(registry, registrySetupData, null, serviceProvider); + var gameRegistry = _registryFactory.CreateRegistry(registrySetupData.GameType); + InitializeRegistry(registrySetupData, null); return gameRegistry; } - private static void InitializeRegistry( - IRegistry registry, - TestGameRegistrySetupData setupData, - IDirectoryInfo? customDirectoryInfo, IServiceProvider serviceProvider) + private void InitializeRegistry(TestGameRegistrySetupData setupData, IDirectoryInfo? customDirectoryInfo) { var gameKeyPath = setupData.GameType == GameType.Eaw ? GameRegistryFactory.EawRegistryPath : GameRegistryFactory.FocRegistryPath; - using var hklm = registry.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); + using var hklm = _registry.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); hklm.DeleteKey(gameKeyPath, true); if (!setupData.CreateRegistry) return; - + using var gameKey = hklm.CreateSubKey(gameKeyPath); if (!setupData.InitRegistry) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 9a61a2d6..8c6e55fa 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,16 +1,14 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO.Abstractions; -using System.Threading; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing; -using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; +using System.IO.Abstractions; +using System.Threading; using Testably.Abstractions.Testing; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; @@ -23,7 +21,7 @@ public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider protected GameInfrastructureTestBase() { - GameInstallation = GameTesting.Game(ServiceProvider); + GameInstallation = GameInfrastructureTesting.Game(ServiceProvider); } protected virtual IFileSystem CreateFileSystem() @@ -38,16 +36,15 @@ protected override void SetupServices(IServiceCollection serviceCollection) PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } - protected static GameIdentity CreateRandomGameIdentity() + protected virtual IGame GetOrÍnstallGame(IGameIdentity? identity = null) { - return new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); + if (GameInstallation.Game is not null) + return GameInstallation.Game; + return identity is not null ? GameInstallation.Install(identity) : GameInstallation.InstallRandom(); } - protected void InstallRandomGame() - { - GameInstallation.Install(CreateRandomGameIdentity()); - } + // TODO: To installation protected IMod CreateAndAddMod(bool isWorkshop, string name, IModDependencyList dependencies) { if (dependencies.Count == 0) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 075c9146..8433b95b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -8,13 +8,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastructureTestBase { - protected readonly IGame Game; - - protected GameInfrastructureTestBaseWithRandomGame() - { - InstallRandomGame(); - Game = GameInstallation.Game; - } + protected IGame Game => GetOrÍnstallGame(identity: null); protected IMod CreateAndAddMod( string name, From fd44d6857d252a5d869a26a4855f6c4d37e49b79 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Thu, 18 Dec 2025 16:22:08 +0100 Subject: [PATCH 24/71] start mod impl --- .../ModBaseTest.cs | 12 +++++++----- .../ModEqualityComparerTest.cs | 19 ++++++++++--------- .../GITestUtilities.cs | 2 +- .../Installation/ITestingGameInstallation.cs | 7 +++++-- .../Game/Installation/TestingGameImpl.cs | 12 +++++++++++- .../Mods/ModInstallations.cs | 16 ++++++++++++++++ .../TestBases/GameInfrastructureTestBase.cs | 2 +- 7 files changed, 51 insertions(+), 19 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 9a5a10f6..b33babcf 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -10,6 +10,7 @@ using Xunit; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; +using PG.StarWarsGame.Infrastructure.Testing.Game; using Semver; using PG.StarWarsGame.Infrastructure.Testing.TestBases; @@ -104,14 +105,15 @@ public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectl [Fact] public void ResolveDependencies_DepOfWrongGame_Throws() { - var otherGameReference = new PetroglyphStarWarsGame(Game, Game.Directory, Game.Name, ServiceProvider); - var wrongGameDep = otherGameReference.InstallAndAddMod("WrongGameRefMod", - GITestUtilities.GetRandomWorkshopFlag(otherGameReference), ServiceProvider); - var mod = CreateMod("Mod", Random.Enum(), wrongGameDep); + var otherGameInstallRef = GameInfrastructureTesting.Game(ServiceProvider); + var otherGame = otherGameInstallRef.Install(Game); + var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod", GITestUtilities.GetRandomWorkshopFlag(otherGame)); + + var mod = CreateMod("Mod", Random.Enum(), wrongGameDep.Mod); var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); - Assert.Equal(wrongGameDep, e.Mod); + Assert.Equal(wrongGameDep.Mod, e.Mod); Assert.Equal(DependencyResolveStatus.Faulted, mod.DependencyResolveStatus); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index c4a45dea..e555c6e2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -1,13 +1,14 @@ -using System; -using System.Collections.Generic; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using System; +using System.Collections.Generic; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; @@ -106,12 +107,12 @@ public void Equals_DependencyAware(bool depAware) [InlineData(false)] [InlineData(true)] public void Equals_GameAware(bool gameAware) - { - + { var modA = CreateAndAddMod("A"); - var sameishGame = new PetroglyphStarWarsGame(Game, Game.Directory, Game.Name, ServiceProvider); - var modSamish = sameishGame.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops, ServiceProvider); + var otherGameInstallRef = GameInfrastructureTesting.Game(ServiceProvider); + otherGameInstallRef.Install(Game); + var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); var diffGame = GameInfrastructureTesting.Game(ServiceProvider) .Install(new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform)); @@ -122,8 +123,8 @@ public void Equals_GameAware(bool gameAware) Assert.True(comparer.Equals(modA, modA)); Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(modA)); - Assert.True(comparer.Equals(modA, modSamish)); - Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(modSamish)); + Assert.True(comparer.Equals(modA, modSamish.Mod)); + Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(modSamish.Mod)); if (gameAware) { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index ded9ade8..7e2da343 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -26,7 +26,7 @@ public static void AssertEqual(this GameDetectionResult expected, GameDetectionR Assert.Equal(expected.InitializationRequired, actual.InitializationRequired); } - public static bool GetRandomWorkshopFlag(IGame game) + public static bool GetRandomWorkshopFlag(IGameIdentity game) { if (game.Platform is not GamePlatform.SteamGold) return false; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs index b446a9d9..0c7ac4f0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs @@ -1,6 +1,7 @@ -using System.Diagnostics.CodeAnalysis; +using PG.StarWarsGame.Infrastructure.Games; +using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; -using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Testing.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; @@ -17,4 +18,6 @@ public interface ITestingGameInstallation void InstallDebug(); IDirectoryInfo GetWrongOriginFocRegistryLocation(); + + ITestingModInstallation InstallAndAddMod(string name, bool workshop); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs index d5046935..ce821cbc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Testing.Mods; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; @@ -46,6 +47,14 @@ public IDirectoryInfo GetWrongOriginFocRegistryLocation() return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallation.OriginBasePath, "corruption")); } + public ITestingModInstallation InstallAndAddMod(string name, bool workshop) + { + ThrowIfNotInstalled(); + var mod = Game.InstallMod(name, workshop, serviceProvider); + Game.AddMod(mod); + return new TestingModImpl(this, mod, serviceProvider); + } + [MemberNotNull(nameof(Game))] private void ThrowIfNotInstalled() @@ -59,4 +68,5 @@ private void ThrowIfInstalled() if (Game is not null) throw new InvalidOperationException("Game already installed for this testing instance. Create a new one."); } -} \ No newline at end of file +} + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs index 8410d975..8bb863b5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs @@ -5,11 +5,27 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Steam; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Utilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +public interface ITestingModInstallation +{ + ITestingGameInstallation GameInstallation { get; } + + IPhysicalMod Mod { get; } +} + +internal sealed class TestingModImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) : ITestingModInstallation +{ + public ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public IPhysicalMod Mod { get; } = mod; +} + public static partial class ModInstallations { public static Mod InstallAndAddMod(this IGame game, string name, bool workshop, IServiceProvider serviceProvider) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 8c6e55fa..4f40e56c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -17,7 +17,7 @@ public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); - protected ITestingGameInstallation GameInstallation; + protected ITestingGameInstallation GameInstallation { get; } protected GameInfrastructureTestBase() { From 399455ca398628c7b3ae9251ad27eb7b37d4f0a8 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Thu, 18 Dec 2025 16:57:41 +0100 Subject: [PATCH 25/71] new gameinstallation api --- .../IGameClientFactoryTest.cs | 2 +- .../SteamPetroglyphStarWarsGameClientTest.cs | 21 ++++--- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 6 +- .../Arguments/GameArgumentsBuilderTest.cs | 2 +- .../Clients/GameClientFactoryTest.cs | 2 +- .../PetroglyphStarWarsGameClientTest.cs | 61 ++++++++++--------- .../GameExecutableFileUtilitiesTest.cs | 12 ++-- .../Detection/CustomGameDetectorTest.cs | 6 +- .../Detection/DirectoryGameDetectorTest.cs | 4 +- .../Detection/GamePlatformIdentifierTest.cs | 6 +- .../Detection/RegistryGameDetectorTest.cs | 4 +- .../GameServices/GameFactoryTest.cs | 10 +-- .../GameServices/SteamGameHelpersTest.cs | 4 +- .../ModBaseTest.cs | 7 +-- .../ModEqualityComparerTest.cs | 9 ++- .../ModServices/ModFactoryTest.cs | 32 +++++----- .../ModServices/ModFinderTest.cs | 47 +++++++------- .../ModGameTypeResolverTestBase.cs | 14 ++--- .../OnlineModGameTypeResolverTest.cs | 3 +- ...oglyphGameInfrastructureIntegrationTest.cs | 4 +- .../PetroglyphStarWarsGameTest.cs | 10 +-- .../Services/LanguageFinderTestBase.cs | 2 +- .../Game/GameInfrastructureTesting.cs | 5 +- .../Installation/ITestingGameInstallation.cs | 11 +--- .../Game/Installation/TestingGameImpl.cs | 54 ++++++---------- .../TestBases/GameInfrastructureTestBase.cs | 21 +++---- ...ameInfrastructureTestBaseWithRandomGame.cs | 2 +- 27 files changed, 169 insertions(+), 192 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs index a4e30480..ff496fb3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/IGameClientFactoryTest.cs @@ -27,7 +27,7 @@ protected override void SetupServices(IServiceCollection serviceCollection) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateClient_CreatesCorrectClientType(GameIdentity identity) { - var game = GetOrÍnstallGame(identity); + var game = GetOrCreateGameInstallation(identity).Game; var factory = ServiceProvider.GetRequiredService(); var client = factory.CreateClient(game); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index 70d5fcba..c8ff0720 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -16,6 +16,7 @@ using AET.Testing.Extensions; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Game; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; @@ -25,16 +26,17 @@ public class SteamPetroglyphStarWarsGameClientTest : PetroglyphStarWarsGameClien private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); private ISteamFakeProcess? _steamProcess; + private ITestingGameInstallation? _gameInstallation; protected override ICollection SupportedPlatforms { get; } = [GamePlatform.SteamGold]; - protected override IGame GetOrÍnstallGame(IGameIdentity? identity = null) + protected override ITestingGameInstallation GetOrCreateGameInstallation(IGameIdentity? identity = null) { - if (GameInstallation.Game is not null) - return GameInstallation.Game; + if (_gameInstallation is not null) + return _gameInstallation; var type = identity?.Type ?? Random.Enum(); var steamIdentity = new GameIdentity(type, GamePlatform.SteamGold); - return GameInstallation.Install(steamIdentity); + return GameInfrastructureTesting.Game(steamIdentity, ServiceProvider); } protected override void BeforePlay() @@ -62,13 +64,13 @@ protected override void SetupServices(IServiceCollection serviceCollection) public void Ctor_SteamClient_NullArgs_Throws() { Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(null!, ServiceProvider)); - Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(GetOrÍnstallGame(), null!)); + Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(GetOrCreateGameInstallation().Game, null!)); } [Fact] public void SteamPetroglyphStarWarsGameClient_Lifecycle() { - var client = new SteamPetroglyphStarWarsGameClient(GetOrÍnstallGame(), ServiceProvider); + var client = new SteamPetroglyphStarWarsGameClient(GetOrCreateGameInstallation().Game, ServiceProvider); Assert.NotNull(client.SteamWrapper); client.Dispose(); @@ -82,15 +84,14 @@ public void Ctor_NonSteamGameThrows(GameIdentity identity) { if (identity.Platform is GamePlatform.SteamGold) return; - var otherGameInstallation = GameInfrastructureTesting.Game(ServiceProvider); - var otherGame = otherGameInstallation.Install(identity); + var otherGame = GameInfrastructureTesting.Game(identity, ServiceProvider).Game; Assert.Throws(() => new SteamPetroglyphStarWarsGameClient(otherGame, ServiceProvider)); } [Fact] public void Play_SteamNotInstalled_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var client = new SteamPetroglyphStarWarsGameClient(game, ServiceProvider); Assert.Throws(client.Play); @@ -105,7 +106,7 @@ public void Play_SteamNotRunning_Throws() // Install Steam (regardless whether the identity is supported) SteamTesting.Steam(ServiceProvider).Install(); - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var expected = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay(game, expected, gameClient => gameClient.Play(), shallThrowGameStartException: true); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 058c4758..014d1e44 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -78,7 +78,7 @@ public void Detect_SteamNotInstalled_ShouldReturnNotInstalled(GameType gameType) var gameId = new GameIdentity(gameType, GamePlatform.SteamGold); var expected = GameDetectionResult.NotInstalled(gameId.Type); - GetOrÍnstallGame(gameId); + GetOrCreateGameInstallation(gameId); var detector = new SteamPetroglyphStarWarsGameDetector(ServiceProvider); var result = detector.Detect(gameType, GamePlatform.SteamGold); @@ -94,7 +94,7 @@ public void Detect_SteamInstalledButGameNotRegisteredToSteam_ShouldReturnNotInst var gameId = new GameIdentity(gameType, GamePlatform.SteamGold); var expected = GameDetectionResult.NotInstalled(gameId.Type); - GetOrÍnstallGame(gameId); + GetOrCreateGameInstallation(gameId); var detector = new SteamPetroglyphStarWarsGameDetector(ServiceProvider); var result = detector.Detect(gameType, GamePlatform.SteamGold); @@ -135,7 +135,7 @@ private GameDetectorTestInfo SetupGame( return new GameDetectorTestInfo(gameIdentity.Type, null, null); // Install Game - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; // Register Game to Steam var lib = steam.InstallDefaultLibrary(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index 1070518d..4d3e0310 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -21,7 +21,7 @@ public sealed class GameArgumentsBuilderTest : GameInfrastructureTestBase public GameArgumentsBuilderTest() { - _game = GetOrÍnstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); + _game = GetOrCreateGameInstallation(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)).Game; } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs index ddc6d6d7..d08cae7a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/GameClientFactoryTest.cs @@ -25,7 +25,7 @@ public void CreateClient_NullArgs_Throws() public void CreateClient_CorrectTypeAndSetsProperty() { var factory = new GameClientFactory(ServiceProvider); - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var client = factory.CreateClient(game); Assert.IsType(client); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 33df9651..0f48e90a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -12,6 +12,8 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Clients; +using PG.StarWarsGame.Infrastructure.Testing.Game; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -23,6 +25,8 @@ public class PetroglyphStarWarsGameClientTest : GameInfrastructureTestBase, IDis private readonly IGameClientFactory _clientFactory; private readonly TestGameProcessLauncher _processLauncher = new(); + private ITestingGameInstallation? _gameInstallation; + protected virtual ICollection SupportedPlatforms => GITestUtilities.RealPlatforms; public virtual void Dispose() @@ -34,20 +38,20 @@ protected virtual void BeforePlay() { } - protected override IGame GetOrÍnstallGame(IGameIdentity? identity = null) + protected override ITestingGameInstallation GetOrCreateGameInstallation(IGameIdentity? identity = null) { - if (GameInstallation.Game is not null) - return GameInstallation.Game; + if (_gameInstallation is not null) + return _gameInstallation; if (identity is not null) { if (!SupportedPlatforms.Contains(identity.Platform)) throw new NotSupportedException($"The requested game platform '{identity.Platform}' is not supported by this client test"); - return GameInstallation.Install(identity); + return _gameInstallation = GameInfrastructureTesting.Game(identity, ServiceProvider); } var newIdentity = new GameIdentity(Random.Enum(), Random.Item(SupportedPlatforms)); - return GameInstallation.Install(newIdentity); + return _gameInstallation = GameInfrastructureTesting.Game(newIdentity, ServiceProvider); } public PetroglyphStarWarsGameClientTest() @@ -66,24 +70,22 @@ protected override void SetupServices(IServiceCollection serviceCollection) public void Ctor_NullArgs_Throws() { Assert.Throws(() => new PetroglyphStarWarsGameClient(null!, ServiceProvider)); - var game = GetOrÍnstallGame(); - Assert.Throws(() => new PetroglyphStarWarsGameClient(game, null!)); + Assert.Throws(() => new PetroglyphStarWarsGameClient(GetOrCreateGameInstallation().Game, null!)); } [Fact] public void Ctor_SetsGame() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; using var client = new PetroglyphStarWarsGameClient(game, ServiceProvider); - Assert.Same(GameInstallation.Game, client.Game); + Assert.Same(game, client.Game); } [Theory] [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void IsDebugAvailable_NoDebugFilesAvailable(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); - using var client = _clientFactory.CreateClient(game); + using var client = _clientFactory.CreateClient(GetOrCreateGameInstallation(gameIdentity).Game); Assert.False(client.IsDebugAvailable()); } @@ -92,16 +94,16 @@ public void IsDebugAvailable_NoDebugFilesAvailable(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void IsDebugAvailable_DebugFilesAvailable(GameType gameType) { - var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); - GameInstallation.InstallDebug(); - using var client = _clientFactory.CreateClient(game); + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)); + gameInstallation.InstallDebug(); + using var client = _clientFactory.CreateClient(gameInstallation.Game); Assert.True(client.IsDebugAvailable()); } [Fact] public void PlayDebug_NullArgs_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var client = _clientFactory.CreateClient(game); Assert.Throws(() => client.Play((IPhysicalMod)null!)); @@ -116,9 +118,10 @@ public void Play_CancelGameStart_Throws(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; if (gameIdentity.Platform == GamePlatform.SteamGold) - GameInstallation.InstallDebug(); + gameInstallation.InstallDebug(); var mod = game.InstallMod("MyMod", false, ServiceProvider); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -150,9 +153,10 @@ public void PlayDebug_ProcessLauncherThrows(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; if (gameIdentity.Platform == GamePlatform.SteamGold) - GameInstallation.InstallDebug(); + gameInstallation.InstallDebug(); var mod = game.InstallMod("MyMod", false, ServiceProvider); var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -177,7 +181,7 @@ public void Play(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay(game, expectedProcessInfo, client => client.Play()); @@ -190,7 +194,7 @@ public void Play_Args(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var arg = new WindowedArgument(); @@ -205,7 +209,7 @@ public void Play_Mod(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var mod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var expectedArguments = new ArgumentCollection([new ModArgumentList([ @@ -220,8 +224,9 @@ public void Play_Mod(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void Debug_DebugIsAvailable(GameType gameType) { - var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); - GameInstallation.InstallDebug(); + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)); + gameInstallation.InstallDebug(); + var game = gameInstallation.Game; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Debug, ArgumentCollection.Empty); TestPlay( @@ -237,7 +242,7 @@ public void Debug_FallbackToRelease(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay( @@ -253,7 +258,7 @@ public void Debug_DoNotFallbackToRelease_Throws(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); TestPlay( @@ -270,7 +275,7 @@ public void PlayDebug_GameExecutablesNotAvailable_Throws(GameIdentity gameIdenti if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -296,7 +301,7 @@ public void PlayDebug_Derived_OnGameStarting_ThrowsCustom(GameIdentity gameIdent if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var derivedClient = new MyTestClient((_, type) => { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs index 6639cfff..dd251ec4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Utilities/GameExecutableFileUtilitiesTest.cs @@ -40,7 +40,7 @@ public static IEnumerable GetGameExeNamesTestData() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetExecutableForGame_NullGame_ThrowsArgumentNullException(GameIdentity gameIdentity) { - GetOrÍnstallGame(gameIdentity); + GetOrCreateGameInstallation(gameIdentity); var buildTypes = new List { GameBuildType.Release, GameBuildType.Debug }; foreach (var buildType in buildTypes) Assert.Throws(() => GameExecutableFileUtilities.GetExecutableForGame(null!, buildType)); @@ -70,11 +70,11 @@ public void GetExecutableForGame_GameExeFilesNotInstalled_ReturnsNull(GameIdenti [MemberData(nameof(GetGameExeNamesTestData))] public void GetExecutableForGame_ReturnsFileHandle(GameIdentity gameIdentity, GameBuildType buildType, string expectedName) { - var game = GetOrÍnstallGame(gameIdentity); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); if (buildType == GameBuildType.Debug) - GameInstallation.InstallDebug(); + gameInstallation.InstallDebug(); - var exeFile = GameExecutableFileUtilities.GetExecutableForGame(game, buildType); + var exeFile = GameExecutableFileUtilities.GetExecutableForGame(gameInstallation.Game, buildType); Assert.NotNull(exeFile); Assert.Equal(expectedName, exeFile.Name); } @@ -84,7 +84,7 @@ public void GetExecutableForGame_ReturnsFileHandle(GameIdentity gameIdentity, Ga [InlineData(GameType.Foc)] public void GetExecutableForGame_SteamHasReleaseButNotDebugFiles(GameType gameType) { - var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)).Game; var releaseExe = GameExecutableFileUtilities.GetExecutableForGame(game, GameBuildType.Release); Assert.NotNull(releaseExe); @@ -100,7 +100,7 @@ public void GetExecutableForGame_DebugFilesForOtherThanSteam_ShouldReturnNull(Ga if (identity.Platform == GamePlatform.SteamGold) return; - var game = GetOrÍnstallGame(identity); + var game = GetOrCreateGameInstallation(identity).Game; using var _ = FileSystem.File.Create(FileSystem.Path.Combine(game.Directory.FullName, "StarWarsG.exe")); Assert.Null(GameExecutableFileUtilities.GetExecutableForGame(game, GameBuildType.Debug)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs index 25f21d29..940121c4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/CustomGameDetectorTest.cs @@ -14,7 +14,7 @@ public class CustomGameDetectorTest : GameInfrastructureTestBase public void Detect_TryDetect_FindGameLocationThrowsException(GameIdentity identity) { var expected = GameDetectionResult.NotInstalled(identity.Type); - var game = GetOrÍnstallGame(identity); + var game = GetOrCreateGameInstallation(identity); Assert.NotNull(game); var detector = new CallbackGameDetectorBase(FindGameThrowsException, ServiceProvider, false); @@ -44,7 +44,7 @@ public void Detect_TryDetect_FindGameLocationReturnsGameWhenItDoesNotExistsOnDis [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_InitializationRequestedIsNotTriggeredWhenSupported_DoNotHandle(GameIdentity identity) { - var game = GetOrÍnstallGame(identity); + var game = GetOrCreateGameInstallation(identity).Game; Assert.NotNull(game); Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_DoNotHandle(game, false); Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_DoNotHandle(game, true); @@ -84,7 +84,7 @@ private void Detect_TryDetect_InitializationRequestedIsTriggeredWhenSupported_Do [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void Detect_TryDetect_InitializationRequestedIsTriggeredAndHandled(GameIdentity identity) { - var game = GetOrÍnstallGame(identity); + var game = GetOrCreateGameInstallation(identity).Game; Assert.NotNull(game); var installed = GameDetectionResult.FromInstalled(identity, game.Directory); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs index 12d4b409..77366fc8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs @@ -23,7 +23,7 @@ protected override IGameDetector CreateDetector(GameDetectorTestInfo gam protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; return new(gameIdentity.Type, game.Directory, null); } @@ -71,7 +71,7 @@ public void Detect_TryDetect_GamesInstalled_WrongPathGiven(GameIdentity identity { TestNotInstalledWithCustomSetup(identity, i => { - if (i != null) GetOrÍnstallGame(i); + if (i != null) GetOrCreateGameInstallation(i); return FileSystem.DirectoryInfo.New("other"); }); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs index 5ddf84d5..e76f09ab 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs @@ -33,7 +33,7 @@ public void NullArgs_ThrowsArgumentNullException() public void GetGamePlatform_WrongGameInstalledReturnsUndefined(GameIdentity identity) { var oppositeGameType = identity.Type == GameType.Foc ? GameType.Eaw : GameType.Foc; - var game = GetOrÍnstallGame(new GameIdentity(oppositeGameType, identity.Platform)); + var game = GetOrCreateGameInstallation(new GameIdentity(oppositeGameType, identity.Platform)).Game; var gameLocation = game.Directory; var actual = _platformIdentifier.GetGamePlatform(identity.Type, ref gameLocation); @@ -57,9 +57,9 @@ public void GetGamePlatform_NoGameInstalledReturnsUndefined(GameType queryGameTy [Fact] public void GetGamePlatform_FocOriginWithSanitization() { - GetOrÍnstallGame(new GameIdentity(GameType.Foc, GamePlatform.Origin)); + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(GameType.Foc, GamePlatform.Origin)); - var locRef = GameInstallation.GetWrongOriginFocRegistryLocation(); + var locRef = gameInstallation.GetWrongOriginFocRegistryLocation(); var locStore = locRef; var actual = _platformIdentifier.GetGamePlatform(GameType.Foc, ref locRef); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs index 5a62cec7..4859a36e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs @@ -44,14 +44,14 @@ protected override IGameDetector CreateDetector(GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var registryContainer = SetupRegistry(game.Type, TestGameRegistrySetupData.Installed(game.Type, game.Directory)); return new GameDetectorTestInfo(game.Type, game.Directory, registryContainer); } protected override GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var registryContainer = SetupRegistry(game.Type, TestGameRegistrySetupData.Uninitialized(gameIdentity.Type)); return new GameDetectorTestInfo(game.Type, game.Directory, registryContainer); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index ab15bdd9..087fd837 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -148,7 +148,7 @@ public void CreateGame_WrongGameIdentityInstalled_WrongPlatform_Throws(GamePlatf var actualGameType = Random.Enum(); // Use Disk so that we can check against more specific platforms - var installedGame = GetOrÍnstallGame(new GameIdentity(actualGameType, GamePlatform.Disk)); + var installedGame = GetOrCreateGameInstallation(new GameIdentity(actualGameType, GamePlatform.Disk)).Game; var createIdentity = new GameIdentity(actualGameType, platform); @@ -171,7 +171,7 @@ public void CreateGame_WrongGameIdentityInstalled_WrongType_Throws(GamePlatform var actualGameType = Random.Enum(); // Use Disk so that we can check against more specific platforms - var installedGame = GetOrÍnstallGame(new GameIdentity(actualGameType, platform)); + var installedGame = GetOrCreateGameInstallation(new GameIdentity(actualGameType, platform)).Game; var createGameType = actualGameType == GameType.Eaw ? GameType.Foc : GameType.Eaw; var createIdentity = new GameIdentity(createGameType, platform); @@ -182,7 +182,7 @@ public void CreateGame_WrongGameIdentityInstalled_WrongType_Throws(GamePlatform [Fact] public void CreateGame_UnidentifiedPlatform_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; Assert.Throws(() => _factory.CreateGame( new GameIdentity(Random.Enum(), GamePlatform.Undefined), game.Directory, @@ -239,7 +239,7 @@ private void AssertGame(IGame game, IGameIdentity expectedIdentity, string expec [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateGame_FromIdentity_GameCreated(GameIdentity gameIdentity) { - var installedGame = GetOrÍnstallGame(gameIdentity); + var installedGame = GetOrCreateGameInstallation(gameIdentity).Game; var expectedName = _nameResolver.ResolveName(gameIdentity, CultureInfo.CurrentCulture); @@ -257,7 +257,7 @@ public void CreateGame_FromIdentity_GameCreated(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateGame_FromDetectionResult_GameCreated(GameIdentity gameIdentity) { - var installedGame = GetOrÍnstallGame(gameIdentity); + var installedGame = GetOrCreateGameInstallation(gameIdentity).Game; var detector = new DirectoryGameDetector(installedGame.Directory, ServiceProvider); var detectionResult = detector.Detect(gameIdentity.Type, gameIdentity.Platform); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs index af6d20d7..f139ec15 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs @@ -27,7 +27,7 @@ public void GetWorkshopsLocation_NullArgs_Throws() [Fact] public void GetWorkshopsLocation_Success() { - var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; var wsDir = _steamGameHelpers.GetWorkshopsLocation(game); @@ -58,7 +58,7 @@ public void GetWorkshopsLocation_CannotFindWorkshopPath() [InlineData(GamePlatform.Origin)] public void GetWorkshopsLocation_FailNoSteam(GamePlatform platform) { - var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), platform)); + var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), platform)).Game; Assert.Throws(() => _steamGameHelpers.GetWorkshopsLocation(game)); Assert.False(_steamGameHelpers.TryGetWorkshopsLocation(game, out _)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index b33babcf..7830c8ce 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -22,7 +22,7 @@ public abstract class ModBaseTest : PlayableModContainerTest protected ModBaseTest() { - Game = GetOrÍnstallGame(); + Game = GetOrCreateGameInstallation().Game; } protected abstract ModBase CreateMod( @@ -105,9 +105,8 @@ public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectl [Fact] public void ResolveDependencies_DepOfWrongGame_Throws() { - var otherGameInstallRef = GameInfrastructureTesting.Game(ServiceProvider); - var otherGame = otherGameInstallRef.Install(Game); - var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod", GITestUtilities.GetRandomWorkshopFlag(otherGame)); + var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); + var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod", GITestUtilities.GetRandomWorkshopFlag(otherGameInstallRef.Game)); var mod = CreateMod("Mod", Random.Enum(), wrongGameDep.Mod); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index e555c6e2..e05ea65e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -3,7 +3,6 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; @@ -110,12 +109,12 @@ public void Equals_GameAware(bool gameAware) { var modA = CreateAndAddMod("A"); - var otherGameInstallRef = GameInfrastructureTesting.Game(ServiceProvider); - otherGameInstallRef.Install(Game); + var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); - var diffGame = GameInfrastructureTesting.Game(ServiceProvider) - .Install(new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform)); + var diffGame = GameInfrastructureTesting + .Game(new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform), ServiceProvider) + .Game; var diffGameMod = diffGame.InstallMod("A", modA.Type == ModType.Workshops, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index e9cadca1..e0317a90 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -47,7 +47,7 @@ protected override void SetupServices(IServiceCollection serviceCollection) [Fact] public void CreatePhysicalMod_NullArgs_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var modData = CreateDetectedModReference(game, "path", null, null); Assert.Throws(() => _factory.CreatePhysicalMod(null!, modData, CultureInfo.CurrentCulture)); @@ -58,7 +58,7 @@ public void CreatePhysicalMod_NullArgs_Throws() [Fact] public void CreatePhysicalMod_VirtualMod_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var modDir = FileSystem.DirectoryInfo.New("path"); modDir.Create(); var modData = new DetectedModReference(new ModReference("SOME_ID", ModType.Virtual), modDir, null); @@ -68,7 +68,7 @@ public void CreatePhysicalMod_VirtualMod_Throws() [Fact] public void CreatePhysicalMod_ModDirectoryNotFound_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var modData = CreateDetectedModReference(game, "path", null, null); modData.Directory.Delete(true); Assert.Throws(() => _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture)); @@ -78,7 +78,7 @@ public void CreatePhysicalMod_ModDirectoryNotFound_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var modDir = game.GetModDirectory("Mod_Name", false, ServiceProvider); var modData = CreateDetectedModReference(game, modDir, false, null); @@ -94,7 +94,7 @@ public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var modDir = game.GetModDirectory("Mod_Name", false, ServiceProvider); var modinfo = new ModinfoData("MyMod"); @@ -113,7 +113,7 @@ public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void CreatePhysicalMod_Steam_WithoutModinfo(GameType gameType) { - var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)).Game; var modDir = game.GetModDirectory("Mod_Name", true, ServiceProvider); var modinfo = new ModinfoData("MyMod"); @@ -132,7 +132,7 @@ public void CreatePhysicalMod_Steam_WithoutModinfo(GameType gameType) [InlineData(GameType.Foc)] public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) { - var game = GetOrÍnstallGame(new GameIdentity(gameType, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)).Game; var modDir = game.GetModDirectory("Mod_Name", true, ServiceProvider); var modRef = CreateDetectedModReference(game, modDir, true, null); @@ -148,7 +148,7 @@ public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var ws = GITestUtilities.GetRandomWorkshopFlag(game); var modDir = game.GetModDirectory("Mod_Name", ws, ServiceProvider); @@ -163,7 +163,7 @@ public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var ws = GITestUtilities.GetRandomWorkshopFlag(game); var modDir = game.GetModDirectory("Mod_Name", ws, ServiceProvider); @@ -177,11 +177,11 @@ public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var oppositeGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; - var otherGame = GameInfrastructureTesting.Game(ServiceProvider) - .Install(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms))); + var otherGame = GameInfrastructureTesting + .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider).Game; var modDir = otherGame.GetModDirectory("Mod_Name", false, ServiceProvider); var modData = CreateDetectedModReference(otherGame, modDir, false, null); @@ -196,7 +196,7 @@ public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) [Fact] public void CreateVirtualMod_NullArgs_Throws() { - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var dep = game.InstallMod("dep", false, ServiceProvider); Assert.Throws(() => _factory.CreateVirtualMod(null!, new ModinfoData("Name") @@ -210,7 +210,7 @@ public void CreateVirtualMod_NullArgs_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var dep = game.InstallMod("dep", false, ServiceProvider); var invalidModinfo = new CustomModInfo(string.Empty) @@ -225,7 +225,7 @@ public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var invalidModinfo = new CustomModInfo("MyVirtualMod") { @@ -239,7 +239,7 @@ public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity game [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var dep = game.InstallMod("dep", false, ServiceProvider); var modinfo = new CustomModInfo("VirtualModName") diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 875d9b81..d2c2eaad 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -38,15 +38,14 @@ public void FindMods_NullArg_Throws() { Assert.Throws(() => _modFinder.FindMods(null!)); Assert.Throws(() => _modFinder.FindMods(null!, FileSystem.Directory.CreateDirectory("path"))); - var game = GetOrÍnstallGame(); - Assert.Throws(() => _modFinder.FindMods(game, null!)); + Assert.Throws(() => _modFinder.FindMods(GetOrCreateGameInstallation().Game, null!)); } [Theory] [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_GameNotExists_Throws(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; game.Directory.Delete(true); Assert.Throws(() => _modFinder.FindMods(game)); Assert.Throws(() => _modFinder.FindMods(game, FileSystem.DirectoryInfo.New("path"))); @@ -56,7 +55,7 @@ public void FindMods_GameNotExists_Throws(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_NoModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; game.ModsLocation.Delete(true); if (game.Platform is GamePlatform.SteamGold) @@ -76,7 +75,7 @@ public void FindMods_NoModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; game.ModsLocation.Create(); if (game.Platform is GamePlatform.SteamGold) @@ -93,7 +92,7 @@ public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdent [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var installedMods = _modFinder.FindMods(game); @@ -107,7 +106,7 @@ public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); expectedMod.InstallInvalidModinfoFile(); @@ -123,7 +122,7 @@ public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var expectedModinfo = new ModinfoData("Variant1"); @@ -142,7 +141,7 @@ public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var modinfoData = new ModinfoData("MyMod"); var expectedMod = game.InstallMod(GITestUtilities.GetRandomWorkshopFlag(game), modinfoData, ServiceProvider); @@ -159,7 +158,7 @@ public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); @@ -192,7 +191,7 @@ public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var main = new ModinfoData("Main"); var info1 = new ModinfoData("MyName1"); @@ -225,7 +224,7 @@ public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var mod1 = game.InstallMod("Mod1", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); var mod2 = game.InstallMod("Mod2", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -244,7 +243,7 @@ public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) { - var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; var steamMod = game.InstallMod("SteamMod", true, ServiceProvider); @@ -272,7 +271,7 @@ public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) [InlineData(GameType.Foc)] public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) { - var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; @@ -299,7 +298,7 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var modPath = FileSystem.DirectoryInfo.New("external/myMod"); modPath.Create(); @@ -313,7 +312,7 @@ public void FindMods_FromExternal(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var modPath = FileSystem.DirectoryInfo.New("external/myMod"); modPath.Create(); @@ -328,7 +327,7 @@ public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameI [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var modPath = FileSystem.DirectoryInfo.New("external/123456"); // Use a number so it may look like a Steam WS ID modPath.Create(); @@ -353,7 +352,7 @@ public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIden [InlineData(GameType.Foc)] public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) { - var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Create(); @@ -373,7 +372,7 @@ public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) [InlineData(GameType.Foc)] public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType type) { - var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Create(); @@ -393,10 +392,10 @@ public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType t public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameType type) { var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; - var game = GetOrÍnstallGame(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms))); + var game = GetOrCreateGameInstallation(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms))).Game; // Other, random platform to shuffle a bit more. - var otherTypeGame = GameInfrastructureTesting.Game(ServiceProvider) - .Install(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms))); + var otherTypeGame = GameInfrastructureTesting + .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider).Game; var wrongMod = otherTypeGame.InstallMod("MyMod", false, ServiceProvider); @@ -409,7 +408,7 @@ public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameTyp [InlineData(GameType.Foc)] public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameType type) { - var game = GetOrÍnstallGame(new GameIdentity(type, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Delete(true); @@ -427,7 +426,7 @@ public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameTyp [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_InvalidModinfoContentIsSkippedButModIsFound(GameIdentity gameIdentity) { - var game = GetOrÍnstallGame(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); expectedMod.InstallModinfoFile(new CustomModinfo(string.Empty)); // string.Empty is not valid diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 475582d5..f9b715c7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -124,7 +124,7 @@ public void Directory_WithModinfo_ModinfoIsAlwaysSuperiorForSteamTypes() }; // Installing FOC, while tags has EAW. So technically, EAW does not even exist. - var game = GetOrÍnstallGame(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)).Game; var steamHelpers = ServiceProvider.GetRequiredService(); // Using a known MODID (RaW), which is FOC, to implicitly assert cache is not used. var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("1129810972"); @@ -146,7 +146,7 @@ public void Directory_SteamWithoutModinfoCannotDecide() // No SteamData here var modinfo = new ModinfoData("Name"); - var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; var steamHelpers = ServiceProvider.GetRequiredService(); @@ -179,7 +179,7 @@ public void Directory_SteamWithInvalidDirName() SteamData = steamData }; - var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; var steamHelpers = ServiceProvider.GetRequiredService(); var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("notASteamId"); @@ -217,7 +217,7 @@ public void Directory_SteamWithoutModinfoButKnownModID(string knownId, ICollecti // No SteamData here var modinfo = new ModinfoData("Name"); - var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; var steamHelpers = ServiceProvider.GetRequiredService(); @@ -248,7 +248,7 @@ public void VirtualMods_VirtualModsAreAlwaysUndecidable() SteamData = steamData }; - var game = GetOrÍnstallGame(); + var game = GetOrCreateGameInstallation().Game; var mod = game.InstallMod("Name", false, ServiceProvider); var info = CreateDetectedModReference(mod.Directory, ModType.Virtual, modinfo); @@ -303,7 +303,7 @@ public void ModsInModsDirUseGameType(GameType gameType) SteamData = steamData }; - var game = GetOrÍnstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))); + var game = GetOrCreateGameInstallation(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))).Game; var mod = game.InstallMod("Name", false, ServiceProvider); var info = CreateDetectedModReference(mod.Directory, ModType.Default, modinfo); @@ -333,7 +333,7 @@ public void ModsNotInModsDirButSomeOtherGameBasesDir_NotDecidable(GameType gameT SteamData = steamData }; - var game = GetOrÍnstallGame(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))); + var game = GetOrCreateGameInstallation(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))).Game; var modDir = game.Directory.CreateSubdirectory("ModsOther").CreateSubdirectory("MyMod"); var mod = game.InstallMod(modDir, false, modinfo, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs index aaa8441c..578f2093 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Threading; using AET.Modinfo.Spec; using AET.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; @@ -28,7 +27,7 @@ public static IEnumerable GetOnlineModsData() [MemberData(nameof(GetOnlineModsData))] public void Online_GetTagsFromSteamOnline(string knownId, ICollection expectedTypes, GameType? incompatibleWith) { - var game = GetOrÍnstallGame(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); + var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; var steamHelpers = ServiceProvider.GetRequiredService(); var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory(knownId); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index d1e0f510..044277d5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -43,8 +43,8 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga { // Init Mods uninitialized - var eaw = GameInfrastructureTesting.Game(ServiceProvider).Install(new GameIdentity(GameType.Eaw, platform)); - var foc = GameInfrastructureTesting.Game(ServiceProvider).Install(new GameIdentity(GameType.Foc, platform)); + var eaw = GameInfrastructureTesting.Game(new GameIdentity(GameType.Eaw, platform), ServiceProvider).Game; + var foc = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, platform), ServiceProvider).Game; GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(GameType.Eaw)); GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(GameType.Foc)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index c0ee0843..3557fe96 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -14,7 +14,7 @@ public class PetroglyphStarWarsGameTest : PlayableModContainerTest private PetroglyphStarWarsGame CreateGame(string? iconPath = null, ICollection? languages = null) { var gameId = new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); - var game = GetOrÍnstallGame(gameId); + var game = GetOrCreateGameInstallation(gameId).Game; if (languages is not null) { foreach (var languageInfo in languages) @@ -63,9 +63,9 @@ public void Equals_GetHashCode() var focSteamId = new GameIdentity(GameType.Foc, GamePlatform.SteamGold); var eawDiskId = new GameIdentity(GameType.Eaw, GamePlatform.Disk); - var eawSteam = GameInfrastructureTesting.Game(ServiceProvider).Install(eawSteamId); - var focSteam = GameInfrastructureTesting.Game(ServiceProvider).Install(focSteamId); - var eawDisc = GameInfrastructureTesting.Game(ServiceProvider).Install(eawDiskId); + var eawSteam = GameInfrastructureTesting.Game(eawSteamId, ServiceProvider).Game; + var focSteam = GameInfrastructureTesting.Game(focSteamId, ServiceProvider).Game; + var eawDisc = GameInfrastructureTesting.Game(eawDiskId, ServiceProvider).Game; Assert.False(eawSteam.Equals(null)); Assert.False(eawSteam.Equals((object)null!)); @@ -100,7 +100,7 @@ public void Equals_GetHashCode() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetModDirTest(GameIdentity gameIdentity) { - var game = GameInstallation.Install(gameIdentity); + var game = GetOrCreateGameInstallation(gameIdentity).Game; var dataLocation = game.ModsLocation; Assert.Equal(FileSystem.Path.GetFullPath(FileSystem.Path.Combine(game.Directory.FullName, "Mods")), dataLocation.FullName); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 8c8fe3ee..e82b14d6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -71,7 +71,7 @@ public void FindLanguages_Mod_WithNoLanguages_UsesGame() [Fact] public void FindLanguages_Mod_WithLanguages_En_De_Steam() { - var game = GameInfrastructureTesting.Game(ServiceProvider).Install(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); + var game = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider).Game; var mod = game.InstallMod("myMod", true, ServiceProvider); InstallModLanguage(mod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(mod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs index 83a8adb9..9c892917 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs @@ -1,4 +1,5 @@ using System; +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; @@ -6,9 +7,9 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game; public static class GameInfrastructureTesting { - public static ITestingGameInstallation Game(IServiceProvider serviceProvider) + public static ITestingGameInstallation Game(IGameIdentity gameIdentity, IServiceProvider serviceProvider) { - return new TestingGameImpl(serviceProvider); + return new TestingGameImpl(gameIdentity, serviceProvider); } public static ITestingGameRegistry Registry(IServiceProvider serviceProvider) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs index 0c7ac4f0..b65a9eb9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs @@ -1,5 +1,4 @@ using PG.StarWarsGame.Infrastructure.Games; -using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Testing.Mods; @@ -7,14 +6,8 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; public interface ITestingGameInstallation { - IGame? Game { get; } - - [MemberNotNull(nameof(Game))] - IGame Install(IGameIdentity gameIdentity); - - [MemberNotNull(nameof(Game))] - IGame InstallRandom(); - + IGame Game { get; } + void InstallDebug(); IDirectoryInfo GetWrongOriginFocRegistryLocation(); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs index ce821cbc..aca991f6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; @@ -8,35 +7,22 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -internal class TestingGameImpl(IServiceProvider serviceProvider) : ITestingGameInstallation +internal class TestingGameImpl : ITestingGameInstallation { - private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); + private readonly IFileSystem _fileSystem; + private readonly IServiceProvider _serviceProvider; - public IGame? Game { get; private set; } + public IGame Game { get; } - [MemberNotNull(nameof(Game))] - public IGame Install(IGameIdentity gameIdentity) + public TestingGameImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) { - ThrowIfInstalled(); - var gameDir = gameIdentity.Type == GameType.Foc - ? GameInstallation.InstallFoc(_fileSystem, gameIdentity.Platform) - : GameInstallation.InstallEaw(_fileSystem, gameIdentity.Platform); - - _fileSystem.InstallModsLocations(gameDir); - - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), serviceProvider); - Assert.True(game.Exists()); - return Game = game; - } - - public IGame InstallRandom() - { - return Install(GITestUtilities.GetRandomGameIdentity(realOnly: true)); + _serviceProvider = serviceProvider; + _fileSystem = serviceProvider.GetRequiredService(); + Game = Install(gameIdentity); } public void InstallDebug() { - ThrowIfNotInstalled(); if (Game.Platform is not GamePlatform.SteamGold) Assert.Fail($"Cannot install Debug files for non-Steam game '{Game}'"); GameInstallation.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); @@ -49,24 +35,22 @@ public IDirectoryInfo GetWrongOriginFocRegistryLocation() public ITestingModInstallation InstallAndAddMod(string name, bool workshop) { - ThrowIfNotInstalled(); - var mod = Game.InstallMod(name, workshop, serviceProvider); + var mod = Game.InstallMod(name, workshop, _serviceProvider); Game.AddMod(mod); - return new TestingModImpl(this, mod, serviceProvider); + return new TestingModImpl(this, mod, _serviceProvider); } - - [MemberNotNull(nameof(Game))] - private void ThrowIfNotInstalled() + private IGame Install(IGameIdentity gameIdentity) { - if (Game is null) - throw new InvalidOperationException("Game not installed"); - } + var gameDir = gameIdentity.Type == GameType.Foc + ? GameInstallation.InstallFoc(_fileSystem, gameIdentity.Platform) + : GameInstallation.InstallEaw(_fileSystem, gameIdentity.Platform); - private void ThrowIfInstalled() - { - if (Game is not null) - throw new InvalidOperationException("Game already installed for this testing instance. Create a new one."); + _fileSystem.InstallModsLocations(gameDir); + + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), _serviceProvider); + Assert.True(game.Exists()); + return game; } } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 4f40e56c..d2f9f9bc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -17,12 +17,8 @@ public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); - protected ITestingGameInstallation GameInstallation { get; } + private ITestingGameInstallation? _gameInstallation; - protected GameInfrastructureTestBase() - { - GameInstallation = GameInfrastructureTesting.Game(ServiceProvider); - } protected virtual IFileSystem CreateFileSystem() { @@ -36,11 +32,12 @@ protected override void SetupServices(IServiceCollection serviceCollection) PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } - protected virtual IGame GetOrÍnstallGame(IGameIdentity? identity = null) - { - if (GameInstallation.Game is not null) - return GameInstallation.Game; - return identity is not null ? GameInstallation.Install(identity) : GameInstallation.InstallRandom(); + protected virtual ITestingGameInstallation GetOrCreateGameInstallation(IGameIdentity? identity = null) + { + if (_gameInstallation is not null) + return _gameInstallation; + identity ??= GITestUtilities.GetRandomGameIdentity(realOnly: true); + return _gameInstallation = GameInfrastructureTesting.Game(identity, ServiceProvider); } @@ -48,7 +45,7 @@ protected virtual IGame GetOrÍnstallGame(IGameIdentity? identity = null) protected IMod CreateAndAddMod(bool isWorkshop, string name, IModDependencyList dependencies) { if (dependencies.Count == 0) - return GameInstallation.Game.InstallAndAddMod(name, isWorkshop, ServiceProvider); + return GetOrCreateGameInstallation().Game.InstallAndAddMod(name, isWorkshop, ServiceProvider); var modinfo = new ModinfoData(name) { @@ -59,6 +56,6 @@ protected IMod CreateAndAddMod(bool isWorkshop, string name, IModDependencyList protected IMod CreateAndAddMod(bool isWorkshop, IModinfo modinfo) { - return GameInstallation.Game.InstallAndAddMod(isWorkshop, modinfo, ServiceProvider); + return GetOrCreateGameInstallation().Game.InstallAndAddMod(isWorkshop, modinfo, ServiceProvider); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 8433b95b..af513ce5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -8,7 +8,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastructureTestBase { - protected IGame Game => GetOrÍnstallGame(identity: null); + protected IGame Game => GetOrCreateGameInstallation(identity: null).Game; protected IMod CreateAndAddMod( string name, From 8e0f57f641325365ef22cd1aac2f3cd52c07123d Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 13:02:04 +0100 Subject: [PATCH 26/71] mod testing wrappers --- .../ModBaseTest.cs | 142 +++++++++--------- .../ModEqualityComparerTest.cs | 6 +- .../ModDependencyGraphBuilderTest.cs | 94 ++++++------ .../Dependencies/ModDependencyResolverTest.cs | 2 +- .../ModDependencyTraverserTest.cs | 31 ++-- .../ModTest.cs | 58 +++---- .../PetroglyphStarWarsGameTest.cs | 25 +-- .../PlayableModContainerTest.cs | 36 ++--- .../PlayableObjectTest.cs | 18 ++- .../VirtualModTest.cs | 18 +-- ...n.Eaw.cs => GameInstallationHelper.Eaw.cs} | 2 +- ...n.Foc.cs => GameInstallationHelper.Foc.cs} | 2 +- ...tallation.cs => GameInstallationHelper.cs} | 2 +- .../Installation/ITestingGameInstallation.cs | 12 +- .../Game/Installation/TestingGameImpl.cs | 46 +++++- .../Mods/ITestingModContainerInstallation.cs | 6 + .../Mods/ITestingModInstallation.cs | 11 ++ .../Mods/ITestingPhysicalModInstallation.cs | 8 + .../ITestingPlayableObjectInstallation.cs | 10 ++ .../Mods/ITestingVirtualModInstallation.cs | 8 + .../Mods/ModInstallations.cs | 16 -- .../Mods/TestingModImpl.cs | 16 ++ .../Mods/TestingPhysicalModImpl.cs | 13 ++ .../Mods/TestingVirtualModImpl.cs | 13 ++ .../TestBases/GameInfrastructureTestBase.cs | 11 +- ...ameInfrastructureTestBaseWithRandomGame.cs | 15 +- 26 files changed, 370 insertions(+), 251 deletions(-) rename test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/{GameInstallation.Eaw.cs => GameInstallationHelper.Eaw.cs} (98%) rename test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/{GameInstallation.Foc.cs => GameInstallationHelper.Foc.cs} (98%) rename test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/{GameInstallation.cs => GameInstallationHelper.cs} (97%) create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 7830c8ce..12fe6f47 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing.Extensions; @@ -25,60 +24,60 @@ protected ModBaseTest() Game = GetOrCreateGameInstallation().Game; } - protected abstract ModBase CreateMod( + protected abstract ITestingModInstallation CreateModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps); - protected IMod CreateOtherMod( + protected ITestingModInstallation CreateOtherModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreateOtherMod(name, GITestUtilities.GetRandomWorkshopFlag(Game), layout, deps); - } - - - protected IMod CreateOtherMod( + return CreateOtherModInstallation(name, GITestUtilities.GetRandomWorkshopFlag(Game), layout, deps); + } + + protected ITestingModInstallation CreateOtherModInstallation( string name, bool isWorkshop, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreateAndAddMod(isWorkshop, name, new DependencyList(deps, layout)); + return CreateAndAddModInstallation(isWorkshop, name, new DependencyList(deps, layout)); } [Fact] public void VersionRange_IsNull() { - var mod = CreateMod("Mod"); + var mod = CreateModInstallation("Mod").Mod; Assert.Null(mod.VersionRange); } - [Theory] - [MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] - public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario testScenario) - { - var mod = ModTestScenarios.CreateTestScenario( - testScenario, - CreateMod, - CreateOtherMod) - .Mod; + // TODO: Re-enable once events are supported again + //[Theory] + //[MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] + //public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario testScenario) + //{ + // var mod = ModTestScenarios.CreateTestScenario( + // testScenario, + // CreateModInstallation, + // CreateOtherModInstallation) + // .Mod; - var expectedDirectDeps = mod.ModInfo!.Dependencies.Select(d => - { - var dep = Game.FindMod(d); - Assert.NotNull(dep); - return dep; - }); + // var expectedDirectDeps = mod.ModInfo!.Dependencies.Select(d => + // { + // var dep = Game.FindMod(d); + // Assert.NotNull(dep); + // return dep; + // }); - mod.ResolveDependencies(); + // mod.ResolveDependencies(); - Assert.Equal(expectedDirectDeps, mod.Dependencies); - Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); + // Assert.Equal(expectedDirectDeps, mod.Dependencies); + // Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); - AssertDependenciesResolved(mod); - } + // AssertDependenciesResolved(mod); + //} [Fact] public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectly() @@ -86,7 +85,7 @@ public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectl // Do not add mod to game var notAddedDep = Game.InstallMod("NotAddedMod", false, ServiceProvider); - var mod = CreateMod("Mod", Random.Enum(), notAddedDep); + var mod = CreateModInstallation("Mod", Random.Enum(), notAddedDep).Mod; Game.AddMod(mod); var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); @@ -108,7 +107,7 @@ public void ResolveDependencies_DepOfWrongGame_Throws() var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod", GITestUtilities.GetRandomWorkshopFlag(otherGameInstallRef.Game)); - var mod = CreateMod("Mod", Random.Enum(), wrongGameDep.Mod); + var mod = CreateModInstallation("Mod", Random.Enum(), wrongGameDep.Mod).Mod; var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); @@ -124,7 +123,7 @@ public void ResolveDependencies_VersionMismatch_Throws() var dep = Game.InstallMod(depLoc, ws, new ModinfoData("B") { Version = new SemVersion(1) }, ServiceProvider); Game.AddMod(dep); - var mod = CreateMod("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))); + var mod = CreateModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; var e = Assert.Throws(mod.ResolveDependencies); Assert.Equal(new ModReference(dep), e.Mod); @@ -143,52 +142,53 @@ public void ResolveDependencies_VersionMatch_Throws() Game.AddMod(b); Game.AddMod(c); - var mod = CreateMod("Mod", deps: + var mod = CreateModInstallation("Mod", deps: [ new ModReference(b.Identifier, b.Type, SemVersionRange.AtLeast(new SemVersion(2))), new ModReference(c.Identifier, c.Type, SemVersionRange.AtLeast(new SemVersion(2))) ] - ); + ).Mod; mod.ResolveDependencies(); Assert.Equal([b, c], mod.Dependencies); Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); } - [Fact] - public void ResolveDependencies_RaiseEvent() - { - var scenario = ModTestScenarios.CreateTestScenario( - ModTestScenarios.TestScenario.SingleDepAndTransitive, - CreateMod, - CreateOtherMod); - - var mod = scenario.Mod; - var b = Game.FindMod(scenario.ExpectedTraversedList![1])!; - - var bRaised = false; - var modRaised = false; - b.DependenciesResolved += (sender, _) => - { - Assert.Equal(b, sender); - bRaised = true; - }; - mod.DependenciesResolved += (sender, _) => - { - Assert.Equal(mod, sender); - modRaised = true; - }; - - mod.ResolveDependencies(); - - Assert.True(bRaised); - Assert.True(modRaised); - } + // TODO: Re-enable once events are supported again + //[Fact] + //public void ResolveDependencies_RaiseEvent() + //{ + // var scenario = ModTestScenarios.CreateTestScenario( + // ModTestScenarios.TestScenario.SingleDepAndTransitive, + // CreateModInstallation, + // CreateOtherModInstallation); + + // var mod = scenario.Mod; + // var b = Game.FindMod(scenario.ExpectedTraversedList![1])!; + + // var bRaised = false; + // var modRaised = false; + // b.DependenciesResolved += (sender, _) => + // { + // Assert.Equal(b, sender); + // bRaised = true; + // }; + // mod.DependenciesResolved += (sender, _) => + // { + // Assert.Equal(mod, sender); + // modRaised = true; + // }; + + // mod.ResolveDependencies(); + + // Assert.True(bRaised); + // Assert.True(modRaised); + //} [Fact] public void ResolveDependencies_AlreadyResolved_DoesNotRaiseEvent() { - var mod = CreateMod("A"); + var mod = CreateModInstallation("A").Mod; mod.ResolveDependencies(); Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); @@ -211,7 +211,7 @@ public void ResolveDependencies_Faulted_DoesNotRaiseEvent() var dep = Game.InstallMod(depLoc, ws, new ModinfoData("B") { Version = new SemVersion(1) }, ServiceProvider); Game.AddMod(dep); - var mod = CreateMod("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))); + var mod = CreateModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; var depsResolvedRaised = false; mod.DependenciesResolved += (_, _) => @@ -244,10 +244,10 @@ private static void AssertDependenciesResolved(IMod mod) [Fact] public void EqualsHashCode() { - var dep = CreateOtherMod("B"); - var mod = CreateMod("A"); - var samish = CreateMod("A"); - var otherA = CreateMod("A", deps: dep); + var dep = CreateOtherModInstallation("B").Mod; + var mod = CreateModInstallation("A").Mod; + var samish = CreateModInstallation("A").Mod; + var otherA = CreateModInstallation("A", deps: dep).Mod; ModBase custom = mod.ModInfo is not null ? new CustomMod(Game, mod.Identifier, mod.Type, mod.ModInfo, ServiceProvider) @@ -287,7 +287,7 @@ public class ModBaseAbstractTest : GameInfrastructureTestBaseWithRandomGame [Fact] public void ResolveDependencies_CalledTwice_Throws() { - var dep = CreateAndAddMod("Dep"); + var dep = CreateAndAddMod("Dep").Mod; var modinfo = new ModinfoData("CustomMod") { Dependencies = new DependencyList(new List { dep }, DependencyResolveLayout.FullResolved) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index e05ea65e..2d52472d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -70,7 +70,7 @@ public void Equals_ShouldAlwaysBeEquals(bool includeDeps, bool includeGame) public void Equals_DependencyAware(bool depAware) { var dep = new ModReference("B", ModType.Default); - var modA = (IPhysicalMod)CreateAndAddMod("A", deps: dep); + var modA = (IPhysicalMod)CreateAndAddMod("A", deps: dep).Mod; var sameishModindo = new ModinfoData("A") { @@ -107,7 +107,7 @@ public void Equals_DependencyAware(bool depAware) [InlineData(true)] public void Equals_GameAware(bool gameAware) { - var modA = CreateAndAddMod("A"); + var modA = CreateAndAddMod("A").Mod; var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); @@ -140,7 +140,7 @@ public void Equals_GameAware(bool gameAware) [Fact] public void ToJson() { - var mod = CreateAndAddMod("A"); + var mod = CreateAndAddMod("A").Mod; var expected = new ModReference(mod).ToJson(); Assert.Equal(expected, mod.ToJson()); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index c9993685..923392a9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -26,7 +26,7 @@ public void NullArgs_Throws() [Fact] public void Build_NoDependencies() { - var mod = CreateAndAddMod("A"); + var mod = CreateAndAddMod("A").Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -36,8 +36,8 @@ public void Build_NoDependencies() [Fact] public void Build_OneDependency() { - var b = CreateAndAddMod("B"); - var mod = CreateAndAddMod("A", Random.Enum(), b); + var b = CreateAndAddMod("B").Mod; + var mod = CreateAndAddMod("A", Random.Enum(), b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -60,8 +60,8 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() { // C is not added to game. Building a graph should not throw, because it's not used. var c = Game.InstallMod("C", false, ServiceProvider); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.FullResolved, b); + var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.FullResolved, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -82,9 +82,9 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() { - var c = CreateAndAddMod("C"); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b); + var c = CreateAndAddMod("C").Mod; + var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -107,10 +107,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant1() { - var d = CreateAndAddMod("D"); - var c = CreateAndAddMod("C"); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveLastItem, b, d); + var d = CreateAndAddMod("D").Mod; + var c = CreateAndAddMod("C").Mod; + var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -133,10 +133,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant2() { - var d = CreateAndAddMod("D"); - var c = CreateAndAddMod("C"); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveLastItem, d, b); + var d = CreateAndAddMod("D").Mod; + var c = CreateAndAddMod("C").Mod; + var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -162,10 +162,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() { - var d = CreateAndAddMod("D"); - var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d); - var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveRecursive, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b); + var d = CreateAndAddMod("D").Mod; + var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveRecursive, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -191,11 +191,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() { - var e = CreateAndAddMod("E"); - var d = CreateAndAddMod("D"); - var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d); - var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveLastItem, e, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b); + var e = CreateAndAddMod("E").Mod; + var d = CreateAndAddMod("D").Mod; + var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -224,11 +224,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant2() { - var e = CreateAndAddMod("E"); - var d = CreateAndAddMod("D"); - var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d); - var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveLastItem, c, e); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b); + var e = CreateAndAddMod("E").Mod; + var d = CreateAndAddMod("D").Mod; + var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -273,7 +273,7 @@ public void Build_TransitiveCycle() { var depA = new ModReference("A", ModType.Default); - var b = CreateAndAddMod("B", Random.Enum(), depA); + var b = CreateAndAddMod("B", Random.Enum(), depA).Mod; var modinfo = new ModinfoData("A") { @@ -301,7 +301,7 @@ public void Build_SelfNotFound_Throws() public void Build_DirectDependencyNotFound_Throws() { var b = Game.InstallMod("B", false, ServiceProvider); - var mod = CreateAndAddMod("A", Random.Enum(), b); + var mod = CreateAndAddMod("A", Random.Enum(), b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(b, e.Mod); @@ -311,8 +311,8 @@ public void Build_DirectDependencyNotFound_Throws() public void Build_TransitiveDependencyNotFound_Throws() { var c = Game.InstallMod("C", false, ServiceProvider); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c); - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b); + var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(c, e.Mod); @@ -335,11 +335,11 @@ public static IEnumerable GetMatchingVersionRanges() [MemberData(nameof(GetMatchingVersionRanges))] public void Build_OneDependency_VersionRangeMatches(SemVersion? version, SemVersionRange ranges) { - var b = CreateAndAddMod(new ModinfoData("B") { Version = version }); + var b = CreateAndAddMod(new ModinfoData("B") { Version = version }).Mod; Assert.Equal(version, b.Version); var mod = CreateAndAddMod("A", Random.Enum(), - new ModReference(b.Identifier, b.Type, ranges)); + new ModReference(b.Identifier, b.Type, ranges)).Mod; var graph = _graphBuilder.Build(mod); @@ -385,11 +385,11 @@ public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion ver var b = CreateAndAddMod(new ModinfoData("B") { Version = version - }); + }).Mod; Assert.Equal(version, b.Version); var mod = CreateAndAddMod("A", Random.Enum(), - new ModReference(b.Identifier, b.Type, range)); + new ModReference(b.Identifier, b.Type, range)).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(b), e.Mod); @@ -403,12 +403,12 @@ public void Build_TransitiveDependency_VersionRangeDoesNotMatches_Throws(SemVers var c = CreateAndAddMod(new ModinfoData("C") { Version = version - }); + }).Mod; Assert.Equal(version, c.Version); - var b = CreateAndAddMod("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}); + var b = CreateAndAddMod("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b); + var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(c), e.Mod); @@ -428,16 +428,16 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th \^ C */ - var b = CreateAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }); + var b = CreateAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; var c = CreateAndAddMod("C", - deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))); + deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: [ new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))), c - ]); + ]).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(b), e.Mod); Assert.Equal(b, e.Dependency); @@ -456,16 +456,16 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th > C */ - var b = CreateAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }); + var b = CreateAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; var c = CreateAndAddMod("C", DependencyResolveLayout.ResolveRecursive, - deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))); + deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: [ c, // Before b in this variant new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))) - ]); + ]).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(b), e.Mod); Assert.Equal(b, e.Dependency); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs index 08312410..8561ae72 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs @@ -129,7 +129,7 @@ public void Resolve_ResolveCompleteChain_DependenciesHaveResolvedDeps_ButResolve private IMod CreateMod(string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IModReference[] deps) { if (deps.Length == 0) - return Game.InstallAndAddMod(name, GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + return GameInstallation.InstallAndAddMod(name, GITestUtilities.GetRandomWorkshopFlag(Game)).Mod; var modinfo = new ModinfoData("A") { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 0216f557..ed022c83 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -21,23 +21,24 @@ public ModDependencyTraverserTest() _traverser = new ModDependencyTraverser(ServiceProvider); } - [Theory] - [MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] - public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) - { + // TODO + //[Theory] + //[MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] + //public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) + //{ - var scenario = ModTestScenarios.CreateTestScenario( - testScenario, - CreateAndAddMod, - CreateAndAddMod); + // var scenario = ModTestScenarios.CreateTestScenario( + // testScenario, + // CreateAndAddModInstallation, + // CreateAndAddModInstallation); - var mod = scenario.Mod; - mod.ResolveDependencies(); + // var mod = scenario.Mod; + // mod.ResolveDependencies(); - var traversedList = _traverser.Traverse(mod); + // var traversedList = _traverser.Traverse(mod); - Assert.Equal(scenario.ExpectedTraversedList, traversedList); - } + // Assert.Equal(scenario.ExpectedTraversedList, traversedList); + //} [Fact] public void Traverse_FaultedResolvedMod_Throws() @@ -45,7 +46,7 @@ public void Traverse_FaultedResolvedMod_Throws() // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddMod("Mod", Random.Enum(), dep); + var mod = CreateAndAddMod("Mod", Random.Enum(), dep).Mod; try { @@ -65,7 +66,7 @@ public void Traverse_NotResolvedMod_Throws() { // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddMod("Mod", Random.Enum(), dep); + var mod = CreateAndAddMod("Mod", Random.Enum(), dep).Mod; Assert.Equal(DependencyResolveStatus.None, mod.DependencyResolveStatus); Assert.Throws(() => _traverser.Traverse(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index b8ead9e7..2e4cc8cc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -32,7 +32,7 @@ private IModReference CreateModRef(string name) return new ModReference(name, modType); } - private Mod CreatePhysicalMod( + private ITestingPhysicalModInstallation CreatePhysicalModInsatllation( string name, string? iconPath = null, ICollection? languages = null, @@ -44,9 +44,10 @@ private Mod CreatePhysicalMod( Dependencies = new DependencyList(deps, layout) }; - var mod = Game.InstallMod(CreateModDirectoryInfo(name), _isWorkshop, modinfo, ServiceProvider); - Game.AddMod(mod); + var modInstallation = GetOrCreateGameInstallation() + .InstallAndAddMod(CreateModDirectoryInfo(name), _isWorkshop, modinfo); + var mod = modInstallation.Mod; if (languages is not null) { foreach (var languageInfo in languages) @@ -56,27 +57,27 @@ private Mod CreatePhysicalMod( if (iconPath is not null) FileSystem.File.Create(FileSystem.Path.Combine(mod.Directory.FullName, iconPath)); - return mod; + return modInstallation; } - protected override ModBase CreateMod( + protected override ITestingModInstallation CreateModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreatePhysicalMod(name, layout: layout, deps: deps); + return CreatePhysicalModInsatllation(name, layout: layout, deps: deps); } - protected override IPlayableObject CreatePlayableObject( + protected override ITestingPlayableObjectInstallation CreatePlayableObjectInstallation( string? iconPath = null, ICollection? languages = null) { - return CreatePhysicalMod("MyMod", iconPath, languages); + return CreatePhysicalModInsatllation("MyMod", iconPath, languages); } - protected override PlayableModContainer CreateModContainer() + protected override ITestingModContainerInstallation CreateModContainerInstallation() { - return CreateMod("MyMod"); + return CreateModInstallation("MyMod"); } [Fact] @@ -150,7 +151,7 @@ public void ValidCtor_Properties_FromModinfo_WithoutDependencies() [Fact] public void ValidCtor_Properties_FromModinfo_WithDependencies() { - var dep = CreateOtherMod("dep"); + var dep = CreateOtherModInstallation("dep").Mod; var ws = GITestUtilities.GetRandomWorkshopFlag(Game); @@ -172,27 +173,28 @@ public void ValidCtor_Properties_FromModinfo_WithDependencies() [Fact] public void ResolveDependencies_NoDependenciesIsNOP() { - var mod = CreateMod("Mod"); + var mod = CreateModInstallation("Mod").Mod; // Should not throw or anything else mod.ResolveDependencies(); Assert.Empty(mod.Dependencies); Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); } - [Theory] - [MemberData(nameof(ModTestScenarios.CycleScenarios), MemberType = typeof(ModTestScenarios))] - public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestScenario testScenario) - { - var mod = ModTestScenarios.CreateTestScenarioCycle( - testScenario, - CreateMod, - CreateOtherMod, - CreateModRef) - .Mod; - - var e = Assert.Throws(mod.ResolveDependencies); - Assert.Equal(mod, e.Mod); - Assert.Null(e.Dependency); - Assert.Equal(DependencyResolveStatus.Faulted, mod.DependencyResolveStatus); - } + // TODO: Enable + //[Theory] + //[MemberData(nameof(ModTestScenarios.CycleScenarios), MemberType = typeof(ModTestScenarios))] + //public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestScenario testScenario) + //{ + // var mod = ModTestScenarios.CreateTestScenarioCycle( + // testScenario, + // CreateModInstallation, + // CreateOtherModInstallation, + // CreateModRef) + // .Mod; + + // var e = Assert.Throws(mod.ResolveDependencies); + // Assert.Equal(mod, e.Mod); + // Assert.Null(e.Dependency); + // Assert.Equal(DependencyResolveStatus.Faulted, mod.DependencyResolveStatus); + //} } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index 3557fe96..9acbec57 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -5,39 +5,44 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Game; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Mods; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; public class PetroglyphStarWarsGameTest : PlayableModContainerTest { - private PetroglyphStarWarsGame CreateGame(string? iconPath = null, ICollection? languages = null) + private ITestingGameInstallation CreateGameInstallation(string? iconPath = null, ICollection? languages = null) { var gameId = new GameIdentity(Random.Enum(), Random.Item(GITestUtilities.RealPlatforms)); - var game = GetOrCreateGameInstallation(gameId).Game; + var gameInstallation = GetOrCreateGameInstallation(gameId); + if (languages is not null) { foreach (var languageInfo in languages) - game.InstallLanguage(languageInfo); + gameInstallation.Game.InstallLanguage(languageInfo); } if (iconPath is not null) { - iconPath = game.Type == GameType.Eaw ? "eaw.ico" : "foc.ico"; - FileSystem.File.Create(FileSystem.Path.Combine(game.Directory.FullName, iconPath)); + iconPath = gameInstallation.Game.Type == GameType.Eaw ? "eaw.ico" : "foc.ico"; + FileSystem.File.Create(FileSystem.Path.Combine(gameInstallation.Game.Directory.FullName, iconPath)); } - return game as PetroglyphStarWarsGame; + return gameInstallation; } - protected override IPlayableObject CreatePlayableObject(string? iconPath = null, ICollection? languages = null) + protected override ITestingPlayableObjectInstallation CreatePlayableObjectInstallation( + string? iconPath = null, + ICollection? languages = null) { - return CreateGame(iconPath, languages); + return CreateGameInstallation(iconPath, languages); } - protected override PlayableModContainer CreateModContainer() + protected override ITestingModContainerInstallation CreateModContainerInstallation() { - return CreateGame(); + return CreateGameInstallation(); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs index d6fb1525..44c61687 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs @@ -1,8 +1,8 @@ using System; using AET.Modinfo.Model; -using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing; +using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Mods; using Xunit; #if NET5_0_OR_GREATER @@ -17,7 +17,7 @@ public abstract class PlayableModContainerTest : PlayableObjectTest { private readonly string _randomModName; - protected abstract PlayableModContainer CreateModContainer(); + protected abstract ITestingModContainerInstallation CreateModContainerInstallation(); protected PlayableModContainerTest() { @@ -28,14 +28,15 @@ protected PlayableModContainerTest() [Fact] public void Mods_NoMods() { - var obj = CreateModContainer(); + var obj = CreateModContainerInstallation().ModContainer; Assert.Empty(obj.Mods); } [Fact] public void AddMod_RemoveMod() { - var container = CreateModContainer(); + var containerInstallation = CreateModContainerInstallation(); + var container = containerInstallation.ModContainer; var game = container.Game; var mod = game.InstallMod(_randomModName, false, ServiceProvider); @@ -85,22 +86,23 @@ public void AddMod_RemoveMod() [Fact] public void AddMod_DifferentGameRef_Throws() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; var game = container.Game; - var otherGame = new PetroglyphStarWarsGame(game, game.Directory, game.Name, ServiceProvider); - var mod = otherGame.InstallAndAddMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + // Same game, just different reference + var otherInstallation = GameInfrastructureTesting.Game(game, ServiceProvider); + var mod = otherInstallation.InstallAndAddMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game)).Mod; Assert.Throws(() => container.AddMod(mod)); } [Fact] public void AddMod_ShouldNotAddSelf() { - var game = CreateModContainer().Game; + var game = CreateModContainerInstallation().GameInstallation; - var isWs = GITestUtilities.GetRandomWorkshopFlag(game); - var mod = game.InstallAndAddMod(_randomModName, isWs, ServiceProvider); - var sameMod = new Mod(game, mod.Identifier, mod.Directory, isWs, mod.Name, ServiceProvider); + var isWs = GITestUtilities.GetRandomWorkshopFlag(game.Game); + var mod = game.InstallAndAddMod(_randomModName, isWs).Mod; + var sameMod = new Mod(game.Game, mod.Identifier, mod.Directory, isWs, mod.Name, ServiceProvider); Assert.False(mod.AddMod(mod)); Assert.False(mod.AddMod(sameMod)); @@ -109,7 +111,7 @@ public void AddMod_ShouldNotAddSelf() [Fact] public void AddMod_RemoveMod_RaiseEvent() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; var game = container.Game; var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -141,7 +143,7 @@ public void AddMod_RemoveMod_RaiseEvent() [Fact] public void RemoveMod_NotExisting_DoesNotRaiseEvent() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; var game = container.Game; var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -166,7 +168,7 @@ public void RemoveMod_NotExisting_DoesNotRaiseEvent() [Fact] public void AddMod_Existing_DoesNotRaiseEvent() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; var game = container.Game; var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -192,7 +194,7 @@ public void AddMod_Existing_DoesNotRaiseEvent() [Fact] public void AddMod_ExistingFromContainer_ShouldBeAlreadyInGame() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; var game = container.Game; var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -204,7 +206,7 @@ public void AddMod_ExistingFromContainer_ShouldBeAlreadyInGame() [Fact] public void FindMod() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; var game = container.Game; var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); @@ -220,7 +222,7 @@ public void FindMod() [Fact] public void ModContainerMethod_NullArgs_Throws() { - var container = CreateModContainer(); + var container = CreateModContainerInstallation().ModContainer; Assert.Throws(() => container.AddMod(null!)); Assert.Throws(() => container.RemoveMod(null!)); Assert.Throws(() => container.FindMod(null!)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs index 4ae165aa..475461ff 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs @@ -1,28 +1,30 @@ -using System.Collections.Generic; -using AET.Modinfo.Spec; +using AET.Modinfo.Spec; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Services.Language; using PG.StarWarsGame.Infrastructure.Testing; +using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using System.Collections.Generic; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; public abstract class PlayableObjectTest : GameInfrastructureTestBase { - protected abstract IPlayableObject CreatePlayableObject(string? iconPath = null, ICollection? languages = null); + protected abstract ITestingPlayableObjectInstallation CreatePlayableObjectInstallation(string? iconPath = null, ICollection? languages = null); [Fact] public void IconFile_NoIcon() { - var obj = CreatePlayableObject(); + var obj = CreatePlayableObjectInstallation().PlayableObject; Assert.Null(obj.IconFile); } [Fact] public void IconFile_IconInstalled() { - var obj = CreatePlayableObject(iconPath: $"{FileSystem.Path.GetRandomFileName()}.ico"); + var obj = CreatePlayableObjectInstallation(iconPath: $"{FileSystem.Path.GetRandomFileName()}.ico") + .PlayableObject; Assert.NotNull(obj.IconFile); Assert.NotNull(obj.IconFile); } @@ -30,7 +32,7 @@ public void IconFile_IconInstalled() [Fact] public void InstalledLanguages_NoLanguagesFound() { - var obj = CreatePlayableObject(); + var obj = CreatePlayableObjectInstallation().PlayableObject; Assert.Empty(obj.InstalledLanguages); // Get a second time Assert.Empty(obj.InstalledLanguages); @@ -40,13 +42,13 @@ public void InstalledLanguages_NoLanguagesFound() public void InstalledLanguages() { var expected = GITestUtilities.GetRandomLanguages(); - var obj = CreatePlayableObject(languages: expected); + var obj = CreatePlayableObjectInstallation(languages: expected).PlayableObject; Assert.Equivalent(expected, obj.InstalledLanguages, true); // Get a second time Assert.Equivalent(expected, obj.InstalledLanguages, true); } - public class PlayableObjectAbstractTest : GameInfrastructureTestBaseWithRandomGame + public class PlayableObectAbstractTest : GameInfrastructureTestBaseWithRandomGame { protected override void SetupServices(IServiceCollection serviceCollection) { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 3e0ae39f..71a47073 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -15,7 +15,7 @@ namespace PG.StarWarsGame.Infrastructure.Test; public class VirtualModTest : ModBaseTest { - private VirtualMod CreateVirtualMod( + private ITestingVirtualModInstallation CreateVirtualMod( string name, string? iconPath = null, ICollection? languages = null, @@ -25,7 +25,7 @@ private VirtualMod CreateVirtualMod( IModDependencyList depList; if (deps.Count == 0) { - var dep = CreateOtherMod("dep", false); + var dep = CreateOtherModInstallation("dep", false).Mod; depList = new DependencyList(new List { dep }, layout); } else @@ -40,12 +40,10 @@ private VirtualMod CreateVirtualMod( Dependencies = depList }; - var mod = new VirtualMod(Game, "VirtualModId", modinfo, ServiceProvider); - Game.AddMod(mod); - return mod; + return GetOrCreateGameInstallation().AddVirtualMod("VirtualModId", modinfo); } - protected override ModBase CreateMod( + protected override ITestingModInstallation CreateModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) @@ -53,16 +51,16 @@ protected override ModBase CreateMod( return CreateVirtualMod(name, layout: layout, deps: deps); } - protected override IPlayableObject CreatePlayableObject( + protected override ITestingPlayableObjectInstallation CreatePlayableObjectInstallation( string? iconPath = null, ICollection? languages = null) { return CreateVirtualMod("Mod", iconPath, languages); } - protected override PlayableModContainer CreateModContainer() + protected override ITestingModContainerInstallation CreateModContainerInstallation() { - return CreateMod("Mod"); + return CreateModInstallation("Mod"); } [Fact] @@ -92,7 +90,7 @@ public void Ctor_EmptyDependencies_Throws() [Fact] public void Ctor_FromModinfo_Properties() { - var dep = CreateOtherMod("dep"); + var dep = CreateOtherModInstallation("dep").Mod; var modinfo = new ModinfoData("VirtualMod") { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Eaw.cs similarity index 98% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Eaw.cs index 48d803e2..2980dec7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Eaw.cs @@ -5,7 +5,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -internal static partial class GameInstallation +internal static partial class GameInstallationHelper { private const string EawNormalPath = "games/eaw"; private const string EawGoldPath = "games/gold/eaw"; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Foc.cs similarity index 98% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Foc.cs index a14e0687..6471ca3d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.Foc.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Foc.cs @@ -5,7 +5,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -internal static partial class GameInstallation +internal static partial class GameInstallationHelper { private const string FocNormalPath = "games/foc"; private const string FocGoldPath = "games/gold/foc"; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.cs similarity index 97% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.cs index f8630fa1..5c52b686 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.cs @@ -4,7 +4,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -internal static partial class GameInstallation +internal static partial class GameInstallationHelper { // Ensure starts on path 'steam'. See SteamInstallation.cs internal const string SteamBasePath = "steam/steamapps/common/Star Wars Empire at War"; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs index b65a9eb9..fd151e6e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs @@ -1,10 +1,12 @@ using PG.StarWarsGame.Infrastructure.Games; using System.IO.Abstractions; +using AET.Modinfo.Model; +using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Testing.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -public interface ITestingGameInstallation +public interface ITestingGameInstallation : ITestingModContainerInstallation { IGame Game { get; } @@ -12,5 +14,11 @@ public interface ITestingGameInstallation IDirectoryInfo GetWrongOriginFocRegistryLocation(); - ITestingModInstallation InstallAndAddMod(string name, bool workshop); + ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop); + + ITestingPhysicalModInstallation InstallAndAddMod(bool workshop, IModinfo modinfo); + + ITestingPhysicalModInstallation InstallAndAddMod(IDirectoryInfo directory, bool workshop, IModinfo modinfo); + + ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs index aca991f6..53e8f4a0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs @@ -1,8 +1,11 @@ -using System; -using System.IO.Abstractions; +using AET.Modinfo.Model; +using AET.Modinfo.Spec; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Mods; +using System; +using System.IO.Abstractions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; @@ -14,6 +17,12 @@ internal class TestingGameImpl : ITestingGameInstallation public IGame Game { get; } + public ITestingGameInstallation GameInstallation => this; + + public PlayableModContainer ModContainer => Game as PlayableModContainer; + + public IPlayableObject PlayableObject => Game; + public TestingGameImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; @@ -25,26 +34,47 @@ public void InstallDebug() { if (Game.Platform is not GamePlatform.SteamGold) Assert.Fail($"Cannot install Debug files for non-Steam game '{Game}'"); - GameInstallation.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); + GameInstallationHelper.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); } public IDirectoryInfo GetWrongOriginFocRegistryLocation() { - return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallation.OriginBasePath, "corruption")); + return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); } - public ITestingModInstallation InstallAndAddMod(string name, bool workshop) + public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop) { var mod = Game.InstallMod(name, workshop, _serviceProvider); Game.AddMod(mod); - return new TestingModImpl(this, mod, _serviceProvider); + return new TestingPhysicalModImpl(this, mod, _serviceProvider); + } + + public ITestingPhysicalModInstallation InstallAndAddMod(bool workshop, IModinfo modinfo) + { + var mod = Game.InstallMod(workshop, modinfo, _serviceProvider); + Game.AddMod(mod); + return new TestingPhysicalModImpl(this, mod, _serviceProvider); + } + + public ITestingPhysicalModInstallation InstallAndAddMod(IDirectoryInfo directory, bool workshop, IModinfo modinfo) + { + var mod = Game.InstallMod(directory, workshop, modinfo, _serviceProvider); + Game.AddMod(mod); + return new TestingPhysicalModImpl(this, mod, _serviceProvider); + } + + public ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo) + { + var mod = new VirtualMod(Game, "VirtualModId", modinfo, _serviceProvider); + Game.AddMod(mod); + return new TestingVirtualModImpl(this, mod, _serviceProvider); } private IGame Install(IGameIdentity gameIdentity) { var gameDir = gameIdentity.Type == GameType.Foc - ? GameInstallation.InstallFoc(_fileSystem, gameIdentity.Platform) - : GameInstallation.InstallEaw(_fileSystem, gameIdentity.Platform); + ? GameInstallationHelper.InstallFoc(_fileSystem, gameIdentity.Platform) + : GameInstallationHelper.InstallEaw(_fileSystem, gameIdentity.Platform); _fileSystem.InstallModsLocations(gameDir); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs new file mode 100644 index 00000000..569b3cba --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs @@ -0,0 +1,6 @@ +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +public interface ITestingModContainerInstallation : ITestingPlayableObjectInstallation +{ + PlayableModContainer ModContainer { get; } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs new file mode 100644 index 00000000..17ec0138 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs @@ -0,0 +1,11 @@ +using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +public interface ITestingModInstallation : ITestingModContainerInstallation +{ + ITestingGameInstallation GameInstallation { get; } + + IMod Mod { get; } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs new file mode 100644 index 00000000..1f8cfab1 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs @@ -0,0 +1,8 @@ +using PG.StarWarsGame.Infrastructure.Mods; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +public interface ITestingPhysicalModInstallation : ITestingModInstallation +{ + new IPhysicalMod Mod { get; } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs new file mode 100644 index 00000000..6840d6fc --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs @@ -0,0 +1,10 @@ +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +public interface ITestingPlayableObjectInstallation +{ + ITestingGameInstallation GameInstallation { get; } + + IPlayableObject PlayableObject { get; } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs new file mode 100644 index 00000000..f96c10e2 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs @@ -0,0 +1,8 @@ +using PG.StarWarsGame.Infrastructure.Mods; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +public interface ITestingVirtualModInstallation : ITestingModInstallation +{ + new IVirtualMod Mod { get; } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs index 8bb863b5..8410d975 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs @@ -5,27 +5,11 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Steam; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Utilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Mods; - -public interface ITestingModInstallation -{ - ITestingGameInstallation GameInstallation { get; } - - IPhysicalMod Mod { get; } -} - -internal sealed class TestingModImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) : ITestingModInstallation -{ - public ITestingGameInstallation GameInstallation { get; } = gameInstallation; - - public IPhysicalMod Mod { get; } = mod; -} - public static partial class ModInstallations { public static Mod InstallAndAddMod(this IGame game, string name, bool workshop, IServiceProvider serviceProvider) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs new file mode 100644 index 00000000..4e0194f0 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs @@ -0,0 +1,16 @@ +using System; +using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +internal class TestingModImpl(ITestingGameInstallation gameInstallation, IMod mod, IServiceProvider serviceProvider) : ITestingModInstallation +{ + public ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public IPlayableObject PlayableObject => Mod; + + public IMod Mod { get; } = mod; + + public PlayableModContainer ModContainer => Mod as ModBase; +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs new file mode 100644 index 00000000..4da799f3 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs @@ -0,0 +1,13 @@ +using System; +using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +internal sealed class TestingPhysicalModImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) + : TestingModImpl(gameInstallation, mod, serviceProvider), ITestingPhysicalModInstallation +{ + public ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public IPhysicalMod Mod { get; } = mod; +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs new file mode 100644 index 00000000..4dbc7197 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs @@ -0,0 +1,13 @@ +using System; +using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; + +namespace PG.StarWarsGame.Infrastructure.Testing.Mods; + +internal sealed class TestingVirtualModImpl(ITestingGameInstallation gameInstallation, IVirtualMod mod, IServiceProvider serviceProvider) + : TestingModImpl(gameInstallation, mod, serviceProvider), ITestingVirtualModInstallation +{ + public ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public IVirtualMod Mod { get; } = mod; +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index d2f9f9bc..6cd63e59 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -3,7 +3,6 @@ using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Game; using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Mods; @@ -42,20 +41,20 @@ protected virtual ITestingGameInstallation GetOrCreateGameInstallation(IGameIden // TODO: To installation - protected IMod CreateAndAddMod(bool isWorkshop, string name, IModDependencyList dependencies) + protected ITestingModInstallation CreateAndAddModInstallation(bool isWorkshop, string name, IModDependencyList dependencies) { if (dependencies.Count == 0) - return GetOrCreateGameInstallation().Game.InstallAndAddMod(name, isWorkshop, ServiceProvider); + return GetOrCreateGameInstallation().InstallAndAddMod(name, isWorkshop); var modinfo = new ModinfoData(name) { Dependencies = dependencies }; - return CreateAndAddMod(isWorkshop, modinfo); + return CreateAndAddModInstallation(isWorkshop, modinfo); } - protected IMod CreateAndAddMod(bool isWorkshop, IModinfo modinfo) + protected ITestingModInstallation CreateAndAddModInstallation(bool isWorkshop, IModinfo modinfo) { - return GetOrCreateGameInstallation().Game.InstallAndAddMod(isWorkshop, modinfo, ServiceProvider); + return GetOrCreateGameInstallation().InstallAndAddMod(isWorkshop, modinfo); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index af513ce5..1211531b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -2,24 +2,27 @@ using AET.Modinfo.Model; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastructureTestBase { - protected IGame Game => GetOrCreateGameInstallation(identity: null).Game; + protected IGame Game => GameInstallation.Game; + + protected ITestingGameInstallation GameInstallation => GetOrCreateGameInstallation(identity: null); - protected IMod CreateAndAddMod( + protected ITestingModInstallation CreateAndAddMod( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreateAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), name, new DependencyList(deps, layout)); + return CreateAndAddModInstallation(GITestUtilities.GetRandomWorkshopFlag(Game), name, new DependencyList(deps, layout)); } - protected IMod CreateAndAddMod(IModinfo modinfo) + protected ITestingModInstallation CreateAndAddMod(IModinfo modinfo) { - return CreateAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modinfo); + return CreateAndAddModInstallation(GITestUtilities.GetRandomWorkshopFlag(Game), modinfo); } } \ No newline at end of file From f7262e2ecd920ad1021dd996621c85fb048ada64 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 13:19:19 +0100 Subject: [PATCH 27/71] enable tests again --- .../ModBaseTest.cs | 103 +++++++++--------- .../ModEqualityComparerTest.cs | 6 +- .../ModDependencyGraphBuilderTest.cs | 94 ++++++++-------- .../ModDependencyTraverserTest.cs | 34 +++--- .../ModTest.cs | 33 +++--- ...ameInfrastructureTestBaseWithRandomGame.cs | 4 +- 6 files changed, 136 insertions(+), 138 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 12fe6f47..73155930 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing.Extensions; @@ -53,31 +54,30 @@ public void VersionRange_IsNull() Assert.Null(mod.VersionRange); } - // TODO: Re-enable once events are supported again - //[Theory] - //[MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] - //public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario testScenario) - //{ - // var mod = ModTestScenarios.CreateTestScenario( - // testScenario, - // CreateModInstallation, - // CreateOtherModInstallation) - // .Mod; + [Theory] + [MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] + public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario testScenario) + { + var mod = ModTestScenarios.CreateTestScenario( + testScenario, + (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateOtherModInstallation(name, layout, dependencies).Mod) + .Mod; - // var expectedDirectDeps = mod.ModInfo!.Dependencies.Select(d => - // { - // var dep = Game.FindMod(d); - // Assert.NotNull(dep); - // return dep; - // }); + var expectedDirectDeps = mod.ModInfo!.Dependencies.Select(d => + { + var dep = Game.FindMod(d); + Assert.NotNull(dep); + return dep; + }); - // mod.ResolveDependencies(); + mod.ResolveDependencies(); - // Assert.Equal(expectedDirectDeps, mod.Dependencies); - // Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); + Assert.Equal(expectedDirectDeps, mod.Dependencies); + Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); - // AssertDependenciesResolved(mod); - //} + AssertDependenciesResolved(mod); + } [Fact] public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectly() @@ -154,36 +154,35 @@ public void ResolveDependencies_VersionMatch_Throws() Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); } - // TODO: Re-enable once events are supported again - //[Fact] - //public void ResolveDependencies_RaiseEvent() - //{ - // var scenario = ModTestScenarios.CreateTestScenario( - // ModTestScenarios.TestScenario.SingleDepAndTransitive, - // CreateModInstallation, - // CreateOtherModInstallation); - - // var mod = scenario.Mod; - // var b = Game.FindMod(scenario.ExpectedTraversedList![1])!; - - // var bRaised = false; - // var modRaised = false; - // b.DependenciesResolved += (sender, _) => - // { - // Assert.Equal(b, sender); - // bRaised = true; - // }; - // mod.DependenciesResolved += (sender, _) => - // { - // Assert.Equal(mod, sender); - // modRaised = true; - // }; - - // mod.ResolveDependencies(); - - // Assert.True(bRaised); - // Assert.True(modRaised); - //} + [Fact] + public void ResolveDependencies_RaiseEvent() + { + var scenario = ModTestScenarios.CreateTestScenario( + ModTestScenarios.TestScenario.SingleDepAndTransitive, + (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateOtherModInstallation(name, layout, dependencies).Mod); + + var mod = scenario.Mod; + var b = Game.FindMod(scenario.ExpectedTraversedList![1])!; + + var bRaised = false; + var modRaised = false; + b.DependenciesResolved += (sender, _) => + { + Assert.Equal(b, sender); + bRaised = true; + }; + mod.DependenciesResolved += (sender, _) => + { + Assert.Equal(mod, sender); + modRaised = true; + }; + + mod.ResolveDependencies(); + + Assert.True(bRaised); + Assert.True(modRaised); + } [Fact] public void ResolveDependencies_AlreadyResolved_DoesNotRaiseEvent() @@ -287,7 +286,7 @@ public class ModBaseAbstractTest : GameInfrastructureTestBaseWithRandomGame [Fact] public void ResolveDependencies_CalledTwice_Throws() { - var dep = CreateAndAddMod("Dep").Mod; + var dep = CreateAndAddModInstallation("Dep").Mod; var modinfo = new ModinfoData("CustomMod") { Dependencies = new DependencyList(new List { dep }, DependencyResolveLayout.FullResolved) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index 2d52472d..790a9fd4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -70,7 +70,7 @@ public void Equals_ShouldAlwaysBeEquals(bool includeDeps, bool includeGame) public void Equals_DependencyAware(bool depAware) { var dep = new ModReference("B", ModType.Default); - var modA = (IPhysicalMod)CreateAndAddMod("A", deps: dep).Mod; + var modA = (IPhysicalMod)CreateAndAddModInstallation("A", deps: dep).Mod; var sameishModindo = new ModinfoData("A") { @@ -107,7 +107,7 @@ public void Equals_DependencyAware(bool depAware) [InlineData(true)] public void Equals_GameAware(bool gameAware) { - var modA = CreateAndAddMod("A").Mod; + var modA = CreateAndAddModInstallation("A").Mod; var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); @@ -140,7 +140,7 @@ public void Equals_GameAware(bool gameAware) [Fact] public void ToJson() { - var mod = CreateAndAddMod("A").Mod; + var mod = CreateAndAddModInstallation("A").Mod; var expected = new ModReference(mod).ToJson(); Assert.Equal(expected, mod.ToJson()); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 923392a9..8502ed96 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -26,7 +26,7 @@ public void NullArgs_Throws() [Fact] public void Build_NoDependencies() { - var mod = CreateAndAddMod("A").Mod; + var mod = CreateAndAddModInstallation("A").Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -36,8 +36,8 @@ public void Build_NoDependencies() [Fact] public void Build_OneDependency() { - var b = CreateAndAddMod("B").Mod; - var mod = CreateAndAddMod("A", Random.Enum(), b).Mod; + var b = CreateAndAddModInstallation("B").Mod; + var mod = CreateAndAddModInstallation("A", Random.Enum(), b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -60,8 +60,8 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() { // C is not added to game. Building a graph should not throw, because it's not used. var c = Game.InstallMod("C", false, ServiceProvider); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.FullResolved, b).Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.FullResolved, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -82,9 +82,9 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() { - var c = CreateAndAddMod("C").Mod; - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var c = CreateAndAddModInstallation("C").Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -107,10 +107,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant1() { - var d = CreateAndAddMod("D").Mod; - var c = CreateAndAddMod("C").Mod; - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; + var d = CreateAndAddModInstallation("D").Mod; + var c = CreateAndAddModInstallation("C").Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -133,10 +133,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant2() { - var d = CreateAndAddMod("D").Mod; - var c = CreateAndAddMod("C").Mod; - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; + var d = CreateAndAddModInstallation("D").Mod; + var c = CreateAndAddModInstallation("C").Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -162,10 +162,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() { - var d = CreateAndAddMod("D").Mod; - var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveRecursive, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var d = CreateAndAddModInstallation("D").Mod; + var c = CreateAndAddModInstallation("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.ResolveRecursive, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -191,11 +191,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() { - var e = CreateAndAddMod("E").Mod; - var d = CreateAndAddMod("D").Mod; - var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var e = CreateAndAddModInstallation("E").Mod; + var d = CreateAndAddModInstallation("D").Mod; + var c = CreateAndAddModInstallation("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -224,11 +224,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant2() { - var e = CreateAndAddMod("E").Mod; - var d = CreateAndAddMod("D").Mod; - var c = CreateAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = CreateAndAddMod("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var e = CreateAndAddModInstallation("E").Mod; + var d = CreateAndAddModInstallation("D").Mod; + var c = CreateAndAddModInstallation("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -273,7 +273,7 @@ public void Build_TransitiveCycle() { var depA = new ModReference("A", ModType.Default); - var b = CreateAndAddMod("B", Random.Enum(), depA).Mod; + var b = CreateAndAddModInstallation("B", Random.Enum(), depA).Mod; var modinfo = new ModinfoData("A") { @@ -301,7 +301,7 @@ public void Build_SelfNotFound_Throws() public void Build_DirectDependencyNotFound_Throws() { var b = Game.InstallMod("B", false, ServiceProvider); - var mod = CreateAndAddMod("A", Random.Enum(), b).Mod; + var mod = CreateAndAddModInstallation("A", Random.Enum(), b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(b, e.Mod); @@ -311,8 +311,8 @@ public void Build_DirectDependencyNotFound_Throws() public void Build_TransitiveDependencyNotFound_Throws() { var c = Game.InstallMod("C", false, ServiceProvider); - var b = CreateAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(c, e.Mod); @@ -335,10 +335,10 @@ public static IEnumerable GetMatchingVersionRanges() [MemberData(nameof(GetMatchingVersionRanges))] public void Build_OneDependency_VersionRangeMatches(SemVersion? version, SemVersionRange ranges) { - var b = CreateAndAddMod(new ModinfoData("B") { Version = version }).Mod; + var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = version }).Mod; Assert.Equal(version, b.Version); - var mod = CreateAndAddMod("A", Random.Enum(), + var mod = CreateAndAddModInstallation("A", Random.Enum(), new ModReference(b.Identifier, b.Type, ranges)).Mod; var graph = _graphBuilder.Build(mod); @@ -382,13 +382,13 @@ public static IEnumerable GetMismatchingVersionsAndRange() [MemberData(nameof(GetMismatchingVersionsAndRange))] public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion version, SemVersionRange? range) { - var b = CreateAndAddMod(new ModinfoData("B") + var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = version }).Mod; Assert.Equal(version, b.Version); - var mod = CreateAndAddMod("A", Random.Enum(), + var mod = CreateAndAddModInstallation("A", Random.Enum(), new ModReference(b.Identifier, b.Type, range)).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); @@ -400,15 +400,15 @@ public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion ver [MemberData(nameof(GetMismatchingVersionsAndRange))] public void Build_TransitiveDependency_VersionRangeDoesNotMatches_Throws(SemVersion version, SemVersionRange? range) { - var c = CreateAndAddMod(new ModinfoData("C") + var c = CreateAndAddModInstallation(new ModinfoData("C") { Version = version }).Mod; Assert.Equal(version, c.Version); - var b = CreateAndAddMod("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; + var b = CreateAndAddModInstallation("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(c), e.Mod); @@ -428,12 +428,12 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th \^ C */ - var b = CreateAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; + var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; - var c = CreateAndAddMod("C", + var c = CreateAndAddModInstallation("C", deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, deps: [ new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))), c @@ -456,12 +456,12 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th > C */ - var b = CreateAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; + var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; - var c = CreateAndAddMod("C", DependencyResolveLayout.ResolveRecursive, + var c = CreateAndAddModInstallation("C", DependencyResolveLayout.ResolveRecursive, deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; - var mod = CreateAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: + var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, deps: [ c, // Before b in this variant new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index ed022c83..9e8930f2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -21,32 +21,32 @@ public ModDependencyTraverserTest() _traverser = new ModDependencyTraverser(ServiceProvider); } - // TODO - //[Theory] - //[MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] - //public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) - //{ - // var scenario = ModTestScenarios.CreateTestScenario( - // testScenario, - // CreateAndAddModInstallation, - // CreateAndAddModInstallation); + [Theory] + [MemberData(nameof(ModTestScenarios.ValidScenarios), MemberType = typeof(ModTestScenarios))] + public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) + { + + var scenario = ModTestScenarios.CreateTestScenario( + testScenario, + (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod); - // var mod = scenario.Mod; - // mod.ResolveDependencies(); + var mod = scenario.Mod; + mod.ResolveDependencies(); - // var traversedList = _traverser.Traverse(mod); + var traversedList = _traverser.Traverse(mod); + + Assert.Equal(scenario.ExpectedTraversedList, traversedList); + } - // Assert.Equal(scenario.ExpectedTraversedList, traversedList); - //} - [Fact] public void Traverse_FaultedResolvedMod_Throws() { // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddMod("Mod", Random.Enum(), dep).Mod; + var mod = CreateAndAddModInstallation("Mod", Random.Enum(), dep).Mod; try { @@ -66,7 +66,7 @@ public void Traverse_NotResolvedMod_Throws() { // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddMod("Mod", Random.Enum(), dep).Mod; + var mod = CreateAndAddModInstallation("Mod", Random.Enum(), dep).Mod; Assert.Equal(DependencyResolveStatus.None, mod.DependencyResolveStatus); Assert.Throws(() => _traverser.Traverse(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index 2e4cc8cc..f8c7624f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -180,21 +180,20 @@ public void ResolveDependencies_NoDependenciesIsNOP() Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); } - // TODO: Enable - //[Theory] - //[MemberData(nameof(ModTestScenarios.CycleScenarios), MemberType = typeof(ModTestScenarios))] - //public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestScenario testScenario) - //{ - // var mod = ModTestScenarios.CreateTestScenarioCycle( - // testScenario, - // CreateModInstallation, - // CreateOtherModInstallation, - // CreateModRef) - // .Mod; - - // var e = Assert.Throws(mod.ResolveDependencies); - // Assert.Equal(mod, e.Mod); - // Assert.Null(e.Dependency); - // Assert.Equal(DependencyResolveStatus.Faulted, mod.DependencyResolveStatus); - //} + [Theory] + [MemberData(nameof(ModTestScenarios.CycleScenarios), MemberType = typeof(ModTestScenarios))] + public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestScenario testScenario) + { + var mod = ModTestScenarios.CreateTestScenarioCycle( + testScenario, + (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateOtherModInstallation(name, layout, dependencies).Mod, + CreateModRef) + .Mod; + + var e = Assert.Throws(mod.ResolveDependencies); + Assert.Equal(mod, e.Mod); + Assert.Null(e.Dependency); + Assert.Equal(DependencyResolveStatus.Faulted, mod.DependencyResolveStatus); + } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 1211531b..29cb111a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -13,7 +13,7 @@ public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastruct protected ITestingGameInstallation GameInstallation => GetOrCreateGameInstallation(identity: null); - protected ITestingModInstallation CreateAndAddMod( + protected ITestingModInstallation CreateAndAddModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) @@ -21,7 +21,7 @@ protected ITestingModInstallation CreateAndAddMod( return CreateAndAddModInstallation(GITestUtilities.GetRandomWorkshopFlag(Game), name, new DependencyList(deps, layout)); } - protected ITestingModInstallation CreateAndAddMod(IModinfo modinfo) + protected ITestingModInstallation CreateAndAddModInstallation(IModinfo modinfo) { return CreateAndAddModInstallation(GITestUtilities.GetRandomWorkshopFlag(Game), modinfo); } From 9c26a56bc598d59d19cb165fe3ac42538270b73d Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 13:22:02 +0100 Subject: [PATCH 28/71] move code --- test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs | 1 - .../SteamPetroglyphStarWarsGameClientTest.cs | 4 ++-- .../SteamPetroglyphStarWarsGameDetectorTest.cs | 4 ++-- .../Clients/Arguments/GameArgumentsBuilderTest.cs | 2 +- .../Clients/PetroglyphStarWarsGameClientTest.cs | 6 +++--- .../GameServices/Detection/RegistryGameDetectorTest.cs | 4 ++-- test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs | 4 ++-- .../ModEqualityComparerTest.cs | 4 ++-- .../Dependencies/ModDependencyGraphBuilderTest.cs | 2 +- .../ModServices/Dependencies/ModDependencyResolverTest.cs | 2 +- .../ModServices/Dependencies/ModDependencyTraverserTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 4 ++-- .../ModServices/ModFinderTest.cs | 4 ++-- .../ModServices/ModGameTypeResolverTestBase.cs | 2 +- test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs | 3 ++- .../PetroglyphGameInfrastructureIntegrationTest.cs | 6 +++--- .../PetroglyphStarWarsGameTest.cs | 5 ++--- .../PlayableModContainerTest.cs | 6 ++++-- .../PlayableObjectTest.cs | 2 +- .../Services/IconFinderTest.cs | 2 +- .../Services/LanguageFinderTestBase.cs | 4 ++-- test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs | 3 ++- .../Game/Installation/GameInstallationHelper.Eaw.cs | 2 +- .../Game/Installation/GameInstallationHelper.Foc.cs | 2 +- .../Game/Installation/GameInstallationHelper.cs | 2 +- .../Game/Installation/ITestingGameInstallation.cs | 4 ++-- .../Game/Installation/TestingGameImpl.cs | 4 ++-- .../Game/Registry/ITestingGameRegistry.cs | 2 +- .../Game/Registry/TestGameRegistrySetupData.cs | 2 +- .../Game/Registry/TestingGameRegistryImpl.cs | 2 +- .../{Game => Installations}/GameInfrastructureTesting.cs | 6 +++--- .../ITestingModContainerInstallation.cs | 2 +- .../ITestingPlayableObjectInstallation.cs | 4 ++-- .../{ => Installations}/Mods/ITestingModInstallation.cs | 4 ++-- .../Mods/ITestingPhysicalModInstallation.cs | 2 +- .../Mods/ITestingVirtualModInstallation.cs | 2 +- .../{ => Installations}/Mods/ModInstallations.Modinfo.cs | 2 +- .../{ => Installations}/Mods/ModInstallations.cs | 2 +- .../{ => Installations}/Mods/TestingModImpl.cs | 4 ++-- .../{ => Installations}/Mods/TestingPhysicalModImpl.cs | 4 ++-- .../{ => Installations}/Mods/TestingVirtualModImpl.cs | 4 ++-- .../TestBases/GameInfrastructureTestBase.cs | 6 +++--- .../TestBases/GameInfrastructureTestBaseWithRandomGame.cs | 4 ++-- 43 files changed, 72 insertions(+), 70 deletions(-) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Installation/GameInstallationHelper.Eaw.cs (97%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Installation/GameInstallationHelper.Foc.cs (97%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Installation/GameInstallationHelper.cs (96%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Installation/ITestingGameInstallation.cs (82%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Installation/TestingGameImpl.cs (95%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Registry/ITestingGameRegistry.cs (80%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Registry/TestGameRegistrySetupData.cs (94%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Game/Registry/TestingGameRegistryImpl.cs (97%) rename test/PG.StarWarsGame.Infrastructure.Testing/{Game => Installations}/GameInfrastructureTesting.cs (67%) rename test/PG.StarWarsGame.Infrastructure.Testing/{Mods => Installations}/ITestingModContainerInstallation.cs (67%) rename test/PG.StarWarsGame.Infrastructure.Testing/{Mods => Installations}/ITestingPlayableObjectInstallation.cs (51%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/ITestingModInstallation.cs (58%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/ITestingPhysicalModInstallation.cs (69%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/ITestingVirtualModInstallation.cs (69%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/ModInstallations.Modinfo.cs (95%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/ModInstallations.cs (98%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/TestingModImpl.cs (75%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/TestingPhysicalModImpl.cs (74%) rename test/PG.StarWarsGame.Infrastructure.Testing/{ => Installations}/Mods/TestingVirtualModImpl.cs (74%) diff --git a/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs b/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs index 90515390..c500d106 100644 --- a/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs @@ -2,7 +2,6 @@ using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Win32; using System; using System.IO.Abstractions; using System.Runtime.InteropServices; diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index c8ff0720..e0cfcc2f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -15,8 +15,8 @@ using System.Runtime.Versioning; using AET.Testing.Extensions; using Xunit; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 014d1e44..541a7b4e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -10,8 +10,8 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index 4d3e0310..dc391c0a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -6,7 +6,7 @@ using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 0f48e90a..01757223 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -12,9 +12,9 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Clients; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs index 4859a36e..e74a97b8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs @@ -6,8 +6,8 @@ using PG.StarWarsGame.Infrastructure.Games.Registry; using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 73155930..d6450a28 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -6,13 +6,13 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Testing.Mods; using Xunit; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; using Semver; using PG.StarWarsGame.Infrastructure.Testing.TestBases; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index 790a9fd4..bab5c62e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -3,11 +3,11 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System; using System.Collections.Generic; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 8502ed96..eeb5faa0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -6,7 +6,7 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs index 8561ae72..0c229900 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs @@ -5,7 +5,7 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 9e8930f2..263d115e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -4,7 +4,7 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index e0317a90..470b9811 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -15,8 +15,8 @@ using PG.StarWarsGame.Infrastructure.Services; using PG.StarWarsGame.Infrastructure.Services.Name; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index d2c2eaad..88fdcbfb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -14,8 +14,8 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index f9b715c7..829e3315 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -12,7 +12,7 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index f8c7624f..8f67aed4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -6,7 +6,8 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 044277d5..805ffb79 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -12,15 +12,15 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index 9acbec57..348a72fc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -4,9 +4,8 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs index 44c61687..a0b967cc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs @@ -2,9 +2,11 @@ using AET.Modinfo.Model; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Mods; using Xunit; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; + + #if NET5_0_OR_GREATER using System.Collections.Generic; #else diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs index 475461ff..aeef5d45 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableObjectTest.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Services.Language; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System.Collections.Generic; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs index e9428f53..2a45a42a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs @@ -6,7 +6,7 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Icon; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using PG.StarWarsGame.Infrastructure.Utilities; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index e82b14d6..2cbe135b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -4,12 +4,12 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Language; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System; using System.Collections.Generic; using Xunit; -using PG.StarWarsGame.Infrastructure.Testing.Game; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Test.Services; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 71a47073..4bb017c1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -7,7 +7,8 @@ using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Semver; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Eaw.cs similarity index 97% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Eaw.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Eaw.cs index 2980dec7..07f5e68b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Eaw.cs @@ -3,7 +3,7 @@ using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; internal static partial class GameInstallationHelper { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Foc.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Foc.cs similarity index 97% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Foc.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Foc.cs index 6471ca3d..5125c64a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.Foc.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Foc.cs @@ -3,7 +3,7 @@ using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; internal static partial class GameInstallationHelper { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.cs similarity index 96% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.cs index 5c52b686..bf6a905b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/GameInstallationHelper.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.cs @@ -2,7 +2,7 @@ using System.IO.Abstractions; using Testably.Abstractions.Testing; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; internal static partial class GameInstallationHelper { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs similarity index 82% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs index fd151e6e..3b80ce44 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs @@ -2,9 +2,9 @@ using System.IO.Abstractions; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; public interface ITestingGameInstallation : ITestingModContainerInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs similarity index 95% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs index 53e8f4a0..c07a2f20 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs @@ -3,12 +3,12 @@ using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System; using System.IO.Abstractions; using Xunit; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; internal class TestingGameImpl : ITestingGameInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs similarity index 80% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs index 9ff12e34..54e925ff 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/ITestingGameRegistry.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs @@ -1,7 +1,7 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; public interface ITestingGameRegistry { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs similarity index 94% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs index 8ed57642..dfe2e0f8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestGameRegistrySetupData.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs @@ -1,7 +1,7 @@ using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; public sealed class TestGameRegistrySetupData { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestingGameRegistryImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs similarity index 97% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestingGameRegistryImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs index 6f82d1c6..11f6110b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/Registry/TestingGameRegistryImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs @@ -8,7 +8,7 @@ using RegistryHive = AnakinRaW.CommonUtilities.Registry.RegistryHive; using RegistryView = AnakinRaW.CommonUtilities.Registry.RegistryView; -namespace PG.StarWarsGame.Infrastructure.Testing.Game.Registry; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; internal sealed class TestingGameRegistryImpl(IServiceProvider serviceProvider) : ITestingGameRegistry { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs similarity index 67% rename from test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs index 9c892917..1d78ff3e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Game/GameInfrastructureTesting.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs @@ -1,9 +1,9 @@ using System; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Game.Registry; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; -namespace PG.StarWarsGame.Infrastructure.Testing.Game; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; public static class GameInfrastructureTesting { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs similarity index 67% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs index 569b3cba..117b6528 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModContainerInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs @@ -1,4 +1,4 @@ -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; public interface ITestingModContainerInstallation : ITestingPlayableObjectInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs similarity index 51% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs index 6840d6fc..8160090b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPlayableObjectInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs @@ -1,6 +1,6 @@ -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; public interface ITestingPlayableObjectInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs similarity index 58% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs index 17ec0138..49f2536b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs @@ -1,7 +1,7 @@ using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public interface ITestingModInstallation : ITestingModContainerInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs similarity index 69% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs index 1f8cfab1..56b6997c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingPhysicalModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs @@ -1,6 +1,6 @@ using PG.StarWarsGame.Infrastructure.Mods; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public interface ITestingPhysicalModInstallation : ITestingModInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs similarity index 69% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs index f96c10e2..5f7e44e5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ITestingVirtualModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs @@ -1,6 +1,6 @@ using PG.StarWarsGame.Infrastructure.Mods; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public interface ITestingVirtualModInstallation : ITestingModInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.Modinfo.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs similarity index 95% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.Modinfo.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs index 39388722..4e8de08c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.Modinfo.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs @@ -4,7 +4,7 @@ using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Mods; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public static partial class ModInstallations { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs similarity index 98% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs index 8410d975..0ed52ef8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs @@ -8,7 +8,7 @@ using PG.StarWarsGame.Infrastructure.Utilities; using Xunit; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public static partial class ModInstallations { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs similarity index 75% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs index 4e0194f0..baaee576 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs @@ -1,8 +1,8 @@ using System; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; internal class TestingModImpl(ITestingGameInstallation gameInstallation, IMod mod, IServiceProvider serviceProvider) : ITestingModInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs similarity index 74% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs index 4da799f3..df740a87 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingPhysicalModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs @@ -1,8 +1,8 @@ using System; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; internal sealed class TestingPhysicalModImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) : TestingModImpl(gameInstallation, mod, serviceProvider), ITestingPhysicalModInstallation diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs similarity index 74% rename from test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs index 4dbc7197..ba1c809a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Mods/TestingVirtualModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs @@ -1,8 +1,8 @@ using System; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -namespace PG.StarWarsGame.Infrastructure.Testing.Mods; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; internal sealed class TestingVirtualModImpl(ITestingGameInstallation gameInstallation, IVirtualMod mod, IServiceProvider serviceProvider) : TestingModImpl(gameInstallation, mod, serviceProvider), ITestingVirtualModInstallation diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 6cd63e59..ff3bcb44 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -3,9 +3,9 @@ using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Testing.Game; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System.IO.Abstractions; using System.Threading; using Testably.Abstractions.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 29cb111a..bc249649 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -2,8 +2,8 @@ using AET.Modinfo.Model; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Testing.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; From 6a8c7b7f4e783d3403f1373f572fbad524491fd1 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 14:01:39 +0100 Subject: [PATCH 29/71] simplify further --- .../ModBaseTest.cs | 24 +---- .../ModEqualityComparerTest.cs | 6 +- .../ModDependencyGraphBuilderTest.cs | 94 +++++++++---------- .../ModDependencyTraverserTest.cs | 8 +- .../ModTest.cs | 10 +- .../VirtualModTest.cs | 4 +- .../Installation/ITestingGameInstallation.cs | 10 +- .../Game/Installation/TestingGameImpl.cs | 25 ++++- .../TestBases/GameInfrastructureTestBase.cs | 28 +++--- ...ameInfrastructureTestBaseWithRandomGame.cs | 19 +--- 10 files changed, 111 insertions(+), 117 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index d6450a28..57298aa5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -30,22 +30,6 @@ protected abstract ITestingModInstallation CreateModInstallation( DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps); - protected ITestingModInstallation CreateOtherModInstallation( - string name, - DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, - params IList deps) - { - return CreateOtherModInstallation(name, GITestUtilities.GetRandomWorkshopFlag(Game), layout, deps); - } - - protected ITestingModInstallation CreateOtherModInstallation( - string name, - bool isWorkshop, - DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, - params IList deps) - { - return CreateAndAddModInstallation(isWorkshop, name, new DependencyList(deps, layout)); - } [Fact] public void VersionRange_IsNull() @@ -61,7 +45,7 @@ public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario var mod = ModTestScenarios.CreateTestScenario( testScenario, (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => CreateOtherModInstallation(name, layout, dependencies).Mod) + (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod) .Mod; var expectedDirectDeps = mod.ModInfo!.Dependencies.Select(d => @@ -160,7 +144,7 @@ public void ResolveDependencies_RaiseEvent() var scenario = ModTestScenarios.CreateTestScenario( ModTestScenarios.TestScenario.SingleDepAndTransitive, (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => CreateOtherModInstallation(name, layout, dependencies).Mod); + (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod); var mod = scenario.Mod; var b = Game.FindMod(scenario.ExpectedTraversedList![1])!; @@ -243,7 +227,7 @@ private static void AssertDependenciesResolved(IMod mod) [Fact] public void EqualsHashCode() { - var dep = CreateOtherModInstallation("B").Mod; + var dep = InstallAndAddMod("B").Mod; var mod = CreateModInstallation("A").Mod; var samish = CreateModInstallation("A").Mod; var otherA = CreateModInstallation("A", deps: dep).Mod; @@ -286,7 +270,7 @@ public class ModBaseAbstractTest : GameInfrastructureTestBaseWithRandomGame [Fact] public void ResolveDependencies_CalledTwice_Throws() { - var dep = CreateAndAddModInstallation("Dep").Mod; + var dep = InstallAndAddMod("Dep").Mod; var modinfo = new ModinfoData("CustomMod") { Dependencies = new DependencyList(new List { dep }, DependencyResolveLayout.FullResolved) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index bab5c62e..3ba15500 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -70,7 +70,7 @@ public void Equals_ShouldAlwaysBeEquals(bool includeDeps, bool includeGame) public void Equals_DependencyAware(bool depAware) { var dep = new ModReference("B", ModType.Default); - var modA = (IPhysicalMod)CreateAndAddModInstallation("A", deps: dep).Mod; + var modA = (IPhysicalMod)InstallAndAddMod("A", deps: dep).Mod; var sameishModindo = new ModinfoData("A") { @@ -107,7 +107,7 @@ public void Equals_DependencyAware(bool depAware) [InlineData(true)] public void Equals_GameAware(bool gameAware) { - var modA = CreateAndAddModInstallation("A").Mod; + var modA = InstallAndAddMod("A").Mod; var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); @@ -140,7 +140,7 @@ public void Equals_GameAware(bool gameAware) [Fact] public void ToJson() { - var mod = CreateAndAddModInstallation("A").Mod; + var mod = InstallAndAddMod("A").Mod; var expected = new ModReference(mod).ToJson(); Assert.Equal(expected, mod.ToJson()); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index eeb5faa0..5a57f2ba 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -26,7 +26,7 @@ public void NullArgs_Throws() [Fact] public void Build_NoDependencies() { - var mod = CreateAndAddModInstallation("A").Mod; + var mod = InstallAndAddMod("A").Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -36,8 +36,8 @@ public void Build_NoDependencies() [Fact] public void Build_OneDependency() { - var b = CreateAndAddModInstallation("B").Mod; - var mod = CreateAndAddModInstallation("A", Random.Enum(), b).Mod; + var b = InstallAndAddMod("B").Mod; + var mod = InstallAndAddMod("A", Random.Enum(), b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -60,8 +60,8 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() { // C is not added to game. Building a graph should not throw, because it's not used. var c = Game.InstallMod("C", false, ServiceProvider); - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.FullResolved, b).Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.FullResolved, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -82,9 +82,9 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() { - var c = CreateAndAddModInstallation("C").Mod; - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var c = InstallAndAddMod("C").Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -107,10 +107,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant1() { - var d = CreateAndAddModInstallation("D").Mod; - var c = CreateAndAddModInstallation("C").Mod; - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; + var d = InstallAndAddMod("D").Mod; + var c = InstallAndAddMod("C").Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -133,10 +133,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant2() { - var d = CreateAndAddModInstallation("D").Mod; - var c = CreateAndAddModInstallation("C").Mod; - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; + var d = InstallAndAddMod("D").Mod; + var c = InstallAndAddMod("C").Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -162,10 +162,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() { - var d = CreateAndAddModInstallation("D").Mod; - var c = CreateAndAddModInstallation("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.ResolveRecursive, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var d = InstallAndAddMod("D").Mod; + var c = InstallAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.ResolveRecursive, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -191,11 +191,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() { - var e = CreateAndAddModInstallation("E").Mod; - var d = CreateAndAddModInstallation("D").Mod; - var c = CreateAndAddModInstallation("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var e = InstallAndAddMod("E").Mod; + var d = InstallAndAddMod("D").Mod; + var c = InstallAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -224,11 +224,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant2() { - var e = CreateAndAddModInstallation("E").Mod; - var d = CreateAndAddModInstallation("D").Mod; - var c = CreateAndAddModInstallation("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var e = InstallAndAddMod("E").Mod; + var d = InstallAndAddMod("D").Mod; + var c = InstallAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -273,7 +273,7 @@ public void Build_TransitiveCycle() { var depA = new ModReference("A", ModType.Default); - var b = CreateAndAddModInstallation("B", Random.Enum(), depA).Mod; + var b = InstallAndAddMod("B", Random.Enum(), depA).Mod; var modinfo = new ModinfoData("A") { @@ -301,7 +301,7 @@ public void Build_SelfNotFound_Throws() public void Build_DirectDependencyNotFound_Throws() { var b = Game.InstallMod("B", false, ServiceProvider); - var mod = CreateAndAddModInstallation("A", Random.Enum(), b).Mod; + var mod = InstallAndAddMod("A", Random.Enum(), b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(b, e.Mod); @@ -311,8 +311,8 @@ public void Build_DirectDependencyNotFound_Throws() public void Build_TransitiveDependencyNotFound_Throws() { var c = Game.InstallMod("C", false, ServiceProvider); - var b = CreateAndAddModInstallation("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(c, e.Mod); @@ -335,10 +335,10 @@ public static IEnumerable GetMatchingVersionRanges() [MemberData(nameof(GetMatchingVersionRanges))] public void Build_OneDependency_VersionRangeMatches(SemVersion? version, SemVersionRange ranges) { - var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = version }).Mod; + var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = version }).Mod; Assert.Equal(version, b.Version); - var mod = CreateAndAddModInstallation("A", Random.Enum(), + var mod = InstallAndAddMod("A", Random.Enum(), new ModReference(b.Identifier, b.Type, ranges)).Mod; var graph = _graphBuilder.Build(mod); @@ -382,13 +382,13 @@ public static IEnumerable GetMismatchingVersionsAndRange() [MemberData(nameof(GetMismatchingVersionsAndRange))] public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion version, SemVersionRange? range) { - var b = CreateAndAddModInstallation(new ModinfoData("B") + var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = version }).Mod; Assert.Equal(version, b.Version); - var mod = CreateAndAddModInstallation("A", Random.Enum(), + var mod = InstallAndAddMod("A", Random.Enum(), new ModReference(b.Identifier, b.Type, range)).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); @@ -400,15 +400,15 @@ public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion ver [MemberData(nameof(GetMismatchingVersionsAndRange))] public void Build_TransitiveDependency_VersionRangeDoesNotMatches_Throws(SemVersion version, SemVersionRange? range) { - var c = CreateAndAddModInstallation(new ModinfoData("C") + var c = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("C") { Version = version }).Mod; Assert.Equal(version, c.Version); - var b = CreateAndAddModInstallation("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; + var b = InstallAndAddMod("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(c), e.Mod); @@ -428,12 +428,12 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th \^ C */ - var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; + var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; - var c = CreateAndAddModInstallation("C", + var c = InstallAndAddMod("C", deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, deps: + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: [ new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))), c @@ -456,12 +456,12 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th > C */ - var b = CreateAndAddModInstallation(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; + var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; - var c = CreateAndAddModInstallation("C", DependencyResolveLayout.ResolveRecursive, + var c = InstallAndAddMod("C", DependencyResolveLayout.ResolveRecursive, deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; - var mod = CreateAndAddModInstallation("A", DependencyResolveLayout.ResolveRecursive, deps: + var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: [ c, // Before b in this variant new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 263d115e..5d7f7db5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -29,8 +29,8 @@ public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) var scenario = ModTestScenarios.CreateTestScenario( testScenario, - (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod); + (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod, + (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod); var mod = scenario.Mod; mod.ResolveDependencies(); @@ -46,7 +46,7 @@ public void Traverse_FaultedResolvedMod_Throws() // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddModInstallation("Mod", Random.Enum(), dep).Mod; + var mod = InstallAndAddMod("Mod", Random.Enum(), dep).Mod; try { @@ -66,7 +66,7 @@ public void Traverse_NotResolvedMod_Throws() { // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = CreateAndAddModInstallation("Mod", Random.Enum(), dep).Mod; + var mod = InstallAndAddMod("Mod", Random.Enum(), dep).Mod; Assert.Equal(DependencyResolveStatus.None, mod.DependencyResolveStatus); Assert.Throws(() => _traverser.Traverse(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index 8f67aed4..b6e1cdb3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -33,7 +33,7 @@ private IModReference CreateModRef(string name) return new ModReference(name, modType); } - private ITestingPhysicalModInstallation CreatePhysicalModInsatllation( + private ITestingPhysicalModInstallation CreatePhysicalModInstallation( string name, string? iconPath = null, ICollection? languages = null, @@ -66,14 +66,14 @@ protected override ITestingModInstallation CreateModInstallation( DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreatePhysicalModInsatllation(name, layout: layout, deps: deps); + return CreatePhysicalModInstallation(name, layout: layout, deps: deps); } protected override ITestingPlayableObjectInstallation CreatePlayableObjectInstallation( string? iconPath = null, ICollection? languages = null) { - return CreatePhysicalModInsatllation("MyMod", iconPath, languages); + return CreatePhysicalModInstallation("MyMod", iconPath, languages); } protected override ITestingModContainerInstallation CreateModContainerInstallation() @@ -152,7 +152,7 @@ public void ValidCtor_Properties_FromModinfo_WithoutDependencies() [Fact] public void ValidCtor_Properties_FromModinfo_WithDependencies() { - var dep = CreateOtherModInstallation("dep").Mod; + var dep = InstallAndAddMod("dep").Mod; var ws = GITestUtilities.GetRandomWorkshopFlag(Game); @@ -188,7 +188,7 @@ public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestS var mod = ModTestScenarios.CreateTestScenarioCycle( testScenario, (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => CreateOtherModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod, CreateModRef) .Mod; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 4bb017c1..7546063a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -26,7 +26,7 @@ private ITestingVirtualModInstallation CreateVirtualMod( IModDependencyList depList; if (deps.Count == 0) { - var dep = CreateOtherModInstallation("dep", false).Mod; + var dep = InstallAndAddMod("dep", false).Mod; depList = new DependencyList(new List { dep }, layout); } else @@ -91,7 +91,7 @@ public void Ctor_EmptyDependencies_Throws() [Fact] public void Ctor_FromModinfo_Properties() { - var dep = CreateOtherModInstallation("dep").Mod; + var dep = InstallAndAddMod("dep").Mod; var modinfo = new ModinfoData("VirtualMod") { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs index 3b80ce44..2be44e55 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs @@ -16,9 +16,15 @@ public interface ITestingGameInstallation : ITestingModContainerInstallation ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop); - ITestingPhysicalModInstallation InstallAndAddMod(bool workshop, IModinfo modinfo); + ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo); + + ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, bool workshop); ITestingPhysicalModInstallation InstallAndAddMod(IDirectoryInfo directory, bool workshop, IModinfo modinfo); - + + ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWorkshop, IModDependencyList dependencies); + + ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDependencyList dependencies); + ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs index c07a2f20..04d11d13 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs @@ -49,7 +49,12 @@ public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool worksh return new TestingPhysicalModImpl(this, mod, _serviceProvider); } - public ITestingPhysicalModInstallation InstallAndAddMod(bool workshop, IModinfo modinfo) + public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo) + { + return InstallAndAddMod(modinfo, GITestUtilities.GetRandomWorkshopFlag(Game)); + } + + public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, bool workshop) { var mod = Game.InstallMod(workshop, modinfo, _serviceProvider); Game.AddMod(mod); @@ -63,6 +68,12 @@ public ITestingPhysicalModInstallation InstallAndAddMod(IDirectoryInfo directory return new TestingPhysicalModImpl(this, mod, _serviceProvider); } + public ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDependencyList dependencies) + { + var workshop = GITestUtilities.GetRandomWorkshopFlag(Game); + return InstallAndAddMod(name, workshop, dependencies); + } + public ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo) { var mod = new VirtualMod(Game, "VirtualModId", modinfo, _serviceProvider); @@ -70,6 +81,18 @@ public ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData mod return new TestingVirtualModImpl(this, mod, _serviceProvider); } + public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWorkshop, IModDependencyList dependencies) + { + if (dependencies.Count == 0) + return InstallAndAddMod(name, isWorkshop); + + var modinfo = new ModinfoData(name) + { + Dependencies = dependencies + }; + return InstallAndAddMod(modinfo, isWorkshop); + } + private IGame Install(IGameIdentity gameIdentity) { var gameDir = gameIdentity.Type == GameType.Foc diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index ff3bcb44..8f864114 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -6,6 +6,7 @@ using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +using System.Collections.Generic; using System.IO.Abstractions; using System.Threading; using Testably.Abstractions.Testing; @@ -14,10 +15,9 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { - protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); - private ITestingGameInstallation? _gameInstallation; + protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); protected virtual IFileSystem CreateFileSystem() { @@ -39,22 +39,20 @@ protected virtual ITestingGameInstallation GetOrCreateGameInstallation(IGameIden return _gameInstallation = GameInfrastructureTesting.Game(identity, ServiceProvider); } - - // TODO: To installation - protected ITestingModInstallation CreateAndAddModInstallation(bool isWorkshop, string name, IModDependencyList dependencies) + protected ITestingPhysicalModInstallation InstallAndAddMod( + string name, + DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, + params IList deps) { - if (dependencies.Count == 0) - return GetOrCreateGameInstallation().InstallAndAddMod(name, isWorkshop); - - var modinfo = new ModinfoData(name) - { - Dependencies = dependencies - }; - return CreateAndAddModInstallation(isWorkshop, modinfo); + return GetOrCreateGameInstallation().InstallAndAddMod(name, new DependencyList(deps, layout)); } - protected ITestingModInstallation CreateAndAddModInstallation(bool isWorkshop, IModinfo modinfo) + protected ITestingPhysicalModInstallation InstallAndAddMod( + string name, + bool workshop, + DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, + params IList deps) { - return GetOrCreateGameInstallation().InstallAndAddMod(isWorkshop, modinfo); + return GetOrCreateGameInstallation().InstallAndAddMod(name, workshop, new DependencyList(deps, layout)); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index bc249649..a5fb59b2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -1,9 +1,5 @@ -using System.Collections.Generic; -using AET.Modinfo.Model; -using AET.Modinfo.Spec; -using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; @@ -12,17 +8,4 @@ public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastruct protected IGame Game => GameInstallation.Game; protected ITestingGameInstallation GameInstallation => GetOrCreateGameInstallation(identity: null); - - protected ITestingModInstallation CreateAndAddModInstallation( - string name, - DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, - params IList deps) - { - return CreateAndAddModInstallation(GITestUtilities.GetRandomWorkshopFlag(Game), name, new DependencyList(deps, layout)); - } - - protected ITestingModInstallation CreateAndAddModInstallation(IModinfo modinfo) - { - return CreateAndAddModInstallation(GITestUtilities.GetRandomWorkshopFlag(Game), modinfo); - } } \ No newline at end of file From 98757eb92e29373f764c3aa1860aaa3efedc35c7 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 14:12:45 +0100 Subject: [PATCH 30/71] move more code --- .../ModBaseTest.cs | 8 ++++--- .../Dependencies/ModDependencyResolverTest.cs | 2 +- .../PlayableModContainerTest.cs | 2 +- .../Services/IconFinderTest.cs | 7 +++---- .../Services/LanguageFinderTestBase.cs | 21 +++++++++---------- .../VirtualModTest.cs | 3 +-- .../Installation/ITestingGameInstallation.cs | 2 ++ .../Game/Installation/TestingGameImpl.cs | 6 ++++++ .../Installations/Mods/ModInstallations.cs | 7 ------- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 57298aa5..881196db 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -13,16 +13,18 @@ using PG.StarWarsGame.Infrastructure.Testing.TestBases; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; namespace PG.StarWarsGame.Infrastructure.Test; public abstract class ModBaseTest : PlayableModContainerTest { - protected readonly IGame Game; + protected IGame Game => GameInstallation.Game; + protected ITestingGameInstallation GameInstallation { get; } protected ModBaseTest() { - Game = GetOrCreateGameInstallation().Game; + GameInstallation = GetOrCreateGameInstallation(); } protected abstract ITestingModInstallation CreateModInstallation( @@ -89,7 +91,7 @@ public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectl public void ResolveDependencies_DepOfWrongGame_Throws() { var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); - var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod", GITestUtilities.GetRandomWorkshopFlag(otherGameInstallRef.Game)); + var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod"); var mod = CreateModInstallation("Mod", Random.Enum(), wrongGameDep.Mod).Mod; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs index 0c229900..00ed784c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs @@ -129,7 +129,7 @@ public void Resolve_ResolveCompleteChain_DependenciesHaveResolvedDeps_ButResolve private IMod CreateMod(string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IModReference[] deps) { if (deps.Length == 0) - return GameInstallation.InstallAndAddMod(name, GITestUtilities.GetRandomWorkshopFlag(Game)).Mod; + return GameInstallation.InstallAndAddMod(name).Mod; var modinfo = new ModinfoData("A") { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs index a0b967cc..dddfe21e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs @@ -93,7 +93,7 @@ public void AddMod_DifferentGameRef_Throws() // Same game, just different reference var otherInstallation = GameInfrastructureTesting.Game(game, ServiceProvider); - var mod = otherInstallation.InstallAndAddMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game)).Mod; + var mod = otherInstallation.InstallAndAddMod(_randomModName).Mod; Assert.Throws(() => container.AddMod(mod)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs index 2a45a42a..dd6f7b89 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs @@ -57,7 +57,7 @@ public void FindIcon_Game_NotInstalledWrongLocation() [Fact] public void FindIcon_Mod_NotInstalled() { - var mod = Game.InstallAndAddMod("Mod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var mod = GameInstallation.InstallAndAddMod("Mod").Mod; FileSystem.File.Create(FileSystem.Path.Combine(mod.Directory.FullName, "Data", "icon.ico")); FileSystem.File.Create(FileSystem.Path.Combine(mod.Directory.FullName, "icon.txt")); FileSystem.File.Create(FileSystem.Path.Combine(mod.Directory.FullName, "icon.ic")); @@ -67,8 +67,7 @@ public void FindIcon_Mod_NotInstalled() [Fact] public void FindIcon_Mod_Installed() { - var mod = Game.InstallAndAddMod("Mod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - + var mod = GameInstallation.InstallAndAddMod("Mod").Mod; var icon1 = $"{FileSystem.Path.GetRandomFileName()}.ico"; var icon2 = $"{FileSystem.Path.GetRandomFileName()}.ico"; @@ -167,7 +166,7 @@ public void FindIcon_Mod_UseIconFromGame() [Fact] public void FindIcon_VirtualMod_UseIconFromModinfo() { - var dep = Game.InstallAndAddMod("dep", false, ServiceProvider); + var dep = GameInstallation.InstallAndAddMod("Mod", false).Mod; var mod = new VirtualMod(Game, "Mod", new ModinfoData("Mod") { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 2cbe135b..9baddd45 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -88,7 +88,7 @@ public void FindLanguages_Mod_WithLanguages_En_De_Steam() [Fact] public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguages() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); @@ -114,7 +114,7 @@ public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguages() [Fact] public void FindLanguages_Mod_InheritLanguage_TargetAndDependencyModDoNotHaveLanguages() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; var modInfo = new ModinfoData("myMod") { @@ -134,7 +134,7 @@ public void FindLanguages_Mod_InheritLanguage_TargetAndDependencyModDoNotHaveLan [Fact] public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguagesAndDependencyIsNotResolved() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; var modInfo = new ModinfoData("myMod") { @@ -154,7 +154,7 @@ public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguagesAndDe [Fact] public void FindLanguages_Mod_TargetModDoesHaveDefaultLanguageInstalled() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); @@ -180,8 +180,7 @@ public void FindLanguages_Mod_TargetModDoesHaveDefaultLanguageInstalled() [Fact] public void FindLanguages_Mod_TargetModDoesHaveModinfoLanguages() { - - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); @@ -217,7 +216,7 @@ public void FindLanguages_Mod_TargetModDoesHaveModinfoLanguages() [Fact] public void FindLanguages_Mod_TargetModDoesHaveModinfoWithDefaultLanguagesExplicitlySet() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); @@ -249,7 +248,7 @@ public void FindLanguages_Mod_TargetModDoesHaveModinfoWithDefaultLanguagesExplic public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndDependencyAlsoDoesNotHaveLanguages_UsesGameFallback() { InstallGameLanguage(new LanguageInfo("de", LanguageSupportLevel.SFX)); - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List @@ -268,7 +267,7 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndDependencyAlsoDoes [Fact] public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndTransitiveDependencyHasLanguages() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); var middleModInfo = new ModinfoData("middleMod") { @@ -296,9 +295,9 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndTransitiveDependen [Fact] public void FindLanguages_VirtualMod_TargetModDoesNotHaveLanguagesAndSecondDependencyHasLanguages() { - var baseMod = Game.InstallAndAddMod("baseMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); - var middleMod = Game.InstallAndAddMod("middleMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var middleMod = GameInstallation.InstallAndAddMod("middleMod").Mod; var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 7546063a..68aa4b62 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -6,7 +6,6 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; -using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Semver; @@ -67,7 +66,7 @@ protected override ITestingModContainerInstallation CreateModContainerInstallati [Fact] public void InvalidCtor_ArgumentNull_Throws() { - Game.InstallAndAddMod("Dep", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + GameInstallation.InstallAndAddMod("Dep"); Assert.Throws(() => new VirtualMod(null!, "VirtualModId", new ModinfoData("Name"), ServiceProvider)); Assert.Throws(() => new VirtualMod(Game, "VirtualModId", null!, ServiceProvider)); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs index 2be44e55..784ed216 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs @@ -14,6 +14,8 @@ public interface ITestingGameInstallation : ITestingModContainerInstallation IDirectoryInfo GetWrongOriginFocRegistryLocation(); + ITestingPhysicalModInstallation InstallAndAddMod(string name); + ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop); ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs index 04d11d13..fb78f781 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs @@ -42,6 +42,12 @@ public IDirectoryInfo GetWrongOriginFocRegistryLocation() return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); } + public ITestingPhysicalModInstallation InstallAndAddMod(string name) + { + var isWorkshop = GITestUtilities.GetRandomWorkshopFlag(Game); + return InstallAndAddMod(name, isWorkshop); + } + public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop) { var mod = Game.InstallMod(name, workshop, _serviceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs index 0ed52ef8..f3cf2c8f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs @@ -12,13 +12,6 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public static partial class ModInstallations { - public static Mod InstallAndAddMod(this IGame game, string name, bool workshop, IServiceProvider serviceProvider) - { - var mod = game.InstallMod(name, workshop, serviceProvider); - game.AddMod(mod); - return mod; - } - public static Mod InstallAndAddMod(this IGame game, bool workshop, IModinfo modinfo, IServiceProvider serviceProvider) { var mod = game.InstallMod(workshop, modinfo, serviceProvider); From 14258454cc82da2ec5e8462a50d4a509cbbf2d4c Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 14:44:14 +0100 Subject: [PATCH 31/71] rename methods --- .../ModBaseTest.cs | 8 +- .../ModEqualityComparerTest.cs | 6 +- .../ModDependencyGraphBuilderTest.cs | 88 +++++++++---------- .../Dependencies/ModDependencyResolverTest.cs | 51 ++++------- .../ModDependencyTraverserTest.cs | 8 +- .../ModTest.cs | 6 +- .../Services/IconFinderTest.cs | 14 ++- .../Services/LanguageFinderTestBase.cs | 16 ++-- .../VirtualModTest.cs | 4 +- .../Installations/Mods/ModInstallations.cs | 7 -- .../TestBases/GameInfrastructureTestBase.cs | 11 +-- 11 files changed, 93 insertions(+), 126 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 881196db..d3a77726 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -47,7 +47,7 @@ public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario var mod = ModTestScenarios.CreateTestScenario( testScenario, (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod) + (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod) .Mod; var expectedDirectDeps = mod.ModInfo!.Dependencies.Select(d => @@ -146,7 +146,7 @@ public void ResolveDependencies_RaiseEvent() var scenario = ModTestScenarios.CreateTestScenario( ModTestScenarios.TestScenario.SingleDepAndTransitive, (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod); + (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod); var mod = scenario.Mod; var b = Game.FindMod(scenario.ExpectedTraversedList![1])!; @@ -229,7 +229,7 @@ private static void AssertDependenciesResolved(IMod mod) [Fact] public void EqualsHashCode() { - var dep = InstallAndAddMod("B").Mod; + var dep = GameInstallation.InstallAndAddMod("B").Mod; var mod = CreateModInstallation("A").Mod; var samish = CreateModInstallation("A").Mod; var otherA = CreateModInstallation("A", deps: dep).Mod; @@ -272,7 +272,7 @@ public class ModBaseAbstractTest : GameInfrastructureTestBaseWithRandomGame [Fact] public void ResolveDependencies_CalledTwice_Throws() { - var dep = InstallAndAddMod("Dep").Mod; + var dep = GameInstallation.InstallAndAddMod("Dep").Mod; var modinfo = new ModinfoData("CustomMod") { Dependencies = new DependencyList(new List { dep }, DependencyResolveLayout.FullResolved) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index 3ba15500..0e2243a7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -70,7 +70,7 @@ public void Equals_ShouldAlwaysBeEquals(bool includeDeps, bool includeGame) public void Equals_DependencyAware(bool depAware) { var dep = new ModReference("B", ModType.Default); - var modA = (IPhysicalMod)InstallAndAddMod("A", deps: dep).Mod; + var modA = (IPhysicalMod)InstallAndAddModWithDependencies("A", deps: dep).Mod; var sameishModindo = new ModinfoData("A") { @@ -107,7 +107,7 @@ public void Equals_DependencyAware(bool depAware) [InlineData(true)] public void Equals_GameAware(bool gameAware) { - var modA = InstallAndAddMod("A").Mod; + var modA = GameInstallation.InstallAndAddMod("A").Mod; var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); @@ -140,7 +140,7 @@ public void Equals_GameAware(bool gameAware) [Fact] public void ToJson() { - var mod = InstallAndAddMod("A").Mod; + var mod = GameInstallation.InstallAndAddMod("A").Mod; var expected = new ModReference(mod).ToJson(); Assert.Equal(expected, mod.ToJson()); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 5a57f2ba..3a07007a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -26,7 +26,7 @@ public void NullArgs_Throws() [Fact] public void Build_NoDependencies() { - var mod = InstallAndAddMod("A").Mod; + var mod = GameInstallation.InstallAndAddMod("A").Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -36,8 +36,8 @@ public void Build_NoDependencies() [Fact] public void Build_OneDependency() { - var b = InstallAndAddMod("B").Mod; - var mod = InstallAndAddMod("A", Random.Enum(), b).Mod; + var b = GameInstallation.InstallAndAddMod("B").Mod; + var mod = InstallAndAddModWithDependencies("A", Random.Enum(), b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -60,8 +60,8 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() { // C is not added to game. Building a graph should not throw, because it's not used. var c = Game.InstallMod("C", false, ServiceProvider); - var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.FullResolved, b).Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.FullResolved, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -82,9 +82,9 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() { - var c = InstallAndAddMod("C").Mod; - var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var c = GameInstallation.InstallAndAddMod("C").Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -107,10 +107,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveRecursive() [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant1() { - var d = InstallAndAddMod("D").Mod; - var c = InstallAndAddMod("C").Mod; - var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; + var d = GameInstallation.InstallAndAddMod("D").Mod; + var c = GameInstallation.InstallAndAddMod("C").Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveLastItem, b, d).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -133,10 +133,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Variant2() { - var d = InstallAndAddMod("D").Mod; - var c = InstallAndAddMod("C").Mod; - var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; + var d = GameInstallation.InstallAndAddMod("D").Mod; + var c = GameInstallation.InstallAndAddMod("C").Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveLastItem, d, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -162,10 +162,10 @@ public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_ResolveLastItem_Var [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() { - var d = InstallAndAddMod("D").Mod; - var c = InstallAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = InstallAndAddMod("B", DependencyResolveLayout.ResolveRecursive, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var d = GameInstallation.InstallAndAddMod("D").Mod; + var c = InstallAndAddModWithDependencies("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.ResolveRecursive, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -191,11 +191,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveRecursive() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() { - var e = InstallAndAddMod("E").Mod; - var d = InstallAndAddMod("D").Mod; - var c = InstallAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = InstallAndAddMod("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var e = GameInstallation.InstallAndAddMod("E").Mod; + var d = GameInstallation.InstallAndAddMod("D").Mod; + var c = InstallAndAddModWithDependencies("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.ResolveLastItem, e, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -224,11 +224,11 @@ public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant1() [Fact] public void Build_ResolveLayoutFromTransitiveApplied_ResolveLastItem_Variant2() { - var e = InstallAndAddMod("E").Mod; - var d = InstallAndAddMod("D").Mod; - var c = InstallAndAddMod("C", DependencyResolveLayout.FullResolved, d).Mod; - var b = InstallAndAddMod("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var e = GameInstallation.InstallAndAddMod("E").Mod; + var d = GameInstallation.InstallAndAddMod("D").Mod; + var c = InstallAndAddModWithDependencies("C", DependencyResolveLayout.FullResolved, d).Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.ResolveLastItem, c, e).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var graph = _graphBuilder.Build(mod); Assert.False(graph.HasCycle()); @@ -262,7 +262,7 @@ public void Build_DirectCycle() depA }, Random.Enum()) }; - var mod = Game.InstallAndAddMod(false, modinfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modinfo, false).Mod; var graph = _graphBuilder.Build(mod); Assert.True(graph.HasCycle()); @@ -273,7 +273,7 @@ public void Build_TransitiveCycle() { var depA = new ModReference("A", ModType.Default); - var b = InstallAndAddMod("B", Random.Enum(), depA).Mod; + var b = InstallAndAddModWithDependencies("B", Random.Enum(), depA).Mod; var modinfo = new ModinfoData("A") { @@ -282,7 +282,7 @@ public void Build_TransitiveCycle() b }, DependencyResolveLayout.ResolveRecursive) }; - var mod = Game.InstallAndAddMod(false, modinfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modinfo, false).Mod; var graph = _graphBuilder.Build(mod); Assert.True(graph.HasCycle()); @@ -301,7 +301,7 @@ public void Build_SelfNotFound_Throws() public void Build_DirectDependencyNotFound_Throws() { var b = Game.InstallMod("B", false, ServiceProvider); - var mod = InstallAndAddMod("A", Random.Enum(), b).Mod; + var mod = InstallAndAddModWithDependencies("A", Random.Enum(), b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(b, e.Mod); @@ -311,8 +311,8 @@ public void Build_DirectDependencyNotFound_Throws() public void Build_TransitiveDependencyNotFound_Throws() { var c = Game.InstallMod("C", false, ServiceProvider); - var b = InstallAndAddMod("B", DependencyResolveLayout.FullResolved, c).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(c, e.Mod); @@ -338,7 +338,7 @@ public void Build_OneDependency_VersionRangeMatches(SemVersion? version, SemVers var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = version }).Mod; Assert.Equal(version, b.Version); - var mod = InstallAndAddMod("A", Random.Enum(), + var mod = InstallAndAddModWithDependencies("A", Random.Enum(), new ModReference(b.Identifier, b.Type, ranges)).Mod; var graph = _graphBuilder.Build(mod); @@ -388,7 +388,7 @@ public void Build_OneDependency_VersionRangeDoesNotMatches_Throws(SemVersion ver }).Mod; Assert.Equal(version, b.Version); - var mod = InstallAndAddMod("A", Random.Enum(), + var mod = InstallAndAddModWithDependencies("A", Random.Enum(), new ModReference(b.Identifier, b.Type, range)).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); @@ -406,9 +406,9 @@ public void Build_TransitiveDependency_VersionRangeDoesNotMatches_Throws(SemVers }).Mod; Assert.Equal(version, c.Version); - var b = InstallAndAddMod("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; + var b = InstallAndAddModWithDependencies("B", deps: new List{new ModReference(c.Identifier, c.Type, range)}).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, b).Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Equal(new ModReference(c), e.Mod); @@ -430,10 +430,10 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th */ var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; - var c = InstallAndAddMod("C", + var c = InstallAndAddModWithDependencies("C", deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, deps: [ new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))), c @@ -458,10 +458,10 @@ public void Build_VersionMismatchInOnlyOneRef_WhereEqualRefHasMatchingVersion_Th */ var b = GetOrCreateGameInstallation().InstallAndAddMod(new ModinfoData("B") { Version = new SemVersion(1, 0, 0) }).Mod; - var c = InstallAndAddMod("C", DependencyResolveLayout.ResolveRecursive, + var c = InstallAndAddModWithDependencies("C", DependencyResolveLayout.ResolveRecursive, deps: new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(2, 0, 0)))).Mod; - var mod = InstallAndAddMod("A", DependencyResolveLayout.ResolveRecursive, deps: + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, deps: [ c, // Before b in this variant new ModReference(b.Identifier, b.Type, SemVersionRange.Equals(new SemVersion(1, 0, 0))) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs index 00ed784c..ff631831 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyResolverTest.cs @@ -4,8 +4,6 @@ using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; -using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -30,7 +28,7 @@ public void InvalidArgs_Throws() [Fact] public void Resolve_NoDependencies() { - var mod = CreateMod("A"); + var mod = GameInstallation.InstallAndAddMod("A").Mod; var dependencies = _resolver.Resolve(mod); Assert.Empty(dependencies); } @@ -45,7 +43,7 @@ public void Resolve_DependencyNot_Found() new ModReference("B", ModType.Default) }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallAndAddMod(false, modinfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modinfo, false).Mod; Assert.Throws(() => _resolver.Resolve(mod)); } @@ -61,15 +59,15 @@ public void Resolve_SelfDependency_WithCycleCheck_Throws() depA }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallAndAddMod(false, modinfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modinfo, false).Mod; Assert.Throws(() => _resolver.Resolve(mod)); } [Fact] public void Resolve_SingleDependency() { - var dep = CreateMod("B"); - var mod = CreateMod("A", DependencyResolveLayout.FullResolved, new ModReference(dep)); + var dep = GameInstallation.InstallAndAddMod("B").Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.FullResolved, new ModReference(dep)).Mod; var deps = _resolver.Resolve(mod); @@ -80,9 +78,9 @@ public void Resolve_SingleDependency() [Fact] public void Resolve_TwoDependency() { - var b = CreateMod("B"); - var c = CreateMod("C"); - var mod = CreateMod("A", DependencyResolveLayout.FullResolved, b, c); + var b = GameInstallation.InstallAndAddMod("B").Mod; + var c = GameInstallation.InstallAndAddMod("C").Mod; + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.FullResolved, b, c).Mod; var deps = _resolver.Resolve(mod); @@ -92,12 +90,12 @@ public void Resolve_TwoDependency() [Fact] public void Resolve_ResolveCompleteChain_DependenciesHaveDeps_ButResolveLayoutIsFullResolved() { - var b2 = CreateMod("B2"); - var b = CreateMod("B", DependencyResolveLayout.ResolveRecursive, b2); - var c2 = CreateMod("C2"); - var c = CreateMod("C", DependencyResolveLayout.ResolveRecursive, c2); + var b2 = GameInstallation.InstallAndAddMod("B2").Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.ResolveRecursive, b2).Mod; + var c2 = GameInstallation.InstallAndAddMod("C2").Mod; + var c = InstallAndAddModWithDependencies("C", DependencyResolveLayout.ResolveRecursive, c2).Mod; // Layout is recursive - var mod = CreateMod("A", DependencyResolveLayout.FullResolved, b, c); + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.FullResolved, b, c).Mod; var deps = _resolver.Resolve(mod); @@ -112,30 +110,17 @@ public void Resolve_ResolveCompleteChain_DependenciesHaveDeps_ButResolveLayoutIs [Fact] public void Resolve_ResolveCompleteChain_DependenciesHaveResolvedDeps_ButResolveLayoutIsFullResolved() { - var b2 = CreateMod("B2"); - var b = CreateMod("B", DependencyResolveLayout.ResolveRecursive, b2); + var b2 = GameInstallation.InstallAndAddMod("B2").Mod; + var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.ResolveRecursive, b2).Mod; b.ResolveDependencies(); - var c2 = CreateMod("C2"); - var c = CreateMod("C", DependencyResolveLayout.ResolveRecursive, c2); + var c2 = GameInstallation.InstallAndAddMod("C2").Mod; + var c = InstallAndAddModWithDependencies("C", DependencyResolveLayout.ResolveRecursive, c2).Mod; c.ResolveDependencies(); - var mod = CreateMod("A", DependencyResolveLayout.FullResolved, b, c); + var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.FullResolved, b, c).Mod; var deps = _resolver.Resolve(mod); // Only b and c, because a has layout FullResolved Assert.Equal([b, c], deps); } - - private IMod CreateMod(string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IModReference[] deps) - { - if (deps.Length == 0) - return GameInstallation.InstallAndAddMod(name).Mod; - - var modinfo = new ModinfoData("A") - { - Dependencies = new DependencyList(deps, layout) - }; - - return Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modinfo, ServiceProvider); - } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 5d7f7db5..20c507c3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -29,8 +29,8 @@ public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) var scenario = ModTestScenarios.CreateTestScenario( testScenario, - (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod, - (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod); + (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod, + (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod); var mod = scenario.Mod; mod.ResolveDependencies(); @@ -46,7 +46,7 @@ public void Traverse_FaultedResolvedMod_Throws() // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = InstallAndAddMod("Mod", Random.Enum(), dep).Mod; + var mod = InstallAndAddModWithDependencies("Mod", Random.Enum(), dep).Mod; try { @@ -66,7 +66,7 @@ public void Traverse_NotResolvedMod_Throws() { // Do not add to provoke faulted var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); - var mod = InstallAndAddMod("Mod", Random.Enum(), dep).Mod; + var mod = InstallAndAddModWithDependencies("Mod", Random.Enum(), dep).Mod; Assert.Equal(DependencyResolveStatus.None, mod.DependencyResolveStatus); Assert.Throws(() => _traverser.Traverse(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index b6e1cdb3..b0321b89 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -152,7 +152,7 @@ public void ValidCtor_Properties_FromModinfo_WithoutDependencies() [Fact] public void ValidCtor_Properties_FromModinfo_WithDependencies() { - var dep = InstallAndAddMod("dep").Mod; + var dep = GameInstallation.InstallAndAddMod("dep").Mod; var ws = GITestUtilities.GetRandomWorkshopFlag(Game); @@ -160,7 +160,7 @@ public void ValidCtor_Properties_FromModinfo_WithDependencies() { Dependencies = new DependencyList(new List{ dep }, DependencyResolveLayout.ResolveLastItem) }; - var mod = Game.InstallAndAddMod(ws, modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo, ws).Mod; Assert.Empty(mod.Dependencies); Assert.Single(((IModIdentity)mod).Dependencies); @@ -188,7 +188,7 @@ public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestS var mod = ModTestScenarios.CreateTestScenarioCycle( testScenario, (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, - (name, layout, dependencies) => InstallAndAddMod(name, layout, dependencies).Mod, + (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod, CreateModRef) .Mod; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs index dd6f7b89..e77093d1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/IconFinderTest.cs @@ -5,8 +5,6 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Icon; -using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using PG.StarWarsGame.Infrastructure.Utilities; using Xunit; @@ -86,7 +84,7 @@ public void FindIcon_Mod_Installed() [Fact] public void FindIcon_Mod_UseIconFromFs_ModinfoIconIsNull() { - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), new ModinfoData("name"), ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(new ModinfoData("name")).Mod; var icon1 = $"{FileSystem.Path.GetRandomFileName()}.ico"; var icon2 = $"{FileSystem.Path.GetRandomFileName()}.ico"; @@ -106,10 +104,10 @@ public void FindIcon_Mod_UseIconFromFs_ModinfoIconIsNull() [Fact] public void FindIcon_Mod_UseIconFromFs_ModinfoIconIsEmpty() { - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), new ModinfoData("name") + var mod = GameInstallation.InstallAndAddMod(new ModinfoData("name") { Icon = string.Empty - }, ServiceProvider); + }).Mod; var icon1 = $"{FileSystem.Path.GetRandomFileName()}.ico"; var icon2 = $"{FileSystem.Path.GetRandomFileName()}.ico"; @@ -129,10 +127,10 @@ public void FindIcon_Mod_UseIconFromFs_ModinfoIconIsEmpty() [Fact] public void FindIcon_Mod_UseIconFromModinfo() { - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), new ModinfoData("name") + var mod = GameInstallation.InstallAndAddMod(new ModinfoData("name") { Icon = "icon.ico" - }, ServiceProvider); + }).Mod; var icon1 = $"{FileSystem.Path.GetRandomFileName()}.ico"; var icon2 = $"{FileSystem.Path.GetRandomFileName()}.ico"; @@ -152,7 +150,7 @@ public void FindIcon_Mod_UseIconFromGame() FileSystem.File.Create(FileSystem.Path.Combine(Game.Directory.FullName, "foc.ico")); var expectedFileName = Game.Type == GameType.Eaw ? "eaw.ico" : "foc.ico"; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), new ModinfoData("name"), ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(new ModinfoData("name")).Mod; FileSystem.File.Create(FileSystem.Path.Combine(mod.Directory.FullName, "Data", "notAnIcon.ico")); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 9baddd45..5e08f4a6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -99,7 +99,7 @@ public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguages() new ModReference(baseMod) }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); var langs = _languageFinder.FindLanguages(mod); @@ -123,7 +123,7 @@ public void FindLanguages_Mod_InheritLanguage_TargetAndDependencyModDoNotHaveLan new ModReference(baseMod) }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); var langs = _languageFinder.FindLanguages(mod); @@ -165,7 +165,7 @@ public void FindLanguages_Mod_TargetModDoesHaveDefaultLanguageInstalled() new ModReference(baseMod) }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); // Only english is installed @@ -196,7 +196,7 @@ public void FindLanguages_Mod_TargetModDoesHaveModinfoLanguages() new LanguageInfo("de", LanguageSupportLevel.SFX) } }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); // Should not be considered @@ -229,7 +229,7 @@ public void FindLanguages_Mod_TargetModDoesHaveModinfoWithDefaultLanguagesExplic // Set language Languages = new List { LanguageInfo.Default } }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); // Should not be considered @@ -256,7 +256,7 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndDependencyAlsoDoes new ModReference(baseMod) }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); var langs = _languageFinder.FindLanguages(mod); @@ -276,7 +276,7 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndTransitiveDependen new ModReference(baseMod) }, DependencyResolveLayout.FullResolved) }; - var middleMod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), middleModInfo, ServiceProvider); + var middleMod = GameInstallation.InstallAndAddMod(middleModInfo).Mod; var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List @@ -284,7 +284,7 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndTransitiveDependen new ModReference(middleMod) }, DependencyResolveLayout.ResolveRecursive) }; - var mod = Game.InstallAndAddMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; mod.ResolveDependencies(); var langs = _languageFinder.FindLanguages(mod); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 68aa4b62..80d86687 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -25,7 +25,7 @@ private ITestingVirtualModInstallation CreateVirtualMod( IModDependencyList depList; if (deps.Count == 0) { - var dep = InstallAndAddMod("dep", false).Mod; + var dep = GameInstallation.InstallAndAddMod("dep", false).Mod; depList = new DependencyList(new List { dep }, layout); } else @@ -90,7 +90,7 @@ public void Ctor_EmptyDependencies_Throws() [Fact] public void Ctor_FromModinfo_Properties() { - var dep = InstallAndAddMod("dep").Mod; + var dep = GameInstallation.InstallAndAddMod("dep").Mod; var modinfo = new ModinfoData("VirtualMod") { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs index f3cf2c8f..f44f3993 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs @@ -12,13 +12,6 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public static partial class ModInstallations { - public static Mod InstallAndAddMod(this IGame game, bool workshop, IModinfo modinfo, IServiceProvider serviceProvider) - { - var mod = game.InstallMod(workshop, modinfo, serviceProvider); - game.AddMod(mod); - return mod; - } - public static Mod InstallMod(this IGame game, string name, bool workshop, IServiceProvider serviceProvider) { return CreateMod(game, name, workshop, serviceProvider, diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 8f864114..d1e2f533 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -39,20 +39,11 @@ protected virtual ITestingGameInstallation GetOrCreateGameInstallation(IGameIden return _gameInstallation = GameInfrastructureTesting.Game(identity, ServiceProvider); } - protected ITestingPhysicalModInstallation InstallAndAddMod( + protected ITestingPhysicalModInstallation InstallAndAddModWithDependencies( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { return GetOrCreateGameInstallation().InstallAndAddMod(name, new DependencyList(deps, layout)); } - - protected ITestingPhysicalModInstallation InstallAndAddMod( - string name, - bool workshop, - DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, - params IList deps) - { - return GetOrCreateGameInstallation().InstallAndAddMod(name, workshop, new DependencyList(deps, layout)); - } } \ No newline at end of file From bc43818c96c36ca80b513557cf76a6801013559b Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 15:45:05 +0100 Subject: [PATCH 32/71] move more code --- .../Arguments/GameArgumentsBuilderTest.cs | 36 ++++++------- .../PetroglyphStarWarsGameClientTest.cs | 10 ++-- .../ModBaseTest.cs | 2 +- .../ModEqualityComparerTest.cs | 14 +++--- .../ModDependencyGraphBuilderTest.cs | 10 ++-- .../ModDependencyTraverserTest.cs | 6 +-- .../ModServices/ModFactoryTest.cs | 15 +++--- .../ModServices/ModFinderTest.cs | 48 +++++++++++------- .../ModGameTypeResolverTestBase.cs | 8 +-- ...oglyphGameInfrastructureIntegrationTest.cs | 14 ++++-- .../PlayableModContainerTest.cs | 50 ++++++++----------- .../Services/LanguageFinderTestBase.cs | 6 +-- .../Installation/ITestingGameInstallation.cs | 4 ++ .../Game/Installation/TestingGameImpl.cs | 19 +++++-- .../Installations/Mods/ModInstallations.cs | 8 +-- 15 files changed, 134 insertions(+), 116 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index dc391c0a..1d1150e8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -6,7 +6,7 @@ using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Testably.Abstractions.Testing; using Xunit; @@ -18,10 +18,27 @@ public sealed class GameArgumentsBuilderTest : GameInfrastructureTestBase private readonly MockFileSystem _fileSystem = new(); private readonly GameArgumentsBuilder _builder = new(); private readonly IGame _game; + private readonly ITestingGameInstallation _gameInstallation; public GameArgumentsBuilderTest() { - _game = GetOrCreateGameInstallation(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)).Game; + _gameInstallation = GetOrCreateGameInstallation(new GameIdentity(GameType.Foc, GamePlatform.SteamGold)); + _game = _gameInstallation.Game; + } + + private IPhysicalMod CreateMod(string name) + { + return _gameInstallation.InstallMod(name, false).Mod; + } + + private (IMod virtualMod, IPhysicalMod dep) CreateVirtualMod() + { + var dep = CreateMod("dep"); + var modinfo = new ModinfoData("VirtualMod") + { + Dependencies = new DependencyList([dep], DependencyResolveLayout.FullResolved) + }; + return (new VirtualMod(_game, modinfo.ToJson(), modinfo, ServiceProvider), dep); } [Fact] @@ -288,19 +305,4 @@ public void DisposedBuilder_Add_ThrowsObjectDisposedException() Assert.Throws(() => _builder.Remove(new WindowedArgument())); Assert.Throws(_builder.Build); } - - private IPhysicalMod CreateMod(string name) - { - return _game.InstallMod(name, false, ServiceProvider); - } - - private (IMod virtualMod, IPhysicalMod dep) CreateVirtualMod() - { - var dep = _game.InstallMod("dep", false, ServiceProvider); - var modinfo = new ModinfoData("VirtualMod") - { - Dependencies = new DependencyList([dep], DependencyResolveLayout.FullResolved) - }; - return (new VirtualMod(_game, modinfo.ToJson(), modinfo, ServiceProvider), dep); - } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 01757223..42905b03 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -14,7 +14,6 @@ using PG.StarWarsGame.Infrastructure.Testing.Clients; using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -122,7 +121,7 @@ public void Play_CancelGameStart_Throws(GameIdentity gameIdentity) var game = gameInstallation.Game; if (gameIdentity.Platform == GamePlatform.SteamGold) gameInstallation.InstallDebug(); - var mod = game.InstallMod("MyMod", false, ServiceProvider); + var mod = gameInstallation.InstallMod("MyMod", false).Mod; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -157,7 +156,7 @@ public void PlayDebug_ProcessLauncherThrows(GameIdentity gameIdentity) var game = gameInstallation.Game; if (gameIdentity.Platform == GamePlatform.SteamGold) gameInstallation.InstallDebug(); - var mod = game.InstallMod("MyMod", false, ServiceProvider); + var mod = gameInstallation.InstallMod("MyMod", false).Mod; var expectedProcessInfo = new GameProcessInfo(game, GameBuildType.Release, ArgumentCollection.Empty); @@ -209,8 +208,9 @@ public void Play_Mod(GameIdentity gameIdentity) if (!SupportedPlatforms.Contains(gameIdentity.Platform)) return; - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var mod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; + var mod = gameInstallation.InstallMod("MyMod").Mod; var expectedArguments = new ArgumentCollection([new ModArgumentList([ new ModArgument(mod.Directory, game.Directory, mod.Type == ModType.Workshops) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index d3a77726..3bd0dc41 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -69,7 +69,7 @@ public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectly() { // Do not add mod to game - var notAddedDep = Game.InstallMod("NotAddedMod", false, ServiceProvider); + var notAddedDep = GameInstallation.InstallMod("NotAddedMod", false).Mod; var mod = CreateModInstallation("Mod", Random.Enum(), notAddedDep).Mod; Game.AddMod(mod); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index 0e2243a7..2f561e43 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -7,7 +7,6 @@ using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System; using System.Collections.Generic; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; @@ -33,8 +32,8 @@ public void GetHashCode_NullArgs_Throws(bool includeDeps, bool includeGame) [InlineData(true, true)] public void Equals_ModsShouldNeverBeEquals(bool includeDeps, bool includeGame) { - var modA = Game.InstallMod("A", false, ServiceProvider); - var modB = Game.InstallMod("B", false, ServiceProvider); + var modA = GameInstallation.InstallMod("A", false).Mod; + var modB = GameInstallation.InstallMod("B", false).Mod; var comparer = new ModEqualityComparer(includeDeps, includeGame); @@ -53,13 +52,13 @@ public void Equals_ModsShouldNeverBeEquals(bool includeDeps, bool includeGame) [InlineData(true, true)] public void Equals_ShouldAlwaysBeEquals(bool includeDeps, bool includeGame) { - var modA = Game.InstallMod("A", false, ServiceProvider); + var modA = GameInstallation.InstallMod("A", false).Mod; var comparer = new ModEqualityComparer(includeDeps, includeGame); Assert.True(comparer.Equals(modA, modA)); Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(modA)); - var samish = Game.InstallMod("A", false, ServiceProvider); + var samish = GameInstallation.InstallMod("A", false).Mod; Assert.True(comparer.Equals(modA, samish)); Assert.Equal(comparer.GetHashCode(modA), comparer.GetHashCode(samish)); } @@ -113,10 +112,9 @@ public void Equals_GameAware(bool gameAware) var modSamish = otherGameInstallRef.InstallAndAddMod(modA.Name, modA.Type == ModType.Workshops); var diffGame = GameInfrastructureTesting - .Game(new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform), ServiceProvider) - .Game; + .Game(new GameIdentity(Game.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw, Game.Platform), ServiceProvider); - var diffGameMod = diffGame.InstallMod("A", modA.Type == ModType.Workshops, ServiceProvider); + var diffGameMod = diffGame.InstallMod("A", modA.Type == ModType.Workshops).Mod; var comparer = new ModEqualityComparer(Random.Bool(), gameAware); Assert.True(comparer.Equals(modA, modA)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 3a07007a..9fbf39e8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -5,8 +5,6 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; -using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using Xunit; @@ -59,7 +57,7 @@ public void Build_OneDependency() public void Build_GraphContainsOnlyVerticesAsDefinedByLayout_FullResolved() { // C is not added to game. Building a graph should not throw, because it's not used. - var c = Game.InstallMod("C", false, ServiceProvider); + var c = GameInstallation.InstallMod("C", false).Mod; var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.FullResolved, b).Mod; var graph = _graphBuilder.Build(mod); @@ -291,7 +289,7 @@ public void Build_TransitiveCycle() [Fact] public void Build_SelfNotFound_Throws() { - var mod = Game.InstallMod("A", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var mod = GameInstallation.InstallMod("A").Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); Assert.Equal(mod, e.Mod); @@ -300,7 +298,7 @@ public void Build_SelfNotFound_Throws() [Fact] public void Build_DirectDependencyNotFound_Throws() { - var b = Game.InstallMod("B", false, ServiceProvider); + var b = GameInstallation.InstallMod("B", false).Mod; var mod = InstallAndAddModWithDependencies("A", Random.Enum(), b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); Assert.Same(Game, e.ModContainer); @@ -310,7 +308,7 @@ public void Build_DirectDependencyNotFound_Throws() [Fact] public void Build_TransitiveDependencyNotFound_Throws() { - var c = Game.InstallMod("C", false, ServiceProvider); + var c = GameInstallation.InstallMod("C", false).Mod; var b = InstallAndAddModWithDependencies("B", DependencyResolveLayout.FullResolved, c).Mod; var mod = InstallAndAddModWithDependencies("A", DependencyResolveLayout.ResolveRecursive, b).Mod; var e = Assert.Throws(() => _graphBuilder.Build(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index 20c507c3..b628af7e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -3,8 +3,6 @@ using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; -using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -44,7 +42,7 @@ public void Traverse_ValidScenarios(ModTestScenarios.TestScenario testScenario) public void Traverse_FaultedResolvedMod_Throws() { // Do not add to provoke faulted - var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var dep = GameInstallation.InstallMod("B").Mod; var mod = InstallAndAddModWithDependencies("Mod", Random.Enum(), dep).Mod; @@ -65,7 +63,7 @@ public void Traverse_FaultedResolvedMod_Throws() public void Traverse_NotResolvedMod_Throws() { // Do not add to provoke faulted - var dep = Game.InstallMod("B", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var dep = GameInstallation.InstallMod("B").Mod; var mod = InstallAndAddModWithDependencies("Mod", Random.Enum(), dep).Mod; Assert.Equal(DependencyResolveStatus.None, mod.DependencyResolveStatus); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 470b9811..1d647ab2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -196,8 +196,9 @@ public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) [Fact] public void CreateVirtualMod_NullArgs_Throws() { - var game = GetOrCreateGameInstallation().Game; - var dep = game.InstallMod("dep", false, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(); + var game = gameInstallation.Game; + var dep = gameInstallation.InstallMod("dep", false).Mod; Assert.Throws(() => _factory.CreateVirtualMod(null!, new ModinfoData("Name") { @@ -210,8 +211,9 @@ public void CreateVirtualMod_NullArgs_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var dep = game.InstallMod("dep", false, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(); + var game = gameInstallation.Game; + var dep = gameInstallation.InstallMod("dep", false).Mod; var invalidModinfo = new CustomModInfo(string.Empty) { @@ -239,8 +241,9 @@ public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity game [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var dep = game.InstallMod("dep", false, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(); + var game = gameInstallation.Game; + var dep = gameInstallation.InstallMod("dep", false).Mod; var modinfo = new CustomModInfo("VirtualModName") { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 88fdcbfb..7889745d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -92,8 +92,10 @@ public void FindMods_EmptyModsDirectory_ShouldNotFindMods(GameIdentity gameIdent [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; + + var expectedMod = gameInstallation.InstallMod("MyMod").Mod; var installedMods = _modFinder.FindMods(game); AssertSingleFoundMod(installedMods, expectedMod, expectedMod.Directory.Name, null); @@ -106,9 +108,10 @@ public void FindMods_OneMod_WithoutModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; - var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var expectedMod = gameInstallation.InstallMod("MyMod").Mod; expectedMod.InstallInvalidModinfoFile(); var installedMods = _modFinder.FindMods(game); @@ -122,9 +125,10 @@ public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; - var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var expectedMod = gameInstallation.InstallMod("MyMod").Mod; var expectedModinfo = new ModinfoData("Variant1"); expectedMod.InstallModinfoFile(expectedModinfo, "variant1"); @@ -158,11 +162,12 @@ public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); - var expectedMod = game.InstallMod("DirName", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var expectedMod = gameInstallation.InstallMod("DirName").Mod; expectedMod.InstallModinfoFile(info1, "variant1"); expectedMod.InstallModinfoFile(info2, "variant2"); @@ -191,12 +196,13 @@ public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var main = new ModinfoData("Main"); var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); - var expectedMod = game.InstallMod("DirName", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var expectedMod = gameInstallation.InstallMod("DirName").Mod; expectedMod.InstallModinfoFile(main); expectedMod.InstallModinfoFile(info1, "variant1"); expectedMod.InstallModinfoFile(info2, "variant2"); @@ -224,9 +230,11 @@ public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var mod1 = game.InstallMod("Mod1", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); - var mod2 = game.InstallMod("Mod2", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; + + var mod1 = gameInstallation.InstallMod("Mod1").Mod; + var mod2 = gameInstallation.InstallMod("Mod2").Mod; var expectedDirs = new[] {mod1.Directory.FullName, mod2.Directory.FullName}; var expectedIds = new[] {mod1.Directory.Name, mod2.Directory.Name}; @@ -243,9 +251,10 @@ public void FindMods_FindAllInstalledMods(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) { - var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)); + var game = gameInstallation.Game; - var steamMod = game.InstallMod("SteamMod", true, ServiceProvider); + var steamMod = gameInstallation.InstallMod("SteamMod", true).Mod; var modinfo = new ModinfoData("Name"); var defaultMod = game.InstallMod(false, modinfo, ServiceProvider); @@ -395,9 +404,9 @@ public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameTyp var game = GetOrCreateGameInstallation(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms))).Game; // Other, random platform to shuffle a bit more. var otherTypeGame = GameInfrastructureTesting - .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider).Game; + .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); - var wrongMod = otherTypeGame.InstallMod("MyMod", false, ServiceProvider); + var wrongMod = otherTypeGame.InstallMod("MyMod", false).Mod; var installedMods = _modFinder.FindMods(game, wrongMod.Directory).ToList(); Assert.Empty(installedMods); @@ -426,8 +435,9 @@ public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameTyp [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_InvalidModinfoContentIsSkippedButModIsFound(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var expectedMod = game.InstallMod("MyMod", GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; + var expectedMod = gameInstallation.InstallMod("MyMod").Mod; expectedMod.InstallModinfoFile(new CustomModinfo(string.Empty)); // string.Empty is not valid var installedMods = _modFinder.FindMods(game); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 829e3315..70e1b497 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -248,8 +248,7 @@ public void VirtualMods_VirtualModsAreAlwaysUndecidable() SteamData = steamData }; - var game = GetOrCreateGameInstallation().Game; - var mod = game.InstallMod("Name", false, ServiceProvider); + var mod = GetOrCreateGameInstallation().InstallMod("Name", false).Mod; var info = CreateDetectedModReference(mod.Directory, ModType.Virtual, modinfo); var resolver = CreateResolver(); @@ -303,8 +302,9 @@ public void ModsInModsDirUseGameType(GameType gameType) SteamData = steamData }; - var game = GetOrCreateGameInstallation(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))).Game; - var mod = game.InstallMod("Name", false, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))); + var game = gameInstallation.Game; + var mod = gameInstallation.InstallMod("Name", false).Mod; var info = CreateDetectedModReference(mod.Directory, ModType.Default, modinfo); var resolver = CreateResolver(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 805ffb79..0ff15827 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Xunit; @@ -43,8 +44,11 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga { // Init Mods uninitialized - var eaw = GameInfrastructureTesting.Game(new GameIdentity(GameType.Eaw, platform), ServiceProvider).Game; - var foc = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, platform), ServiceProvider).Game; + var eawInstallation = GameInfrastructureTesting.Game(new GameIdentity(GameType.Eaw, platform), ServiceProvider); + var focInstallation = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, platform), ServiceProvider); + + var eaw = eawInstallation.Game; + var foc = focInstallation.Game; GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(GameType.Eaw)); GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(TestGameRegistrySetupData.Uninitialized(GameType.Foc)); @@ -82,7 +86,7 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga CreateExternalMod(actualFoc); if (platform == GamePlatform.SteamGold) CreateAndAddSteamScenario(actualFoc); - Eaw_CreateModInModsDir(eaw); + Eaw_CreateModInModsDir(eawInstallation); // Test Mod detection @@ -293,9 +297,9 @@ private void CreateExternalMod(IGame game) } - private void Eaw_CreateModInModsDir(IGame game) + private void Eaw_CreateModInModsDir(ITestingGameInstallation installation) { - game.InstallMod("In-Mods-Dir", false, ServiceProvider); + installation.InstallMod("In-Mods-Dir", false); } private class DetectedModReferenceEqualityComparer : IEqualityComparer diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs index dddfe21e..3826ae7e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs @@ -4,9 +4,6 @@ using PG.StarWarsGame.Infrastructure.Testing; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; - - #if NET5_0_OR_GREATER using System.Collections.Generic; #else @@ -39,10 +36,9 @@ public void AddMod_RemoveMod() { var containerInstallation = CreateModContainerInstallation(); var container = containerInstallation.ModContainer; - var game = container.Game; - var mod = game.InstallMod(_randomModName, false, ServiceProvider); - var modSame = game.InstallMod(_randomModName, false, ServiceProvider); + var mod = containerInstallation.GameInstallation.InstallMod(_randomModName, false).Mod; + var modSame = containerInstallation.GameInstallation.InstallMod(_randomModName, false).Mod; Assert.DoesNotContain(mod, container.Mods); Assert.DoesNotContain(modSame, container.Mods); @@ -113,10 +109,9 @@ public void AddMod_ShouldNotAddSelf() [Fact] public void AddMod_RemoveMod_RaiseEvent() { - var container = CreateModContainerInstallation().ModContainer; - var game = container.Game; - - var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var containerInstallation = CreateModContainerInstallation(); + var container = containerInstallation.ModContainer; + var mod = containerInstallation.GameInstallation.InstallMod(_randomModName).Mod; var evtAdd = Assert.Raises( a => container.ModsCollectionModified += a, @@ -145,10 +140,9 @@ public void AddMod_RemoveMod_RaiseEvent() [Fact] public void RemoveMod_NotExisting_DoesNotRaiseEvent() { - var container = CreateModContainerInstallation().ModContainer; - var game = container.Game; - - var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var containerInstallation = CreateModContainerInstallation(); + var container = containerInstallation.ModContainer; + var mod = containerInstallation.GameInstallation.InstallMod(_randomModName).Mod; var containerRaised = false; container.ModsCollectionModified += (_, _) => @@ -162,18 +156,19 @@ public void RemoveMod_NotExisting_DoesNotRaiseEvent() gameRaised = true; }; - game.RemoveMod(mod); + container.Game.RemoveMod(mod); Assert.False(containerRaised); Assert.False(gameRaised); } [Fact] - public void AddMod_Existing_DoesNotRaiseEvent() + public void AddMod_AlreadyExisting_DoesNotRaiseEvent() { - var container = CreateModContainerInstallation().ModContainer; - var game = container.Game; + var containerInstallation = CreateModContainerInstallation(); + var container = containerInstallation.ModContainer; + var mod = containerInstallation.GameInstallation.InstallMod(_randomModName).Mod; - var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + // Add before registering events container.AddMod(mod); var containerRaised = false; @@ -196,23 +191,22 @@ public void AddMod_Existing_DoesNotRaiseEvent() [Fact] public void AddMod_ExistingFromContainer_ShouldBeAlreadyInGame() { - var container = CreateModContainerInstallation().ModContainer; - var game = container.Game; - - var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); + var containerInstallation = CreateModContainerInstallation(); + var container = containerInstallation.ModContainer; + var game = containerInstallation.GameInstallation.Game; + var mod = containerInstallation.GameInstallation.InstallMod(_randomModName).Mod; + Assert.True(container.AddMod(mod)); - Assert.False(game.AddMod(mod)); } [Fact] public void FindMod() { - var container = CreateModContainerInstallation().ModContainer; - var game = container.Game; + var containerInstallation = CreateModContainerInstallation(); + var container = containerInstallation.ModContainer; + var mod = containerInstallation.GameInstallation.InstallMod(_randomModName).Mod; - var mod = game.InstallMod(_randomModName, GITestUtilities.GetRandomWorkshopFlag(game), ServiceProvider); - Assert.True(container.AddMod(mod)); Assert.Same(mod, container.FindMod(mod)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 5e08f4a6..2025dd62 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -62,7 +62,7 @@ public void FindLanguages_Game_WithLanguages_En_De() public void FindLanguages_Mod_WithNoLanguages_UsesGame() { InstallGameLanguage(new LanguageInfo("de", LanguageSupportLevel.SFX)); - var mod = Game.InstallMod("myMod", GITestUtilities.GetRandomWorkshopFlag(Game), ServiceProvider); + var mod = GameInstallation.InstallMod("myMod").Mod; var langs = _languageFinder.FindLanguages(mod); Assert.Equivalent(new List { new LanguageInfo("de", LanguageSupportLevel.SFX) }, langs, true); @@ -71,8 +71,8 @@ public void FindLanguages_Mod_WithNoLanguages_UsesGame() [Fact] public void FindLanguages_Mod_WithLanguages_En_De_Steam() { - var game = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider).Game; - var mod = game.InstallMod("myMod", true, ServiceProvider); + var game = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); + var mod = game.InstallMod("myMod", true).Mod; InstallModLanguage(mod, new LanguageInfo("de", LanguageSupportLevel.SFX)); InstallModLanguage(mod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs index 784ed216..0b0ca732 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs @@ -14,6 +14,10 @@ public interface ITestingGameInstallation : ITestingModContainerInstallation IDirectoryInfo GetWrongOriginFocRegistryLocation(); + ITestingPhysicalModInstallation InstallMod(string name); + + ITestingPhysicalModInstallation InstallMod(string name, bool workshop); + ITestingPhysicalModInstallation InstallAndAddMod(string name); ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs index fb78f781..3c12731e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs @@ -42,6 +42,19 @@ public IDirectoryInfo GetWrongOriginFocRegistryLocation() return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); } + public ITestingPhysicalModInstallation InstallMod(string name, bool workshop) + { + var mod = ModInstallations.CreateMod(Game, name, workshop, _serviceProvider, + modDir => new Mod(Game, name, modDir, workshop, name, _serviceProvider)); + return new TestingPhysicalModImpl(this, mod, _serviceProvider); + } + + public ITestingPhysicalModInstallation InstallMod(string name) + { + var workshop = GITestUtilities.GetRandomWorkshopFlag(Game); + return InstallMod(name, workshop); + } + public ITestingPhysicalModInstallation InstallAndAddMod(string name) { var isWorkshop = GITestUtilities.GetRandomWorkshopFlag(Game); @@ -50,9 +63,9 @@ public ITestingPhysicalModInstallation InstallAndAddMod(string name) public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop) { - var mod = Game.InstallMod(name, workshop, _serviceProvider); - Game.AddMod(mod); - return new TestingPhysicalModImpl(this, mod, _serviceProvider); + var modInstallation = InstallMod(name, workshop); + Game.AddMod(modInstallation.Mod); + return modInstallation; } public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs index f44f3993..a9a436d7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs @@ -12,12 +12,6 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public static partial class ModInstallations { - public static Mod InstallMod(this IGame game, string name, bool workshop, IServiceProvider serviceProvider) - { - return CreateMod(game, name, workshop, serviceProvider, - modDir => new Mod(game, name, modDir, workshop, name, serviceProvider)); - } - public static Mod InstallMod(this IGame game, bool workshop, IModinfo modinfo, IServiceProvider serviceProvider) { var name = modinfo.Name; @@ -30,7 +24,7 @@ public static Mod InstallMod(this IGame game, IDirectoryInfo directory, bool isW return CreateMod(game, directory, dir => new Mod(game, modinfo.Name, dir, isWorkshop, modinfo, serviceProvider)); } - private static Mod CreateMod(IGame game, string modName, bool workshop, IServiceProvider serviceProvider, Func modFactory) + internal static Mod CreateMod(IGame game, string modName, bool workshop, IServiceProvider serviceProvider, Func modFactory) { var modDir = game.Directory.FileSystem.DirectoryInfo.New(game.GetModDirectory(modName, workshop, serviceProvider)); return CreateMod(game, modDir, modFactory); From c96acd9399f41284b9d61969cadceaac18af1048 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 15:46:09 +0100 Subject: [PATCH 33/71] move namespace --- .../SteamPetroglyphStarWarsGameClientTest.cs | 2 +- .../Clients/Arguments/GameArgumentsBuilderTest.cs | 2 +- .../Clients/PetroglyphStarWarsGameClientTest.cs | 2 +- test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs | 2 +- .../PetroglyphGameInfrastructureIntegrationTest.cs | 2 +- .../PetroglyphStarWarsGameTest.cs | 2 +- .../Game/{Installation => }/GameInstallationHelper.Eaw.cs | 2 +- .../Game/{Installation => }/GameInstallationHelper.Foc.cs | 2 +- .../Game/{Installation => }/GameInstallationHelper.cs | 2 +- .../Game/{Installation => }/ITestingGameInstallation.cs | 2 +- .../Installations/Game/{Installation => }/TestingGameImpl.cs | 2 +- .../Installations/GameInfrastructureTesting.cs | 2 +- .../Installations/ITestingPlayableObjectInstallation.cs | 2 +- .../Installations/Mods/ITestingModInstallation.cs | 2 +- .../Installations/Mods/TestingModImpl.cs | 2 +- .../Installations/Mods/TestingPhysicalModImpl.cs | 2 +- .../Installations/Mods/TestingVirtualModImpl.cs | 2 +- .../TestBases/GameInfrastructureTestBase.cs | 2 +- .../TestBases/GameInfrastructureTestBaseWithRandomGame.cs | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/{Installation => }/GameInstallationHelper.Eaw.cs (99%) rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/{Installation => }/GameInstallationHelper.Foc.cs (99%) rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/{Installation => }/GameInstallationHelper.cs (99%) rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/{Installation => }/ITestingGameInstallation.cs (98%) rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/{Installation => }/TestingGameImpl.cs (99%) diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index e0cfcc2f..78477177 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -15,8 +15,8 @@ using System.Runtime.Versioning; using AET.Testing.Extensions; using Xunit; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs index 1d1150e8..d7e8a165 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentsBuilderTest.cs @@ -6,7 +6,7 @@ using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 42905b03..23abbd64 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -13,7 +13,7 @@ using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Clients; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 3bd0dc41..b051f041 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -13,7 +13,7 @@ using PG.StarWarsGame.Infrastructure.Testing.TestBases; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 0ff15827..510565d1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -20,9 +20,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Xunit; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index 348a72fc..aef4c741 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -5,7 +5,7 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs similarity index 99% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Eaw.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs index 07f5e68b..09f9c650 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs @@ -3,7 +3,7 @@ using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; internal static partial class GameInstallationHelper { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Foc.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs similarity index 99% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Foc.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs index 5125c64a..6128da8d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.Foc.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs @@ -3,7 +3,7 @@ using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; internal static partial class GameInstallationHelper { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs similarity index 99% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs index bf6a905b..ab39a43c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/GameInstallationHelper.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs @@ -2,7 +2,7 @@ using System.IO.Abstractions; using Testably.Abstractions.Testing; -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; internal static partial class GameInstallationHelper { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs similarity index 98% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs index 0b0ca732..211cff19 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs @@ -4,7 +4,7 @@ using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; public interface ITestingGameInstallation : ITestingModContainerInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs similarity index 99% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs index 3c12731e..60901992 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Installation/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs @@ -8,7 +8,7 @@ using System.IO.Abstractions; using Xunit; -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; internal class TestingGameImpl : ITestingGameInstallation { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs index 1d78ff3e..ac86f2cb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs @@ -1,6 +1,6 @@ using System; using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs index 8160090b..b4578f88 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs @@ -1,4 +1,4 @@ -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs index 49f2536b..bb4f0865 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs @@ -1,5 +1,5 @@ using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs index baaee576..df2e6170 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs @@ -1,6 +1,6 @@ using System; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs index df740a87..a0250778 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs @@ -1,6 +1,6 @@ using System; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs index ba1c809a..db43788e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs @@ -1,6 +1,6 @@ using System; using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index d1e2f533..da8df496 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System.Collections.Generic; using System.IO.Abstractions; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index a5fb59b2..93134746 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -1,5 +1,5 @@ using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Installation; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; From 95ceb6d7dc726f9329148d72b68b77a25f87f6e1 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 16:20:58 +0100 Subject: [PATCH 34/71] remove method --- .../ModBaseTest.cs | 26 +++++----- .../ModServices/ModFinderTest.cs | 12 +++-- .../ModTest.cs | 16 +++---- .../Services/LanguageFinderTestBase.cs | 5 +- .../VirtualModTest.cs | 4 +- .../Game/ITestingGameInstallation.cs | 15 +++++- .../Installations/Game/TestingGameImpl.cs | 48 ++++++++++++++++--- .../Installations/Mods/ModInstallations.cs | 9 +--- 8 files changed, 88 insertions(+), 47 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index b051f041..78e9f542 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -27,7 +27,7 @@ protected ModBaseTest() GameInstallation = GetOrCreateGameInstallation(); } - protected abstract ITestingModInstallation CreateModInstallation( + protected abstract ITestingModInstallation CreateAndAddModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps); @@ -36,7 +36,7 @@ protected abstract ITestingModInstallation CreateModInstallation( [Fact] public void VersionRange_IsNull() { - var mod = CreateModInstallation("Mod").Mod; + var mod = CreateAndAddModInstallation("Mod").Mod; Assert.Null(mod.VersionRange); } @@ -46,7 +46,7 @@ public void ResolveDependencies_ResolvesCorrectly(ModTestScenarios.TestScenario { var mod = ModTestScenarios.CreateTestScenario( testScenario, - (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod, (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod) .Mod; @@ -71,7 +71,7 @@ public void ResolveDependencies_DepNotAdded_Throws_ThenAddingModResolvesCorrectl // Do not add mod to game var notAddedDep = GameInstallation.InstallMod("NotAddedMod", false).Mod; - var mod = CreateModInstallation("Mod", Random.Enum(), notAddedDep).Mod; + var mod = CreateAndAddModInstallation("Mod", Random.Enum(), notAddedDep).Mod; Game.AddMod(mod); var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); @@ -93,7 +93,7 @@ public void ResolveDependencies_DepOfWrongGame_Throws() var otherGameInstallRef = GameInfrastructureTesting.Game(Game, ServiceProvider); var wrongGameDep = otherGameInstallRef.InstallAndAddMod("WrongGameRefMod"); - var mod = CreateModInstallation("Mod", Random.Enum(), wrongGameDep.Mod).Mod; + var mod = CreateAndAddModInstallation("Mod", Random.Enum(), wrongGameDep.Mod).Mod; var e = Assert.Throws(mod.ResolveDependencies); Assert.Same(Game, e.ModContainer); @@ -109,7 +109,7 @@ public void ResolveDependencies_VersionMismatch_Throws() var dep = Game.InstallMod(depLoc, ws, new ModinfoData("B") { Version = new SemVersion(1) }, ServiceProvider); Game.AddMod(dep); - var mod = CreateModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; + var mod = CreateAndAddModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; var e = Assert.Throws(mod.ResolveDependencies); Assert.Equal(new ModReference(dep), e.Mod); @@ -128,7 +128,7 @@ public void ResolveDependencies_VersionMatch_Throws() Game.AddMod(b); Game.AddMod(c); - var mod = CreateModInstallation("Mod", deps: + var mod = CreateAndAddModInstallation("Mod", deps: [ new ModReference(b.Identifier, b.Type, SemVersionRange.AtLeast(new SemVersion(2))), new ModReference(c.Identifier, c.Type, SemVersionRange.AtLeast(new SemVersion(2))) @@ -145,7 +145,7 @@ public void ResolveDependencies_RaiseEvent() { var scenario = ModTestScenarios.CreateTestScenario( ModTestScenarios.TestScenario.SingleDepAndTransitive, - (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod, (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod); var mod = scenario.Mod; @@ -173,7 +173,7 @@ public void ResolveDependencies_RaiseEvent() [Fact] public void ResolveDependencies_AlreadyResolved_DoesNotRaiseEvent() { - var mod = CreateModInstallation("A").Mod; + var mod = CreateAndAddModInstallation("A").Mod; mod.ResolveDependencies(); Assert.Equal(DependencyResolveStatus.Resolved, mod.DependencyResolveStatus); @@ -196,7 +196,7 @@ public void ResolveDependencies_Faulted_DoesNotRaiseEvent() var dep = Game.InstallMod(depLoc, ws, new ModinfoData("B") { Version = new SemVersion(1) }, ServiceProvider); Game.AddMod(dep); - var mod = CreateModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; + var mod = CreateAndAddModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; var depsResolvedRaised = false; mod.DependenciesResolved += (_, _) => @@ -230,9 +230,9 @@ private static void AssertDependenciesResolved(IMod mod) public void EqualsHashCode() { var dep = GameInstallation.InstallAndAddMod("B").Mod; - var mod = CreateModInstallation("A").Mod; - var samish = CreateModInstallation("A").Mod; - var otherA = CreateModInstallation("A", deps: dep).Mod; + var mod = CreateAndAddModInstallation("A").Mod; + var samish = CreateAndAddModInstallation("A").Mod; + var otherA = CreateAndAddModInstallation("A", deps: dep).Mod; ModBase custom = mod.ModInfo is not null ? new CustomMod(Game, mod.Identifier, mod.Type, mod.ModInfo, ServiceProvider) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 7889745d..1ad10af4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -145,10 +145,11 @@ public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var modinfoData = new ModinfoData("MyMod"); - var expectedMod = game.InstallMod(GITestUtilities.GetRandomWorkshopFlag(game), modinfoData, ServiceProvider); + var expectedMod = gameInstallation.InstallMod(modinfoData).Mod; expectedMod.InstallModinfoFile(modinfoData); var installedMods = _modFinder.FindMods(game); @@ -257,7 +258,7 @@ public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) var steamMod = gameInstallation.InstallMod("SteamMod", true).Mod; var modinfo = new ModinfoData("Name"); - var defaultMod = game.InstallMod(false, modinfo, ServiceProvider); + var defaultMod = gameInstallation.InstallMod(modinfo, false).Mod; defaultMod.InstallModinfoFile(modinfo); @@ -280,7 +281,8 @@ public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) [InlineData(GameType.Foc)] public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) { - var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)); + var game = gameInstallation.Game; var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; @@ -296,7 +298,7 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) }; - var modOfWrongGameType = game.InstallMod(true, modinfo, ServiceProvider); + var modOfWrongGameType = gameInstallation.InstallMod(modinfo, true).Mod; modOfWrongGameType.InstallModinfoFile(modinfo); Assert.Empty(_modFinder.FindMods(game)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index b0321b89..c4053f6c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -33,7 +33,7 @@ private IModReference CreateModRef(string name) return new ModReference(name, modType); } - private ITestingPhysicalModInstallation CreatePhysicalModInstallation( + private ITestingPhysicalModInstallation CreateAndAddPhysicalModInstallation( string name, string? iconPath = null, ICollection? languages = null, @@ -46,7 +46,7 @@ private ITestingPhysicalModInstallation CreatePhysicalModInstallation( }; var modInstallation = GetOrCreateGameInstallation() - .InstallAndAddMod(CreateModDirectoryInfo(name), _isWorkshop, modinfo); + .InstallAndAddMod(modinfo, CreateModDirectoryInfo(name), _isWorkshop); var mod = modInstallation.Mod; if (languages is not null) @@ -61,24 +61,24 @@ private ITestingPhysicalModInstallation CreatePhysicalModInstallation( return modInstallation; } - protected override ITestingModInstallation CreateModInstallation( + protected override ITestingModInstallation CreateAndAddModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) { - return CreatePhysicalModInstallation(name, layout: layout, deps: deps); + return CreateAndAddPhysicalModInstallation(name, layout: layout, deps: deps); } protected override ITestingPlayableObjectInstallation CreatePlayableObjectInstallation( string? iconPath = null, ICollection? languages = null) { - return CreatePhysicalModInstallation("MyMod", iconPath, languages); + return CreateAndAddPhysicalModInstallation("MyMod", iconPath, languages); } protected override ITestingModContainerInstallation CreateModContainerInstallation() { - return CreateModInstallation("MyMod"); + return CreateAndAddModInstallation("MyMod"); } [Fact] @@ -174,7 +174,7 @@ public void ValidCtor_Properties_FromModinfo_WithDependencies() [Fact] public void ResolveDependencies_NoDependenciesIsNOP() { - var mod = CreateModInstallation("Mod").Mod; + var mod = CreateAndAddModInstallation("Mod").Mod; // Should not throw or anything else mod.ResolveDependencies(); Assert.Empty(mod.Dependencies); @@ -187,7 +187,7 @@ public void ResolveDependencies_ResolvesCycle_Throws(ModTestScenarios.CycleTestS { var mod = ModTestScenarios.CreateTestScenarioCycle( testScenario, - (name, layout, dependencies) => CreateModInstallation(name, layout, dependencies).Mod, + (name, layout, dependencies) => CreateAndAddModInstallation(name, layout, dependencies).Mod, (name, layout, dependencies) => InstallAndAddModWithDependencies(name, layout, dependencies).Mod, CreateModRef) .Mod; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 2025dd62..358bd6b9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -9,7 +9,6 @@ using System.Collections.Generic; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Test.Services; @@ -143,7 +142,7 @@ public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguagesAndDe new ModReference(baseMod) }, DependencyResolveLayout.FullResolved) }; - var mod = Game.InstallMod(GITestUtilities.GetRandomWorkshopFlag(Game), modInfo, ServiceProvider); + var mod = GameInstallation.InstallMod(modInfo).Mod; // Do not resolve dependencies here! var langs = _languageFinder.FindLanguages(mod); @@ -318,7 +317,7 @@ public void FindLanguages_VirtualMod_TargetModDoesNotHaveLanguagesAndSecondDepen [Fact] public void FindLanguages_Mod_FromModinfo_WithNoLanguages() { - var mod = Game.InstallMod(GITestUtilities.GetRandomWorkshopFlag(Game), new ModinfoData("myMod"), ServiceProvider); + var mod = GameInstallation.InstallMod(new ModinfoData("myMod")).Mod; var langs = _languageFinder.FindLanguages(mod); Assert.Equivalent(new List(), langs, true); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs index 80d86687..4722df50 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/VirtualModTest.cs @@ -43,7 +43,7 @@ private ITestingVirtualModInstallation CreateVirtualMod( return GetOrCreateGameInstallation().AddVirtualMod("VirtualModId", modinfo); } - protected override ITestingModInstallation CreateModInstallation( + protected override ITestingModInstallation CreateAndAddModInstallation( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, params IList deps) @@ -60,7 +60,7 @@ protected override ITestingPlayableObjectInstallation CreatePlayableObjectInstal protected override ITestingModContainerInstallation CreateModContainerInstallation() { - return CreateModInstallation("Mod"); + return CreateAndAddModInstallation("Mod"); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs index 211cff19..7b965823 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs @@ -18,6 +18,15 @@ public interface ITestingGameInstallation : ITestingModContainerInstallation ITestingPhysicalModInstallation InstallMod(string name, bool workshop); + ITestingPhysicalModInstallation InstallMod(IModinfo modinfo); + + ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, bool workshop); + + ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory); + + ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory, bool workshop); + + ITestingPhysicalModInstallation InstallAndAddMod(string name); ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop); @@ -26,11 +35,15 @@ public interface ITestingGameInstallation : ITestingModContainerInstallation ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, bool workshop); - ITestingPhysicalModInstallation InstallAndAddMod(IDirectoryInfo directory, bool workshop, IModinfo modinfo); + ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory); + + ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory, bool workshops); ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWorkshop, IModDependencyList dependencies); ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDependencyList dependencies); + + ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs index 60901992..ce8876af 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs @@ -49,6 +49,33 @@ public ITestingPhysicalModInstallation InstallMod(string name, bool workshop) return new TestingPhysicalModImpl(this, mod, _serviceProvider); } + public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo) + { + var workshop = GITestUtilities.GetRandomWorkshopFlag(Game); + return InstallMod(modinfo, workshop); + } + + public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, bool workshop) + { + var name = modinfo.Name; + var mod = ModInstallations.CreateMod(Game, name, workshop, _serviceProvider, modDir + => new Mod(Game, name, modDir, workshop, modinfo, _serviceProvider)); + return new TestingPhysicalModImpl(this, mod, _serviceProvider); + } + + public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory) + { + var workshop = GITestUtilities.GetRandomWorkshopFlag(Game); + return InstallMod(modinfo, directory, workshop); + } + + public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory, bool workshop) + { + var mod = ModInstallations.CreateMod(Game, directory, dir => + new Mod(Game, modinfo.Name, dir, workshop, modinfo, _serviceProvider)); + return new TestingPhysicalModImpl(this, mod, _serviceProvider); + } + public ITestingPhysicalModInstallation InstallMod(string name) { var workshop = GITestUtilities.GetRandomWorkshopFlag(Game); @@ -75,16 +102,23 @@ public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo) public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, bool workshop) { - var mod = Game.InstallMod(workshop, modinfo, _serviceProvider); - Game.AddMod(mod); - return new TestingPhysicalModImpl(this, mod, _serviceProvider); + var modInstallation = InstallMod(modinfo, workshop); + Game.AddMod(modInstallation.Mod); + return modInstallation; } - public ITestingPhysicalModInstallation InstallAndAddMod(IDirectoryInfo directory, bool workshop, IModinfo modinfo) + public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory) { - var mod = Game.InstallMod(directory, workshop, modinfo, _serviceProvider); - Game.AddMod(mod); - return new TestingPhysicalModImpl(this, mod, _serviceProvider); + var modInstallation = InstallMod(modinfo, directory); + Game.AddMod(modInstallation.Mod); + return modInstallation; + } + + public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory, bool workshops) + { + var modInstallation = InstallMod(modinfo, directory, workshops); + Game.AddMod(modInstallation.Mod); + return modInstallation; } public ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDependencyList dependencies) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs index a9a436d7..99efe710 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs @@ -12,13 +12,6 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public static partial class ModInstallations { - public static Mod InstallMod(this IGame game, bool workshop, IModinfo modinfo, IServiceProvider serviceProvider) - { - var name = modinfo.Name; - return CreateMod(game, name, workshop, serviceProvider, - modDir => new Mod(game, name, modDir, workshop, modinfo, serviceProvider)); - } - public static Mod InstallMod(this IGame game, IDirectoryInfo directory, bool isWorkshop, IModinfo modinfo, IServiceProvider serviceProvider) { return CreateMod(game, directory, dir => new Mod(game, modinfo.Name, dir, isWorkshop, modinfo, serviceProvider)); @@ -30,7 +23,7 @@ internal static Mod CreateMod(IGame game, string modName, bool workshop, IServic return CreateMod(game, modDir, modFactory); } - private static Mod CreateMod(IGame game, IDirectoryInfo directory, Func modFactory) + internal static Mod CreateMod(IGame game, IDirectoryInfo directory, Func modFactory) { Assert.True(game.ModsLocation.Exists); var mod = modFactory(directory); From f5c9a1b5fef8af8bf504d5e472f57214a60ba484 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 17:01:37 +0100 Subject: [PATCH 35/71] remove modinstallation --- .../ModBaseTest.cs | 16 ++-- .../ModServices/ModFactoryTest.cs | 69 ++++++++------- .../ModServices/ModFinderTest.cs | 30 ++++--- .../ModGameTypeResolverTestBase.cs | 18 ++-- .../ModTest.cs | 10 +-- ...oglyphGameInfrastructureIntegrationTest.cs | 24 +++--- .../Game/ITestingGameInstallation.cs | 10 +-- ....cs => TestingGameInstallationImpl.Mod.cs} | 86 +++++++++---------- .../Game/TestingGameInstallationImpl.cs | 54 ++++++++++++ .../GameInfrastructureTesting.cs | 2 +- .../Installations/Mods/ModInstallations.cs | 59 ------------- 11 files changed, 191 insertions(+), 187 deletions(-) rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/{TestingGameImpl.cs => TestingGameInstallationImpl.Mod.cs} (65%) create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs delete mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 78e9f542..1a13d191 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -105,8 +105,8 @@ public void ResolveDependencies_DepOfWrongGame_Throws() public void ResolveDependencies_VersionMismatch_Throws() { var ws = GITestUtilities.GetRandomWorkshopFlag(Game); - var depLoc = FileSystem.DirectoryInfo.New(Game.GetModDirectory("B", ws, ServiceProvider)); - var dep = Game.InstallMod(depLoc, ws, new ModinfoData("B") { Version = new SemVersion(1) }, ServiceProvider); + var depLoc = GameInstallation.GetModDirectory("B", ws); + var dep = GameInstallation.InstallMod(new ModinfoData("B") { Version = new SemVersion(1) }, depLoc, ws).Mod; Game.AddMod(dep); var mod = CreateAndAddModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; @@ -121,10 +121,10 @@ public void ResolveDependencies_VersionMismatch_Throws() public void ResolveDependencies_VersionMatch_Throws() { var ws = GITestUtilities.GetRandomWorkshopFlag(Game); - var bLoc = FileSystem.DirectoryInfo.New(Game.GetModDirectory("B", ws, ServiceProvider)); - var cLoc = FileSystem.DirectoryInfo.New(Game.GetModDirectory("C", ws, ServiceProvider)); - var b = Game.InstallMod(bLoc, ws, new ModinfoData("B") { Version = new SemVersion(3) }, ServiceProvider); - var c = Game.InstallMod(cLoc, ws, new ModinfoData("C") { Version = null! }, ServiceProvider); + var bLoc = GameInstallation.GetModDirectory("B", ws); + var cLoc = GameInstallation.GetModDirectory("C", ws); + var b = GameInstallation.InstallMod(new ModinfoData("B") { Version = new SemVersion(3) }, bLoc, ws).Mod; + var c = GameInstallation.InstallMod(new ModinfoData("C") { Version = null! }, cLoc, ws).Mod; Game.AddMod(b); Game.AddMod(c); @@ -192,8 +192,8 @@ public void ResolveDependencies_AlreadyResolved_DoesNotRaiseEvent() public void ResolveDependencies_Faulted_DoesNotRaiseEvent() { var ws = GITestUtilities.GetRandomWorkshopFlag(Game); - var depLoc = FileSystem.DirectoryInfo.New(Game.GetModDirectory("B", ws, ServiceProvider)); - var dep = Game.InstallMod(depLoc, ws, new ModinfoData("B") { Version = new SemVersion(1) }, ServiceProvider); + var depLoc = GameInstallation.GetModDirectory("B", ws); + var dep = GameInstallation.InstallMod(new ModinfoData("B") { Version = new SemVersion(1) }, depLoc, ws).Mod; Game.AddMod(dep); var mod = CreateAndAddModInstallation("Mod", deps: new ModReference(dep.Identifier, dep.Type, SemVersionRange.AtLeast(new SemVersion(2)))).Mod; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 1d647ab2..92c45cf8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.IO.Abstractions; using System.Text.Json; using AET.Modinfo; using AET.Modinfo.Model; @@ -16,7 +17,7 @@ using PG.StarWarsGame.Infrastructure.Services.Name; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using Xunit; @@ -47,8 +48,9 @@ protected override void SetupServices(IServiceCollection serviceCollection) [Fact] public void CreatePhysicalMod_NullArgs_Throws() { - var game = GetOrCreateGameInstallation().Game; - var modData = CreateDetectedModReference(game, "path", null, null); + var gameInstallation = GetOrCreateGameInstallation(); + var game = gameInstallation.Game; + var modData = CreateDetectedModReference(gameInstallation, FileSystem.DirectoryInfo.New("path"), null, null); Assert.Throws(() => _factory.CreatePhysicalMod(null!, modData, CultureInfo.CurrentCulture)); Assert.Throws(() => _factory.CreatePhysicalMod(game, null!, CultureInfo.CurrentCulture)); @@ -68,8 +70,9 @@ public void CreatePhysicalMod_VirtualMod_Throws() [Fact] public void CreatePhysicalMod_ModDirectoryNotFound_Throws() { - var game = GetOrCreateGameInstallation().Game; - var modData = CreateDetectedModReference(game, "path", null, null); + var gameInstallation = GetOrCreateGameInstallation(); + var game = gameInstallation.Game; + var modData = CreateDetectedModReference(gameInstallation, FileSystem.DirectoryInfo.New("path"), null, null); modData.Directory.Delete(true); Assert.Throws(() => _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture)); } @@ -78,10 +81,11 @@ public void CreatePhysicalMod_ModDirectoryNotFound_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var modDir = game.GetModDirectory("Mod_Name", false, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; + var modDir = gameInstallation.GetModDirectory("Mod_Name", false); - var modData = CreateDetectedModReference(game, modDir, false, null); + var modData = CreateDetectedModReference(gameInstallation, modDir, false, null); var mod = _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture); Assert.Null(mod.ModInfo); @@ -94,12 +98,13 @@ public void CreatePhysicalMod_FromModsDir_WithoutModinfo(GameIdentity gameIdenti [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; - var modDir = game.GetModDirectory("Mod_Name", false, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; + var modDir = gameInstallation.GetModDirectory("Mod_Name", false); var modinfo = new ModinfoData("MyMod"); - var modData = CreateDetectedModReference(game, modDir, false, modinfo); + var modData = CreateDetectedModReference(gameInstallation, modDir, false, modinfo); var mod = _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture); Assert.Same(modinfo, mod.ModInfo); @@ -113,12 +118,13 @@ public void CreatePhysicalMod_FromModsDir_WithModinfo(GameIdentity gameIdentity) [InlineData(GameType.Foc)] public void CreatePhysicalMod_Steam_WithoutModinfo(GameType gameType) { - var game = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)).Game; - var modDir = game.GetModDirectory("Mod_Name", true, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)); + var game = gameInstallation.Game; + var modDir = gameInstallation.GetModDirectory("Mod_Name", true); var modinfo = new ModinfoData("MyMod"); - var modRef = CreateDetectedModReference(game, modDir, true, modinfo); + var modRef = CreateDetectedModReference(gameInstallation, modDir, true, modinfo); var mod = _factory.CreatePhysicalMod(game, modRef, CultureInfo.CurrentCulture); Assert.Same(modinfo, mod.ModInfo); @@ -132,10 +138,11 @@ public void CreatePhysicalMod_Steam_WithoutModinfo(GameType gameType) [InlineData(GameType.Foc)] public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) { - var game = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)).Game; - var modDir = game.GetModDirectory("Mod_Name", true, ServiceProvider); + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(gameType, GamePlatform.SteamGold)); + var game = gameInstallation.Game; + var modDir = gameInstallation.GetModDirectory("Mod_Name", true); - var modRef = CreateDetectedModReference(game, modDir, true, null); + var modRef = CreateDetectedModReference(gameInstallation, modDir, true, null); var mod = _factory.CreatePhysicalMod(game, modRef, CultureInfo.CurrentCulture); Assert.Null(mod.ModInfo); @@ -148,13 +155,14 @@ public void CreatePhysicalMod_Steam_WithModinfo(GameType gameType) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var ws = GITestUtilities.GetRandomWorkshopFlag(game); - var modDir = game.GetModDirectory("Mod_Name", ws, ServiceProvider); + var modDir = gameInstallation.GetModDirectory("Mod_Name", ws); var invalidModinfo = new CustomModInfo(string.Empty); // string.Empty is not valid - var modData = CreateDetectedModReference(game, modDir, ws, invalidModinfo); + var modData = CreateDetectedModReference(gameInstallation, modDir, ws, invalidModinfo); Assert.Throws(() => _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture)); } @@ -163,11 +171,12 @@ public void CreatePhysicalMod_WithInvalidModinfo(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var ws = GITestUtilities.GetRandomWorkshopFlag(game); - var modDir = game.GetModDirectory("Mod_Name", ws, ServiceProvider); - var modData = CreateDetectedModReference(game, modDir, ws, null); + var modDir = gameInstallation.GetModDirectory("Mod_Name", ws); + var modData = CreateDetectedModReference(gameInstallation, modDir, ws, null); _nameResolver.ReturnCorrectName = false; Assert.Throws(() => _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture)); @@ -180,11 +189,11 @@ public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) var game = GetOrCreateGameInstallation(gameIdentity).Game; var oppositeGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; - var otherGame = GameInfrastructureTesting - .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider).Game; + var otherGameInstallation = GameInfrastructureTesting + .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); - var modDir = otherGame.GetModDirectory("Mod_Name", false, ServiceProvider); - var modData = CreateDetectedModReference(otherGame, modDir, false, null); + var modDir = otherGameInstallation.GetModDirectory("Mod_Name", false); + var modData = CreateDetectedModReference(otherGameInstallation, modDir, false, null); Assert.Throws(() => _factory.CreatePhysicalMod(game, modData, CultureInfo.CurrentCulture)); } @@ -261,10 +270,10 @@ public void CreateVirtualMod(GameIdentity gameIdentity) #endregion - protected DetectedModReference CreateDetectedModReference(IGame game, string path, bool? isWorkshop, IModinfo? modinfo) + protected DetectedModReference CreateDetectedModReference(ITestingGameInstallation gameInstallation, IDirectoryInfo path, bool? isWorkshop, IModinfo? modinfo) { - var mod = game.InstallMod(FileSystem.DirectoryInfo.New(path), isWorkshop ?? GITestUtilities.GetRandomWorkshopFlag(game), - new ModinfoData("MyMod"), ServiceProvider); + var workshop = isWorkshop ?? GITestUtilities.GetRandomWorkshopFlag(gameInstallation.Game); + var mod = gameInstallation.InstallMod(new ModinfoData("MyMod"), path, workshop).Mod; return new DetectedModReference(new ModReference(mod), mod.Directory, modinfo); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 1ad10af4..078add8d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -309,11 +309,12 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var modPath = FileSystem.DirectoryInfo.New("external/myMod"); modPath.Create(); - var mod = game.InstallMod(modPath, false, new ModinfoData("MyMod"), ServiceProvider); + var mod = gameInstallation.InstallMod(new ModinfoData("MyMod"), modPath, false).Mod; var installedMods = _modFinder.FindMods(game, mod.Directory).ToList(); AssertSingleFoundMod(installedMods, mod, mod.Directory.FullName, null); @@ -323,11 +324,12 @@ public void FindMods_FromExternal(GameIdentity gameIdentity) [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var modPath = FileSystem.DirectoryInfo.New("external/myMod"); modPath.Create(); - var mod = game.InstallMod(modPath, false, new ModinfoData("MyMod"), ServiceProvider); + var mod = gameInstallation.InstallMod(new ModinfoData("MyMod"), modPath, false).Mod; modPath.Delete(true); var installedMods = _modFinder.FindMods(game, mod.Directory).ToList(); @@ -338,14 +340,15 @@ public void FindMods_FromExternal_DirectoryNotFoundShouldSkip(GameIdentity gameI [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIdentity) { - var game = GetOrCreateGameInstallation(gameIdentity).Game; + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); + var game = gameInstallation.Game; var modPath = FileSystem.DirectoryInfo.New("external/123456"); // Use a number so it may look like a Steam WS ID modPath.Create(); var main = new ModinfoData("Main"); var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); - var expectedMod = game.InstallMod(modPath, false, main, ServiceProvider); + var expectedMod = gameInstallation.InstallMod(main, modPath, false).Mod; expectedMod.InstallModinfoFile(main); expectedMod.InstallModinfoFile(info1, "variant1"); expectedMod.InstallModinfoFile(info2, "variant2"); @@ -363,7 +366,8 @@ public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIden [InlineData(GameType.Foc)] public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) { - var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)); + var game = gameInstallation.Game; var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Create(); @@ -371,7 +375,7 @@ public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) var modPath = FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(steamLocation.FullName, "notASteamID")); modPath.Create(); - var expectedMod = game.InstallMod(modPath, false, new ModinfoData("MyMod"), ServiceProvider); + var expectedMod = gameInstallation.InstallMod(new ModinfoData("MyMod"), modPath, false).Mod; Assert.Equal(ModType.Default ,expectedMod.Type); var installedMods = _modFinder.FindMods(game, expectedMod.Directory).ToList(); @@ -383,7 +387,8 @@ public void FindMods_FromExternal_InsideSteamWsDirWithNonIdName(GameType type) [InlineData(GameType.Foc)] public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType type) { - var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)); + var game = gameInstallation.Game; var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Create(); @@ -391,7 +396,7 @@ public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType t var modPath = FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(steamLocation.FullName, "notASteamID")); modPath.Create(); - game.InstallMod(modPath, false, new ModinfoData("MyMod"), ServiceProvider); + gameInstallation.InstallMod(new ModinfoData("MyMod"), modPath, false); var installedMods = _modFinder.FindMods(game).ToList(); Assert.Empty(installedMods); @@ -419,7 +424,8 @@ public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameTyp [InlineData(GameType.Foc)] public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameType type) { - var game = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)); + var game = gameInstallation.Game; var steamHelper = ServiceProvider.GetRequiredService(); var steamLocation = steamHelper.GetWorkshopsLocation(game); steamLocation.Delete(true); @@ -427,7 +433,7 @@ public void FindMods_NoSteamWsDirectoryExistsShouldStillFindExternalMods(GameTyp var modPath = FileSystem.DirectoryInfo.New("external/MyMod"); modPath.Create(); - game.InstallMod(modPath, false, new ModinfoData("MyMod"), ServiceProvider); + gameInstallation.InstallMod(new ModinfoData("MyMod"), modPath, false); var installedMods = _modFinder.FindMods(game).ToList(); Assert.Empty(installedMods); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 70e1b497..08388d87 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -12,7 +12,6 @@ using PG.StarWarsGame.Infrastructure.Services.Detection; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Xunit; @@ -146,14 +145,14 @@ public void Directory_SteamWithoutModinfoCannotDecide() // No SteamData here var modinfo = new ModinfoData("Name"); - var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); // Using an ID here, which never points to a real mod. - var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("1234"); + var modDir = steamHelpers.GetWorkshopsLocation(gameInstallation.Game).CreateSubdirectory("1234"); - var steamMod = game.InstallMod(modDir, true, modinfo, ServiceProvider); + var steamMod = gameInstallation.InstallMod(modinfo, modDir, true).Mod; var info = CreateDetectedModReference(steamMod.Directory, ModType.Workshops, modinfo); var resolver = CreateResolver(); @@ -179,12 +178,12 @@ public void Directory_SteamWithInvalidDirName() SteamData = steamData }; - var game = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(Random.Enum(), GamePlatform.SteamGold)); var steamHelpers = ServiceProvider.GetRequiredService(); - var modDir = steamHelpers.GetWorkshopsLocation(game).CreateSubdirectory("notASteamId"); + var modDir = steamHelpers.GetWorkshopsLocation(gameInstallation.Game).CreateSubdirectory("notASteamId"); - var steamMod = game.InstallMod(modDir, true, modinfo, ServiceProvider); + var steamMod = gameInstallation.InstallMod(modinfo, modDir, true).Mod; // This asserts that we do not use steam data from modinfo if the directory is not a valid steam workshops id var info = CreateDetectedModReference(steamMod.Directory, ModType.Workshops, modinfo); @@ -333,9 +332,10 @@ public void ModsNotInModsDirButSomeOtherGameBasesDir_NotDecidable(GameType gameT SteamData = steamData }; - var game = GetOrCreateGameInstallation(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))).Game; + var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(gameType, Random.Item(GITestUtilities.RealPlatforms))); + var game = gameInstallation.Game; var modDir = game.Directory.CreateSubdirectory("ModsOther").CreateSubdirectory("MyMod"); - var mod = game.InstallMod(modDir, false, modinfo, ServiceProvider); + var mod = gameInstallation.InstallMod(modinfo, modDir, false).Mod; var info = CreateDetectedModReference(mod.Directory, ModType.Default, modinfo); var resolver = CreateResolver(); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index c4053f6c..a89867b3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -24,7 +24,7 @@ public ModTest() private IDirectoryInfo CreateModDirectoryInfo(string name) { - return FileSystem.DirectoryInfo.New(Game.GetModDirectory(name, _isWorkshop, ServiceProvider)); + return GameInstallation.GetModDirectory(name, _isWorkshop); } private IModReference CreateModRef(string name) @@ -96,9 +96,9 @@ public void InvalidCtor_Throws() public void ValidCtor_Properties_FromName() { var ws = GITestUtilities.GetRandomWorkshopFlag(Game); - var loc = Game.GetModDirectory("Mod", ws, ServiceProvider); + var loc = GameInstallation.GetModDirectory("Mod", ws); - var mod = new Mod(Game, "ModId", FileSystem.DirectoryInfo.New(loc), ws, "Mod", ServiceProvider); + var mod = new Mod(Game, "ModId", loc, ws, "Mod", ServiceProvider); Assert.Same(Game, mod.Game); Assert.Equal("Mod", mod.Name); @@ -121,7 +121,7 @@ public void ValidCtor_Properties_FromName() public void ValidCtor_Properties_FromModinfo_WithoutDependencies() { var ws = GITestUtilities.GetRandomWorkshopFlag(Game); - var loc = Game.GetModDirectory("Mod", ws, ServiceProvider); + var loc = GameInstallation.GetModDirectory("Mod", ws); var modInfo = new ModinfoData("Mod") { @@ -129,7 +129,7 @@ public void ValidCtor_Properties_FromModinfo_WithoutDependencies() Version = new SemVersion(1, 0, 0), Languages = new List(), }; - var mod = new Mod(Game, "ModId", FileSystem.DirectoryInfo.New(loc), ws, modInfo, ServiceProvider); + var mod = new Mod(Game, "ModId", loc, ws, modInfo, ServiceProvider); Assert.Same(Game, mod.Game); Assert.Equal("Mod", mod.Name); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 510565d1..a34d0330 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -20,9 +20,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Test; @@ -83,9 +83,9 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga AssertExpectedGame(foc, actualFoc); // Init Mods - CreateExternalMod(actualFoc); + CreateExternalMod(focInstallation); if (platform == GamePlatform.SteamGold) - CreateAndAddSteamScenario(actualFoc); + CreateAndAddSteamScenario(focInstallation); Eaw_CreateModInModsDir(eawInstallation); @@ -219,18 +219,18 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga } } - private void CreateAndAddSteamScenario(IGame actualFoc) + private void CreateAndAddSteamScenario(ITestingGameInstallation gameInstallation) { - Assert.Equal(GamePlatform.SteamGold, actualFoc.Platform); + var game = gameInstallation.Game; + Assert.Equal(GamePlatform.SteamGold, game.Platform); var steamHelper = ServiceProvider.GetRequiredService(); - var republicAtWarDir = FileSystem.Path.Combine(steamHelper.GetWorkshopsLocation(actualFoc).FullName, "1129810972"); // This is RaW's Steam ID - actualFoc.InstallMod(FileSystem.DirectoryInfo.New(republicAtWarDir), true, new ModinfoData("NOT USED"), ServiceProvider); + var republicAtWarDir = FileSystem.Path.Combine(steamHelper.GetWorkshopsLocation(game).FullName, "1129810972"); // This is RaW's Steam ID + gameInstallation.InstallMod(new ModinfoData("NOT USED"), FileSystem.DirectoryInfo.New(republicAtWarDir), true); - var rawSubModDir = FileSystem.Path.Combine(steamHelper.GetWorkshopsLocation(actualFoc).FullName, "123456"); // Just some ID - var rawSubMod = actualFoc.InstallMod(FileSystem.DirectoryInfo.New(rawSubModDir), true, - new ModinfoData("NOT USED"), ServiceProvider); + var rawSubModDir = FileSystem.Path.Combine(steamHelper.GetWorkshopsLocation(game).FullName, "123456"); // Just some ID + var rawSubMod = gameInstallation.InstallMod(new ModinfoData("NOT USED"), FileSystem.DirectoryInfo.New(rawSubModDir), true).Mod; var rawSubModModinfoContent = @" @@ -290,10 +290,10 @@ private void AssertModAddToGame(IGame game, IMod mod, Action assertAction) assertAction(mod); } - private void CreateExternalMod(IGame game) + private void CreateExternalMod(ITestingGameInstallation gameInstallation) { var modinfo = new ModinfoData("NAME NOT TAKE CAUSE NO MODINFO"); - game.InstallMod(FileSystem.DirectoryInfo.New("externalMods/MyExternalMod"), false, modinfo, ServiceProvider); + gameInstallation.InstallMod(modinfo, FileSystem.DirectoryInfo.New("externalMods/MyExternalMod"), false); } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs index 7b965823..56e53a34 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs @@ -1,8 +1,8 @@ -using PG.StarWarsGame.Infrastructure.Games; -using System.IO.Abstractions; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +using System.IO.Abstractions; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; @@ -43,7 +43,7 @@ public interface ITestingGameInstallation : ITestingModContainerInstallation ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDependencyList dependencies); - - ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo); + + IDirectoryInfo GetModDirectory(string name, bool workshop); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs similarity index 65% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs index ce8876af..46271eab 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs @@ -3,49 +3,20 @@ using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System; using System.IO.Abstractions; +using PG.StarWarsGame.Infrastructure.Utilities; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; -internal class TestingGameImpl : ITestingGameInstallation +internal partial class TestingGameInstallationImpl { - private readonly IFileSystem _fileSystem; - private readonly IServiceProvider _serviceProvider; - - public IGame Game { get; } - - public ITestingGameInstallation GameInstallation => this; - - public PlayableModContainer ModContainer => Game as PlayableModContainer; - - public IPlayableObject PlayableObject => Game; - - public TestingGameImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - _fileSystem = serviceProvider.GetRequiredService(); - Game = Install(gameIdentity); - } - - public void InstallDebug() - { - if (Game.Platform is not GamePlatform.SteamGold) - Assert.Fail($"Cannot install Debug files for non-Steam game '{Game}'"); - GameInstallationHelper.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); - } - - public IDirectoryInfo GetWrongOriginFocRegistryLocation() - { - return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); - } - public ITestingPhysicalModInstallation InstallMod(string name, bool workshop) { - var mod = ModInstallations.CreateMod(Game, name, workshop, _serviceProvider, - modDir => new Mod(Game, name, modDir, workshop, name, _serviceProvider)); + var mod = CreateMod(name, workshop, modDir => new Mod(Game, name, modDir, workshop, name, _serviceProvider)); return new TestingPhysicalModImpl(this, mod, _serviceProvider); } @@ -58,8 +29,7 @@ public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo) public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, bool workshop) { var name = modinfo.Name; - var mod = ModInstallations.CreateMod(Game, name, workshop, _serviceProvider, modDir - => new Mod(Game, name, modDir, workshop, modinfo, _serviceProvider)); + var mod = CreateMod(name, workshop, modDir => new Mod(Game, name, modDir, workshop, modinfo, _serviceProvider)); return new TestingPhysicalModImpl(this, mod, _serviceProvider); } @@ -71,8 +41,7 @@ public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryIn public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory, bool workshop) { - var mod = ModInstallations.CreateMod(Game, directory, dir => - new Mod(Game, modinfo.Name, dir, workshop, modinfo, _serviceProvider)); + var mod = CreateMod(directory, dir => new Mod(Game, modinfo.Name, dir, workshop, modinfo, _serviceProvider)); return new TestingPhysicalModImpl(this, mod, _serviceProvider); } @@ -146,17 +115,42 @@ public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWork return InstallAndAddMod(modinfo, isWorkshop); } - private IGame Install(IGameIdentity gameIdentity) + public IDirectoryInfo GetModDirectory(string name, bool workshop) { - var gameDir = gameIdentity.Type == GameType.Foc - ? GameInstallationHelper.InstallFoc(_fileSystem, gameIdentity.Platform) - : GameInstallationHelper.InstallEaw(_fileSystem, gameIdentity.Platform); + if (!workshop) + return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(Game.ModsLocation.FullName, name)); + if (workshop && Game.Platform is not GamePlatform.SteamGold) + { + Assert.Fail($"Game: {Game}, Mod: {name}, {workshop}"); + throw new InvalidOperationException("compiler flow"); + } + + var steamHelpers = _serviceProvider.GetRequiredService(); + var wsDir = steamHelpers.GetWorkshopsLocation(Game); + Assert.True(wsDir.Exists); - _fileSystem.InstallModsLocations(gameDir); + var nameHash = name.GetHashCode(); + var steamId = (ulong)nameHash; + if (!_fileSystem.Directory.Exists(_fileSystem.Path.Combine(wsDir.FullName, steamId.ToString()))) + { + steamHelpers.ToSteamWorkshopsId(steamId.ToString(), out var id); + Assert.Equal(steamId, id); + } + return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(wsDir.FullName, steamId.ToString())); + } - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), _serviceProvider); - Assert.True(game.Exists()); - return game; + private Mod CreateMod(string modName, bool workshop, Func modFactory) + { + var modDir = GetModDirectory(modName, workshop); + return CreateMod(modDir, modFactory); } -} + private Mod CreateMod(IDirectoryInfo directory, Func modFactory) + { + Assert.True(Game.ModsLocation.Exists); + var mod = modFactory(directory); + mod.Directory.Create(); + mod.DataDirectory().Create(); + return mod; + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs new file mode 100644 index 00000000..58ae7819 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs @@ -0,0 +1,54 @@ +using Microsoft.Extensions.DependencyInjection; +using PG.StarWarsGame.Infrastructure.Games; +using System; +using System.IO.Abstractions; +using Xunit; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; + +internal partial class TestingGameInstallationImpl : ITestingGameInstallation +{ + private readonly IFileSystem _fileSystem; + private readonly IServiceProvider _serviceProvider; + + public IGame Game { get; } + + public ITestingGameInstallation GameInstallation => this; + + public PlayableModContainer ModContainer => Game as PlayableModContainer; + + public IPlayableObject PlayableObject => Game; + + public TestingGameInstallationImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + _fileSystem = serviceProvider.GetRequiredService(); + Game = Install(gameIdentity); + } + + public void InstallDebug() + { + if (Game.Platform is not GamePlatform.SteamGold) + Assert.Fail($"Cannot install Debug files for non-Steam game '{Game}'"); + GameInstallationHelper.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); + } + + public IDirectoryInfo GetWrongOriginFocRegistryLocation() + { + return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); + } + + private IGame Install(IGameIdentity gameIdentity) + { + var gameDir = gameIdentity.Type == GameType.Foc + ? GameInstallationHelper.InstallFoc(_fileSystem, gameIdentity.Platform) + : GameInstallationHelper.InstallEaw(_fileSystem, gameIdentity.Platform); + + _fileSystem.InstallModsLocations(gameDir); + + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), _serviceProvider); + Assert.True(game.Exists()); + return game; + } +} + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs index ac86f2cb..86defd58 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs @@ -9,7 +9,7 @@ public static class GameInfrastructureTesting { public static ITestingGameInstallation Game(IGameIdentity gameIdentity, IServiceProvider serviceProvider) { - return new TestingGameImpl(gameIdentity, serviceProvider); + return new TestingGameInstallationImpl(gameIdentity, serviceProvider); } public static ITestingGameRegistry Registry(IServiceProvider serviceProvider) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs deleted file mode 100644 index 99efe710..00000000 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.IO.Abstractions; -using AET.Modinfo.Spec; -using Microsoft.Extensions.DependencyInjection; -using PG.StarWarsGame.Infrastructure.Games; -using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Services.Steam; -using PG.StarWarsGame.Infrastructure.Utilities; -using Xunit; - -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; - -public static partial class ModInstallations -{ - public static Mod InstallMod(this IGame game, IDirectoryInfo directory, bool isWorkshop, IModinfo modinfo, IServiceProvider serviceProvider) - { - return CreateMod(game, directory, dir => new Mod(game, modinfo.Name, dir, isWorkshop, modinfo, serviceProvider)); - } - - internal static Mod CreateMod(IGame game, string modName, bool workshop, IServiceProvider serviceProvider, Func modFactory) - { - var modDir = game.Directory.FileSystem.DirectoryInfo.New(game.GetModDirectory(modName, workshop, serviceProvider)); - return CreateMod(game, modDir, modFactory); - } - - internal static Mod CreateMod(IGame game, IDirectoryInfo directory, Func modFactory) - { - Assert.True(game.ModsLocation.Exists); - var mod = modFactory(directory); - mod.Directory.Create(); - mod.DataDirectory().Create(); - return mod; - } - - public static string GetModDirectory(this IGame game, string name, bool workshop, IServiceProvider serviceProvider) - { - var fs = game.Directory.FileSystem; - if (!workshop) - return fs.Path.Combine(game.ModsLocation.FullName, name); - if (workshop && game.Platform is not GamePlatform.SteamGold) - { - Assert.Fail($"Game: {game}, Mod: {name}, {workshop}"); - throw new InvalidOperationException("compiler flow"); - } - - var steamHelpers = serviceProvider.GetRequiredService(); - var wsDir = steamHelpers.GetWorkshopsLocation(game); - Assert.True(wsDir.Exists); - - var nameHash = name.GetHashCode(); - var steamId = (ulong)nameHash; - if (!fs.Directory.Exists(fs.Path.Combine(wsDir.FullName, steamId.ToString()))) - { - steamHelpers.ToSteamWorkshopsId(steamId.ToString(), out var id); - Assert.Equal(steamId, id); - } - return fs.Path.Combine(wsDir.FullName, steamId.ToString()); - } -} From afb279ec25c86d615439c085b4b52c4a129d5c60 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 17:13:45 +0100 Subject: [PATCH 36/71] base classes --- .../Game/TestingGameInstallationImpl.Mod.cs | 24 +++++----- .../Game/TestingGameInstallationImpl.cs | 30 +++++------- .../Mods/ITestingPhysicalModInstallation.cs | 7 ++- .../Installations/Mods/TestingModImpl.cs | 16 ------- .../Mods/TestingModInstallationImpl.cs | 17 +++++++ .../Mods/TestingPhysicalModImpl.cs | 13 ------ .../TestingPhysicalModInstallationImpl.cs | 46 +++++++++++++++++++ ...s => TestingVirtualModInstallationImpl.cs} | 4 +- .../TestingModContainerInstallation.cs | 9 ++++ .../TestingPlayableObjectInstallationImpl.cs | 17 +++++++ 10 files changed, 121 insertions(+), 62 deletions(-) delete mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs delete mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs rename test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/{TestingVirtualModImpl.cs => TestingVirtualModInstallationImpl.cs} (56%) create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs index 46271eab..0bdbbb94 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs @@ -16,8 +16,8 @@ internal partial class TestingGameInstallationImpl { public ITestingPhysicalModInstallation InstallMod(string name, bool workshop) { - var mod = CreateMod(name, workshop, modDir => new Mod(Game, name, modDir, workshop, name, _serviceProvider)); - return new TestingPhysicalModImpl(this, mod, _serviceProvider); + var mod = CreateMod(name, workshop, modDir => new Mod(Game, name, modDir, workshop, name, ServiceProvider)); + return new TestingPhysicalModInstallationImpl(this, mod, ServiceProvider); } public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo) @@ -29,8 +29,8 @@ public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo) public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, bool workshop) { var name = modinfo.Name; - var mod = CreateMod(name, workshop, modDir => new Mod(Game, name, modDir, workshop, modinfo, _serviceProvider)); - return new TestingPhysicalModImpl(this, mod, _serviceProvider); + var mod = CreateMod(name, workshop, modDir => new Mod(Game, name, modDir, workshop, modinfo, ServiceProvider)); + return new TestingPhysicalModInstallationImpl(this, mod, ServiceProvider); } public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory) @@ -41,8 +41,8 @@ public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryIn public ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory, bool workshop) { - var mod = CreateMod(directory, dir => new Mod(Game, modinfo.Name, dir, workshop, modinfo, _serviceProvider)); - return new TestingPhysicalModImpl(this, mod, _serviceProvider); + var mod = CreateMod(directory, dir => new Mod(Game, modinfo.Name, dir, workshop, modinfo, ServiceProvider)); + return new TestingPhysicalModInstallationImpl(this, mod, ServiceProvider); } public ITestingPhysicalModInstallation InstallMod(string name) @@ -98,9 +98,9 @@ public ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDepende public ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo) { - var mod = new VirtualMod(Game, "VirtualModId", modinfo, _serviceProvider); + var mod = new VirtualMod(Game, "VirtualModId", modinfo, ServiceProvider); Game.AddMod(mod); - return new TestingVirtualModImpl(this, mod, _serviceProvider); + return new TestingVirtualModInstallationImpl(this, mod, ServiceProvider); } public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWorkshop, IModDependencyList dependencies) @@ -118,25 +118,25 @@ public ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWork public IDirectoryInfo GetModDirectory(string name, bool workshop) { if (!workshop) - return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(Game.ModsLocation.FullName, name)); + return FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(Game.ModsLocation.FullName, name)); if (workshop && Game.Platform is not GamePlatform.SteamGold) { Assert.Fail($"Game: {Game}, Mod: {name}, {workshop}"); throw new InvalidOperationException("compiler flow"); } - var steamHelpers = _serviceProvider.GetRequiredService(); + var steamHelpers = ServiceProvider.GetRequiredService(); var wsDir = steamHelpers.GetWorkshopsLocation(Game); Assert.True(wsDir.Exists); var nameHash = name.GetHashCode(); var steamId = (ulong)nameHash; - if (!_fileSystem.Directory.Exists(_fileSystem.Path.Combine(wsDir.FullName, steamId.ToString()))) + if (!FileSystem.Directory.Exists(FileSystem.Path.Combine(wsDir.FullName, steamId.ToString()))) { steamHelpers.ToSteamWorkshopsId(steamId.ToString(), out var id); Assert.Equal(steamId, id); } - return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(wsDir.FullName, steamId.ToString())); + return FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(wsDir.FullName, steamId.ToString())); } private Mod CreateMod(string modName, bool workshop, Func modFactory) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs index 58ae7819..9234fe51 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs @@ -1,28 +1,22 @@ -using Microsoft.Extensions.DependencyInjection; -using PG.StarWarsGame.Infrastructure.Games; +using PG.StarWarsGame.Infrastructure.Games; using System; using System.IO.Abstractions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; -internal partial class TestingGameInstallationImpl : ITestingGameInstallation +internal partial class TestingGameInstallationImpl : TestingModContainerInstallation, ITestingGameInstallation { - private readonly IFileSystem _fileSystem; - private readonly IServiceProvider _serviceProvider; - public IGame Game { get; } - public ITestingGameInstallation GameInstallation => this; + public override ITestingGameInstallation GameInstallation => this; - public PlayableModContainer ModContainer => Game as PlayableModContainer; + public override PlayableModContainer ModContainer => Game as PlayableModContainer; - public IPlayableObject PlayableObject => Game; + public override IPlayableObject PlayableObject => Game; - public TestingGameInstallationImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) + public TestingGameInstallationImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) : base(serviceProvider) { - _serviceProvider = serviceProvider; - _fileSystem = serviceProvider.GetRequiredService(); Game = Install(gameIdentity); } @@ -30,23 +24,23 @@ public void InstallDebug() { if (Game.Platform is not GamePlatform.SteamGold) Assert.Fail($"Cannot install Debug files for non-Steam game '{Game}'"); - GameInstallationHelper.CreateFile(_fileSystem, _fileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); + GameInstallationHelper.CreateFile(FileSystem, FileSystem.Path.Combine(Game.Directory.FullName, "StarWarsI.exe")); } public IDirectoryInfo GetWrongOriginFocRegistryLocation() { - return _fileSystem.DirectoryInfo.New(_fileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); + return FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); } private IGame Install(IGameIdentity gameIdentity) { var gameDir = gameIdentity.Type == GameType.Foc - ? GameInstallationHelper.InstallFoc(_fileSystem, gameIdentity.Platform) - : GameInstallationHelper.InstallEaw(_fileSystem, gameIdentity.Platform); + ? GameInstallationHelper.InstallFoc(FileSystem, gameIdentity.Platform) + : GameInstallationHelper.InstallEaw(FileSystem, gameIdentity.Platform); - _fileSystem.InstallModsLocations(gameDir); + FileSystem.InstallModsLocations(gameDir); - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), _serviceProvider); + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), ServiceProvider); Assert.True(game.Exists()); return game; } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs index 56b6997c..602b1e5f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs @@ -1,8 +1,13 @@ -using PG.StarWarsGame.Infrastructure.Mods; +using AET.Modinfo.Spec; +using PG.StarWarsGame.Infrastructure.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public interface ITestingPhysicalModInstallation : ITestingModInstallation { new IPhysicalMod Mod { get; } + + IModinfoFile InstallInvalidModinfoFile(string? variantSubFileName = null); + + IModinfoFile InstallModinfoFile(IModinfo modinfo, string? variantSubFileName = null); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs deleted file mode 100644 index df2e6170..00000000 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModImpl.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; - -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; - -internal class TestingModImpl(ITestingGameInstallation gameInstallation, IMod mod, IServiceProvider serviceProvider) : ITestingModInstallation -{ - public ITestingGameInstallation GameInstallation { get; } = gameInstallation; - - public IPlayableObject PlayableObject => Mod; - - public IMod Mod { get; } = mod; - - public PlayableModContainer ModContainer => Mod as ModBase; -} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs new file mode 100644 index 00000000..0b409939 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs @@ -0,0 +1,17 @@ +using System; +using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; + +internal class TestingModInstallationImpl(ITestingGameInstallation gameInstallation, IMod mod, IServiceProvider serviceProvider) + : TestingModContainerInstallation(serviceProvider), ITestingModInstallation +{ + public override ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public override IPlayableObject PlayableObject => Mod; + + public IMod Mod { get; } = mod; + + public override PlayableModContainer ModContainer => Mod as ModBase; +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs deleted file mode 100644 index a0250778..00000000 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModImpl.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; - -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; - -internal sealed class TestingPhysicalModImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) - : TestingModImpl(gameInstallation, mod, serviceProvider), ITestingPhysicalModInstallation -{ - public ITestingGameInstallation GameInstallation { get; } = gameInstallation; - - public IPhysicalMod Mod { get; } = mod; -} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs new file mode 100644 index 00000000..7175209a --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using AET.Modinfo.File; +using AET.Modinfo.Spec; +using PG.StarWarsGame.Infrastructure.Mods; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; + +internal sealed class TestingPhysicalModInstallationImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) + : TestingModInstallationImpl(gameInstallation, mod, serviceProvider), ITestingPhysicalModInstallation +{ + public new ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public new IPhysicalMod Mod { get; } = mod; + + public IModinfoFile InstallInvalidModinfoFile(string? variantSubFileName = null) + { + return InstallModinfoFile(stream => { stream.WriteByte(0); }, variantSubFileName); + } + + public IModinfoFile InstallModinfoFile(IModinfo modinfo, string? variantSubFileName = null) + { + return InstallModinfoFile(modinfo.ToJson, variantSubFileName); + } + + private IModinfoFile InstallModinfoFile(Action writeAction, string? variantSubFileName) + { + var dir = Mod.Directory; + dir.Create(); + + var modinfoFilePath = FileSystem.Path.Combine(dir.FullName, + variantSubFileName != null + ? $"{variantSubFileName}-modinfo.json" + : "modinfo.json"); + + using var fileStream = FileSystem.FileStream.New(modinfoFilePath, FileMode.Create); + writeAction(fileStream); + + var fileInfo = FileSystem.FileInfo.New(modinfoFilePath); + + if (variantSubFileName is null) + return new MainModinfoFile(fileInfo); + return new ModinfoVariantFile(fileInfo); + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs similarity index 56% rename from test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs rename to test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs index db43788e..ab5a1863 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs @@ -4,8 +4,8 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; -internal sealed class TestingVirtualModImpl(ITestingGameInstallation gameInstallation, IVirtualMod mod, IServiceProvider serviceProvider) - : TestingModImpl(gameInstallation, mod, serviceProvider), ITestingVirtualModInstallation +internal sealed class TestingVirtualModInstallationImpl(ITestingGameInstallation gameInstallation, IVirtualMod mod, IServiceProvider serviceProvider) + : TestingModInstallationImpl(gameInstallation, mod, serviceProvider), ITestingVirtualModInstallation { public ITestingGameInstallation GameInstallation { get; } = gameInstallation; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs new file mode 100644 index 00000000..8ce0debd --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs @@ -0,0 +1,9 @@ +using System; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; + +internal abstract class TestingModContainerInstallation(IServiceProvider serviceProvider) + : TestingPlayableObjectInstallationImpl(serviceProvider), ITestingModContainerInstallation +{ + public abstract PlayableModContainer ModContainer { get; } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs new file mode 100644 index 00000000..bd724a64 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs @@ -0,0 +1,17 @@ +using System; +using System.IO.Abstractions; +using Microsoft.Extensions.DependencyInjection; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; + +internal abstract class TestingPlayableObjectInstallationImpl(IServiceProvider serviceProvider) + : ITestingPlayableObjectInstallation +{ + protected readonly IServiceProvider ServiceProvider = serviceProvider; + protected readonly IFileSystem FileSystem = serviceProvider.GetRequiredService(); + + public abstract ITestingGameInstallation GameInstallation { get; } + + public abstract IPlayableObject PlayableObject { get; } +} \ No newline at end of file From a4b37e6666304f16dbde1c1b65e55b7d20810a06 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 17:19:30 +0100 Subject: [PATCH 37/71] remove modinstallation --- .../ModServices/ModFinderTest.cs | 65 ++++++++++--------- ...oglyphGameInfrastructureIntegrationTest.cs | 5 +- .../Mods/ModInstallations.Modinfo.cs | 49 -------------- 3 files changed, 37 insertions(+), 82 deletions(-) delete mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 078add8d..877cf65f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -15,7 +15,6 @@ using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Installations; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using Semver; using Xunit; @@ -111,8 +110,9 @@ public void FindMods_OneMod_WithInvalidModinfo(GameIdentity gameIdentity) var gameInstallation = GetOrCreateGameInstallation(gameIdentity); var game = gameInstallation.Game; - var expectedMod = gameInstallation.InstallMod("MyMod").Mod; - expectedMod.InstallInvalidModinfoFile(); + var expectedModInstallation = gameInstallation.InstallMod("MyMod"); + expectedModInstallation.InstallInvalidModinfoFile(); + var expectedMod = expectedModInstallation.Mod; var installedMods = _modFinder.FindMods(game); AssertSingleFoundMod(installedMods, expectedMod, expectedMod.Directory.Name, null); @@ -128,11 +128,12 @@ public void FindMods_OneMod_WithOneInvalidModinfoVariant(GameIdentity gameIdenti var gameInstallation = GetOrCreateGameInstallation(gameIdentity); var game = gameInstallation.Game; - var expectedMod = gameInstallation.InstallMod("MyMod").Mod; + var expectedModInstallation = gameInstallation.InstallMod("MyMod"); var expectedModinfo = new ModinfoData("Variant1"); + var expectedMod = expectedModInstallation.Mod; - expectedMod.InstallModinfoFile(expectedModinfo, "variant1"); - expectedMod.InstallInvalidModinfoFile("variant2"); + expectedModInstallation.InstallModinfoFile(expectedModinfo, "variant1"); + expectedModInstallation.InstallInvalidModinfoFile("variant2"); var installedMods = _modFinder.FindMods(game); AssertSingleFoundMod(installedMods, expectedMod, $"{expectedMod.Directory.Name}:Variant1", expectedModinfo); @@ -149,8 +150,9 @@ public void FindMods_OneMod_WithMainModinfo(GameIdentity gameIdentity) var game = gameInstallation.Game; var modinfoData = new ModinfoData("MyMod"); - var expectedMod = gameInstallation.InstallMod(modinfoData).Mod; - expectedMod.InstallModinfoFile(modinfoData); + var expectedModInstallation = gameInstallation.InstallMod(modinfoData); + expectedModInstallation.InstallModinfoFile(modinfoData); + var expectedMod = expectedModInstallation.Mod; var installedMods = _modFinder.FindMods(game); AssertSingleFoundMod(installedMods, expectedMod, expectedMod.Directory.Name, modinfoData); @@ -168,9 +170,10 @@ public void FindMods_WithOnlyManyVariantModinfos(GameIdentity gameIdentity) var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); - var expectedMod = gameInstallation.InstallMod("DirName").Mod; - expectedMod.InstallModinfoFile(info1, "variant1"); - expectedMod.InstallModinfoFile(info2, "variant2"); + var expectedModInstallation = gameInstallation.InstallMod("DirName"); + expectedModInstallation.InstallModinfoFile(info1, "variant1"); + expectedModInstallation.InstallModinfoFile(info2, "variant2"); + var expectedMod = expectedModInstallation.Mod; var installedMods = _modFinder.FindMods(game).ToList(); AssertMultipleModsOfSameLocation( @@ -203,10 +206,11 @@ public void FindMods_WithMainAndManyVariantModinfos(GameIdentity gameIdentity) var main = new ModinfoData("Main"); var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); - var expectedMod = gameInstallation.InstallMod("DirName").Mod; - expectedMod.InstallModinfoFile(main); - expectedMod.InstallModinfoFile(info1, "variant1"); - expectedMod.InstallModinfoFile(info2, "variant2"); + var expectedModInstallation = gameInstallation.InstallMod("DirName"); + expectedModInstallation.InstallModinfoFile(main); + expectedModInstallation.InstallModinfoFile(info1, "variant1"); + expectedModInstallation.InstallModinfoFile(info2, "variant2"); + var expectedMod = expectedModInstallation.Mod; var installedMods = _modFinder.FindMods(game).ToList(); AssertMultipleModsOfSameLocation( @@ -258,8 +262,9 @@ public void FindMods_Steam_ShouldAddWorkshopsAndMods(GameType type) var steamMod = gameInstallation.InstallMod("SteamMod", true).Mod; var modinfo = new ModinfoData("Name"); - var defaultMod = gameInstallation.InstallMod(modinfo, false).Mod; - defaultMod.InstallModinfoFile(modinfo); + var defaultModInstallation = gameInstallation.InstallMod(modinfo, false); + defaultModInstallation.InstallModinfoFile(modinfo); + var defaultMod = defaultModInstallation.Mod; var installedMods = _modFinder.FindMods(game).ToList(); @@ -298,11 +303,11 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) }; - var modOfWrongGameType = gameInstallation.InstallMod(modinfo, true).Mod; + var modOfWrongGameType = gameInstallation.InstallMod(modinfo, true); modOfWrongGameType.InstallModinfoFile(modinfo); Assert.Empty(_modFinder.FindMods(game)); - Assert.Empty(_modFinder.FindMods(game, modOfWrongGameType.Directory)); + Assert.Empty(_modFinder.FindMods(game, modOfWrongGameType.Mod.Directory)); } [Theory] @@ -348,15 +353,15 @@ public void FindMods_FromExternal_WithVariantModinfoLayout(GameIdentity gameIden var main = new ModinfoData("Main"); var info1 = new ModinfoData("MyName1"); var info2 = new ModinfoData("MyName2"); - var expectedMod = gameInstallation.InstallMod(main, modPath, false).Mod; - expectedMod.InstallModinfoFile(main); - expectedMod.InstallModinfoFile(info1, "variant1"); - expectedMod.InstallModinfoFile(info2, "variant2"); + var expectedModInstallation = gameInstallation.InstallMod(main, modPath, false); + expectedModInstallation.InstallModinfoFile(main); + expectedModInstallation.InstallModinfoFile(info1, "variant1"); + expectedModInstallation.InstallModinfoFile(info2, "variant2"); - var baseId = expectedMod.Directory.FullName; + var baseId = expectedModInstallation.Mod.Directory.FullName; - var installedMods = _modFinder.FindMods(game, expectedMod.Directory).ToList(); - AssertMultipleModsOfSameLocation(installedMods, 3, expectedMod.Directory.FullName, ModType.Default, + var installedMods = _modFinder.FindMods(game, expectedModInstallation.Mod.Directory).ToList(); + AssertMultipleModsOfSameLocation(installedMods, 3, expectedModInstallation.Mod.Directory.FullName, ModType.Default, [$"{baseId}", $"{baseId}:MyName1", $"{baseId}:MyName2"], ["Main", "MyName1", "MyName2"]); } @@ -445,13 +450,13 @@ public void FindMods_InvalidModinfoContentIsSkippedButModIsFound(GameIdentity ga { var gameInstallation = GetOrCreateGameInstallation(gameIdentity); var game = gameInstallation.Game; - var expectedMod = gameInstallation.InstallMod("MyMod").Mod; - expectedMod.InstallModinfoFile(new CustomModinfo(string.Empty)); // string.Empty is not valid + var expectedModInstallation = gameInstallation.InstallMod("MyMod"); + expectedModInstallation.InstallModinfoFile(new CustomModinfo(string.Empty)); // string.Empty is not valid var installedMods = _modFinder.FindMods(game); - var expectedId = expectedMod.Type == ModType.Workshops ? ((ulong)"MyMod".GetHashCode()).ToString() : "MyMod"; + var expectedId = expectedModInstallation.Mod.Type == ModType.Workshops ? ((ulong)"MyMod".GetHashCode()).ToString() : "MyMod"; - AssertSingleFoundMod(installedMods, expectedMod, expectedId, null); + AssertSingleFoundMod(installedMods, expectedModInstallation.Mod, expectedId, null); } private static void AssertSingleFoundMod(IEnumerable foundMods, IPhysicalMod expectedMod, string expectedId, IModinfo? expectedModinfo) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index a34d0330..63451188 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -22,7 +22,6 @@ using System.Linq; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Test; @@ -230,7 +229,7 @@ private void CreateAndAddSteamScenario(ITestingGameInstallation gameInstallation var rawSubModDir = FileSystem.Path.Combine(steamHelper.GetWorkshopsLocation(game).FullName, "123456"); // Just some ID - var rawSubMod = gameInstallation.InstallMod(new ModinfoData("NOT USED"), FileSystem.DirectoryInfo.New(rawSubModDir), true).Mod; + var rawSubModInstallation = gameInstallation.InstallMod(new ModinfoData("NOT USED"), FileSystem.DirectoryInfo.New(rawSubModDir), true); var rawSubModModinfoContent = @" @@ -254,7 +253,7 @@ private void CreateAndAddSteamScenario(ITestingGameInstallation gameInstallation ], } }"; - rawSubMod.InstallModinfoFile(ModinfoData.Parse(rawSubModModinfoContent)); + rawSubModInstallation.InstallModinfoFile(ModinfoData.Parse(rawSubModModinfoContent)); } private void AssertModFinderResult(ICollection finderResult, diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs deleted file mode 100644 index 4e8de08c..00000000 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ModInstallations.Modinfo.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.IO; -using AET.Modinfo.File; -using AET.Modinfo.Spec; -using PG.StarWarsGame.Infrastructure.Mods; - -namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; - -public static partial class ModInstallations -{ - public static IModinfoFile InstallInvalidModinfoFile(this IPhysicalMod mod, string? variantSubFileName = null) - { - return InstallModinfoFile(mod, stream => { stream.WriteByte(0); }, variantSubFileName); - } - - public static IModinfoFile InstallModinfoFile( - this IPhysicalMod mod, - IModinfo modinfo, - string? variantSubFileName = null) - { - return InstallModinfoFile(mod, modinfo.ToJson, variantSubFileName); - } - - private static IModinfoFile InstallModinfoFile( - this IPhysicalMod mod, - Action writeAction, - string? variantSubFileName) - { - var dir = mod.Directory; - dir.Create(); - - var fs = dir.FileSystem; - - var modinfoFilePath = fs.Path.Combine(dir.FullName, - variantSubFileName != null - ? $"{variantSubFileName}-modinfo.json" - : "modinfo.json"); - - using var fileStream = fs.FileStream.New(modinfoFilePath, FileMode.Create); - writeAction(fileStream); - - var fileInfo = fs.FileInfo.New(modinfoFilePath); - - if (variantSubFileName is null) - return new MainModinfoFile(fileInfo); - return new ModinfoVariantFile(fileInfo); - } - -} \ No newline at end of file From 92c2613c5e1c388889e8622a62b537fa680400aa Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 17:42:32 +0100 Subject: [PATCH 38/71] move langauge installtion --- .../ModTest.cs | 7 +- .../PetroglyphStarWarsGameTest.cs | 2 +- .../Services/LanguageFinderTestBase.cs | 74 ++++++++++--------- .../Game/ITestingGameInstallation.cs | 2 +- .../Game/TestingGameInstallationImpl.cs | 10 ++- .../ITestingPlayableObjectInstallation.cs | 10 ++- .../Mods/ITestingPhysicalModInstallation.cs | 2 +- .../TestingPhysicalModInstallationImpl.cs | 9 ++- .../PlayableObjectTestingExtensions.cs | 52 +++++++++++++ .../PlayableObjectTestingExtensions.cs | 53 ------------- 10 files changed, 123 insertions(+), 98 deletions(-) create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs delete mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs index a89867b3..2ce248cb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModTest.cs @@ -48,15 +48,14 @@ private ITestingPhysicalModInstallation CreateAndAddPhysicalModInstallation( var modInstallation = GetOrCreateGameInstallation() .InstallAndAddMod(modinfo, CreateModDirectoryInfo(name), _isWorkshop); - var mod = modInstallation.Mod; if (languages is not null) { - foreach (var languageInfo in languages) - mod.InstallLanguage(languageInfo); + foreach (var languageInfo in languages) + modInstallation.InstallLanguage(languageInfo); } if (iconPath is not null) - FileSystem.File.Create(FileSystem.Path.Combine(mod.Directory.FullName, iconPath)); + FileSystem.File.Create(FileSystem.Path.Combine(modInstallation.Mod.Directory.FullName, iconPath)); return modInstallation; } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index aef4c741..8b80c214 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -20,7 +20,7 @@ private ITestingGameInstallation CreateGameInstallation(string? iconPath = null, if (languages is not null) { foreach (var languageInfo in languages) - gameInstallation.Game.InstallLanguage(languageInfo); + gameInstallation.InstallLanguage(languageInfo); } if (iconPath is not null) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs index 358bd6b9..99da7aa6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Services/LanguageFinderTestBase.cs @@ -3,12 +3,12 @@ using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Language; -using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System; using System.Collections.Generic; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Installations; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; namespace PG.StarWarsGame.Infrastructure.Test.Services; @@ -21,8 +21,9 @@ public LanguageFinderTest() _languageFinder = new InstalledLanguageFinder(ServiceProvider); } - private void InstallGameLanguage(LanguageInfo language) => Game.InstallLanguage(language); - private void InstallModLanguage(IPhysicalMod mod, LanguageInfo language) => mod.InstallLanguage(language); + private void InstallGameLanguage(LanguageInfo language) => GameInstallation.InstallLanguage(language); + + private void InstallModLanguage(ITestingPhysicalModInstallation modInstallation, LanguageInfo language) => modInstallation.InstallLanguage(language); [Fact] public void Ctor_NullArgTest_Throws() @@ -71,11 +72,11 @@ public void FindLanguages_Mod_WithNoLanguages_UsesGame() public void FindLanguages_Mod_WithLanguages_En_De_Steam() { var game = GameInfrastructureTesting.Game(new GameIdentity(GameType.Foc, GamePlatform.SteamGold), ServiceProvider); - var mod = game.InstallMod("myMod", true).Mod; - InstallModLanguage(mod, new LanguageInfo("de", LanguageSupportLevel.SFX)); - InstallModLanguage(mod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); + var modInstallation = game.InstallMod("myMod", true); + InstallModLanguage(modInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); + InstallModLanguage(modInstallation, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); - var langs = _languageFinder.FindLanguages(mod); + var langs = _languageFinder.FindLanguages(modInstallation.Mod); Assert.Equivalent(new List { @@ -87,15 +88,15 @@ public void FindLanguages_Mod_WithLanguages_En_De_Steam() [Fact] public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguages() { - var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; - InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); - InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); + var baseModInstallation = GameInstallation.InstallAndAddMod("baseMod"); + InstallModLanguage(baseModInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); + InstallModLanguage(baseModInstallation, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List { - new ModReference(baseMod) + new ModReference(baseModInstallation.Mod) }, DependencyResolveLayout.FullResolved) }; var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; @@ -153,22 +154,23 @@ public void FindLanguages_Mod_InheritLanguage_TargetModDoesNotHaveLanguagesAndDe [Fact] public void FindLanguages_Mod_TargetModDoesHaveDefaultLanguageInstalled() { - var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; - InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); - InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); + var baseModInstallation = GameInstallation.InstallAndAddMod("baseMod"); + InstallModLanguage(baseModInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); + InstallModLanguage(baseModInstallation, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List { - new ModReference(baseMod) + new ModReference(baseModInstallation.Mod) }, DependencyResolveLayout.FullResolved) }; - var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; + var modInstallation = GameInstallation.InstallAndAddMod(modInfo); + var mod = modInstallation.Mod; mod.ResolveDependencies(); // Only english is installed - InstallModLanguage(mod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); + InstallModLanguage(modInstallation, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); var langs = _languageFinder.FindLanguages(mod); @@ -179,15 +181,15 @@ public void FindLanguages_Mod_TargetModDoesHaveDefaultLanguageInstalled() [Fact] public void FindLanguages_Mod_TargetModDoesHaveModinfoLanguages() { - var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; - InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); - InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); + var baseModInstallation = GameInstallation.InstallAndAddMod("baseMod"); + InstallModLanguage(baseModInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); + InstallModLanguage(baseModInstallation, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List { - new ModReference(baseMod) + new ModReference(baseModInstallation.Mod) }, DependencyResolveLayout.FullResolved), Languages = new List { @@ -195,11 +197,12 @@ public void FindLanguages_Mod_TargetModDoesHaveModinfoLanguages() new LanguageInfo("de", LanguageSupportLevel.SFX) } }; - var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; + var modInstallation = GameInstallation.InstallAndAddMod(modInfo); + var mod = modInstallation.Mod; mod.ResolveDependencies(); // Should not be considered - InstallModLanguage(mod, new LanguageInfo("it", LanguageSupportLevel.FullLocalized)); + InstallModLanguage(modInstallation, new LanguageInfo("it", LanguageSupportLevel.FullLocalized)); var langs = _languageFinder.FindLanguages(mod); @@ -215,24 +218,25 @@ public void FindLanguages_Mod_TargetModDoesHaveModinfoLanguages() [Fact] public void FindLanguages_Mod_TargetModDoesHaveModinfoWithDefaultLanguagesExplicitlySet() { - var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; - InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); - InstallModLanguage(baseMod, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); + var baseModInstallation = GameInstallation.InstallAndAddMod("baseMod"); + InstallModLanguage(baseModInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); + InstallModLanguage(baseModInstallation, new LanguageInfo("en", LanguageSupportLevel.FullLocalized)); var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List { - new ModReference(baseMod) + new ModReference(baseModInstallation.Mod) }, DependencyResolveLayout.FullResolved), // Set language Languages = new List { LanguageInfo.Default } }; - var mod = GameInstallation.InstallAndAddMod(modInfo).Mod; + var modInstallation = GameInstallation.InstallAndAddMod(modInfo); + var mod = modInstallation.Mod; mod.ResolveDependencies(); // Should not be considered - InstallModLanguage(mod, new LanguageInfo("it", LanguageSupportLevel.FullLocalized)); + InstallModLanguage(modInstallation, new LanguageInfo("it", LanguageSupportLevel.FullLocalized)); var langs = _languageFinder.FindLanguages(mod); @@ -266,13 +270,13 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndDependencyAlsoDoes [Fact] public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndTransitiveDependencyHasLanguages() { - var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; - InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); + var baseModInstallation = GameInstallation.InstallAndAddMod("baseMod"); + InstallModLanguage(baseModInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); var middleModInfo = new ModinfoData("middleMod") { Dependencies = new DependencyList(new List { - new ModReference(baseMod) + new ModReference(baseModInstallation.Mod) }, DependencyResolveLayout.FullResolved) }; var middleMod = GameInstallation.InstallAndAddMod(middleModInfo).Mod; @@ -294,14 +298,14 @@ public void FindLanguages_Mod_TargetModDoesNotHaveLanguagesAndTransitiveDependen [Fact] public void FindLanguages_VirtualMod_TargetModDoesNotHaveLanguagesAndSecondDependencyHasLanguages() { - var baseMod = GameInstallation.InstallAndAddMod("baseMod").Mod; - InstallModLanguage(baseMod, new LanguageInfo("de", LanguageSupportLevel.SFX)); + var baseModInstallation = GameInstallation.InstallAndAddMod("baseMod"); + InstallModLanguage(baseModInstallation, new LanguageInfo("de", LanguageSupportLevel.SFX)); var middleMod = GameInstallation.InstallAndAddMod("middleMod").Mod; var modInfo = new ModinfoData("myMod") { Dependencies = new DependencyList(new List { - new ModReference(middleMod), new ModReference(baseMod) + new ModReference(middleMod), new ModReference(baseModInstallation.Mod) }, DependencyResolveLayout.ResolveRecursive) }; var mod = new VirtualMod(Game, "VirtualModId", modInfo, ServiceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs index 56e53a34..516e0de8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs @@ -6,7 +6,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; -public interface ITestingGameInstallation : ITestingModContainerInstallation +public interface ITestingGameInstallation : ITestingModContainerInstallation, ITestingPhysicalPlayableObjectInstallation { IGame Game { get; } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs index 9234fe51..10be7168 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs @@ -1,6 +1,7 @@ using PG.StarWarsGame.Infrastructure.Games; using System; using System.IO.Abstractions; +using AET.Modinfo.Spec; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; @@ -11,10 +12,12 @@ internal partial class TestingGameInstallationImpl : TestingModContainerInstalla public override ITestingGameInstallation GameInstallation => this; - public override PlayableModContainer ModContainer => Game as PlayableModContainer; + IPhysicalPlayableObject ITestingPhysicalPlayableObjectInstallation.PlayableObject => Game; public override IPlayableObject PlayableObject => Game; + public override PlayableModContainer ModContainer => Game as PlayableModContainer; + public TestingGameInstallationImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) : base(serviceProvider) { Game = Install(gameIdentity); @@ -32,6 +35,11 @@ public IDirectoryInfo GetWrongOriginFocRegistryLocation() return FileSystem.DirectoryInfo.New(FileSystem.Path.Combine(GameInstallationHelper.OriginBasePath, "corruption")); } + public void InstallLanguage(ILanguageInfo language) + { + PlayableObjectTestingUtilities.InstallLanguage(Game, language, FileSystem); + } + private IGame Install(IGameIdentity gameIdentity) { var gameDir = gameIdentity.Type == GameType.Foc diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs index b4578f88..ab089789 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs @@ -1,4 +1,5 @@ -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; +using AET.Modinfo.Spec; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; @@ -7,4 +8,11 @@ public interface ITestingPlayableObjectInstallation ITestingGameInstallation GameInstallation { get; } IPlayableObject PlayableObject { get; } +} + +public interface ITestingPhysicalPlayableObjectInstallation : ITestingPlayableObjectInstallation +{ + new IPhysicalPlayableObject PlayableObject { get; } + + void InstallLanguage(ILanguageInfo language); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs index 602b1e5f..3f4720a0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs @@ -3,7 +3,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; -public interface ITestingPhysicalModInstallation : ITestingModInstallation +public interface ITestingPhysicalModInstallation : ITestingModInstallation, ITestingPhysicalPlayableObjectInstallation { new IPhysicalMod Mod { get; } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs index 7175209a..6c9e2316 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs @@ -8,10 +8,17 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; internal sealed class TestingPhysicalModInstallationImpl(ITestingGameInstallation gameInstallation, IPhysicalMod mod, IServiceProvider serviceProvider) - : TestingModInstallationImpl(gameInstallation, mod, serviceProvider), ITestingPhysicalModInstallation + : TestingModInstallationImpl(gameInstallation, mod, serviceProvider), ITestingPhysicalModInstallation, ITestingPhysicalPlayableObjectInstallation { public new ITestingGameInstallation GameInstallation { get; } = gameInstallation; + + public IPhysicalPlayableObject PlayableObject => Mod; + public void InstallLanguage(ILanguageInfo language) + { + PlayableObjectTestingUtilities.InstallLanguage(PlayableObject, language, FileSystem); + } + public new IPhysicalMod Mod { get; } = mod; public IModinfoFile InstallInvalidModinfoFile(string? variantSubFileName = null) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs new file mode 100644 index 00000000..ab710b55 --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs @@ -0,0 +1,52 @@ +using System.IO.Abstractions; +using AET.Modinfo.Spec; +using PG.StarWarsGame.Infrastructure.Services.Language; +using PG.StarWarsGame.Infrastructure.Utilities; +using Xunit; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; + +internal static class PlayableObjectTestingUtilities +{ + public static void InstallLanguage(IPhysicalPlayableObject obj, ILanguageInfo language, IFileSystem fileSystem) + { + var languageName = LanguageInfoUtilities.GetEnglishName(language); + var dataDir = obj.DataDirectory(); + Assert.NotNull(languageName); + if (language.Support.HasFlag(LanguageSupportLevel.Text)) + InstallText(dataDir, languageName, fileSystem); + if (language.Support.HasFlag(LanguageSupportLevel.SFX)) + InstallSfx(dataDir, languageName, fileSystem); + if (language.Support.HasFlag(LanguageSupportLevel.Speech)) + InstallSpeech(dataDir, languageName, fileSystem); + } + + private static void InstallText(IDirectoryInfo dataDir, string languageName, IFileSystem fileSystem) + { + var masterTextFileName = $"MasterTextFile_{languageName}.dat"; + + var dir = fileSystem.Path.Combine(dataDir.FullName, "Text"); + fileSystem.Directory.CreateDirectory(dir); + + var filePath = fileSystem.Path.Combine(dir, masterTextFileName); + using var _ = fileSystem.File.Create(filePath); + } + + private static void InstallSfx(IDirectoryInfo dataDir, string languageName, IFileSystem fileSystem) + { + var sfxFileName = $"SFX2D_{languageName}.meg"; + + var dir = fileSystem.Path.Combine(dataDir.FullName, "Audio", "SFX"); + fileSystem.Directory.CreateDirectory(dir); + + var filePath = fileSystem.Path.Combine(dir, sfxFileName); + using var _ = fileSystem.File.Create(filePath); + } + + private static void InstallSpeech(IDirectoryInfo dataDir, string languageName, IFileSystem fileSystem) + { + var sfxFileName = $"{languageName}Speech.meg"; + var filePath = fileSystem.Path.Combine(dataDir.FullName, sfxFileName); + using var _ = fileSystem.File.Create(filePath); + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs deleted file mode 100644 index 3de6f41c..00000000 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PlayableObjectTestingExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -using AET.Modinfo.Spec; -using PG.StarWarsGame.Infrastructure.Services.Language; -using PG.StarWarsGame.Infrastructure.Utilities; -using Xunit; - -namespace PG.StarWarsGame.Infrastructure.Testing; - -public static class PlayableObjectTestingExtensions -{ - public static void InstallLanguage(this IPhysicalPlayableObject obj, ILanguageInfo language) - { - var languageName = LanguageInfoUtilities.GetEnglishName(language); - Assert.NotNull(languageName); - if (language.Support.HasFlag(LanguageSupportLevel.Text)) - obj.InstallText(languageName); - if (language.Support.HasFlag(LanguageSupportLevel.SFX)) - obj.InstallSfx(languageName); - if (language.Support.HasFlag(LanguageSupportLevel.Speech)) - obj.InstallSpeech(languageName); - } - - private static void InstallText(this IPhysicalPlayableObject obj, string languageName) - { - var fs = obj.Directory.FileSystem; - var masterTextFileName = $"MasterTextFile_{languageName}.dat"; - - var dir = fs.Path.Combine(obj.DataDirectory().FullName, "Text"); - fs.Directory.CreateDirectory(dir); - - var filePath = fs.Path.Combine(dir, masterTextFileName); - using var _ = fs.File.Create(filePath); - } - - private static void InstallSfx(this IPhysicalPlayableObject obj, string languageName) - { - var fs = obj.Directory.FileSystem; - var sfxFileName = $"SFX2D_{languageName}.meg"; - - var dir = fs.Path.Combine(obj.DataDirectory().FullName, "Audio", "SFX"); - fs.Directory.CreateDirectory(dir); - - var filePath = fs.Path.Combine(dir, sfxFileName); - using var _ = fs.File.Create(filePath); - } - - private static void InstallSpeech(this IPhysicalPlayableObject obj, string languageName) - { - var fs = obj.Directory.FileSystem; - var sfxFileName = $"{languageName}Speech.meg"; - var filePath = fs.Path.Combine(obj.DataDirectory().FullName, sfxFileName); - using var _ = fs.File.Create(filePath); - } -} \ No newline at end of file From 5c959d7d1211b54785c43c7f633d498a98ccfa14 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 19 Dec 2025 17:54:43 +0100 Subject: [PATCH 39/71] some corrections --- .../Linux/LinuxSteamRegistry.cs | 1 + .../SteamWrapperTestBase.cs | 2 +- .../TestBases/SteamTestBase.cs | 1 + test/AET.Testing/ExceptionHelpers.cs | 8 ++++---- .../SteamPetroglyphStarWarsGameClientTest.cs | 2 +- .../SteamWorkshopWebpageDownloaderTest.cs | 4 ++-- .../ModBaseTest.cs | 1 + .../ModEqualityComparerTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 14 +++++++------- .../ModServices/ModFinderTest.cs | 15 +++++++++------ .../PetroglyphStarWarsGameTest.cs | 2 +- .../Game/TestingGameInstallationImpl.cs | 2 +- .../Installations/Mods/ITestingModInstallation.cs | 2 +- .../Mods/TestingModInstallationImpl.cs | 2 +- .../Mods/TestingPhysicalModInstallationImpl.cs | 2 +- .../Mods/TestingVirtualModInstallationImpl.cs | 4 ++-- .../TestBases/GameInfrastructureTestBase.cs | 1 + 17 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs b/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs index e8c040ad..f02d947e 100644 --- a/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs +++ b/src/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs @@ -17,6 +17,7 @@ internal class LinuxSteamRegistry(IServiceProvider serviceProvider) : Disposable public IDirectoryInfo? InstallationDirectory { get; } public int? ProcessId { get; } + public IRegistryKey? OpenSteamRegistryKey() { throw new NotImplementedException(); diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 125ec804..306b61f3 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -360,7 +360,7 @@ public async Task WaitSteamRunningAndLoggedInAsync_UserDoesNotLoginBeforeCancell private void StopSteam() { - Steam?.Registry.SetPid(null); + Steam.Registry.SetPid(null); ProcessHelper!.SetRunningPid(null); } diff --git a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs index f976d963..ba2cf675 100644 --- a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs @@ -7,6 +7,7 @@ namespace AET.SteamAbstraction.Testing.TestBases; public abstract class SteamTestBase : TestBaseWithServiceProvider, IDisposable { protected readonly ITestingSteamInstallation Steam; + protected SteamTestBase() { Steam = SteamTesting.Steam(ServiceProvider); diff --git a/test/AET.Testing/ExceptionHelpers.cs b/test/AET.Testing/ExceptionHelpers.cs index 8d0ccb98..b5554fbd 100644 --- a/test/AET.Testing/ExceptionHelpers.cs +++ b/test/AET.Testing/ExceptionHelpers.cs @@ -8,10 +8,10 @@ namespace AET.Testing; public class ExceptionHelpers { public static void ValidateExceptionProperties(Exception e, - Exception innerException = null, - string message = null, - string source = null, - string stackTrace = null, + Exception? innerException = null, + string? message = null, + string? source = null, + string? stackTrace = null, bool validateMessage = true) { Assert.Equal(innerException, e.InnerException); diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index 78477177..ed489a85 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -36,7 +36,7 @@ protected override ITestingGameInstallation GetOrCreateGameInstallation(IGameIde return _gameInstallation; var type = identity?.Type ?? Random.Enum(); var steamIdentity = new GameIdentity(type, GamePlatform.SteamGold); - return GameInfrastructureTesting.Game(steamIdentity, ServiceProvider); + return _gameInstallation = GameInfrastructureTesting.Game(steamIdentity, ServiceProvider); } protected override void BeforePlay() diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamWorkshopWebpageDownloaderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamWorkshopWebpageDownloaderTest.cs index 74bbf63a..1b448854 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamWorkshopWebpageDownloaderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamWorkshopWebpageDownloaderTest.cs @@ -14,8 +14,8 @@ public async Task GetSteamWorkshopsPageHtmlAsync() var html = await downloader.GetSteamWorkshopsPageHtmlAsync(1129810972, CultureInfo.InvariantCulture); var htmlDe = await downloader.GetSteamWorkshopsPageHtmlAsync(1129810972, new CultureInfo("de")); - var lang = html!.GetElementbyId("language_pulldown").InnerText; - var langDe = htmlDe!.GetElementbyId("language_pulldown").InnerText; + var lang = html.GetElementbyId("language_pulldown").InnerText; + var langDe = htmlDe.GetElementbyId("language_pulldown").InnerText; Assert.Equal("language", lang); Assert.Equal("Sprache", langDe); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 1a13d191..69346eee 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -24,6 +24,7 @@ public abstract class ModBaseTest : PlayableModContainerTest protected ModBaseTest() { + // ReSharper disable once VirtualMemberCallInConstructor GameInstallation = GetOrCreateGameInstallation(); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index 2f561e43..c5d72146 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -69,7 +69,7 @@ public void Equals_ShouldAlwaysBeEquals(bool includeDeps, bool includeGame) public void Equals_DependencyAware(bool depAware) { var dep = new ModReference("B", ModType.Default); - var modA = (IPhysicalMod)InstallAndAddModWithDependencies("A", deps: dep).Mod; + var modA = InstallAndAddModWithDependencies("A", deps: dep).Mod; var sameishModindo = new ModinfoData("A") { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index 92c45cf8..a142f3ac 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -220,7 +220,7 @@ public void CreateVirtualMod_NullArgs_Throws() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod_WithInvalidModinfo(GameIdentity gameIdentity) { - var gameInstallation = GetOrCreateGameInstallation(); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); var game = gameInstallation.Game; var dep = gameInstallation.InstallMod("dep", false).Mod; @@ -250,7 +250,7 @@ public void CreateVirtualMod_WithInvalidModinfo_NoDependencies(GameIdentity game [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void CreateVirtualMod(GameIdentity gameIdentity) { - var gameInstallation = GetOrCreateGameInstallation(); + var gameInstallation = GetOrCreateGameInstallation(gameIdentity); var game = gameInstallation.Game; var dep = gameInstallation.InstallMod("dep", false).Mod; @@ -306,7 +306,7 @@ public bool Equals(IModIdentity? other) } public string Name { get; } = name; - public SemVersion? Version { get; } + public SemVersion? Version => null; public IModDependencyList Dependencies { get; init; } = DependencyList.EmptyDependencyList; public string ToJson() { @@ -318,12 +318,12 @@ public void ToJson(Stream stream) JsonSerializer.Serialize(stream, this, JsonSerializerOptions.Default); } - public string? Summary { get; } - public string? Icon { get; } + public string? Summary => null; + public string? Icon => null; public IDictionary Custom { get; } = new Dictionary(); - public ISteamData? SteamData { get; } + public ISteamData? SteamData => null; public IReadOnlyCollection Languages { get; } = new List(); - public bool LanguagesExplicitlySet { get; } + public bool LanguagesExplicitlySet => false; } } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 877cf65f..3cb7bea6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -473,6 +473,7 @@ private static void AssertSingleFoundMod(IEnumerable found Assert.Equal(expectedId, foundMod.ModReference.Identifier); } + // ReSharper disable ParameterOnlyUsedForPreconditionCheck.Local private static void AssertMultipleModsOfSameLocation( ICollection detectedMods, int expectedCount, @@ -493,6 +494,7 @@ private static void AssertMultipleModsOfSameLocation( Assert.Equivalent(expectedModinfoNames, detectedMods.Select(x => x.Modinfo?.Name), true); } + // ReSharper restore ParameterOnlyUsedForPreconditionCheck.Local private class CustomModinfo(string name) : IModinfo { @@ -502,8 +504,9 @@ public bool Equals(IModIdentity? other) } public string Name { get; } = name; - public SemVersion? Version { get; } - public IModDependencyList Dependencies { get; } = DependencyList.EmptyDependencyList; + public SemVersion? Version => null; + public IModDependencyList Dependencies => DependencyList.EmptyDependencyList; + public string ToJson() { return JsonSerializer.Serialize(this, JsonSerializerOptions.Default); @@ -514,11 +517,11 @@ public void ToJson(Stream stream) JsonSerializer.Serialize(stream, this, JsonSerializerOptions.Default); } - public string? Summary { get; } - public string? Icon { get; } + public string? Summary => null; + public string? Icon => null; public IDictionary Custom { get; } = new Dictionary(); - public ISteamData? SteamData { get; } + public ISteamData? SteamData => null; public IReadOnlyCollection Languages { get; } = new List(); - public bool LanguagesExplicitlySet { get; } + public bool LanguagesExplicitlySet => false; } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index 8b80c214..fabf010f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -71,7 +71,7 @@ public void Equals_GetHashCode() var focSteam = GameInfrastructureTesting.Game(focSteamId, ServiceProvider).Game; var eawDisc = GameInfrastructureTesting.Game(eawDiskId, ServiceProvider).Game; - Assert.False(eawSteam.Equals(null)); + Assert.False(eawSteam.Equals(null!)); Assert.False(eawSteam.Equals((object)null!)); Assert.False(eawSteam.Equals(new object())); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs index 10be7168..ea2d1415 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs @@ -16,7 +16,7 @@ internal partial class TestingGameInstallationImpl : TestingModContainerInstalla public override IPlayableObject PlayableObject => Game; - public override PlayableModContainer ModContainer => Game as PlayableModContainer; + public override PlayableModContainer ModContainer => (Game as PlayableModContainer)!; public TestingGameInstallationImpl(IGameIdentity gameIdentity, IServiceProvider serviceProvider) : base(serviceProvider) { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs index bb4f0865..7a671624 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs @@ -5,7 +5,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; public interface ITestingModInstallation : ITestingModContainerInstallation { - ITestingGameInstallation GameInstallation { get; } + new ITestingGameInstallation GameInstallation { get; } IMod Mod { get; } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs index 0b409939..f918a8c5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs @@ -13,5 +13,5 @@ internal class TestingModInstallationImpl(ITestingGameInstallation gameInstallat public IMod Mod { get; } = mod; - public override PlayableModContainer ModContainer => Mod as ModBase; + public override PlayableModContainer ModContainer => (Mod as ModBase)!; } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs index 6c9e2316..66851de6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs @@ -12,7 +12,7 @@ internal sealed class TestingPhysicalModInstallationImpl(ITestingGameInstallatio { public new ITestingGameInstallation GameInstallation { get; } = gameInstallation; - public IPhysicalPlayableObject PlayableObject => Mod; + public new IPhysicalPlayableObject PlayableObject => Mod; public void InstallLanguage(ILanguageInfo language) { diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs index ab5a1863..40f53b86 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs @@ -7,7 +7,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; internal sealed class TestingVirtualModInstallationImpl(ITestingGameInstallation gameInstallation, IVirtualMod mod, IServiceProvider serviceProvider) : TestingModInstallationImpl(gameInstallation, mod, serviceProvider), ITestingVirtualModInstallation { - public ITestingGameInstallation GameInstallation { get; } = gameInstallation; + public new ITestingGameInstallation GameInstallation { get; } = gameInstallation; - public IVirtualMod Mod { get; } = mod; + public new IVirtualMod Mod { get; } = mod; } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index da8df496..c6b83f54 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -7,6 +7,7 @@ using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using System.Threading; using Testably.Abstractions.Testing; From d5e86192edc4e58fd9b5613de7d2a9b31b7e41c8 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sat, 20 Dec 2025 11:15:23 +0100 Subject: [PATCH 40/71] start documenting code --- .../SteamRegistryTestBase.cs | 12 +++-- .../Windows/WindowsSteamRegistryTest.cs | 5 ++- .../AssemblyInfo.cs | 3 -- .../ISteamFakeProcess.cs | 6 +++ .../ITestingSteamInstallation.cs | 44 ++++++++++++++++++- .../ITestingSteamLibrary.cs | 33 +++++++++++++- .../ITestingSteamRegistry.cs | 14 ++++++ .../SteamInstallationExtensions.cs | 16 +++++++ .../TestBases/InMemorySteamTestBase.cs | 7 +++ .../TestBases/SteamTestBase.cs | 21 +++++++++ .../TestProcessHelper.cs | 41 +++++++++++++++-- .../TestingSteamConstants.cs | 12 ++++- .../TestingSteamUserLoginMetadata.cs | 24 ++++++++-- .../TestBaseWithServiceProvider.cs | 23 ++++++++++ 14 files changed, 238 insertions(+), 23 deletions(-) delete mode 100644 test/AET.SteamAbstraction.Testing/AssemblyInfo.cs diff --git a/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs b/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs index d250857a..9a4496c7 100644 --- a/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs @@ -1,4 +1,5 @@ using AET.SteamAbstraction.Registry; +using AET.SteamAbstraction.Testing; using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; @@ -18,9 +19,6 @@ public abstract class SteamRegistryTestBase : TestBaseWithServiceProvider ? new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike) : new InMemoryRegistry(); - protected readonly string SteamInstallPath = "steamDir"; - protected readonly string SteamExePath = "steamDir/steam"; - protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); @@ -48,8 +46,8 @@ public void TestInstallationProperties_SteamInstalled() { var registry = CreateRegistry(); - Assert.Equal(FileSystem.FileInfo.New(SteamExePath).FullName, registry.ExecutableFile!.FullName); - Assert.Equal(FileSystem.DirectoryInfo.New(SteamInstallPath).FullName, registry.InstallationDirectory!.FullName); + Assert.Equal(FileSystem.FileInfo.New(TestingSteamConstants.SteamExePath).FullName, registry.ExecutableFile!.FullName); + Assert.Equal(FileSystem.DirectoryInfo.New(TestingSteamConstants.SteamInstallPath).FullName, registry.InstallationDirectory!.FullName); Assert.True(registry.ProcessId is null or 0); } @@ -58,8 +56,8 @@ public void TestInstallationProperties_SteamInstalledAndRunning() { var registry = CreateRegistry(); - Assert.Equal(FileSystem.FileInfo.New(SteamExePath).FullName, registry.ExecutableFile!.FullName); - Assert.Equal(FileSystem.DirectoryInfo.New(SteamInstallPath).FullName, registry.InstallationDirectory!.FullName); + Assert.Equal(FileSystem.FileInfo.New(TestingSteamConstants.SteamExePath).FullName, registry.ExecutableFile!.FullName); + Assert.Equal(FileSystem.DirectoryInfo.New(TestingSteamConstants.SteamInstallPath).FullName, registry.InstallationDirectory!.FullName); SetSteamPid(1234); diff --git a/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs b/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs index 6cd0fa0a..e19e1423 100644 --- a/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs +++ b/test/AET.SteamAbstraction.Test/Windows/WindowsSteamRegistryTest.cs @@ -1,6 +1,7 @@ #if Windows using AET.SteamAbstraction.Registry; +using AET.SteamAbstraction.Testing; using AnakinRaW.CommonUtilities.Registry; using Xunit; @@ -17,8 +18,8 @@ internal WindowsSteamRegistry CreateWindowsRegistry(bool steamExists = true) using var hkcu = InternalRegistry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default); using var steamKey = hkcu.CreateSubKey("Software\\Valve\\Steam")!; - steamKey.SetValue("SteamExe", FileSystem.Path.GetFullPath(SteamExePath)); - steamKey.SetValue("SteamPath", FileSystem.Path.GetFullPath(SteamInstallPath)); + steamKey.SetValue("SteamExe", FileSystem.Path.GetFullPath(TestingSteamConstants.SteamExePath)); + steamKey.SetValue("SteamPath", FileSystem.Path.GetFullPath(TestingSteamConstants.SteamInstallPath)); } return registry; diff --git a/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs b/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs deleted file mode 100644 index 81d8889c..00000000 --- a/test/AET.SteamAbstraction.Testing/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("AET.SteamAbstraction.Test")] \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs b/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs index 239ad43f..7d9c9372 100644 --- a/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs +++ b/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs @@ -1,6 +1,12 @@ namespace AET.SteamAbstraction.Testing; +/// +/// Represents a fake Steam process for testing purposes. +/// public interface ISteamFakeProcess { + /// + /// Terminates the associated process. + /// void Kill(); } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs index 81532f0b..5f74a93a 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs @@ -5,27 +5,69 @@ namespace AET.SteamAbstraction.Testing; +/// +/// Represents a testing Steam installation that can be manipulated for testing purposes. +/// public interface ITestingSteamInstallation : IDisposable { + /// + /// Gets the directory where the Steam is installed or if the test installation is not installed. + /// IDirectoryInfo? InstallationDirectory { get; } + /// + /// Gets the testing registry. + /// ITestingSteamRegistry Registry { get; } + /// + /// Installs the testing Steam installation to the file system and registry. + /// [SupportedOSPlatform("windows")] void Install(); + /// + /// Installs the testing Steam installation to the file system only. + /// void InstallSteamFilesOnly(); + /// + /// Starts a simulated Steam process for the specified process ID. + /// + /// The process identifier (PID) of the process to simulate. + /// An instance representing the simulated Steam process. [SupportedOSPlatform("windows")] ISteamFakeProcess FakeStart(int pid); + /// + /// Installs the default Steam game library. + /// + /// to add the installed library to the configuration; otherwise, . The default is . + /// An instance representing the newly installed game library. ITestingSteamLibrary InstallDefaultLibrary(bool addToConfig = true); + /// + /// Installs a new Steam game library at the specified path and returns the library. + /// + /// The path where the new Steam library will be installed. + /// to add the installed library to the configuration; otherwise, . The default is . + /// An instance representing the newly installed game library. ITestingSteamLibrary InstallLibrary(string path, bool addToConfig = true); + /// + /// Writes an invalid "loginusers.vdf". + /// void WriteCorruptLoginUsers(); + /// + /// Deletes the "loginusers.vdf" file. + /// void DeleteLoginUsersFile(); - + + /// + /// Writes the specified Steam user login information to a new "loginusers.vdf". + /// + /// A parameter array of collections containing the login metadata for each Steam user to write. + /// An representing the file containing the written login user data. IFileInfo WriteLoginUsers(params IEnumerable? users); } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs index d0e8cbad..721ff763 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs @@ -4,22 +4,53 @@ namespace AET.SteamAbstraction.Testing; +/// +/// Represents a testing Steam game library that can be manipulated for testing purposes. +/// public interface ITestingSteamLibrary : ISteamLibrary { + /// + /// Installs a game with the specified game ID, name, and manifest file name, and returns the associated + /// Steam application manifest. + /// + /// The ID of the game to install. + /// The display name of the game to be installed. + /// The name of the manifest file to use for installation. + /// A object representing the installed game's manifest. SteamAppManifest InstallGame(uint id, string gameName, string appManifestName); + /// + /// Installs a game with the specified game ID, name, number of installed depots and app state, and returns the associated + /// Steam application manifest. + /// + /// The ID of the game to install. + /// The display name of the game to be installed. + /// The number of depots to be installed. + /// The state of the installed game. + /// A object representing the installed game's manifest. SteamAppManifest InstallGame( uint id, string gameName, uint numberDepots = 1, SteamAppState appState = SteamAppState.StateFullyInstalled); + /// + /// Installs a game with the specified game ID, name, a list of installed depots and app state, and returns the associated + /// Steam application manifest. + /// + /// The ID of the game to install. + /// The display name of the game to be installed. + /// A list of depots to be installed. + /// The state of the installed game. + /// A object representing the installed game's manifest. SteamAppManifest InstallGame( uint id, string gameName, IList depots, SteamAppState appState = SteamAppState.StateFullyInstalled); - + /// + /// Creates an intentionally corrupted game manifest. + /// void InstallCorruptApp(); } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs index b771f3c5..0180c7a2 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs @@ -4,6 +4,9 @@ namespace AET.SteamAbstraction.Testing; +/// +/// Defines methods and properties for querying and manipulating a test Steam client's registry state. +/// public interface ITestingSteamRegistry : IDisposable { /// @@ -21,11 +24,22 @@ public interface ITestingSteamRegistry : IDisposable /// int? ProcessId { get; } + /// + /// Registers a test installation of the Steam client to the registry. + /// [SupportedOSPlatform("windows")] void InstallSteam(); + /// + /// Writes the specified process identifier as running Steam process to the registry. + /// + /// The process identifier to set. to indicate Steam is not running. [SupportedOSPlatform("windows")] void SetPid(int? pid); + /// + /// Writes the identifier for the current user to the registry. + /// + /// The unique identifier to assign to the user. void SetUserId(uint userId); } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs index 87c7202e..e2c452b9 100644 --- a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs +++ b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs @@ -2,13 +2,29 @@ namespace AET.SteamAbstraction.Testing; +/// +/// Provides factory methods for creating abstractions of Steam installations for testing purposes. +/// +/// +/// This class is intended for use in testing scenarios where mock or test implementations of Steam-related services are required. +/// public static class SteamTesting { + /// + /// Creates a new instance of a Steam installation abstraction for testing using the specified service provider. + /// + /// The service provider used to resolve dependencies required by the testing Steam installation. + /// An instance of initialized with the provided service provider. public static ITestingSteamInstallation Steam(IServiceProvider serviceProvider) { return new TestingSteamInstallationImpl(serviceProvider); } + /// + /// Creates a new instance of a Steam registry abstraction for testing using the specified service provider. + /// + /// The service provider used to resolve dependencies required by the testing Steam registry implementation. + /// An instance of initialized with the provided service provider. public static ITestingSteamRegistry SteamRegistry(IServiceProvider serviceProvider) { return new TestingSteamRegistryImpl(serviceProvider); diff --git a/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs index 81722ebf..97d0f632 100644 --- a/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs @@ -6,10 +6,17 @@ namespace AET.SteamAbstraction.Testing.TestBases; +/// +/// Provides a base class for Steam-related tests that work with in-memory file system and registry. +/// public abstract class InMemorySteamTestBase : SteamTestBase { + /// + /// Gets the in-memory file system used for testing. + /// protected readonly MockFileSystem FileSystem = new(); + /// protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); diff --git a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs index ba2cf675..9b5a0a15 100644 --- a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs @@ -4,21 +4,42 @@ namespace AET.SteamAbstraction.Testing.TestBases; +/// +/// Provides a base class for integration tests that require access to a testing Steam installation and related +/// services. +/// +/// +/// Inheritors can use the protected instance to interact with a +/// test Steam environment. The class ensures that required Steam services are initialized and disposed +/// appropriately. +/// public abstract class SteamTestBase : TestBaseWithServiceProvider, IDisposable { + /// + /// Gets the testing Steam installation instance for use in tests. + /// protected readonly ITestingSteamInstallation Steam; + /// + /// Initializes a new instance of the SteamTestBase class for use in derived test classes. + /// + /// + /// This protected constructor is intended to be called by subclasses to set up the Steam testing + /// environment. It initializes the Steam property using the provided service provider. + /// protected SteamTestBase() { Steam = SteamTesting.Steam(ServiceProvider); } + /// protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); SteamAbstractionLayer.InitializeServices(serviceCollection); } + /// public virtual void Dispose() { Steam.Dispose(); diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index de43bc63..487fb158 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -9,6 +9,9 @@ namespace AET.SteamAbstraction.Testing; +/// +/// +/// public sealed class TestProcessHelper : IProcessHelper { private readonly IFileSystem _fileSystem; @@ -16,26 +19,53 @@ public sealed class TestProcessHelper : IProcessHelper private int? _pid; - public TestProcessHelper(IServiceProvider sp) + /// + /// Initializes a new instance of the class using the specified service provider. + /// + /// The service provider to use. + public TestProcessHelper(IServiceProvider serviceProvider) { - _fileSystem = sp.GetRequiredService(); - _registry = SteamTesting.SteamRegistry(sp); + _fileSystem = serviceProvider.GetRequiredService(); + _registry = SteamTesting.SteamRegistry(serviceProvider); } + + /// + /// Gets the actual process linked to this . + /// public Process? CurrentProcess { get; private set; } + /// + /// Gets or sets a value indicating whether the process start should be delayed when is called. + /// public bool DelayStart { get; set; } + /// + /// Sets the running process identifier. + /// + /// + /// This method can be used to simulate a running process with the specified PID without actually starting a real process using . + /// + /// The PID to use. Use to indicate no process is running. public void SetRunningPid(int? pid) { _pid = pid; } + /// + /// Checks whether the specified process identifier is the same as the process identifier linked to this . + /// + /// + /// The process identifier of this is either set by using or . + /// + /// + /// public bool IsProcessRunning(int pid) { return pid == _pid; } + /// public Process StartProcess(ProcessStartInfo startInfo) { var expectedFileName = _registry.ExecutableFile?.FullName; @@ -56,7 +86,10 @@ public Process StartProcess(ProcessStartInfo startInfo) return p; } - internal void KillCurrent() + /// + /// Terminates the current process linked to this , if any and sets the PID to . + /// + public void KillCurrent() { try { diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs b/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs index 25525d48..eabc7296 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs @@ -1,8 +1,18 @@ namespace AET.SteamAbstraction.Testing; -internal static class TestingSteamConstants +/// +/// Provides constant values for Steam installation paths used in testing scenarios. +/// +public static class TestingSteamConstants { // Ensure starts on path 'steam'. See GameInstallation.cs + /// + /// The root directory name for testing Steam installations. + /// public const string SteamInstallPath = "steam"; + + /// + /// The path to the testing Steam executable. + /// public const string SteamExePath = "steam/steam.exe"; } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs b/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs index 090b7aee..ce34e41e 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs @@ -1,15 +1,31 @@ namespace AET.SteamAbstraction.Testing; +/// +/// Represent metadata about a Steam user login. +/// public sealed class TestingSteamUserLoginMetadata { + /// + /// Gets or sets the ID of the login user. + /// public ulong UserId { get; init; } + + /// + /// Gets or sets a value indicating whether the user wants to use Steam in offline mode. + /// public bool UserWantsOffline { get; init; } - public bool MostRecent { get; init; } - public TestingSteamUserLoginMetadata() - { - } + /// + /// Gets or sets a value indicating whether this login is the most recent one. + /// + public bool MostRecent { get; init; } + /// + /// Initializes a new instance of the class. + /// + /// The user id. + /// The information whether this user represents the most recent login. + /// The information whether this user wants to stay offline. public TestingSteamUserLoginMetadata(ulong userId, bool mostRecent = false, bool userWantsOffline = false) { UserId = userId; diff --git a/test/AET.Testing/TestBaseWithServiceProvider.cs b/test/AET.Testing/TestBaseWithServiceProvider.cs index 7216d9da..3040ca31 100644 --- a/test/AET.Testing/TestBaseWithServiceProvider.cs +++ b/test/AET.Testing/TestBaseWithServiceProvider.cs @@ -3,10 +3,29 @@ namespace AET.Testing; +/// +/// Provides a base class for test fixtures that require an initialized for dependency +/// injection. +/// +/// Derive from this class to set up and access services using dependency injection in test scenarios. +/// Override to register custom services required for your +/// tests. public abstract class TestBaseWithServiceProvider { + /// + /// Provides access to the application's service provider for resolving dependencies within derived classes. + /// protected readonly IServiceProvider ServiceProvider; + /// + /// Initializes a new instance of the class and configures the service provider using the specified service + /// collection. + /// + /// + /// This constructor creates a new service collection, invokes the method to allow + /// derived classes to register services, and then builds the service provider. Derived classes should override + /// SetupServices to customize service registration. + /// protected TestBaseWithServiceProvider() { var sc = new ServiceCollection(); @@ -15,6 +34,10 @@ protected TestBaseWithServiceProvider() ServiceProvider = sc.BuildServiceProvider(); } + /// + /// Configures test services by adding them to the specified service collection. + /// + /// The collection of service descriptors to which application services are added. protected virtual void SetupServices(IServiceCollection serviceCollection) { } From 3f6b6a3e60980bffb3f2093a8cbdb6037887b191 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sat, 20 Dec 2025 11:21:26 +0100 Subject: [PATCH 41/71] clean warnings --- .../AET.SteamAbstraction.Testing.csproj | 2 +- .../CompilerHelpers/Attributes.cs | 5 ++++- test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs | 6 ++++-- test/AET.SteamAbstraction.Testing/TestProcessHelper.cs | 3 +++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index a0fe0108..016388c4 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -16,7 +16,7 @@ - + true true true diff --git a/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs b/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs index e20fb274..e1dc9a46 100644 --- a/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs +++ b/test/AET.SteamAbstraction.Testing/CompilerHelpers/Attributes.cs @@ -7,7 +7,10 @@ namespace System.Runtime.Versioning; /// Base type for all platform-specific API attributes. /// -internal abstract class OSPlatformAttribute(string PlatformName) : Attribute; +internal abstract class OSPlatformAttribute(string platformName) : Attribute +{ + public string PlatformName { get; } = platformName; +} /// /// Records the platform that the project targeted. diff --git a/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs b/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs index d8dca256..d75a42a8 100644 --- a/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs +++ b/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs @@ -1,8 +1,10 @@ -using System; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Runtime.Versioning; namespace AET.SteamAbstraction.Testing; +[SupportedOSPlatform("windows")] internal sealed class SteamFakeProcessImpl : ISteamFakeProcess { private readonly TestProcessHelper _processHelper; diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index 487fb158..99706486 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO.Abstractions; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Threading.Tasks; using Xunit; @@ -66,6 +67,7 @@ public bool IsProcessRunning(int pid) } /// + [SupportedOSPlatform("windows")] public Process StartProcess(ProcessStartInfo startInfo) { var expectedFileName = _registry.ExecutableFile?.FullName; @@ -89,6 +91,7 @@ public Process StartProcess(ProcessStartInfo startInfo) /// /// Terminates the current process linked to this , if any and sets the PID to . /// + [SupportedOSPlatform("windows")] public void KillCurrent() { try From 8f066149e118534c236f786c376b0a1fd047f3fe Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:08:58 +0100 Subject: [PATCH 42/71] try test xuint 3 --- .github/workflows/test.yml | 2 +- PetroGlyphGameInfrastructure.slnx | 12 ++++++--- .../Utilities/IProcessHelper.cs | 25 ++++++++++++++++++- .../AET.SteamAbstraction.Test.csproj | 11 ++++---- .../AET.SteamAbstraction.Testing.csproj | 2 +- .../TestProcessHelper.cs | 6 +++-- test/AET.Testing/AET.Testing.csproj | 5 ++-- 7 files changed, 48 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ecb52d5c..df6c8a33 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,4 @@ jobs: dotnet-version: '10.0.x' - name: Build & Test in Release Mode - run: dotnet test --configuration Release --logger "GitHubActions" \ No newline at end of file + run: dotnet test --configuration Release --report-github \ No newline at end of file diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index 6a3d4a42..731dea8b 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -6,13 +6,19 @@ - - + + + + + + - + + + diff --git a/src/AET.SteamAbstraction/Utilities/IProcessHelper.cs b/src/AET.SteamAbstraction/Utilities/IProcessHelper.cs index d5698aa0..74a95f1b 100644 --- a/src/AET.SteamAbstraction/Utilities/IProcessHelper.cs +++ b/src/AET.SteamAbstraction/Utilities/IProcessHelper.cs @@ -1,10 +1,33 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; namespace AET.SteamAbstraction.Utilities; +/// +/// Provides utility methods for managing and interacting with system processes. +/// internal interface IProcessHelper { + /// + /// Determines whether a process with the specified process identifier (PID) is currently running. + /// + /// The process identifier (PID) to check. + /// + /// if a process with the specified PID is running; otherwise, . + /// + /// + /// This method attempts to retrieve the process by its PID. If the process does not exist or cannot be accessed, + /// it returns . + /// bool IsProcessRunning(int pid); + /// + /// Starts a new process using the specified configuration. + /// + /// The object that specifies the configuration for the process to be started. + /// A object that represents the started process, or if the process could not be started. + /// Thrown if is . + /// Thrown if no file name is specified in . + /// Thrown if an error occurs when opening the associated file. Process? StartProcess(ProcessStartInfo startInfo); } \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index b841e134..878fdfdd 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -9,21 +9,22 @@ $(TargetFrameworks);net481 false true + Exe + true - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - + + runtime; build; native; contentfiles; analyzers; buildtransitive all + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 016388c4..9dcb1934 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -28,7 +28,7 @@ - + diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index 99706486..e6ac756f 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -11,7 +11,7 @@ namespace AET.SteamAbstraction.Testing; /// -/// +/// Provides a test for managing and simulating process-related operations. /// public sealed class TestProcessHelper : IProcessHelper { @@ -60,7 +60,9 @@ public void SetRunningPid(int? pid) /// The process identifier of this is either set by using or . /// /// - /// + /// + /// if a process with the specified PID is running; otherwise, . + /// public bool IsProcessRunning(int pid) { return pid == _pid; diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index 81c5a783..2919423f 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -17,7 +17,7 @@ - true + true @@ -29,7 +29,8 @@ - + + all runtime; build; native; contentfiles; analyzers; buildtransitive From e798ea3c496aca83bbbd9258362cf1f70e39e2c5 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:16:41 +0100 Subject: [PATCH 43/71] test --- test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 878fdfdd..fbb2ccaf 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -10,7 +10,6 @@ false true Exe - true From 6172bfc2877a3e8efec803969c093ede783bc685 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:21:26 +0100 Subject: [PATCH 44/71] test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index df6c8a33..41e066a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,4 @@ jobs: dotnet-version: '10.0.x' - name: Build & Test in Release Mode - run: dotnet test --configuration Release --report-github \ No newline at end of file + run: dotnet test --configuration Release \ No newline at end of file From e703e170509cb438772360ee6c45dc35b40a870b Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:25:36 +0100 Subject: [PATCH 45/71] test --- PetroGlyphGameInfrastructure.slnx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index 731dea8b..982c2052 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -7,17 +7,17 @@ - + - + - + From c279c15ea7c6bf4e2d931fdddf39947e8354c626 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:26:53 +0100 Subject: [PATCH 46/71] remove --- PetroGlyphGameInfrastructure.slnx | 9 --------- ...StarWarsGame.Infrastructure.Clients.Steam.Test.csproj | 4 +--- .../PG.StarWarsGame.Infrastructure.Test.csproj | 1 - 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index 982c2052..401e7e72 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -6,19 +6,10 @@ - - - - - - - - - diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index 9a243dfd..8d0d2e67 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -1,4 +1,4 @@ - + PG.StarWarsGame.Infrastructure.Clients.Steam.Test @@ -34,8 +34,6 @@ - - diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index d5d6af2c..a8b24e6e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -35,7 +35,6 @@ - From 81fb90b3501481c9bbe2c088689f07a5a8de3b6f Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:47:45 +0100 Subject: [PATCH 47/71] enable test --- global.json | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 00000000..8f73781c --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "test": { + "runner": "Microsoft.Testing.Platform" + } +} \ No newline at end of file From 7b84107c7386de6e9ed5a0812cf5aa5e3e295d5f Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:49:47 +0100 Subject: [PATCH 48/71] try enable logging --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41e066a2..df6c8a33 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,4 @@ jobs: dotnet-version: '10.0.x' - name: Build & Test in Release Mode - run: dotnet test --configuration Release \ No newline at end of file + run: dotnet test --configuration Release --report-github \ No newline at end of file From 5e2c33c9fbf189579558c82a89df011ea3125f44 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 10:58:27 +0100 Subject: [PATCH 49/71] re-add tests --- PetroGlyphGameInfrastructure.slnx | 3 +++ .../AET.SteamAbstraction.Test.csproj | 3 +-- ...arsGame.Infrastructure.Clients.Steam.Test.csproj | 13 +++++++------ .../PG.StarWarsGame.Infrastructure.Test.csproj | 10 +++++----- .../PG.StarWarsGame.Infrastructure.Testing.csproj | 1 - 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index 401e7e72..6a3d4a42 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -6,10 +6,13 @@ + + + diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index fbb2ccaf..9b48feeb 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -17,13 +17,12 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index 8d0d2e67..519bcd7e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -9,18 +9,17 @@ $(TargetFrameworks);net481 false true + Exe - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - + - + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -34,6 +33,8 @@ + + diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index a8b24e6e..4129356c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -9,19 +9,18 @@ $(TargetFrameworks);net481 false true + Exe - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + - + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -35,6 +34,7 @@ + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index f7fa9639..fb3f33f0 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -29,7 +29,6 @@ - From 98160f7a334ad53c320579affc20fe175e6b2f79 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 11:04:38 +0100 Subject: [PATCH 50/71] ignore no tests on linux --- ...G.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index 519bcd7e..25913609 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -12,11 +12,16 @@ Exe + + + $(TestingPlatformCommandLineArguments) --ignore-exit-code 8 + + + - From f30f0bd4cf6f025797484ab49e4ed3642f6a9e53 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 11:35:49 +0100 Subject: [PATCH 51/71] try fix linux --- .github/workflows/test.yml | 6 +++++- ...PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj | 6 ------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index df6c8a33..362dc9aa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,4 +26,8 @@ jobs: dotnet-version: '10.0.x' - name: Build & Test in Release Mode - run: dotnet test --configuration Release --report-github \ No newline at end of file + run: dotnet test --configuration Release --report-github + # Ignore exit code 8 on Linux (zero tests are now allowed) + # TODO: Remove this when linux is supported + env: + TESTINGPLATFORM_EXITCODE_IGNORE: ${{ matrix.os == 'ubuntu-latest' && '8' || '' }} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index 25913609..e2f8ed1d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -12,12 +12,6 @@ Exe - - - $(TestingPlatformCommandLineArguments) --ignore-exit-code 8 - - - From dafbe2d9d7778f62eff86d7dd8fa796ce2f5d262 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 13:33:34 +0100 Subject: [PATCH 52/71] code documentation --- test/AET.Testing/AET.Testing.csproj | 4 +- .../PlatformSpecificFactAttribute.cs | 18 +++ .../PlatformSpecificTheoryAttribute.cs | 18 +++ .../Attributes/TestPlatformIdentifier.cs | 13 ++ test/AET.Testing/ExceptionHelpers.cs | 18 ++- .../Extensions/AssertExtensions.cs | 15 ++- .../Extensions/RandomExtensions.cs | 122 ++++++++++++++++-- .../Extensions/StringExtensions.cs | 53 ++++++-- test/AET.Testing/ReferenceEqualityComparer.cs | 30 ++++- test/AET.Testing/TestHelpers.cs | 24 ---- test/AET.Testing/TestingHelpers.cs | 47 +++++++ .../TestBases/GameInfrastructureTestBase.cs | 7 +- 12 files changed, 310 insertions(+), 59 deletions(-) delete mode 100644 test/AET.Testing/TestHelpers.cs create mode 100644 test/AET.Testing/TestingHelpers.cs diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index 2919423f..c05d4fa2 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -16,8 +16,8 @@ - - + true + true true diff --git a/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs index 02ab035d..a87e8446 100644 --- a/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs +++ b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs @@ -5,8 +5,26 @@ namespace AET.Testing.Attributes; +/// +/// Test attribute that specifies the test should only run on specific platforms. +/// +/// +/// This attribute allows you to define platform-specific tests by specifying the target platforms +/// using . If the current platform does not match any of the specified +/// platforms, the test will be skipped with an appropriate message. +/// public sealed class PlatformSpecificFactAttribute : FactAttribute { + /// + /// Initializes a new instance of the class with the specified target platforms. + /// + /// + /// An array of values that specify the platforms on which the test should run. + /// + /// + /// If the current platform does not match any of the specified , the test will be skipped + /// with a message indicating that the test execution is not supported on the current platform. + /// public PlatformSpecificFactAttribute(params TestPlatformIdentifier[] platformIds) { var platforms = platformIds.Select(targetPlatform => OSPlatform.Create(Enum.GetName(typeof(TestPlatformIdentifier), targetPlatform)!.ToUpper())); diff --git a/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs index 0724c67c..858fffe0 100644 --- a/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs +++ b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs @@ -5,8 +5,26 @@ namespace AET.Testing.Attributes; +/// +/// A theory attribute that specifies the test should only run on specific platforms. +/// +/// +/// This attribute allows you to define platform-specific tests by specifying the target platforms +/// using . If the current platform does not match any of the specified +/// platforms, the test will be skipped with an appropriate message. +/// public sealed class PlatformSpecificTheoryAttribute : TheoryAttribute { + /// + /// Initializes a new instance of the class with the specified target platforms. + /// + /// + /// An array of values that specify the platforms on which the test should run. + /// + /// + /// If the current platform does not match any of the specified , the test will be skipped + /// with a message indicating that the test execution is not supported on the current platform. + /// public PlatformSpecificTheoryAttribute(params TestPlatformIdentifier[] platformIds) { var platforms = platformIds.Select(targetPlatform => OSPlatform.Create(Enum.GetName(typeof(TestPlatformIdentifier), targetPlatform)!.ToUpper())); diff --git a/test/AET.Testing/Attributes/TestPlatformIdentifier.cs b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs index 7c45e26e..4f06cce5 100644 --- a/test/AET.Testing/Attributes/TestPlatformIdentifier.cs +++ b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs @@ -2,9 +2,22 @@ namespace AET.Testing.Attributes; +/// +/// Represents identifiers for test platforms used to specify platform-specific test execution. +/// +/// +/// This enumeration is used in conjunction with attributes like +/// and to define tests that should only run on specific platforms. +/// [Flags] public enum TestPlatformIdentifier { + /// + /// Represents the Windows platform. + /// Windows = 1, + /// + /// Represents a Linux platform. + /// Linux = 2, } \ No newline at end of file diff --git a/test/AET.Testing/ExceptionHelpers.cs b/test/AET.Testing/ExceptionHelpers.cs index b5554fbd..ecca19eb 100644 --- a/test/AET.Testing/ExceptionHelpers.cs +++ b/test/AET.Testing/ExceptionHelpers.cs @@ -5,8 +5,20 @@ namespace AET.Testing; // Based on https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Exception.Helpers.cs -public class ExceptionHelpers +/// +/// Provides helper methods for validating properties of exceptions in unit tests. +/// +public static class ExceptionHelpers { + /// + /// Validates the properties of the specified instance against the provided values. + /// + /// The exception instance to validate. + /// The expected inner exception of . Defaults to null. + /// The expected message of . Defaults to null. + /// The expected source of . Defaults to null. + /// The expected stack trace of . Defaults to null. + /// A value indicating whether to validate the property. public static void ValidateExceptionProperties(Exception e, Exception? innerException = null, string? message = null, @@ -16,13 +28,9 @@ public static void ValidateExceptionProperties(Exception e, { Assert.Equal(innerException, e.InnerException); if (validateMessage) - { Assert.Equal(message, e.Message); - } else - { Assert.NotNull(e.Message); - } Assert.Equal(source, e.Source); Assert.Equal(stackTrace, e.StackTrace); } diff --git a/test/AET.Testing/Extensions/AssertExtensions.cs b/test/AET.Testing/Extensions/AssertExtensions.cs index 7e93fb1d..bf4533ec 100644 --- a/test/AET.Testing/Extensions/AssertExtensions.cs +++ b/test/AET.Testing/Extensions/AssertExtensions.cs @@ -3,10 +3,19 @@ namespace AET.Testing.Extensions; +/// +/// Provides extension methods for the class. +/// public static class AssertExtensions { extension(Assert) { + /// + /// Verifies that the specified action does not throw any exception. + /// + /// The type of the result returned by the action. + /// A delegate to the code to be tested. + /// The result of the executed test code. public static T AssertDoesNotThrowException(Func action) { try @@ -20,9 +29,13 @@ public static T AssertDoesNotThrowException(Func action) } } + /// + /// Verifies that the specified action does not throw any exception. + /// + /// A delegate to the code to be tested. public static void AssertDoesNotThrowException(Action action) { - AssertDoesNotThrowException(() => action); + Assert.AssertDoesNotThrowException(() => action); } } } \ No newline at end of file diff --git a/test/AET.Testing/Extensions/RandomExtensions.cs b/test/AET.Testing/Extensions/RandomExtensions.cs index cd2ca323..3d6e6e8e 100644 --- a/test/AET.Testing/Extensions/RandomExtensions.cs +++ b/test/AET.Testing/Extensions/RandomExtensions.cs @@ -3,6 +3,9 @@ namespace AET.Testing.Extensions; +/// +/// Provides extension methods for the class. +/// public static class RandomExtensions { private static readonly Random Random = new(); @@ -10,41 +13,92 @@ public static class RandomExtensions extension(Random) { + /// + /// Generates a random value. + /// + /// + /// A randomly generated value. + /// public static bool Bool() { return Random.Next() % 2 == 0; } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static sbyte SByte() { return (sbyte)Random.Next(sbyte.MinValue, sbyte.MaxValue); } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static byte Byte() { return (byte)Random.Next(byte.MinValue, byte.MaxValue); } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static short Short() { return (short)Random.Next(short.MinValue, short.MaxValue); } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static ushort UShort() { return (ushort)Random.Next(ushort.MinValue, ushort.MaxValue); } + /// + /// Generates a random value. + /// + /// + /// In contrast to , this method can return the full range of values, including negative values. + /// + /// + /// A randomly generated value within the range of to . + /// public static int Int() { return Random.Next(int.MinValue, int.MaxValue); } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static uint UInt() { return (uint)Random.Int(); } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static long Long() { #if NET || NETSTANDARD2_1_OR_GREATER @@ -58,19 +112,49 @@ public static long Long() #endif } + /// + /// Generates a random value. + /// + /// + /// A randomly generated value within the range of to . + /// public static ulong ULong() { return (ulong)Random.Long(); } + /// + /// Returns a random value from the enumeration type . + /// + /// + /// The enumeration type from which a random value will be selected. Must be a struct and an . + /// + /// + /// A randomly selected value from the enumeration type . + /// + /// + /// Thrown if is not an enumeration type. + /// public static T Enum() where T : struct, Enum { - var values = System.Enum.GetValues(typeof(T)); - return (T)values.GetValue(Random.Next(values.Length))!; + var values = +#if NET5_0_OR_GREATER + System.Enum.GetValues(); +#else + (T[])System.Enum.GetValues(typeof(T)); +#endif + return values[Random.Next(values.Length)]; } // From: https://stackoverflow.com/questions/648196/random-row-from-linq-to-sql/648240#648240 + /// + /// Selects a random item from the provided sequence of items. + /// + /// The type of the elements in the sequence. + /// The sequence of items to select from. + /// A randomly selected item from the sequence. + /// Thrown if the sequence is empty. public static T Item(IEnumerable items) { T current = default!; @@ -86,21 +170,39 @@ public static T Item(IEnumerable items) : current; } + /// + /// Generates a random string of the specified length using a mix of letters (any case), numbers and special characters + /// + /// The desired length of the generated string. Must be a non-negative value. + /// A randomly generated string of the specified length. Returns an empty string if is 0. + /// Thrown when is less than 0. public static unsafe string GetRandomStringOfLength(int length) { - if (length < 0) - throw new ArgumentOutOfRangeException(nameof(length)); + switch (length) + { + case < 0: + throw new ArgumentOutOfRangeException(nameof(length)); + case 0: + return string.Empty; + } - var result = new string('\0', length); + var buffer = length <= 256 + ? stackalloc char[length] + : new char[length]; - fixed (char* p = result) + var random = Random; + for (var i = 0; i < buffer.Length; i++) { - var span = new Span(p, length); - for (var i = 0; i < span.Length; i++) - span[i] = AllowedChars[Random.Next(0, AllowedChars.Length)]; + var index = random.Next(AllowedChars.Length); + buffer[i] = AllowedChars[index]; } - return result; +#if NET + return new string(buffer); +#else + fixed (char* t = buffer) + return new string(t, 0, length); +#endif } } } \ No newline at end of file diff --git a/test/AET.Testing/Extensions/StringExtensions.cs b/test/AET.Testing/Extensions/StringExtensions.cs index fd769ac6..68d4946c 100644 --- a/test/AET.Testing/Extensions/StringExtensions.cs +++ b/test/AET.Testing/Extensions/StringExtensions.cs @@ -2,30 +2,57 @@ namespace AET.Testing.Extensions; +/// +/// Provides extension methods for string manipulation and testing. +/// public static class StringExtensions { private static readonly Random Random = new(); extension(string) { - public static string ShuffleCasing(string input) + /// + /// Randomly shuffles the casing of the characters in the specified string. + /// + /// The input string whose character casing will be shuffled. + /// A new string with randomly shuffled character casing. + /// Thrown if is null. + public static unsafe string ShuffleCasing(string input) { - var characters = input.ToCharArray(); + if (input is null) + throw new ArgumentNullException(nameof(input)); - for (var i = 0; i < characters.Length; i++) + if (input.Length == 0) + return string.Empty; + + var buffer = input.Length <= 256 + ? stackalloc char[input.Length] + : new char[input.Length]; + + input.AsSpan().CopyTo(buffer); + + var rnd = Random; + + for (var i = 0; i < buffer.Length; i++) { - if (char.IsLetter(characters[i])) - { - if (Random.Next(2) == 0) - { - characters[i] = char.IsUpper(characters[i]) - ? char.ToLower(characters[i]) - : char.ToUpper(characters[i]); - } - } + var c = buffer[i]; + if (!char.IsLetter(c)) + continue; + + if (rnd.Next(2) != 0) + continue; + + buffer[i] = char.IsUpper(c) + ? char.ToLower(c) + : char.ToUpper(c); } - return new string(characters); +#if NET + return new string(buffer); +#else + fixed (char* t = buffer) + return new string(t, 0, buffer.Length); +#endif } } } \ No newline at end of file diff --git a/test/AET.Testing/ReferenceEqualityComparer.cs b/test/AET.Testing/ReferenceEqualityComparer.cs index 11eeac94..42c1e128 100644 --- a/test/AET.Testing/ReferenceEqualityComparer.cs +++ b/test/AET.Testing/ReferenceEqualityComparer.cs @@ -1,20 +1,46 @@ #if !NET5_0_OR_GREATER +using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace AET.Testing; +/// +/// An that uses reference equality () +/// instead of value equality() when comparing two object instances. +/// +/// +/// The type cannot be instantiated. +/// Instead, use the property to access the singleton instance of this type. +/// public sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer { + /// + /// Gets the singleton instance. + /// + public static ReferenceEqualityComparer Instance { get; } = new(); + private ReferenceEqualityComparer() { } - public static ReferenceEqualityComparer Instance { get; } = new(); - + /// + /// Determines whether two object references refer to the same object instance. + /// + /// The first object to compare. + /// The second object to compare. + /// + /// if both and + /// refer to the same object instance or if both are ; otherwise, . + /// public new bool Equals(object? x, object? y) => ReferenceEquals(x, y); + /// + /// Returns a hash code for the specified object. The returned hash code is based on the object identity, not on the contents of the object. + /// + /// The object for which to retrieve the hash code. + /// A hash code for the identity of . public int GetHashCode(object? obj) { return RuntimeHelpers.GetHashCode(obj!); diff --git a/test/AET.Testing/TestHelpers.cs b/test/AET.Testing/TestHelpers.cs deleted file mode 100644 index ef4b9471..00000000 --- a/test/AET.Testing/TestHelpers.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.IO; - -namespace AET.Testing; - -public class TestHelpers -{ - public static Stream GetEmbeddedResource(Type type, string path) - { - var assembly = type.Assembly; - var resourcePath = $"{assembly.GetName().Name}.Resources.{path}"; - return assembly.GetManifestResourceStream(resourcePath) ?? - throw new IOException($"Could not find embedded resource: '{resourcePath}'"); - } - - public static byte[] GetEmbeddedResourceAsByteArray(Type type, string path) - { - using var stream = GetEmbeddedResource(type, path); - using var ms = new MemoryStream(); - stream.CopyTo(ms); - ms.Position = 0; - return ms.ToArray(); - } -} \ No newline at end of file diff --git a/test/AET.Testing/TestingHelpers.cs b/test/AET.Testing/TestingHelpers.cs new file mode 100644 index 00000000..2ccf751d --- /dev/null +++ b/test/AET.Testing/TestingHelpers.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; + +namespace AET.Testing; + +/// +/// Provides common helper methods useful creating test code. +/// +public class TestingHelpers +{ + /// + /// Retrieves an embedded resource stream from the specified assembly and path. + /// + /// + /// Embedded resources are expected to be located in the "Resources" folder of the assembly. + /// + /// A from the assembly containing the embedded resource. + /// The relative path of the embedded resource within the assembly. + /// A representing the embedded resource. + /// Thrown when the specified embedded resource cannot be found. + public static Stream GetEmbeddedResource(Type type, string path) + { + var assembly = type.Assembly; + var resourcePath = $"{assembly.GetName().Name}.Resources.{path}"; + return assembly.GetManifestResourceStream(resourcePath) ?? + throw new IOException($"Could not find embedded resource: '{resourcePath}'"); + } + + /// + /// Retrieves an embedded resource as a byte array from the specified assembly and path. + /// + /// + /// Embedded resources are expected to be located in the "Resources" folder of the assembly. + /// + /// A from the assembly containing the embedded resource. + /// The relative path of the embedded resource within the assembly. + /// A byte array containing the content of the embedded resource. + /// Thrown when the specified embedded resource cannot be found. + public static byte[] GetEmbeddedResourceAsByteArray(Type type, string path) + { + using var stream = GetEmbeddedResource(type, path); + using var ms = new MemoryStream(); + stream.CopyTo(ms); + ms.Position = 0; + return ms.ToArray(); + } +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index c6b83f54..78239eee 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,4 +1,5 @@ -using AET.Modinfo.Model; +using System; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing; using Microsoft.Extensions.DependencyInjection; @@ -18,7 +19,9 @@ public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { private ITestingGameInstallation? _gameInstallation; - protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem); + [field:MaybeNull, AllowNull] + protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem) + ?? throw new InvalidOperationException("Creation of file system must not return null."); protected virtual IFileSystem CreateFileSystem() { From 32ba00e3f5e24ab0d3fcc5c9f3e230a7fbeb4693 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 15:38:37 +0100 Subject: [PATCH 53/71] document code --- .../TestBaseWithServiceProvider.cs | 4 +- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 4 +- .../PetroglyphStarWarsGameClientTest.cs | 2 +- .../Processes/GameProcessLauncherTest.cs | 22 +-- .../Detection/DirectoryGameDetectorTest.cs | 2 +- ...oglyphGameInfrastructureIntegrationTest.cs | 2 +- .../Clients/TestGameProcessLauncher.cs | 54 +++++++ .../GITestUtilities.cs | 59 +++++++- .../Game/ITestingGameInstallation.cs | 132 ++++++++++++++++-- .../Game/Registry/ITestingGameRegistry.cs | 26 +++- .../Registry/TestGameRegistrySetupData.cs | 57 ++++++-- .../Game/Registry/TestingGameRegistryImpl.cs | 2 +- .../Game/TestingGameInstallationImpl.Mod.cs | 7 - .../GameInfrastructureTesting.cs | 20 +++ .../ITestingModContainerInstallation.cs | 6 + ...stingPhysicalPlayableObjectInstallation.cs | 24 ++++ .../ITestingPlayableObjectInstallation.cs | 20 +-- .../Mods/ITestingModInstallation.cs | 9 +- .../Mods/ITestingPhysicalModInstallation.cs | 22 +++ .../Mods/ITestingVirtualModInstallation.cs | 6 + ...StarWarsGame.Infrastructure.Testing.csproj | 2 +- .../TestBases/GameDetectorTestBase.cs | 87 ++++++++++++ .../TestBases/GameDetectorTestBase_Tests.cs | 4 +- .../TestBases/GameInfrastructureTestBase.cs | 41 ++++++ ...ameInfrastructureTestBaseWithRandomGame.cs | 12 +- 25 files changed, 562 insertions(+), 64 deletions(-) create mode 100644 test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs diff --git a/test/AET.Testing/TestBaseWithServiceProvider.cs b/test/AET.Testing/TestBaseWithServiceProvider.cs index 3040ca31..42b9c2c9 100644 --- a/test/AET.Testing/TestBaseWithServiceProvider.cs +++ b/test/AET.Testing/TestBaseWithServiceProvider.cs @@ -35,9 +35,9 @@ protected TestBaseWithServiceProvider() } /// - /// Configures test services by adding them to the specified service collection. + /// Configures test services by adding them to the specified . /// - /// The collection of service descriptors to which application services are added. + /// The to which services will be added. protected virtual void SetupServices(IServiceCollection serviceCollection) { } diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 541a7b4e..470974e1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -42,7 +42,7 @@ protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdent { return SetupGame(gameIdentity, (game, otherGameType) => { - GameInfrastructureTesting.Registry(ServiceProvider).CreateInstlled(game); + GameInfrastructureTesting.Registry(ServiceProvider).CreateInstalled(game); GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); }); } @@ -112,7 +112,7 @@ public void Detect_SteamInstalledButGameNotFullyInstalled_ShouldReturnNotInstall var info = SetupGame(gameId, (game, otherGameType) => { - GameInfrastructureTesting.Registry(ServiceProvider).CreateInstlled(game); + GameInfrastructureTesting.Registry(ServiceProvider).CreateInstalled(game); GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); }, SteamAppState.StateUpdateRequired); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index 23abbd64..ff3bc380 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -62,7 +62,7 @@ protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); PetroglyphGameInfrastructure.InitializeServices(serviceCollection); - serviceCollection.AddSingleton(_processLauncher); + TestGameProcessLauncher.RegisterAsService(serviceCollection, _processLauncher); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs index cd2d8ea9..46c436bf 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs @@ -18,20 +18,17 @@ public class GameProcessLauncherTest : GameInfrastructureTestBaseWithRandomGame, private readonly GameProcessLauncher _launcher; private readonly IFileInfo _executable; - // We need to use the real FS here, cause Process.Start uses it too. - private readonly IFileSystem _realFileSystem = new RealFileSystem(); - private GameProcess? _gameProcess; public GameProcessLauncherTest() { _launcher = new GameProcessLauncher(ServiceProvider); - var tempDir = _realFileSystem.Path.Combine(_realFileSystem.Path.GetTempPath(), "GameProcessLauncherTest"); - _realFileSystem.Directory.CreateDirectory(tempDir); + var tempDir = FileSystem.Path.Combine(FileSystem.Path.GetTempPath(), "GameProcessLauncherTest"); + FileSystem.Directory.CreateDirectory(tempDir); var executableName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "TestExecutable.bat" : "TestExecutable.sh"; - _executable = _realFileSystem.FileInfo.New(_realFileSystem.Path.Combine(tempDir, executableName)); + _executable = FileSystem.FileInfo.New(FileSystem.Path.Combine(tempDir, executableName)); var scriptContent = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "@echo off\r\n" + @@ -39,12 +36,17 @@ public GameProcessLauncherTest() "exit 0" : "#!/bin/bash\nsleep 5\nexit 0"; - _realFileSystem.File.WriteAllText(_executable.FullName,scriptContent); + FileSystem.File.WriteAllText(_executable.FullName,scriptContent); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) Process.Start("chmod", $"+x {_executable.FullName}")!.WaitForExit(); } + protected override IFileSystem CreateFileSystem() + { + return new RealFileSystem(); + } + [Fact] public void StartGameProcess_ValidExecutable_Succeeds() { @@ -137,9 +139,9 @@ public void Dispose() _gameProcess?.Process.Kill(); _gameProcess?.Dispose(); - var tempDir = _realFileSystem.Path.GetDirectoryName(_executable.FullName); - if (_realFileSystem.Directory.Exists(tempDir)) - _realFileSystem.Directory.Delete(tempDir, true); + var tempDir = FileSystem.Path.GetDirectoryName(_executable.FullName); + if (FileSystem.Directory.Exists(tempDir)) + FileSystem.Directory.Delete(tempDir, true); } catch { diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs index 77366fc8..784f36f5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/DirectoryGameDetectorTest.cs @@ -24,7 +24,7 @@ protected override IGameDetector CreateDetector(GameDetectorTestInfo gam protected override GameDetectorTestInfo SetupGame(GameIdentity gameIdentity) { var game = GetOrCreateGameInstallation(gameIdentity).Game; - return new(gameIdentity.Type, game.Directory, null); + return new GameDetectorTestInfo(gameIdentity.Type, game.Directory, null); } [Fact] diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs index 63451188..693dee4f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphGameInfrastructureIntegrationTest.cs @@ -63,7 +63,7 @@ public void FullWorkflow_WithGamesAndMultipleModsWithMultipleModsDependencies(Ga gameDetector.InitializationRequested += (_, args) => { var game = args.GameType == GameType.Eaw ? eaw : foc; - GameInfrastructureTesting.Registry(ServiceProvider).CreateInstlled(game); + GameInfrastructureTesting.Registry(ServiceProvider).CreateInstalled(game); args.Handled = true; initCount++; }; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs index d976757e..a830ee69 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs @@ -2,22 +2,68 @@ using System.Diagnostics; using System.IO.Abstractions; using System.Runtime.InteropServices; +using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Clients; using PG.StarWarsGame.Infrastructure.Clients.Processes; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing.Clients; +/// +/// Provides a test implementation for launching game processes and asserting the process creation in a controlled testing environment. +/// +/// +/// This class is designed to simulate the behavior of a game process launcher, allowing for assertions and +/// controlled exceptions during testing scenarios. It ensures that the expected executable and process +/// information match the provided inputs. +/// public sealed class TestGameProcessLauncher : IGameProcessLauncher, IDisposable { private Process? _process; + /// + /// Gets or sets a value indicating whether the should throw + /// a when attempting to start a game process. + /// + /// + /// if a should be thrown during the game process start; + /// otherwise, . + /// + /// + /// This property is primarily used in testing scenarios to simulate failure conditions + /// when starting a game process. + /// public bool ThrowsGameStartException { get; set; } + /// + /// Gets or sets the expected executable file for the game process during testing. + /// public IFileInfo ExpectedExecutable { get; set; } = null!; + /// + /// Gets or sets the expected process information used for validating the game process during testing. + /// public GameProcessInfo ExpectedProcessInfo { get; set; } = null!; + /// + /// Registers the specified instance as a singleton service in the provided . + /// + /// The to which the service will be added. + /// The instance to register as the implementation of . + public static void RegisterAsService(IServiceCollection serviceCollection, TestGameProcessLauncher processLauncher) + { + serviceCollection.AddSingleton(processLauncher); + } + + /// + /// Initiates the execution of a fake game process using the provided executable. + /// The inputs and are for asserted + /// against and . + /// + /// The executable file that will be launched to start the game process. + /// An object containing details about the game process, such as the game instance, build type, and any additional arguments. + /// A new instance of representing the running game process. + /// Thrown if is set to . public IGameProcess StartGameProcess(IFileInfo executable, GameProcessInfo processInfo) { Assert.Equal(ExpectedExecutable.FullName, executable.FullName); @@ -37,6 +83,14 @@ public IGameProcess StartGameProcess(IFileInfo executable, GameProcessInfo proce return new GameProcess(process, processInfo); } + /// + /// Releases the resources used by the instance, including terminating + /// and disposing of any associated game process. + /// + /// + /// This method ensures that any running game process started by this launcher is properly terminated + /// and its resources are released. Exceptions during the disposal process are suppressed. + /// public void Dispose() { try diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index 7e2da343..e4d79a80 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -11,13 +11,24 @@ namespace PG.StarWarsGame.Infrastructure.Testing; // ReSharper disable once InconsistentNaming +/// +/// Provides utility methods for testing game infrastructure components. +/// public static class GITestUtilities { + private static readonly string[] PossibleLanguages = ["en", "de", "es", "it"]; + + /// + /// Gets a collection of real game platforms. + /// public static ICollection RealPlatforms { get; } = [GamePlatform.Disk, GamePlatform.DiskGold, GamePlatform.SteamGold, GamePlatform.GoG, GamePlatform.Origin]; - private static readonly string[] PossibleLanguages = ["en", "de", "es", "it"]; - + /// + /// Verifies that two instances are equal by comparing their properties. + /// + /// The expected instance. + /// The actual instance to compare against the expected one. public static void AssertEqual(this GameDetectionResult expected, GameDetectionResult actual) { Assert.Equal(expected.Installed, actual.Installed); @@ -26,6 +37,13 @@ public static void AssertEqual(this GameDetectionResult expected, GameDetectionR Assert.Equal(expected.InitializationRequired, actual.InitializationRequired); } + /// + /// Generates a random workshop flag for the specified game based on its platform. + /// + /// The game identity for which the workshop flag is being determined. + /// + /// A random value, which is never if does not support workshops. + /// public static bool GetRandomWorkshopFlag(IGameIdentity game) { if (game.Platform is not GamePlatform.SteamGold) @@ -33,11 +51,28 @@ public static bool GetRandomWorkshopFlag(IGameIdentity game) return Random.Bool(); } + /// + /// Retrieves a collection of real game platforms as enumerable test data. + /// + /// + /// An of object arrays, where each array contains a single . + /// public static IEnumerable GetRealPlatforms() { return RealPlatforms.Select(platform => (object[])[platform]); } + /// + /// Generates a collection of real game identities for testing purposes. + /// + /// + /// This method yields game identities for all supported platforms and game types, + /// including both Empire at War (Eaw) and Forces of Corruption (Foc). + /// + /// + /// An of arrays where each element contains + /// a single instance representing a specific game type and platform. + /// public static IEnumerable RealGameIdentities() { foreach (var platform in RealPlatforms) @@ -47,6 +82,13 @@ public static IEnumerable RealGameIdentities() } } + /// + /// Generates a collection of random languages with also randomized support levels. + /// + /// + /// A collection of objects, where each object represents a language + /// and its corresponding support level. + /// public static ICollection GetRandomLanguages() { var languages = new HashSet(); @@ -61,7 +103,18 @@ public static ICollection GetRandomLanguages() return languages; } - public static GameIdentity GetRandomGameIdentity(bool realOnly = true) + /// + /// Generates a random instance. + /// + /// + /// If set to , the method will only use platforms defined in . + /// If set to , the method will include also the platform. + /// + /// + /// A randomly generated object, containing a random + /// and a platform determined by the parameter. + /// + public static IGameIdentity GetRandomGameIdentity(bool realOnly = true) { var platforms = realOnly ? RealPlatforms : (GamePlatform[])Enum.GetValues(typeof(GamePlatform)); return new GameIdentity(Random.Enum(), Random.Item(platforms)); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs index 516e0de8..6e5b39bb 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs @@ -1,4 +1,5 @@ -using AET.Modinfo.Model; +using System; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; @@ -6,44 +7,155 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game; +/// +/// Represents an abstraction for a test installation game installation, providing methods and properties to install mods. +/// public interface ITestingGameInstallation : ITestingModContainerInstallation, ITestingPhysicalPlayableObjectInstallation { + /// + /// Gets the game instance associated with this installation. + /// IGame Game { get; } + /// + /// Installs debug executable files to the game installation. + /// void InstallDebug(); - + + /// + /// Retrieves the incorrect directory from the EA Origin Forces of Corruption setup that gets written to the registry. + /// + /// The directory information of the incorrect registry location. IDirectoryInfo GetWrongOriginFocRegistryLocation(); - + + /// + /// Installs a mod with the specified name. + /// + /// + /// Depending on the platform of the game installation, the installed mod is randomly selected to be a normal or Workshops mod. + /// + /// The name of the mod to install. + /// An instance of representing the installed mod. ITestingPhysicalModInstallation InstallMod(string name); + /// + /// Installs a mod with the specified name and workshop flag. + /// + /// The name of the mod to install. + /// Indicates whether the mod is a Workshops mod. + /// An instance of representing the installed mod. ITestingPhysicalModInstallation InstallMod(string name, bool workshop); + /// + /// Installs a mod using the provided mod information. + /// + /// + /// Depending on the platform of the game installation, the installed mod is randomly selected to be a normal or Workshops mod. + /// + /// The mod information to use for installation. + /// An instance of representing the installed mod. ITestingPhysicalModInstallation InstallMod(IModinfo modinfo); - + + /// + /// Installs a mod using the provided mod information and workshop flag. + /// + /// The mod information to use for installation. + /// Indicates whether the mod is a Workshops mod. + /// An instance of representing the installed mod. ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, bool workshop); - - ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory); - + + /// + /// Installs a mod using the provided mod information, directory, and workshop flag. + /// + /// The mod information to use for installation. + /// The directory where the mod will be installed. + /// Indicates whether the mod is a workshop mod. + /// An instance of representing the installed mod. ITestingPhysicalModInstallation InstallMod(IModinfo modinfo, IDirectoryInfo directory, bool workshop); - + /// + /// Installs and adds a mod with the specified name to the game installation. + /// + /// + /// Depending on the platform of the game installation, the installed mod is randomly selected to be a normal or Workshops mod. + /// + /// The name of the mod to install and add. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(string name); + /// + /// Installs and adds a mod with the specified name and workshop flag to the game installation. + /// + /// The name of the mod to install and add. + /// Indicates whether the mod is a Workshops mod. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(string name, bool workshop); + /// + /// Installs and adds a mod using the provided mod information to the game installation. + /// + /// + /// Depending on the platform of the game installation, the installed mod is randomly selected to be a normal or Workshops mod. + /// + /// The mod information to use for installation and addition. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo); + /// + /// Installs and adds a mod using the provided mod information and workshop flag to the game installation. + /// + /// The mod information to use for installation and addition. + /// Indicates whether the mod is a Workshops mod. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, bool workshop); - ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory); - + /// + /// Installs and adds a mod using the provided mod information, directory, and workshop flag to the game installation. + /// + /// The mod information to use for installation and addition. + /// The directory where the mod will be installed and added. + /// Indicates whether the mod is a Workshops mod. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory, bool workshops); + /// + /// Installs and adds a mod with the specified name, workshop flag, and dependencies to the game installation. + /// + /// The name of the mod to install and add. + /// Indicates whether the mod is a Workshops mod. + /// The dependencies of the mod. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(string name, bool isWorkshop, IModDependencyList dependencies); + /// + /// Installs and adds a mod with the specified name and dependencies to the game installation. + /// + /// + /// Depending on the platform of the game installation, the installed mod is randomly selected to be a normal or Workshops mod. + /// + /// The name of the mod to install and add. + /// The dependencies of the mod. + /// An instance of representing the installed and added mod. ITestingPhysicalModInstallation InstallAndAddMod(string name, IModDependencyList dependencies); + /// + /// Adds a virtual mod with the specified name and mod information to the game installation. + /// + /// The name of the virtual mod to add. + /// The mod information of the virtual mod. + /// An instance of representing the added virtual mod. ITestingVirtualModInstallation AddVirtualMod(string name, ModinfoData modinfo); + /// + /// Gets the directory of a mod for the specified name and workshop flag. + /// + /// The created is not created on the file system. + /// The name of the mod. + /// Indicates whether the mod is a workshop mod. + /// The directory information of the mod. + /// + /// Thrown when is + /// but the associated game is not a Steam installation. + /// IDirectoryInfo GetModDirectory(string name, bool workshop); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs index 54e925ff..6370016c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs @@ -3,11 +3,35 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; +/// +/// Represents an abstraction for a test registry that provides access to the actual . +/// public interface ITestingGameRegistry { + /// + /// Creates a game registry instance for a game type that does not exist in the registry. + /// + /// The type of the game for which the registry should be created. + /// An instance of representing a non-existing game registry. IGameRegistry CreateNonExistingRegistry(GameType gameType); - IGameRegistry CreateInstlled(IGame game); + /// + /// Creates a registry for a game that is considered installed. + /// + /// The game for which the registry is to be created. + /// An instance of representing the installed game registry. + IGameRegistry CreateInstalled(IGame game); + /// + /// Creates an instance of based on the provided setup data. + /// + /// The setup data used to configure the game registry. + /// + /// An instance of configured according to the provided setup data. + /// + /// + /// This method is intended for testing purposes and allows for the creation of a game registry + /// that simulates various states, such as installed or uninitialized. + /// IGameRegistry CreateFrom(TestGameRegistrySetupData registrySetupData); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs index dfe2e0f8..fa4ccb9a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs @@ -3,24 +3,56 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; +/// +/// Represents the setup data for configuring a test game registry. +/// public sealed class TestGameRegistrySetupData { + /// + /// Gets or sets the type of the game. + /// public required GameType GameType { get; init; } - + + /// + /// Gets or sets a value indicating whether to create the registry. + /// public bool CreateRegistry { get; set; } - + + /// + /// Gets or sets a value indicating whether to initialize the registry. + /// public bool InitRegistry { get; set; } - + + /// + /// Gets or sets the installation path of the game. + /// public string? InstallPath { get; set; } - + + /// + /// Gets or sets the revision number of the game. + /// public int? Revision { get; set; } - + + /// + /// Gets or sets the EAW Gold version identifier. + /// public int? EawGold { get; set; } - + + /// + /// Gets or sets the path to the game launcher. + /// public string? Launcher { get; set; } - + + /// + /// Gets or sets the CD key for the game. + /// public string? CdKey { get; set; } - + + /// + /// Creates an uninitialized setup data instance for the specified game type. + /// + /// The type of the game. + /// A new instance of with default values for uninitialized state. public static TestGameRegistrySetupData Uninitialized(GameType gameType) { return new TestGameRegistrySetupData @@ -30,12 +62,17 @@ public static TestGameRegistrySetupData Uninitialized(GameType gameType) InitRegistry = false }; } - + + /// + /// Creates a setup data instance for an installed game. + /// + /// The type of the game. + /// The directory information of the game installation. + /// A new instance of configured for an installed game. public static TestGameRegistrySetupData Installed(GameType gameType, IDirectoryInfo gameLocation) { var revision = gameType == GameType.Eaw ? 10105 : 10100; var launcherPath = gameType == GameType.Eaw ? $"{gameLocation.FullName}\\LaunchEAW.exe" : null; - return new TestGameRegistrySetupData { GameType = gameType, diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs index 11f6110b..07eef776 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs @@ -20,7 +20,7 @@ public IGameRegistry CreateNonExistingRegistry(GameType gameType) return _registryFactory.CreateRegistry(gameType); } - public IGameRegistry CreateInstlled(IGame game) + public IGameRegistry CreateInstalled(IGame game) { return CreateFrom(TestGameRegistrySetupData.Installed(game.Type, game.Directory)); } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs index 0bdbbb94..36d548dd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs @@ -76,13 +76,6 @@ public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, bool w return modInstallation; } - public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory) - { - var modInstallation = InstallMod(modinfo, directory); - Game.AddMod(modInstallation.Mod); - return modInstallation; - } - public ITestingPhysicalModInstallation InstallAndAddMod(IModinfo modinfo, IDirectoryInfo directory, bool workshops) { var modInstallation = InstallMod(modinfo, directory, workshops); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs index 86defd58..1274656b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs @@ -5,13 +5,33 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations; +/// +/// Provides utility methods for creating testing game installations and registries +/// within the Petroglyph Star Wars game infrastructure testing environment. +/// +/// +/// This class serves as a static entry point for creating instances of +/// and . +/// It is designed to facilitate testing scenarios by providing test environments of game installations and registries. +/// public static class GameInfrastructureTesting { + /// + /// Creates a new instance of for the specified and service provider. + /// + /// The identity of the game for which the testing installation is being created. + /// The service provider used to resolve dependencies required by the testing installation. + /// An instance of representing the testing installation for the specified game. public static ITestingGameInstallation Game(IGameIdentity gameIdentity, IServiceProvider serviceProvider) { return new TestingGameInstallationImpl(gameIdentity, serviceProvider); } + /// + /// Creates a new instance of . + /// + /// The used to resolve dependencies required by the registry. + /// An instance of that provides methods to create and manage test game registries. public static ITestingGameRegistry Registry(IServiceProvider serviceProvider) { return new TestingGameRegistryImpl(serviceProvider); diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs index 117b6528..8bc1bbd4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs @@ -1,6 +1,12 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations; +/// +/// Represents an abstraction for a test installation that provides access to a . +/// public interface ITestingModContainerInstallation : ITestingPlayableObjectInstallation { + /// + /// Gets the associated with this installation. + /// PlayableModContainer ModContainer { get; } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs new file mode 100644 index 00000000..a8d5e52d --- /dev/null +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs @@ -0,0 +1,24 @@ +using AET.Modinfo.Spec; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; + +/// +/// Represents an abstraction for a test installation that provides access +/// to a and its associated . +/// +public interface ITestingPhysicalPlayableObjectInstallation : ITestingPlayableObjectInstallation +{ + /// + /// Gets the physical playable object associated with this test installation. + /// This object represents a playable entity stored on the file system, such as a game or mod, + /// and provides access to its directory and other related properties. + /// + new IPhysicalPlayableObject PlayableObject { get; } + + /// + /// Installs the specified language for the playable object. + /// + /// The language information to be installed. + void InstallLanguage(ILanguageInfo language); +} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs index ab089789..72d0ca3c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs @@ -1,18 +1,20 @@ -using AET.Modinfo.Spec; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; +/// +/// Represents an abstraction for a test installation that provides access +/// to a and its associated . +/// public interface ITestingPlayableObjectInstallation { + /// + /// Gets the game installation associated with this testing playable object installation. + /// ITestingGameInstallation GameInstallation { get; } + /// + /// Gets the playable object associated with the test installation. + /// IPlayableObject PlayableObject { get; } -} - -public interface ITestingPhysicalPlayableObjectInstallation : ITestingPlayableObjectInstallation -{ - new IPhysicalPlayableObject PlayableObject { get; } - - void InstallLanguage(ILanguageInfo language); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs index 7a671624..3a8ae6a1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs @@ -1,11 +1,14 @@ using PG.StarWarsGame.Infrastructure.Mods; -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +/// +/// Represents an abstraction for a test installation of a mod of the Petroglyph Star Wars game infrastructure. +/// public interface ITestingModInstallation : ITestingModContainerInstallation { - new ITestingGameInstallation GameInstallation { get; } - + /// + /// Gets the mod associated with this testing mod installation. + /// IMod Mod { get; } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs index 3f4720a0..dc24c53d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs @@ -3,11 +3,33 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +/// +/// Represents an abstraction for a test installation of a physical mod of the Petroglyph Star Wars game infrastructure. +/// public interface ITestingPhysicalModInstallation : ITestingModInstallation, ITestingPhysicalPlayableObjectInstallation { + /// + /// Gets the physical mod associated with this testing installation. + /// + /// + /// This property provides access to the instance that represents + /// the mod being tested. The mod is expected to be located on the file system and adheres + /// to the structure and requirements defined for physical mods. + /// new IPhysicalMod Mod { get; } + /// + /// Installs an invalid modinfo file to the mod installation. + /// + /// An optional name for the modinfo variant. If not specified, the main modinfo file is created. + /// An instance of representing the installed, invalid modinfo file. IModinfoFile InstallInvalidModinfoFile(string? variantSubFileName = null); + /// + /// Installs a modinfo file to the mod installation. + /// + /// The modinfo data to be installed. + /// An optional name for the modinfo variant. If not specified, the main modinfo file is created. + /// An instance of representing the installed modinfo file. IModinfoFile InstallModinfoFile(IModinfo modinfo, string? variantSubFileName = null); } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs index 5f7e44e5..fb118bfc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs @@ -2,7 +2,13 @@ namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; +/// +/// Represents an abstraction for a test installation of a virtual mod of the Petroglyph Star Wars game infrastructure. +/// public interface ITestingVirtualModInstallation : ITestingModInstallation { + /// + /// Gets the virtual mod associated of the test installation. + /// new IVirtualMod Mod { get; } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index fb3f33f0..61d57204 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -16,7 +16,7 @@ - + true true true diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs index af63094d..1005b292 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs @@ -7,22 +7,72 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; +/// +/// Provides a base class for testing game detectors in the Petroglyph Star Wars Game infrastructure. +/// +/// The type of the setup information used by the game detector during testing. public abstract partial class GameDetectorTestBase : GameInfrastructureTestBase { + /// + /// Gets a value indicating whether the game detector is aware of uninitialized game installation. + /// protected abstract bool SupportInitialization { get; } + /// + /// Gets the collection of game platforms that are supported by the game detector. + /// protected abstract ICollection SupportedPlatforms { get; } + /// + /// Gets a value indicating whether the game detector, which support initialization, support suppressing the initialization requests. + /// protected abstract bool CanDisableInitRequest { get; } + /// + /// Creates an instance of a game detector for testing purposes. + /// + /// + /// The setup information required for the game detector, including game type, directory information, + /// and any additional setup-specific data. + /// + /// + /// A value indicating whether the detector should handle initialization events. + /// + /// An instance of configured based on the specified setup information. protected abstract IGameDetector CreateDetector(GameDetectorTestInfo gameInfo, bool shallHandleInitialization); + /// + /// Sets up the game environment for testing based on the specified game identity. + /// + /// The identity of the game. + /// A instance containing the setup information for the specified game identity. protected abstract GameDetectorTestInfo SetupGame(GameIdentity gameIdentity); + /// + /// Prepares the necessary setup so that the game detector shall detect an uninitialized game. + /// + /// The representing the uninitialized game. + /// A instance containing the setup information required for the test. protected abstract GameDetectorTestInfo SetupForRequiredInitialization(GameIdentity gameIdentity); + /// + /// Handles the initialization process for the game detector during testing. + /// + /// A value indicating whether the initialization should be simulated as successful. + /// The containing the setup information required for initialization. protected abstract void HandleInitialization(bool shallInitSuccessfully, GameDetectorTestInfo info); + /// + /// Tests the core functionality of the game detector by verifying detection results for a specified game identity. + /// + /// The representing the game to be detected. + /// + /// A function to provide custom setup logic for the test, returning a instance. + /// If , is used. + /// + /// + /// A function to create the expected based on the provided test information. + /// The platforms to query during by the detector. protected void TestDetectorCore( GameIdentity identity, Func>? customSetup, @@ -32,6 +82,26 @@ protected void TestDetectorCore( TestDetectorCore(identity, false, customSetup, expectedResultFactory, null, queryPlatforms); } + /// + /// Tests the core functionality of the game detector by verifying detection results for a specified game identity. + /// + /// The representing the game to be detected. + /// A boolean indicating whether initialization events should be handled during detection. + /// + /// A function to provide custom setup logic for the test, returning a instance. + /// If , is used. + /// + /// + /// A function to create the expected based on the provided test information. + /// + /// A predicate to handle initialization events, allowing custom logic to determine if the event is handled. + /// Can be if no initialization handling is requested. + /// + /// The platforms to query during by the detector. + /// + /// This method validates the detection result and ensures that initialization events are triggered or not + /// based on the provided parameters and the detector's capabilities. + /// protected void TestDetectorCore( GameIdentity identity, bool shallHandleInitialization, @@ -76,12 +146,29 @@ protected void TestDetectorCore( Assert.Equal(shouldTriggerInitEvent, eventTriggered); } + /// + /// Represents information required for setting up the test environment for the game detector. + /// + /// The type of the custom setup information. protected class GameDetectorTestInfo(GameType gameType, IDirectoryInfo? directoryInfo, TInfo? setupInfo) { + /// + /// Gets the type of the game being tested. + /// public GameType GameType { get; } = gameType; + /// + /// Gets the directory information for the to be detected game. + /// + /// + /// This property provides access to the directory where the game files are located. + /// It may return to indicate the game shall not get installed. + /// public IDirectoryInfo? GameDirectory { get; } = directoryInfo; + /// + /// Gets the optional, custom setup information required for configuring the game detector. + /// public TInfo? DetectorSetupInfo { get; } = setupInfo; } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs index c85f49bd..56dc70cc 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs @@ -4,6 +4,7 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public partial class GameDetectorTestBase { private void TestDetectorGameInstalled(GameIdentity identity, params GamePlatform[] queryPlatforms) @@ -182,4 +183,5 @@ public void Detect_TryDetect_TestRequiresGameInitialization_DetectorCanHandle_Do }, queryPlatforms: []); } -} \ No newline at end of file +} +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 78239eee..fe3ab9bd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -15,19 +15,48 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; +/// +/// Provides a base class for testing infrastructure components of the Petroglyph Star Wars game test framework. +/// This class facilitates the setup of services, file system management, and game or mod installations +/// required for testing purposes. +/// public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider { private ITestingGameInstallation? _gameInstallation; + /// + /// Gets the file system abstraction used for testing purposes. + /// This property provides access to an instance, which is lazily initialized + /// and can be overridden by derived classes to customize the file system behavior. + /// + /// + /// The file system is initialized using the method. If the initialization + /// fails or returns null, an is thrown. + /// [field:MaybeNull, AllowNull] protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem) ?? throw new InvalidOperationException("Creation of file system must not return null."); + /// + /// Creates and returns a new instance of the file system abstraction for testing purposes. + /// + /// + /// This method is invoked to initialize the property. By default, it returns + /// a instance, but derived classes can override this method to provide + /// a custom implementation of . + /// + /// + /// An instance of representing the file system abstraction to be used in tests. + /// protected virtual IFileSystem CreateFileSystem() { return new MockFileSystem(); } + /// + /// Configures test services by adding them to the specified . + /// + /// The to which services will be added. protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); @@ -35,6 +64,11 @@ protected override void SetupServices(IServiceCollection serviceCollection) PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } + /// + /// Retrieves an existing game installation or creates a new one if it does not already exist. + /// + /// The optional identity of the game. If not provided, a random game identity will be used. + /// An instance of representing the game installation. protected virtual ITestingGameInstallation GetOrCreateGameInstallation(IGameIdentity? identity = null) { if (_gameInstallation is not null) @@ -43,6 +77,13 @@ protected virtual ITestingGameInstallation GetOrCreateGameInstallation(IGameIden return _gameInstallation = GameInfrastructureTesting.Game(identity, ServiceProvider); } + /// + /// Installs a mod with the specified name and dependencies into the game installation and adds it to the collection of the game. + /// + /// The name of the mod to be installed. + /// Specifies the dependency resolution layout to be used. Defaults to . + /// A collection of mod dependencies to be resolved and added. + /// An instance of representing the installed mod. protected ITestingPhysicalModInstallation InstallAndAddModWithDependencies( string name, DependencyResolveLayout layout = DependencyResolveLayout.FullResolved, diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 93134746..1ff4dcbd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -3,9 +3,19 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; +/// +/// Serves as a specialized base class for testing infrastructure components of the Petroglyph Star Wars game test framework +/// with a randomly initialized game instance. +/// public abstract class GameInfrastructureTestBaseWithRandomGame : GameInfrastructureTestBase { + /// + /// Gets the instance of the game associated with the current test context. + /// protected IGame Game => GameInstallation.Game; - + + /// + /// Gets the instance of the associated with the current test context. + /// protected ITestingGameInstallation GameInstallation => GetOrCreateGameInstallation(identity: null); } \ No newline at end of file From 14a9c8f364ab9ed67e7d9d4201d3f0b3331fc126 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 15:45:49 +0100 Subject: [PATCH 54/71] resolve some warnings --- .../CompilerHelpers/Attributes.cs | 45 +++++++++++++++++++ .../SteamWrapperTestBase.cs | 14 +++--- ...SteamPetroglyphStarWarsGameDetectorTest.cs | 2 + .../Processes/GameProcessLauncherTest.cs | 2 +- .../Clients/Processes/GameProcessTest.cs | 14 +++--- 5 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 test/AET.SteamAbstraction.Test/CompilerHelpers/Attributes.cs diff --git a/test/AET.SteamAbstraction.Test/CompilerHelpers/Attributes.cs b/test/AET.SteamAbstraction.Test/CompilerHelpers/Attributes.cs new file mode 100644 index 00000000..e1dc9a46 --- /dev/null +++ b/test/AET.SteamAbstraction.Test/CompilerHelpers/Attributes.cs @@ -0,0 +1,45 @@ +#if !NET5_0_OR_GREATER +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +namespace System.Runtime.Versioning; + +/// +/// Base type for all platform-specific API attributes. +/// + +internal abstract class OSPlatformAttribute(string platformName) : Attribute +{ + public string PlatformName { get; } = platformName; +} + +/// +/// Records the platform that the project targeted. +/// +[AttributeUsage(AttributeTargets.Assembly)] +internal sealed class TargetPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); + +/// +/// Records the operating system (and minimum version) that supports an API. Multiple attributes can be +/// applied to indicate support on multiple operating systems. +/// +/// +/// Callers can apply a +/// or use guards to prevent calls to APIs on unsupported operating systems. +/// +/// A given platform should only be specified once. +/// +[AttributeUsage(AttributeTargets.Assembly | + AttributeTargets.Class | + AttributeTargets.Constructor | + AttributeTargets.Enum | + AttributeTargets.Event | + AttributeTargets.Field | + AttributeTargets.Interface | + AttributeTargets.Method | + AttributeTargets.Module | + AttributeTargets.Property | + AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] +internal sealed class SupportedOSPlatformAttribute(string platformName) : OSPlatformAttribute(platformName); +// ReSharper restore InconsistentNaming +#endif \ No newline at end of file diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 306b61f3..5bef47dd 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using AET.SteamAbstraction.Library; @@ -14,6 +15,7 @@ namespace AET.SteamAbstraction.Test; +[SupportedOSPlatform("windows")] public abstract class SteamWrapperTestBase : InMemorySteamTestBase { private readonly ISteamWrapperFactory _wrapperFactory; @@ -209,7 +211,7 @@ public void UserWantsOfflineMode() Steam.DeleteLoginUsersFile(); Assert.Null(wrapper.UserWantsOfflineMode); - Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(ulong.MaxValue, false, false)); + Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(ulong.MaxValue, mostRecent: false, userWantsOffline: false)); Assert.False(wrapper.UserWantsOfflineMode); // Not most recent @@ -227,7 +229,7 @@ public void UserWantsOfflineMode() // Not most recent Steam.WriteLoginUsers( new TestingSteamUserLoginMetadata(ulong.MaxValue, false, true), - new TestingSteamUserLoginMetadata(456, true, false)); + new TestingSteamUserLoginMetadata(456, true, userWantsOffline: false)); Assert.False(wrapper.UserWantsOfflineMode); Steam.WriteCorruptLoginUsers(); @@ -265,7 +267,7 @@ public async Task WaitSteamRunningAndLoggedInAsync_SteamNotRunningAndShouldNotSt LoginUser(12345); - await Assert.ThrowsAsync(async () => await wrapper.WaitSteamRunningAndLoggedInAsync(false)); + await Assert.ThrowsAsync(async () => await wrapper.WaitSteamRunningAndLoggedInAsync(false, TestContext.Current.CancellationToken)); Assert.Equal(0u, wrapper.GetCurrentUserId()); } @@ -279,7 +281,7 @@ public async Task TestWaitSteamRunningAndLoggedInAsync_LoggedIn() FakeStartSteam(); LoginUser(12345); - await wrapper.WaitSteamRunningAndLoggedInAsync(false); + await wrapper.WaitSteamRunningAndLoggedInAsync(false, TestContext.Current.CancellationToken); Assert.Equal(12345u, wrapper.GetCurrentUserId()); } @@ -290,7 +292,7 @@ public async Task TestWaitSteamRunningAndLoggedInAsync_DelayedLogin() InstallSteam(); var wrapper = CreateWrapper(); - var waitTask = wrapper.WaitSteamRunningAndLoggedInAsync(true); + var waitTask = wrapper.WaitSteamRunningAndLoggedInAsync(true, TestContext.Current.CancellationToken); // Ensure that code had time to proceed to past running check. then wait a little more. await wrapper.WaitSteamRunningAsync(CancellationToken.None) @@ -381,6 +383,6 @@ protected virtual void LoginUser(uint userId) { Assert.NotNull(Steam); Steam.Registry.SetUserId(userId); - Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(userId, true, false)); + Steam.WriteLoginUsers(new TestingSteamUserLoginMetadata(userId, true, userWantsOffline: false)); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index 470974e1..af5eaea5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Runtime.Versioning; using AET.SteamAbstraction; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing; @@ -17,6 +18,7 @@ namespace PG.StarWarsGame.Infrastructure.Clients.Steam.Test; +[SupportedOSPlatform("windows")] public class SteamPetroglyphStarWarsGameDetectorTest : GameDetectorTestBase { private readonly IRegistry _registry = new InMemoryRegistry(InMemoryRegistryCreationFlags.WindowsLike); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs index 46c436bf..a9a58b66 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessLauncherTest.cs @@ -111,7 +111,7 @@ public async Task StartGameProcess_ValidExecutable_WaitForExitAsync() Assert.Equal(_executable.FullName, internalProcess.StartInfo.FileName); Assert.Empty(internalProcess.StartInfo.Arguments); - await process.WaitForExitAsync(); + await process.WaitForExitAsync(TestContext.Current.CancellationToken); Assert.Equal(GameProcessState.Closed, process.State); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs index ee39f1c0..51af599b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs @@ -51,8 +51,8 @@ public async Task WaitForGameProcessExitAsync_CompletesOnProcessExit() Assert.Equal(GameProcessState.Running, gameProcess.State); - var exitTask = gameProcess.WaitForExitAsync(); - process.StandardInput.WriteLine(); + var exitTask = gameProcess.WaitForExitAsync(TestContext.Current.CancellationToken); + await process.StandardInput.WriteLineAsync(); await exitTask; Assert.True(process.HasExited); @@ -86,7 +86,7 @@ public async Task Exit_ClosesProcess() process.WaitForExit(); - await gameProcess.WaitForExitAsync(); + await gameProcess.WaitForExitAsync(TestContext.Current.CancellationToken); Assert.True(process.HasExited); Assert.Equal(GameProcessState.Closed, gameProcess.State); @@ -109,12 +109,12 @@ public async Task Exit_DoubleExitDoesNotThrow() { b.SignalAndWait(); gameProcess.Exit(); - }); + }, TestContext.Current.CancellationToken); var t2 = Task.Run(() => { b.SignalAndWait(); gameProcess.Exit(); - }); + }, TestContext.Current.CancellationToken); await Task.WhenAll(t1, t2); @@ -299,12 +299,12 @@ public async Task Dispose_CompletesWaitForExitAsyncSilently() var processInfo = new GameProcessInfo(Game, GameBuildType.Release, ArgumentCollection.Empty); var gameProcess = new GameProcess(process, processInfo); - var waitTask = gameProcess.WaitForExitAsync(); + var waitTask = gameProcess.WaitForExitAsync(TestContext.Current.CancellationToken); gameProcess.Dispose(); // WaitForExitAsync continues listening - var t = await Task.WhenAny(waitTask, Task.Delay(2000)); + var t = await Task.WhenAny(waitTask, Task.Delay(2000, TestContext.Current.CancellationToken)); Assert.NotSame(t, waitTask); } } \ No newline at end of file From 708c19931770e543d0e87ac65ba9e274c102fed3 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 15:48:14 +0100 Subject: [PATCH 55/71] remove warning --- test/AET.SteamAbstraction.Testing/TestProcessHelper.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index e6ac756f..4866af47 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -68,7 +68,14 @@ public bool IsProcessRunning(int pid) return pid == _pid; } - /// + /// + /// Starts a new process using the specified configuration. + /// + /// The object that specifies the configuration for the process to be started. + /// A object that represents the started process, or if the process could not be started. + /// Thrown if is . + /// Thrown if no file name is specified in . + /// Thrown if an error occurs when opening the associated file. [SupportedOSPlatform("windows")] public Process StartProcess(ProcessStartInfo startInfo) { From 31c9bec015adcca25be919e0b705751b7511d034 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 15:51:16 +0100 Subject: [PATCH 56/71] do not use async write line --- .../Clients/Processes/GameProcessTest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs index 51af599b..a0fa157f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Processes/GameProcessTest.cs @@ -52,7 +52,8 @@ public async Task WaitForGameProcessExitAsync_CompletesOnProcessExit() Assert.Equal(GameProcessState.Running, gameProcess.State); var exitTask = gameProcess.WaitForExitAsync(TestContext.Current.CancellationToken); - await process.StandardInput.WriteLineAsync(); + // ReSharper disable once MethodHasAsyncOverload + process.StandardInput.WriteLine(); await exitTask; Assert.True(process.HasExited); From 0249ec270a0a3bf397ce71bbc5b0cc242974f936 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 16:51:54 +0100 Subject: [PATCH 57/71] rename method --- test/AET.Testing/Extensions/AssertExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/AET.Testing/Extensions/AssertExtensions.cs b/test/AET.Testing/Extensions/AssertExtensions.cs index bf4533ec..5cd54492 100644 --- a/test/AET.Testing/Extensions/AssertExtensions.cs +++ b/test/AET.Testing/Extensions/AssertExtensions.cs @@ -16,7 +16,7 @@ public static class AssertExtensions /// The type of the result returned by the action. /// A delegate to the code to be tested. /// The result of the executed test code. - public static T AssertDoesNotThrowException(Func action) + public static T DoesNotThrowException(Func action) { try { @@ -33,9 +33,9 @@ public static T AssertDoesNotThrowException(Func action) /// Verifies that the specified action does not throw any exception. /// /// A delegate to the code to be tested. - public static void AssertDoesNotThrowException(Action action) + public static void DoesNotThrowException(Action action) { - Assert.AssertDoesNotThrowException(() => action); + Assert.DoesNotThrowException(() => action); } } } \ No newline at end of file From c6e2f7df9732e0a5e59478b3bff93f8d3ae169ae Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 17:24:57 +0100 Subject: [PATCH 58/71] test base with filesystem --- .../AET.SteamAbstraction.Testing.csproj | 10 --- test/AET.Testing/AET.Testing.csproj | 10 ++- test/AET.Testing/TestBaseWithFileSystem.cs | 63 +++++++++++++++++++ .../TestBaseWithServiceProvider.cs | 10 ++- ...StarWarsGame.Infrastructure.Testing.csproj | 6 -- .../TestBases/GameInfrastructureTestBase.cs | 39 +----------- 6 files changed, 78 insertions(+), 60 deletions(-) create mode 100644 test/AET.Testing/TestBaseWithFileSystem.cs diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 9dcb1934..d7e44274 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -26,16 +26,6 @@ - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index c05d4fa2..5517d2a5 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -29,9 +29,17 @@ + - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/AET.Testing/TestBaseWithFileSystem.cs b/test/AET.Testing/TestBaseWithFileSystem.cs new file mode 100644 index 00000000..83d47f8f --- /dev/null +++ b/test/AET.Testing/TestBaseWithFileSystem.cs @@ -0,0 +1,63 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO.Abstractions; +using System.Threading; +using Microsoft.Extensions.DependencyInjection; +using Testably.Abstractions.Testing; + +namespace AET.Testing; + +/// +/// A test base that automatically registers an as service. +/// +public abstract class TestBaseWithFileSystem : TestBaseWithServiceProvider +{ + /// + /// Gets the file system abstraction used for testing purposes. + /// This property provides access to an instance, which is lazily initialized + /// and can be overridden by derived classes to customize the file system behavior. + /// + /// + /// The file system is initialized using the method. If the initialization + /// fails or returns null, an is thrown. + /// + [field: MaybeNull, AllowNull] + protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem) + ?? throw new InvalidOperationException("Creation of file system must not return null."); + + /// + /// Initializes a new instance of the class and configures the service provider. + /// + /// + /// This constructor creates a new service collection, invokes the method to allow + /// derived classes to register services, and then builds the service provider. Derived classes should override + /// SetupServices to customize service registration. + /// + protected TestBaseWithFileSystem() + { + } + + /// + /// Creates and returns a new instance of the file system abstraction for testing purposes. + /// + /// + /// This method is invoked to initialize the property. By default, it returns + /// a instance, but derived classes can override this method to provide + /// a custom implementation of . + /// + /// + /// An instance of representing the file system abstraction to be used in tests. + /// + protected virtual IFileSystem CreateFileSystem() + { + return new MockFileSystem(); + } + + + /// + protected override void SetupServices(IServiceCollection serviceCollection) + { + base.SetupServices(serviceCollection); + serviceCollection.AddSingleton(FileSystem); + } +} \ No newline at end of file diff --git a/test/AET.Testing/TestBaseWithServiceProvider.cs b/test/AET.Testing/TestBaseWithServiceProvider.cs index 42b9c2c9..97302af4 100644 --- a/test/AET.Testing/TestBaseWithServiceProvider.cs +++ b/test/AET.Testing/TestBaseWithServiceProvider.cs @@ -1,11 +1,10 @@ -using System; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; +using System; namespace AET.Testing; /// -/// Provides a base class for test fixtures that require an initialized for dependency -/// injection. +/// Provides a base class for test fixtures that provides and for dependency injection. /// /// Derive from this class to set up and access services using dependency injection in test scenarios. /// Override to register custom services required for your @@ -18,8 +17,7 @@ public abstract class TestBaseWithServiceProvider protected readonly IServiceProvider ServiceProvider; /// - /// Initializes a new instance of the class and configures the service provider using the specified service - /// collection. + /// Initializes a new instance of the class and configures the service provider. /// /// /// This constructor creates a new service collection, invokes the method to allow diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 61d57204..5d4c80b9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -25,12 +25,6 @@ snupkg - - - - - - all diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index fe3ab9bd..2ffc3d81 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,5 +1,4 @@ -using System; -using AET.Modinfo.Model; +using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing; using Microsoft.Extensions.DependencyInjection; @@ -8,10 +7,6 @@ using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.IO.Abstractions; -using System.Threading; -using Testably.Abstractions.Testing; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; @@ -20,39 +15,10 @@ namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; /// This class facilitates the setup of services, file system management, and game or mod installations /// required for testing purposes. /// -public abstract class GameInfrastructureTestBase : TestBaseWithServiceProvider +public abstract class GameInfrastructureTestBase : TestBaseWithFileSystem { private ITestingGameInstallation? _gameInstallation; - /// - /// Gets the file system abstraction used for testing purposes. - /// This property provides access to an instance, which is lazily initialized - /// and can be overridden by derived classes to customize the file system behavior. - /// - /// - /// The file system is initialized using the method. If the initialization - /// fails or returns null, an is thrown. - /// - [field:MaybeNull, AllowNull] - protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem) - ?? throw new InvalidOperationException("Creation of file system must not return null."); - - /// - /// Creates and returns a new instance of the file system abstraction for testing purposes. - /// - /// - /// This method is invoked to initialize the property. By default, it returns - /// a instance, but derived classes can override this method to provide - /// a custom implementation of . - /// - /// - /// An instance of representing the file system abstraction to be used in tests. - /// - protected virtual IFileSystem CreateFileSystem() - { - return new MockFileSystem(); - } - /// /// Configures test services by adding them to the specified . /// @@ -60,7 +26,6 @@ protected virtual IFileSystem CreateFileSystem() protected override void SetupServices(IServiceCollection serviceCollection) { base.SetupServices(serviceCollection); - serviceCollection.AddSingleton(FileSystem); PetroglyphGameInfrastructure.InitializeServices(serviceCollection); } From afce1c0c15ef10361d57f07db66765e4fb2280f4 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Mon, 22 Dec 2025 18:31:08 +0100 Subject: [PATCH 59/71] rename method --- .../Extensions/RandomExtensions.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/test/AET.Testing/Extensions/RandomExtensions.cs b/test/AET.Testing/Extensions/RandomExtensions.cs index 3d6e6e8e..24dbde4c 100644 --- a/test/AET.Testing/Extensions/RandomExtensions.cs +++ b/test/AET.Testing/Extensions/RandomExtensions.cs @@ -176,8 +176,23 @@ public static T Item(IEnumerable items) /// The desired length of the generated string. Must be a non-negative value. /// A randomly generated string of the specified length. Returns an empty string if is 0. /// Thrown when is less than 0. - public static unsafe string GetRandomStringOfLength(int length) + public static string String(int length) { + return Random.String(length, AllowedChars); + } + + /// + /// Generates a random string of the specified length using the specified pool of characters. + /// + /// The desired length of the generated string. Must be a non-negative value. + /// The pool of characters to pick random characters from. + /// A randomly generated string of the specified length. Returns an empty string if is 0. + /// Thrown when is less than 0. + /// Thrown when is empty or . + public static unsafe string String(int length, ReadOnlySpan charPool) + { + if (charPool == ReadOnlySpan.Empty || charPool.IsEmpty) + throw new ArgumentException("charPool must not be null or empty", nameof(charPool)); switch (length) { case < 0: @@ -193,8 +208,8 @@ public static unsafe string GetRandomStringOfLength(int length) var random = Random; for (var i = 0; i < buffer.Length; i++) { - var index = random.Next(AllowedChars.Length); - buffer[i] = AllowedChars[index]; + var index = random.Next(charPool.Length); + buffer[i] = charPool[index]; } #if NET From 646ba2daa83baacdf7f19c5c96218f4d8d44a606 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 23 Dec 2025 12:35:33 +0100 Subject: [PATCH 60/71] add opposite extension method --- .../CompilerHelpers/Attributes.cs | 5 ++++- .../SteamPetroglyphStarWarsGameDetectorTest.cs | 3 +-- .../Detection/GamePlatformIdentifierTest.cs | 3 +-- .../Detection/RegistryGameDetectorTest.cs | 4 +--- .../ModBaseTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 5 ++--- .../ModServices/ModFinderTest.cs | 9 +++------ .../ModServices/ModGameTypeResolverTestBase.cs | 2 +- .../GITestUtilities.cs | 13 +++++++++++++ .../TestBases/GameDetectorTestBase_Tests.cs | 4 +--- 10 files changed, 28 insertions(+), 22 deletions(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs index e20fb274..e1dc9a46 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/CompilerHelpers/Attributes.cs @@ -7,7 +7,10 @@ namespace System.Runtime.Versioning; /// Base type for all platform-specific API attributes. /// -internal abstract class OSPlatformAttribute(string PlatformName) : Attribute; +internal abstract class OSPlatformAttribute(string platformName) : Attribute +{ + public string PlatformName { get; } = platformName; +} /// /// Records the platform that the project targeted. diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs index af5eaea5..3b4230e4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameDetectorTest.cs @@ -145,8 +145,7 @@ private GameDetectorTestInfo SetupGame( lib.InstallGame(32470, "Star Wars Empire at War", depots, appState); // To Registry - var otherGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; - registrySetup(game, otherGameType); + registrySetup(game, gameIdentity.Type.Opposite()); return new GameDetectorTestInfo(gameIdentity.Type, game.Directory, null); } diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs index e76f09ab..e446e92e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/GamePlatformIdentifierTest.cs @@ -32,8 +32,7 @@ public void NullArgs_ThrowsArgumentNullException() [MemberData(nameof(GITestUtilities.RealGameIdentities), MemberType = typeof(GITestUtilities))] public void GetGamePlatform_WrongGameInstalledReturnsUndefined(GameIdentity identity) { - var oppositeGameType = identity.Type == GameType.Foc ? GameType.Eaw : GameType.Foc; - var game = GetOrCreateGameInstallation(new GameIdentity(oppositeGameType, identity.Platform)).Game; + var game = GetOrCreateGameInstallation(new GameIdentity(identity.Type.Opposite(), identity.Platform)).Game; var gameLocation = game.Directory; var actual = _platformIdentifier.GetGamePlatform(identity.Type, ref gameLocation); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs index e74a97b8..040d85b9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/Detection/RegistryGameDetectorTest.cs @@ -58,10 +58,8 @@ protected override GameDetectorTestInfo SetupForRequiredI private GameRegistryContainer SetupRegistry(GameType gameType, TestGameRegistrySetupData registrySetup) { - var otherGameType = gameType == GameType.Eaw ? GameType.Foc : GameType.Eaw; - var gameRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateFrom(registrySetup); - var defaultRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(otherGameType); + var defaultRegistry = GameInfrastructureTesting.Registry(ServiceProvider).CreateNonExistingRegistry(gameType.Opposite()); IGameRegistry eawRegistry; IGameRegistry focRegistry; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 69346eee..79a240af 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -239,7 +239,7 @@ public void EqualsHashCode() ? new CustomMod(Game, mod.Identifier, mod.Type, mod.ModInfo, ServiceProvider) : new CustomMod(Game, mod.Identifier, mod.Type, mod.Name, ServiceProvider); - Assert.False(mod.Equals(null)); + Assert.False(mod.Equals(null!)); Assert.False(mod.Equals((object)null!)); Assert.False(mod.Equals((IModIdentity)null!)); Assert.False(mod.Equals((IModReference)null!)); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index a142f3ac..f15c481f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -187,10 +187,9 @@ public void CreatePhysicalMod_InvalidNameResolved_Throws(GameIdentity gameIdenti public void CreatePhysicalMod_ModNotCompatible_Throws(GameIdentity gameIdentity) { var game = GetOrCreateGameInstallation(gameIdentity).Game; - - var oppositeGameType = gameIdentity.Type == GameType.Eaw ? GameType.Foc : GameType.Eaw; + var otherGameInstallation = GameInfrastructureTesting - .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + .Game(new GameIdentity(gameIdentity.Type.Opposite(), Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); var modDir = otherGameInstallation.GetModDirectory("Mod_Name", false); var modData = CreateDetectedModReference(otherGameInstallation, modDir, false, null); diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 3cb7bea6..8785a301 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -288,15 +288,13 @@ public void FindMods_Steam_ShouldNotContainModOfWrongGame(GameType type) { var gameInstallation = GetOrCreateGameInstallation(new GameIdentity(type, GamePlatform.SteamGold)); var game = gameInstallation.Game; - - var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; - + var steamData = new SteamData( new Random().Next(0, int.MaxValue).ToString(), "path", Random.Enum(), "Title", - [$"{oppositeGameType.ToString().ToUpper()}"]); + [$"{type.Opposite().ToString().ToUpper()}"]); var modinfo = new ModinfoData("Name") { SteamData = steamData @@ -412,11 +410,10 @@ public void FindMods_ModInsideSteamWsDirWithNonIdName_ShouldBeSkipped(GameType t [InlineData(GameType.Foc)] public void FindMods_ModInstalledInWrongGameModsDirectoryShouldBeSkipped(GameType type) { - var oppositeGameType = type is GameType.Eaw ? GameType.Foc : GameType.Eaw; var game = GetOrCreateGameInstallation(new GameIdentity(type, Random.Item(GITestUtilities.RealPlatforms))).Game; // Other, random platform to shuffle a bit more. var otherTypeGame = GameInfrastructureTesting - .Game(new GameIdentity(oppositeGameType, Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); + .Game(new GameIdentity(type.Opposite(), Random.Item(GITestUtilities.RealPlatforms)), ServiceProvider); var wrongMod = otherTypeGame.InstallMod("MyMod", false).Mod; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 08388d87..715abe8f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -203,7 +203,7 @@ public static IEnumerable GetCachedModsTestData() if (knownMod.Value.Types.Length == 2) incompatible = null; else - incompatible = knownMod.Value.Types.First() == GameType.Foc ? GameType.Eaw : GameType.Foc; + incompatible = knownMod.Value.Types.First().Opposite(); yield return [knownMod.Key.ToString(), knownMod.Value.Types, incompatible!]; } diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index e4d79a80..fc9b73a6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -119,4 +119,17 @@ public static IGameIdentity GetRandomGameIdentity(bool realOnly = true) var platforms = realOnly ? RealPlatforms : (GamePlatform[])Enum.GetValues(typeof(GamePlatform)); return new GameIdentity(Random.Enum(), Random.Item(platforms)); } + + /// + /// Gets the opposite . + /// + /// The current . + /// + /// The opposite . If the input is , the result is ; + /// if the input is , the result is . + /// + public static GameType Opposite(this GameType type) + { + return (GameType)((int)type ^ 1); + } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs index 56dc70cc..cab7245b 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs @@ -63,13 +63,11 @@ public void Detect_TryDetect_GameNotInstalled(GameIdentity identity) public void Detect_TryDetect_TypeOfDesiredPlatformNotFound(GameIdentity identity) { // Install the opposite of the desired game type. - var typeToInstall = identity.Type == GameType.Foc ? GameType.Eaw : GameType.Foc; - var expected = GameDetectionResult.NotInstalled(identity.Type); TestDetectorCore( identity, - _ => SetupGame(new GameIdentity(typeToInstall, identity.Platform)), // Set up the opposite game + _ => SetupGame(new GameIdentity(identity.Type.Opposite(), identity.Platform)), // Set up the opposite game _ => expected, identity.Platform ); From b2097877419f24577f1e353d1aa91f70bec92d32 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 23 Dec 2025 12:35:47 +0100 Subject: [PATCH 61/71] support vs testting --- .../AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj | 2 -- .../PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj | 3 +-- .../PG.StarWarsGame.Infrastructure.Test.csproj | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 9b48feeb..5bc57a99 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -14,9 +14,7 @@ - - diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index e2f8ed1d..04fa4fc9 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -14,8 +14,7 @@ - - + diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index 4129356c..8014f0ec 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -14,11 +14,8 @@ - - - From 65b307ff36b736d65219d33313258d9d3932be38 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 23 Dec 2025 18:52:10 +0100 Subject: [PATCH 62/71] update logging --- .../Services/Detection/Mods/ModGameTypeResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs index 5ace74a3..fc4ecd97 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs @@ -85,7 +85,7 @@ public bool IsDefinitelyNotCompatibleToGame(IModinfo? modinfo, GameType expected private bool GetGameType(ISteamData? steamData, out ReadOnlyFrugalList gameTypes) { gameTypes = default; - Logger?.LogTrace($"Try getting game type from steam data '[{string.Join(",", steamData?.Tags ?? ["tags n/a"])}]'"); + Logger?.LogTrace("Try getting game type from steam data '[{Tags}]'", string.Join(",", steamData?.Tags ?? ["tags n/a"])); return steamData is not null && GetGameTypesFromTags(steamData.Tags, out gameTypes); } From d8407c6429e4612d6de4aa0edb02073948322ff8 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 23 Dec 2025 18:58:37 +0100 Subject: [PATCH 63/71] prepare package --- .../AET.SteamAbstraction.Testing.csproj | 2 +- test/AET.Testing/AET.Testing.csproj | 4 ++-- .../PG.StarWarsGame.Infrastructure.Testing.csproj | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index d7e44274..fd9fb515 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index 5517d2a5..e2a7ab20 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -35,11 +35,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 5d4c80b9..caee0ad5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -2,7 +2,7 @@ PG.StarWarsGame.Infrastructure.TestingUtilities - netstandard2.0 + netstandard2.0;net10.0 true false @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From a5b3776a68871df402fd2b9f28436f1812f794d2 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Tue, 23 Dec 2025 19:09:04 +0100 Subject: [PATCH 64/71] nullable --- .../Installations/Game/TestingGameInstallationImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs index ea2d1415..6ec6815a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs @@ -48,7 +48,7 @@ private IGame Install(IGameIdentity gameIdentity) FileSystem.InstallModsLocations(gameDir); - var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString(), ServiceProvider); + var game = new PetroglyphStarWarsGame(gameIdentity, gameDir, gameIdentity.ToString()!, ServiceProvider); Assert.True(game.Exists()); return game; } From 6f9125c92918b76a65ec0506261a861c684af1fd Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Wed, 24 Dec 2025 15:05:45 +0100 Subject: [PATCH 65/71] add copyright --- src/AET.SteamAbstraction/AET.SteamAbstraction.csproj | 6 +++--- .../PG.StarWarsGame.Infrastructure.csproj | 12 ++++++------ .../Utilities/PlayableObjectExtensions.cs | 2 +- .../AET.SteamAbstraction.Test.csproj | 1 + .../ISteamFakeProcess.cs | 5 ++++- .../ITestingSteamInstallation.cs | 5 ++++- .../ITestingSteamLibrary.cs | 5 ++++- .../ITestingSteamRegistry.cs | 5 ++++- .../SteamFakeProcessImpl.cs | 5 ++++- .../SteamInstallationExtensions.cs | 5 ++++- .../TestBases/InMemorySteamTestBase.cs | 5 ++++- .../TestBases/SteamTestBase.cs | 5 ++++- .../TestProcessHelper.cs | 5 ++++- .../TestingSteamConstants.cs | 5 ++++- .../TestingSteamInstallationImpl.Library.cs | 5 ++++- .../TestingSteamInstallationImpl.User.cs | 5 ++++- .../TestingSteamInstallationImpl.cs | 5 ++++- .../TestingSteamLibrary.cs | 5 ++++- .../TestingSteamRegistryImpl.cs | 5 ++++- .../TestingSteamUserLoginMetadata.cs | 5 ++++- test/AET.Testing/AET.Testing.csproj | 2 +- .../Attributes/PlatformSpecificFactAttribute.cs | 5 ++++- .../Attributes/PlatformSpecificTheoryAttribute.cs | 5 ++++- .../AET.Testing/Attributes/TestPlatformIdentifier.cs | 5 ++++- test/AET.Testing/ExceptionHelpers.cs | 5 ++++- test/AET.Testing/Extensions/AssertExtensions.cs | 5 ++++- test/AET.Testing/Extensions/RandomExtensions.cs | 5 ++++- test/AET.Testing/Extensions/StringExtensions.cs | 5 ++++- test/AET.Testing/ReferenceEqualityComparer.cs | 6 ++++-- test/AET.Testing/TestBaseWithFileSystem.cs | 5 ++++- test/AET.Testing/TestBaseWithServiceProvider.cs | 5 ++++- test/AET.Testing/TestingHelpers.cs | 5 ++++- .../Clients/TestGameProcessLauncher.cs | 5 ++++- .../GITestUtilities.cs | 5 ++++- .../Installations/Game/GameInstallationHelper.Eaw.cs | 5 ++++- .../Installations/Game/GameInstallationHelper.Foc.cs | 5 ++++- .../Installations/Game/GameInstallationHelper.cs | 5 ++++- .../Installations/Game/ITestingGameInstallation.cs | 5 ++++- .../Game/Registry/ITestingGameRegistry.cs | 5 ++++- .../Game/Registry/TestGameRegistrySetupData.cs | 5 ++++- .../Game/Registry/TestingGameRegistryImpl.cs | 5 ++++- .../Game/TestingGameInstallationImpl.Mod.cs | 5 ++++- .../Game/TestingGameInstallationImpl.cs | 5 ++++- .../Installations/GameInfrastructureTesting.cs | 5 ++++- .../ITestingModContainerInstallation.cs | 5 ++++- .../ITestingPhysicalPlayableObjectInstallation.cs | 5 ++++- .../ITestingPlayableObjectInstallation.cs | 5 ++++- .../Installations/Mods/ITestingModInstallation.cs | 5 ++++- .../Mods/ITestingPhysicalModInstallation.cs | 5 ++++- .../Mods/ITestingVirtualModInstallation.cs | 5 ++++- .../Installations/Mods/TestingModInstallationImpl.cs | 5 ++++- .../Mods/TestingPhysicalModInstallationImpl.cs | 5 ++++- .../Mods/TestingVirtualModInstallationImpl.cs | 5 ++++- .../Installations/PlayableObjectTestingExtensions.cs | 5 ++++- .../Installations/TestingModContainerInstallation.cs | 5 ++++- .../TestingPlayableObjectInstallationImpl.cs | 5 ++++- .../TestBases/GameDetectorTestBase.cs | 5 ++++- .../TestBases/GameDetectorTestBase_Tests.cs | 5 ++++- .../TestBases/GameInfrastructureTestBase.cs | 5 ++++- .../GameInfrastructureTestBaseWithRandomGame.cs | 5 ++++- 60 files changed, 232 insertions(+), 67 deletions(-) diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj index b7cae14e..1f9b241c 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;netstandard2.1 AET.SteamAbstraction @@ -22,15 +22,15 @@ - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj index 08e22e06..b6db1189 100644 --- a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj +++ b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj @@ -26,6 +26,12 @@ + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -34,11 +40,5 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - \ No newline at end of file diff --git a/src/PG.StarWarsGame.Infrastructure/Utilities/PlayableObjectExtensions.cs b/src/PG.StarWarsGame.Infrastructure/Utilities/PlayableObjectExtensions.cs index 1518573c..5d746392 100644 --- a/src/PG.StarWarsGame.Infrastructure/Utilities/PlayableObjectExtensions.cs +++ b/src/PG.StarWarsGame.Infrastructure/Utilities/PlayableObjectExtensions.cs @@ -87,7 +87,7 @@ public static IEnumerable DataFiles( subPath ??= string.Empty; var fs = playableObject.Directory.FileSystem; var searchLocation = fs.Path.Combine("Data", subPath); - return EnumerateFiles(playableObject, fileSearchPattern, searchLocation, searchRecursive); + return playableObject.EnumerateFiles(fileSearchPattern, searchLocation, searchRecursive); } /// diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 5bc57a99..f216c14b 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -13,6 +13,7 @@ + diff --git a/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs b/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs index 7d9c9372..669b3183 100644 --- a/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs +++ b/test/AET.SteamAbstraction.Testing/ISteamFakeProcess.cs @@ -1,4 +1,7 @@ -namespace AET.SteamAbstraction.Testing; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +namespace AET.SteamAbstraction.Testing; /// /// Represents a fake Steam process for testing purposes. diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs index 5f74a93a..92f0d4a6 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamInstallation.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Collections.Generic; using System.IO.Abstractions; using System.Runtime.Versioning; diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs index 721ff763..1038c94c 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamLibrary.cs @@ -1,4 +1,7 @@ -using AET.SteamAbstraction.Games; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Library; using System.Collections.Generic; diff --git a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs index 0180c7a2..941a7440 100644 --- a/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs +++ b/test/AET.SteamAbstraction.Testing/ITestingSteamRegistry.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO.Abstractions; using System.Runtime.Versioning; diff --git a/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs b/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs index d75a42a8..e2cd1256 100644 --- a/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs +++ b/test/AET.SteamAbstraction.Testing/SteamFakeProcessImpl.cs @@ -1,4 +1,7 @@ -using Microsoft.Extensions.DependencyInjection; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using Microsoft.Extensions.DependencyInjection; using System; using System.Runtime.Versioning; diff --git a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs index e2c452b9..45ef2cb1 100644 --- a/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs +++ b/test/AET.SteamAbstraction.Testing/SteamInstallationExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; namespace AET.SteamAbstraction.Testing; diff --git a/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs index 97d0f632..ca3960ec 100644 --- a/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/InMemorySteamTestBase.cs @@ -1,4 +1,7 @@ -using System.IO.Abstractions; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System.IO.Abstractions; using System.Runtime.InteropServices; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; diff --git a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs index 9b5a0a15..32a42d16 100644 --- a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using AET.Testing; using Microsoft.Extensions.DependencyInjection; diff --git a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs index 4866af47..1123462d 100644 --- a/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs +++ b/test/AET.SteamAbstraction.Testing/TestProcessHelper.cs @@ -1,4 +1,7 @@ -using AET.SteamAbstraction.Utilities; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.SteamAbstraction.Utilities; using Microsoft.Extensions.DependencyInjection; using System; using System.Diagnostics; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs b/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs index eabc7296..fc967ccd 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamConstants.cs @@ -1,4 +1,7 @@ -namespace AET.SteamAbstraction.Testing; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +namespace AET.SteamAbstraction.Testing; /// /// Provides constant values for Steam installation paths used in testing scenarios. diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index 01b10874..447dbfb5 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs index e581fb07..a2fdcdea 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.User.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; using System.Text; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs index 882e6f00..d052c714 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.cs @@ -1,4 +1,7 @@ -using Microsoft.Extensions.DependencyInjection; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using Microsoft.Extensions.DependencyInjection; using System; using System.IO.Abstractions; using System.Runtime.Versioning; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs b/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs index 8ce5e898..b5443b18 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamLibrary.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Collections.Generic; using System.IO.Abstractions; using System.Text; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs b/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs index 0742e343..8adfbf16 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamRegistryImpl.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO.Abstractions; using AET.SteamAbstraction.Registry; using Microsoft.Extensions.DependencyInjection; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs b/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs index ce34e41e..417a5ea3 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamUserLoginMetadata.cs @@ -1,4 +1,7 @@ -namespace AET.SteamAbstraction.Testing; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +namespace AET.SteamAbstraction.Testing; /// /// Represent metadata about a Steam user login. diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index e2a7ab20..d96deaa8 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -27,7 +27,7 @@ - + diff --git a/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs index a87e8446..10b857ee 100644 --- a/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs +++ b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Linq; using System.Runtime.InteropServices; using Xunit; diff --git a/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs index 858fffe0..94f785ea 100644 --- a/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs +++ b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Linq; using System.Runtime.InteropServices; using Xunit; diff --git a/test/AET.Testing/Attributes/TestPlatformIdentifier.cs b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs index 4f06cce5..90562360 100644 --- a/test/AET.Testing/Attributes/TestPlatformIdentifier.cs +++ b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; namespace AET.Testing.Attributes; diff --git a/test/AET.Testing/ExceptionHelpers.cs b/test/AET.Testing/ExceptionHelpers.cs index ecca19eb..0919f724 100644 --- a/test/AET.Testing/ExceptionHelpers.cs +++ b/test/AET.Testing/ExceptionHelpers.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using Xunit; namespace AET.Testing; diff --git a/test/AET.Testing/Extensions/AssertExtensions.cs b/test/AET.Testing/Extensions/AssertExtensions.cs index 5cd54492..52a09ac4 100644 --- a/test/AET.Testing/Extensions/AssertExtensions.cs +++ b/test/AET.Testing/Extensions/AssertExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using Xunit; namespace AET.Testing.Extensions; diff --git a/test/AET.Testing/Extensions/RandomExtensions.cs b/test/AET.Testing/Extensions/RandomExtensions.cs index 24dbde4c..2dfc7b80 100644 --- a/test/AET.Testing/Extensions/RandomExtensions.cs +++ b/test/AET.Testing/Extensions/RandomExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Collections.Generic; namespace AET.Testing.Extensions; diff --git a/test/AET.Testing/Extensions/StringExtensions.cs b/test/AET.Testing/Extensions/StringExtensions.cs index 68d4946c..2f1d61bc 100644 --- a/test/AET.Testing/Extensions/StringExtensions.cs +++ b/test/AET.Testing/Extensions/StringExtensions.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; namespace AET.Testing.Extensions; diff --git a/test/AET.Testing/ReferenceEqualityComparer.cs b/test/AET.Testing/ReferenceEqualityComparer.cs index 42c1e128..22bfb8d2 100644 --- a/test/AET.Testing/ReferenceEqualityComparer.cs +++ b/test/AET.Testing/ReferenceEqualityComparer.cs @@ -1,5 +1,7 @@ -#if !NET5_0_OR_GREATER -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +#if !NET5_0_OR_GREATER using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/test/AET.Testing/TestBaseWithFileSystem.cs b/test/AET.Testing/TestBaseWithFileSystem.cs index 83d47f8f..faab29d1 100644 --- a/test/AET.Testing/TestBaseWithFileSystem.cs +++ b/test/AET.Testing/TestBaseWithFileSystem.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Diagnostics.CodeAnalysis; using System.IO.Abstractions; using System.Threading; diff --git a/test/AET.Testing/TestBaseWithServiceProvider.cs b/test/AET.Testing/TestBaseWithServiceProvider.cs index 97302af4..a9eb74f2 100644 --- a/test/AET.Testing/TestBaseWithServiceProvider.cs +++ b/test/AET.Testing/TestBaseWithServiceProvider.cs @@ -1,4 +1,7 @@ -using Microsoft.Extensions.DependencyInjection; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using Microsoft.Extensions.DependencyInjection; using System; namespace AET.Testing; diff --git a/test/AET.Testing/TestingHelpers.cs b/test/AET.Testing/TestingHelpers.cs index 2ccf751d..2decdd7b 100644 --- a/test/AET.Testing/TestingHelpers.cs +++ b/test/AET.Testing/TestingHelpers.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO; namespace AET.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs index a830ee69..7ff7e9ef 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Clients/TestGameProcessLauncher.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Diagnostics; using System.IO.Abstractions; using System.Runtime.InteropServices; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index fc9b73a6..0ae9ca2d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -1,4 +1,7 @@ -using AET.Modinfo.Model; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.Modinfo.Model; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs index 09f9c650..5994c21f 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Eaw.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs index 6128da8d..1d71c3d3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.Foc.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; using Testably.Abstractions.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs index ab39a43c..02f7e041 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/GameInstallationHelper.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO.Abstractions; using Testably.Abstractions.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs index 6e5b39bb..22fc129e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/ITestingGameInstallation.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using AET.Modinfo.Model; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Games; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs index 6370016c..e5ddb391 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/ITestingGameRegistry.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Games; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs index fa4ccb9a..344ab245 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestGameRegistrySetupData.cs @@ -1,4 +1,7 @@ -using System.IO.Abstractions; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs index 07eef776..8a95ba29 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/Registry/TestingGameRegistryImpl.cs @@ -1,4 +1,7 @@ -using AnakinRaW.CommonUtilities.Registry; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs index 36d548dd..b30b909a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.Mod.cs @@ -1,4 +1,7 @@ -using AET.Modinfo.Model; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.Modinfo.Model; using AET.Modinfo.Spec; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs index 6ec6815a..01023614 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Game/TestingGameInstallationImpl.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Games; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Games; using System; using System.IO.Abstractions; using AET.Modinfo.Spec; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs index 1274656b..930957bd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/GameInfrastructureTesting.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game.Registry; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs index 8bc1bbd4..766477c4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingModContainerInstallation.cs @@ -1,4 +1,7 @@ -namespace PG.StarWarsGame.Infrastructure.Testing.Installations; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +namespace PG.StarWarsGame.Infrastructure.Testing.Installations; /// /// Represents an abstraction for a test installation that provides access to a . diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs index a8d5e52d..309e441d 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPhysicalPlayableObjectInstallation.cs @@ -1,4 +1,7 @@ -using AET.Modinfo.Spec; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs index 72d0ca3c..2406d3a8 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/ITestingPlayableObjectInstallation.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs index 3a8ae6a1..3820bc05 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingModInstallation.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Mods; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs index dc24c53d..7d71a8ba 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingPhysicalModInstallation.cs @@ -1,4 +1,7 @@ -using AET.Modinfo.Spec; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs index fb118bfc..c192978c 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/ITestingVirtualModInstallation.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Mods; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Mods; namespace PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs index f918a8c5..809678a2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingModInstallationImpl.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs index 66851de6..3656bde7 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingPhysicalModInstallationImpl.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO; using AET.Modinfo.File; using AET.Modinfo.Spec; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs index 40f53b86..8fe85001 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/Mods/TestingVirtualModInstallationImpl.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs index ab710b55..266ee7aa 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/PlayableObjectTestingExtensions.cs @@ -1,4 +1,7 @@ -using System.IO.Abstractions; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System.IO.Abstractions; using AET.Modinfo.Spec; using PG.StarWarsGame.Infrastructure.Services.Language; using PG.StarWarsGame.Infrastructure.Utilities; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs index 8ce0debd..be350738 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingModContainerInstallation.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; namespace PG.StarWarsGame.Infrastructure.Testing.Installations; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs index bd724a64..d8777254 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/Installations/TestingPlayableObjectInstallationImpl.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.IO.Abstractions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs index 1005b292..4799cdcd 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using System; using System.Collections.Generic; using System.IO.Abstractions; using PG.StarWarsGame.Infrastructure.Games; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs index cab7245b..440994c2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameDetectorTestBase_Tests.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Games; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 2ffc3d81..80f23c06 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -1,4 +1,7 @@ -using AET.Modinfo.Model; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using AET.Modinfo.Model; using AET.Modinfo.Spec; using AET.Testing; using Microsoft.Extensions.DependencyInjection; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs index 1ff4dcbd..453ffad6 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBaseWithRandomGame.cs @@ -1,4 +1,7 @@ -using PG.StarWarsGame.Infrastructure.Games; +// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; From 69a4da1f120937bf3bafe229fad8953ca4779c10 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 16 Jan 2026 14:35:04 +0100 Subject: [PATCH 66/71] update deps --- Directory.Build.props | 5 ++--- LICENSE | 2 +- sampleApp/SampleApplication.csproj | 2 +- .../AET.SteamAbstraction.csproj | 14 +++++++------- .../PG.StarWarsGame.Infrastructure.csproj | 14 +++++++------- .../Detection/Mods/IModGameTypeResolver.cs | 4 ++-- .../Detection/Mods/ModGameTypeResolver.cs | 12 ++++++------ .../Detection/Mods/OfflineModGameTypeResolver.cs | 15 +++++++-------- .../Detection/Mods/OnlineModGameTypeResolver.cs | 4 ++-- .../AET.SteamAbstraction.Test.csproj | 6 +++--- test/AET.Testing/AET.Testing.csproj | 8 ++++---- ...sGame.Infrastructure.Clients.Steam.Test.csproj | 4 ++-- .../PG.StarWarsGame.Infrastructure.Test.csproj | 2 +- 13 files changed, 45 insertions(+), 47 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b10fafc0..aec3b0e0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ Alamo Engine Tools and Contributors - Copyright © 2025 Alamo Engine Tools and contributors. All rights reserved. + Copyright © 2026 Alamo Engine Tools and contributors. All rights reserved. Alamo Engine Tools petroglyph, alamo, glyphx, foc, eaw https://github.com/AlamoEngine-Tools/PetroglyphGameInfrastructure @@ -32,8 +32,7 @@ 3.9.50 - - runtime; build; native; contentfiles; analyzers; buildtransitive + all diff --git a/LICENSE b/LICENSE index 10fdbec7..23fe8695 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 Alamo Engine Tools +Copyright (c) 2026 Alamo Engine Tools Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/sampleApp/SampleApplication.csproj b/sampleApp/SampleApplication.csproj index e8b2d631..032d5a8c 100644 --- a/sampleApp/SampleApplication.csproj +++ b/sampleApp/SampleApplication.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj index 1f9b241c..b994e61f 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj @@ -21,13 +21,13 @@ true - - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj index b6db1189..c6941d12 100644 --- a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj +++ b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj @@ -22,16 +22,16 @@ true - - - - + + + + - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/IModGameTypeResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/IModGameTypeResolver.cs index f6502b16..bd966fc4 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/IModGameTypeResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/IModGameTypeResolver.cs @@ -21,7 +21,7 @@ public interface IModGameTypeResolver /// When this method returns , the assured game types will be stored in this variable. /// when the game type could be determined; if there is no clear evidence of the actual game type. /// is . - public bool TryGetGameType(DetectedModReference modInformation, out ReadOnlyFrugalList gameTypes); + public bool TryGetGameType(DetectedModReference modInformation, out ImmutableFrugalList gameTypes); /// /// Tries to determine the from a specified modinfo data. @@ -32,7 +32,7 @@ public interface IModGameTypeResolver /// The modinfo data. /// When this method returns , the assured game types will be stored in this variable. /// when the game type could be determined; if there is no clear evidence of the actual game type. - public bool TryGetGameType(IModinfo? modinfo, out ReadOnlyFrugalList gameTypes); + public bool TryGetGameType(IModinfo? modinfo, out ImmutableFrugalList gameTypes); /// /// Determines whether the specified mod information are definitely not compatible to a game type. diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs index fc4ecd97..29a370a7 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/ModGameTypeResolver.cs @@ -37,7 +37,7 @@ protected ModGameTypeResolver(IServiceProvider serviceProvider) } /// - public bool TryGetGameType(DetectedModReference modInformation, out ReadOnlyFrugalList gameTypes) + public bool TryGetGameType(DetectedModReference modInformation, out ImmutableFrugalList gameTypes) { if (modInformation == null) throw new ArgumentNullException(nameof(modInformation)); @@ -56,10 +56,10 @@ public bool TryGetGameType(DetectedModReference modInformation, out ReadOnlyFrug /// The information of the mod. /// When this method returns , the assured game types will be stored in this variable. /// when the game type could be determined; if there is no clear evidence of the actual game type. - protected internal abstract bool TryGetGameTypeCore(DetectedModReference modInformation, out ReadOnlyFrugalList gameTypes); + protected internal abstract bool TryGetGameTypeCore(DetectedModReference modInformation, out ImmutableFrugalList gameTypes); /// - public virtual bool TryGetGameType(IModinfo? modinfo, out ReadOnlyFrugalList gameTypes) + public virtual bool TryGetGameType(IModinfo? modinfo, out ImmutableFrugalList gameTypes) { return GetGameType(modinfo?.SteamData, out gameTypes); } @@ -82,14 +82,14 @@ public bool IsDefinitelyNotCompatibleToGame(IModinfo? modinfo, GameType expected return TryGetGameType(modinfo, out var gameTypes) && !gameTypes.Contains(expectedGameType); } - private bool GetGameType(ISteamData? steamData, out ReadOnlyFrugalList gameTypes) + private bool GetGameType(ISteamData? steamData, out ImmutableFrugalList gameTypes) { gameTypes = default; Logger?.LogTrace("Try getting game type from steam data '[{Tags}]'", string.Join(",", steamData?.Tags ?? ["tags n/a"])); return steamData is not null && GetGameTypesFromTags(steamData.Tags, out gameTypes); } - internal static bool GetGameTypesFromTags(IEnumerable tags, out ReadOnlyFrugalList gameTypes) + internal static bool GetGameTypesFromTags(IEnumerable tags, out ImmutableFrugalList gameTypes) { var mutableGameTypes = new FrugalList(); @@ -104,7 +104,7 @@ internal static bool GetGameTypesFromTags(IEnumerable tags, out ReadOnly mutableGameTypes.Add(GameType.Foc); } - gameTypes = mutableGameTypes.AsReadOnly(); + gameTypes = mutableGameTypes.ToImmutableList(); return gameTypes.Count > 0; } } \ No newline at end of file diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OfflineModGameTypeResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OfflineModGameTypeResolver.cs index cfb2fd01..abed607f 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OfflineModGameTypeResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OfflineModGameTypeResolver.cs @@ -23,7 +23,7 @@ public sealed class OfflineModGameTypeResolver(IServiceProvider serviceProvider) /// - protected internal override bool TryGetGameTypeCore(DetectedModReference modInformation, out ReadOnlyFrugalList gameTypes) + protected internal override bool TryGetGameTypeCore(DetectedModReference modInformation, out ImmutableFrugalList gameTypes) { gameTypes = default; @@ -47,21 +47,21 @@ protected internal override bool TryGetGameTypeCore(DetectedModReference modInfo if (detector.Detect(GameType.Foc, GamePlatform.Undefined).Installed) { Logger?.LogTrace("{ModRef} is located in FoC's Mods directory.", modInformation.ModReference); - gameTypes = new ReadOnlyFrugalList(GameType.Foc); + gameTypes = ImmutableFrugalList.Single(GameType.Foc); return true; } if (detector.Detect(GameType.Eaw, GamePlatform.Undefined).Installed) { Logger?.LogTrace("{ModRef} is located in EaW's Mods directory.", modInformation.ModReference); - gameTypes = new ReadOnlyFrugalList(GameType.Eaw); + gameTypes = ImmutableFrugalList.Single(GameType.Eaw); return true; } return false; } - private bool HandleWorkshop(DetectedModReference modInformation, out ReadOnlyFrugalList gameTypes) + private bool HandleWorkshop(DetectedModReference modInformation, out ImmutableFrugalList gameTypes) { gameTypes = default; if (modInformation.ModReference.Type == ModType.Workshops) @@ -69,15 +69,14 @@ private bool HandleWorkshop(DetectedModReference modInformation, out ReadOnlyFru if (!_steamGameHelpers.ToSteamWorkshopsId(modInformation.Directory.Name, out var steamId)) return false; - // Modinfo is superior to cache, because this value can change faster, - // than new distribution of this library might release. - // so that the cache would then be invalid. + // Modinfo is superior to cache, because a modinfo file can change more frequently + // than new release of this library (and therefore the cache). if (TryGetGameType(modInformation.Modinfo, out gameTypes)) return true; if (_cache.ContainsMod(steamId)) { - gameTypes = new ReadOnlyFrugalList(_cache.GetGameTypes(steamId)); + gameTypes = ImmutableFrugalList.Create(_cache.GetGameTypes(steamId)); return true; } } diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs index 0f0f1c3a..4174d29e 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Mods/OnlineModGameTypeResolver.cs @@ -25,14 +25,14 @@ public sealed class OnlineModGameTypeResolver(IServiceProvider serviceProvider) private readonly ISteamWorkshopWebpageDownloader _steamWebpageDownloader = serviceProvider.GetRequiredService(); /// - protected internal override bool TryGetGameTypeCore(DetectedModReference modInformation, out ReadOnlyFrugalList gameTypes) + protected internal override bool TryGetGameTypeCore(DetectedModReference modInformation, out ImmutableFrugalList gameTypes) { if (_offlineResolver.TryGetGameTypeCore(modInformation, out gameTypes)) return true; return modInformation.ModReference.Type == ModType.Workshops && GetGameTypeFromSteamPage(modInformation.Directory.Name, out gameTypes); } - private bool GetGameTypeFromSteamPage(string steamIdValue, out ReadOnlyFrugalList gameTypes) + private bool GetGameTypeFromSteamPage(string steamIdValue, out ImmutableFrugalList gameTypes) { gameTypes = default; if (!_steamGameHelpers.ToSteamWorkshopsId(steamIdValue, out var steamId)) diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index f216c14b..3888cd48 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -13,10 +13,10 @@ - - + + - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj index d96deaa8..7ea46d2a 100644 --- a/test/AET.Testing/AET.Testing.csproj +++ b/test/AET.Testing/AET.Testing.csproj @@ -28,10 +28,10 @@ - - - - + + + + diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index 04fa4fc9..91704cd2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -15,8 +15,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index 8014f0ec..a0624957 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -16,7 +16,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From ea0bb05cb7b693dd2e5af2d2599a1a7f57222f39 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Fri, 16 Jan 2026 14:52:29 +0100 Subject: [PATCH 67/71] update to new CommonUtilities --- PetroGlyphGameInfrastructure.slnx | 1 - .../AET.SteamAbstraction.Test.csproj | 1 - .../ProcessHelperTest.cs | 2 +- .../SteamAppManifestTest.cs | 2 +- .../SteamLibraryFinderTest.cs | 2 +- .../SteamRegistryFactoryTest.cs | 2 +- .../SteamRegistryTestBase.cs | 2 +- .../SteamWrapperFactoryTest.cs | 4 +- .../SteamWrapperIntegrationTest.cs | 2 +- .../SteamWrapperTestBase.cs | 2 +- .../AET.SteamAbstraction.Testing.csproj | 2 +- .../TestBases/SteamTestBase.cs | 2 +- .../TestingSteamInstallationImpl.Library.cs | 2 +- test/AET.Testing/AET.Testing.csproj | 48 ---- .../PlatformSpecificFactAttribute.cs | 39 --- .../PlatformSpecificTheoryAttribute.cs | 39 --- .../Attributes/TestPlatformIdentifier.cs | 26 -- test/AET.Testing/ExceptionHelpers.cs | 40 ---- .../Extensions/AssertExtensions.cs | 44 ---- .../Extensions/RandomExtensions.cs | 226 ------------------ .../Extensions/StringExtensions.cs | 61 ----- test/AET.Testing/ReferenceEqualityComparer.cs | 51 ---- test/AET.Testing/TestBaseWithFileSystem.cs | 66 ----- .../TestBaseWithServiceProvider.cs | 45 ---- test/AET.Testing/TestingHelpers.cs | 50 ---- .../SteamPetroglyphStarWarsGameClientTest.cs | 2 +- .../Arguments/ArgumentValueSerializerTest.cs | 2 +- .../Clients/Arguments/FlagArgumentTest.cs | 2 +- .../Clients/Arguments/GameArgumentTest.cs | 2 +- .../Clients/Arguments/GameArgumentTestBase.cs | 2 +- .../Arguments/GameArgumentTestClasses.cs | 2 +- .../Clients/Arguments/NamedArgumentTest.cs | 2 +- .../PetroglyphStarWarsGameClientTest.cs | 2 +- .../GameExceptionTest.cs | 14 +- .../GameIdentityTest.cs | 2 +- .../GameServices/GameFactoryTest.cs | 2 +- .../GameServices/SteamGameHelpersTest.cs | 2 +- .../Registry/GameRegistryIntegrationTest.cs | 2 +- .../ModBaseTest.cs | 2 +- .../ModEqualityComparerTest.cs | 2 +- .../ModDependencyGraphBuilderTest.cs | 2 +- .../ModDependencyTraverserTest.cs | 2 +- .../ModServices/ModFactoryTest.cs | 2 +- .../ModServices/ModFinderTest.cs | 2 +- .../ModGameTypeResolverTestBase.cs | 2 +- .../OnlineModGameTypeResolverTest.cs | 2 +- ...PG.StarWarsGame.Infrastructure.Test.csproj | 1 - .../PetroglyphStarWarsGameTest.cs | 2 +- .../PlayableModContainerTest.cs | 2 +- .../GITestUtilities.cs | 2 +- ...StarWarsGame.Infrastructure.Testing.csproj | 2 +- .../TestBases/GameInfrastructureTestBase.cs | 2 +- 52 files changed, 44 insertions(+), 782 deletions(-) delete mode 100644 test/AET.Testing/AET.Testing.csproj delete mode 100644 test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs delete mode 100644 test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs delete mode 100644 test/AET.Testing/Attributes/TestPlatformIdentifier.cs delete mode 100644 test/AET.Testing/ExceptionHelpers.cs delete mode 100644 test/AET.Testing/Extensions/AssertExtensions.cs delete mode 100644 test/AET.Testing/Extensions/RandomExtensions.cs delete mode 100644 test/AET.Testing/Extensions/StringExtensions.cs delete mode 100644 test/AET.Testing/ReferenceEqualityComparer.cs delete mode 100644 test/AET.Testing/TestBaseWithFileSystem.cs delete mode 100644 test/AET.Testing/TestBaseWithServiceProvider.cs delete mode 100644 test/AET.Testing/TestingHelpers.cs diff --git a/PetroGlyphGameInfrastructure.slnx b/PetroGlyphGameInfrastructure.slnx index 6a3d4a42..d5941e25 100644 --- a/PetroGlyphGameInfrastructure.slnx +++ b/PetroGlyphGameInfrastructure.slnx @@ -11,7 +11,6 @@ - diff --git a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj index 3888cd48..57b5bd66 100644 --- a/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj +++ b/test/AET.SteamAbstraction.Test/AET.SteamAbstraction.Test.csproj @@ -31,7 +31,6 @@ - diff --git a/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs b/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs index 5b836674..82e6b7e4 100644 --- a/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs +++ b/test/AET.SteamAbstraction.Test/ProcessHelperTest.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using AET.SteamAbstraction.Utilities; -using AET.Testing; +using AnakinRaW.CommonUtilities.Testing; using Microsoft.Extensions.DependencyInjection; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs index d32cc5b7..d3b61675 100644 --- a/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamAppManifestTest.cs @@ -3,8 +3,8 @@ using System.IO.Abstractions; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Testing.TestBases; -using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.Registry; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index 760c6725..b88662fa 100644 --- a/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -2,7 +2,7 @@ using System.Linq; using AET.SteamAbstraction.Library; using AET.SteamAbstraction.Testing.TestBases; -using AET.Testing.Attributes; +using AnakinRaW.CommonUtilities.Testing.Attributes; using Xunit; #if NET5_0_OR_GREATER diff --git a/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs b/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs index c500d106..6803f25f 100644 --- a/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs @@ -1,10 +1,10 @@ using AET.SteamAbstraction.Registry; -using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using System; using System.IO.Abstractions; using System.Runtime.InteropServices; +using AnakinRaW.CommonUtilities.Testing; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs b/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs index 9a4496c7..ede7d671 100644 --- a/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamRegistryTestBase.cs @@ -1,12 +1,12 @@ using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Testing; -using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; using System; using System.IO.Abstractions; using System.Reflection; using System.Runtime.InteropServices; +using AnakinRaW.CommonUtilities.Testing; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs b/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs index 2d4fc260..4ca43ff6 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs @@ -1,7 +1,7 @@ using System.IO.Abstractions; -using AET.Testing; -using AET.Testing.Attributes; using AnakinRaW.CommonUtilities.Registry; +using AnakinRaW.CommonUtilities.Testing; +using AnakinRaW.CommonUtilities.Testing.Attributes; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs b/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs index 639ea54c..6a2ad8e7 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperIntegrationTest.cs @@ -1,9 +1,9 @@ using System.IO.Abstractions; using System.Runtime.InteropServices; using System.Threading.Tasks; -using AET.Testing; using AnakinRaW.CommonUtilities.Registry; using AnakinRaW.CommonUtilities.Registry.Windows; +using AnakinRaW.CommonUtilities.Testing; using Microsoft.Extensions.DependencyInjection; using Testably.Abstractions; using Xunit; diff --git a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs index 5bef47dd..606a410a 100644 --- a/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs +++ b/test/AET.SteamAbstraction.Test/SteamWrapperTestBase.cs @@ -8,8 +8,8 @@ using AET.SteamAbstraction.Testing; using AET.SteamAbstraction.Testing.TestBases; using AET.SteamAbstraction.Utilities; -using AET.Testing.Extensions; using AnakinRaW.CommonUtilities; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using Xunit; diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index fd9fb515..5147426d 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -26,6 +26,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -34,6 +35,5 @@ - diff --git a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs index 32a42d16..06e5e5fb 100644 --- a/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs +++ b/test/AET.SteamAbstraction.Testing/TestBases/SteamTestBase.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for details. using System; -using AET.Testing; +using AnakinRaW.CommonUtilities.Testing; using Microsoft.Extensions.DependencyInjection; namespace AET.SteamAbstraction.Testing.TestBases; diff --git a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs index 447dbfb5..847bf5ab 100644 --- a/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs +++ b/test/AET.SteamAbstraction.Testing/TestingSteamInstallationImpl.Library.cs @@ -7,8 +7,8 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; -using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.FileSystem; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Xunit; namespace AET.SteamAbstraction.Testing; diff --git a/test/AET.Testing/AET.Testing.csproj b/test/AET.Testing/AET.Testing.csproj deleted file mode 100644 index 7ea46d2a..00000000 --- a/test/AET.Testing/AET.Testing.csproj +++ /dev/null @@ -1,48 +0,0 @@ - - - - AET.Testing - netstandard2.0;net10.0 - true - false - - - - AET.Testing - Provides common utilities for testing projects, used by Alamo Engine Tools. - AlamoEngineTools.Testing - alamo,petroglyph,glyphx,testing - en - - - - true - true - true - - - true - snupkg - true - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - diff --git a/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs deleted file mode 100644 index 10b857ee..00000000 --- a/test/AET.Testing/Attributes/PlatformSpecificFactAttribute.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using System.Linq; -using System.Runtime.InteropServices; -using Xunit; - -namespace AET.Testing.Attributes; - -/// -/// Test attribute that specifies the test should only run on specific platforms. -/// -/// -/// This attribute allows you to define platform-specific tests by specifying the target platforms -/// using . If the current platform does not match any of the specified -/// platforms, the test will be skipped with an appropriate message. -/// -public sealed class PlatformSpecificFactAttribute : FactAttribute -{ - /// - /// Initializes a new instance of the class with the specified target platforms. - /// - /// - /// An array of values that specify the platforms on which the test should run. - /// - /// - /// If the current platform does not match any of the specified , the test will be skipped - /// with a message indicating that the test execution is not supported on the current platform. - /// - public PlatformSpecificFactAttribute(params TestPlatformIdentifier[] platformIds) - { - var platforms = platformIds.Select(targetPlatform => OSPlatform.Create(Enum.GetName(typeof(TestPlatformIdentifier), targetPlatform)!.ToUpper())); - var platformMatches = platforms.Any(RuntimeInformation.IsOSPlatform); - - if (!platformMatches) - Skip = "Test execution is not supported on the current platform"; - } -} \ No newline at end of file diff --git a/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs b/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs deleted file mode 100644 index 94f785ea..00000000 --- a/test/AET.Testing/Attributes/PlatformSpecificTheoryAttribute.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using System.Linq; -using System.Runtime.InteropServices; -using Xunit; - -namespace AET.Testing.Attributes; - -/// -/// A theory attribute that specifies the test should only run on specific platforms. -/// -/// -/// This attribute allows you to define platform-specific tests by specifying the target platforms -/// using . If the current platform does not match any of the specified -/// platforms, the test will be skipped with an appropriate message. -/// -public sealed class PlatformSpecificTheoryAttribute : TheoryAttribute -{ - /// - /// Initializes a new instance of the class with the specified target platforms. - /// - /// - /// An array of values that specify the platforms on which the test should run. - /// - /// - /// If the current platform does not match any of the specified , the test will be skipped - /// with a message indicating that the test execution is not supported on the current platform. - /// - public PlatformSpecificTheoryAttribute(params TestPlatformIdentifier[] platformIds) - { - var platforms = platformIds.Select(targetPlatform => OSPlatform.Create(Enum.GetName(typeof(TestPlatformIdentifier), targetPlatform)!.ToUpper())); - var platformMatches = platforms.Any(RuntimeInformation.IsOSPlatform); - - if (!platformMatches) - Skip = "Test execution is not supported on the current platform"; - } -} \ No newline at end of file diff --git a/test/AET.Testing/Attributes/TestPlatformIdentifier.cs b/test/AET.Testing/Attributes/TestPlatformIdentifier.cs deleted file mode 100644 index 90562360..00000000 --- a/test/AET.Testing/Attributes/TestPlatformIdentifier.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; - -namespace AET.Testing.Attributes; - -/// -/// Represents identifiers for test platforms used to specify platform-specific test execution. -/// -/// -/// This enumeration is used in conjunction with attributes like -/// and to define tests that should only run on specific platforms. -/// -[Flags] -public enum TestPlatformIdentifier -{ - /// - /// Represents the Windows platform. - /// - Windows = 1, - /// - /// Represents a Linux platform. - /// - Linux = 2, -} \ No newline at end of file diff --git a/test/AET.Testing/ExceptionHelpers.cs b/test/AET.Testing/ExceptionHelpers.cs deleted file mode 100644 index 0919f724..00000000 --- a/test/AET.Testing/ExceptionHelpers.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using Xunit; - -namespace AET.Testing; - -// Based on https://github.com/dotnet/runtime/blob/main/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Exception.Helpers.cs - -/// -/// Provides helper methods for validating properties of exceptions in unit tests. -/// -public static class ExceptionHelpers -{ - /// - /// Validates the properties of the specified instance against the provided values. - /// - /// The exception instance to validate. - /// The expected inner exception of . Defaults to null. - /// The expected message of . Defaults to null. - /// The expected source of . Defaults to null. - /// The expected stack trace of . Defaults to null. - /// A value indicating whether to validate the property. - public static void ValidateExceptionProperties(Exception e, - Exception? innerException = null, - string? message = null, - string? source = null, - string? stackTrace = null, - bool validateMessage = true) - { - Assert.Equal(innerException, e.InnerException); - if (validateMessage) - Assert.Equal(message, e.Message); - else - Assert.NotNull(e.Message); - Assert.Equal(source, e.Source); - Assert.Equal(stackTrace, e.StackTrace); - } -} \ No newline at end of file diff --git a/test/AET.Testing/Extensions/AssertExtensions.cs b/test/AET.Testing/Extensions/AssertExtensions.cs deleted file mode 100644 index 52a09ac4..00000000 --- a/test/AET.Testing/Extensions/AssertExtensions.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using Xunit; - -namespace AET.Testing.Extensions; - -/// -/// Provides extension methods for the class. -/// -public static class AssertExtensions -{ - extension(Assert) - { - /// - /// Verifies that the specified action does not throw any exception. - /// - /// The type of the result returned by the action. - /// A delegate to the code to be tested. - /// The result of the executed test code. - public static T DoesNotThrowException(Func action) - { - try - { - return action(); - } - catch (Exception e) - { - Assert.Fail($"Expected no exception to be thrown but got '{e.GetType().Name}' instead"); - return default; - } - } - - /// - /// Verifies that the specified action does not throw any exception. - /// - /// A delegate to the code to be tested. - public static void DoesNotThrowException(Action action) - { - Assert.DoesNotThrowException(() => action); - } - } -} \ No newline at end of file diff --git a/test/AET.Testing/Extensions/RandomExtensions.cs b/test/AET.Testing/Extensions/RandomExtensions.cs deleted file mode 100644 index 2dfc7b80..00000000 --- a/test/AET.Testing/Extensions/RandomExtensions.cs +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using System.Collections.Generic; - -namespace AET.Testing.Extensions; - -/// -/// Provides extension methods for the class. -/// -public static class RandomExtensions -{ - private static readonly Random Random = new(); - private static readonly string AllowedChars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz0123456789!@$?_-"; - - extension(Random) - { - /// - /// Generates a random value. - /// - /// - /// A randomly generated value. - /// - public static bool Bool() - { - return Random.Next() % 2 == 0; - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static sbyte SByte() - { - return (sbyte)Random.Next(sbyte.MinValue, sbyte.MaxValue); - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static byte Byte() - { - return (byte)Random.Next(byte.MinValue, byte.MaxValue); - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static short Short() - { - return (short)Random.Next(short.MinValue, short.MaxValue); - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static ushort UShort() - { - return (ushort)Random.Next(ushort.MinValue, ushort.MaxValue); - } - - /// - /// Generates a random value. - /// - /// - /// In contrast to , this method can return the full range of values, including negative values. - /// - /// - /// A randomly generated value within the range of to . - /// - public static int Int() - { - return Random.Next(int.MinValue, int.MaxValue); - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static uint UInt() - { - return (uint)Random.Int(); - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static long Long() - { -#if NET || NETSTANDARD2_1_OR_GREATER - Span buf = stackalloc byte[8]; - Random.NextBytes(buf); - return BitConverter.ToInt64(buf); -#else - var buf = new byte[8]; - Random.NextBytes(buf); - return BitConverter.ToInt64(buf, 0); -#endif - } - - /// - /// Generates a random value. - /// - /// - /// A randomly generated value within the range of to . - /// - public static ulong ULong() - { - return (ulong)Random.Long(); - } - - /// - /// Returns a random value from the enumeration type . - /// - /// - /// The enumeration type from which a random value will be selected. Must be a struct and an . - /// - /// - /// A randomly selected value from the enumeration type . - /// - /// - /// Thrown if is not an enumeration type. - /// - public static T Enum() where T : struct, Enum - { - var values = -#if NET5_0_OR_GREATER - System.Enum.GetValues(); -#else - (T[])System.Enum.GetValues(typeof(T)); -#endif - return values[Random.Next(values.Length)]; - } - - - // From: https://stackoverflow.com/questions/648196/random-row-from-linq-to-sql/648240#648240 - /// - /// Selects a random item from the provided sequence of items. - /// - /// The type of the elements in the sequence. - /// The sequence of items to select from. - /// A randomly selected item from the sequence. - /// Thrown if the sequence is empty. - public static T Item(IEnumerable items) - { - T current = default!; - var count = 0; - foreach (var element in items) - { - count++; - if (Random.Next(count) == 0) - current = element; - } - return count == 0 - ? throw new InvalidOperationException("Sequence was empty") - : current; - } - - /// - /// Generates a random string of the specified length using a mix of letters (any case), numbers and special characters - /// - /// The desired length of the generated string. Must be a non-negative value. - /// A randomly generated string of the specified length. Returns an empty string if is 0. - /// Thrown when is less than 0. - public static string String(int length) - { - return Random.String(length, AllowedChars); - } - - /// - /// Generates a random string of the specified length using the specified pool of characters. - /// - /// The desired length of the generated string. Must be a non-negative value. - /// The pool of characters to pick random characters from. - /// A randomly generated string of the specified length. Returns an empty string if is 0. - /// Thrown when is less than 0. - /// Thrown when is empty or . - public static unsafe string String(int length, ReadOnlySpan charPool) - { - if (charPool == ReadOnlySpan.Empty || charPool.IsEmpty) - throw new ArgumentException("charPool must not be null or empty", nameof(charPool)); - switch (length) - { - case < 0: - throw new ArgumentOutOfRangeException(nameof(length)); - case 0: - return string.Empty; - } - - var buffer = length <= 256 - ? stackalloc char[length] - : new char[length]; - - var random = Random; - for (var i = 0; i < buffer.Length; i++) - { - var index = random.Next(charPool.Length); - buffer[i] = charPool[index]; - } - -#if NET - return new string(buffer); -#else - fixed (char* t = buffer) - return new string(t, 0, length); -#endif - } - } -} \ No newline at end of file diff --git a/test/AET.Testing/Extensions/StringExtensions.cs b/test/AET.Testing/Extensions/StringExtensions.cs deleted file mode 100644 index 2f1d61bc..00000000 --- a/test/AET.Testing/Extensions/StringExtensions.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; - -namespace AET.Testing.Extensions; - -/// -/// Provides extension methods for string manipulation and testing. -/// -public static class StringExtensions -{ - private static readonly Random Random = new(); - - extension(string) - { - /// - /// Randomly shuffles the casing of the characters in the specified string. - /// - /// The input string whose character casing will be shuffled. - /// A new string with randomly shuffled character casing. - /// Thrown if is null. - public static unsafe string ShuffleCasing(string input) - { - if (input is null) - throw new ArgumentNullException(nameof(input)); - - if (input.Length == 0) - return string.Empty; - - var buffer = input.Length <= 256 - ? stackalloc char[input.Length] - : new char[input.Length]; - - input.AsSpan().CopyTo(buffer); - - var rnd = Random; - - for (var i = 0; i < buffer.Length; i++) - { - var c = buffer[i]; - if (!char.IsLetter(c)) - continue; - - if (rnd.Next(2) != 0) - continue; - - buffer[i] = char.IsUpper(c) - ? char.ToLower(c) - : char.ToUpper(c); - } - -#if NET - return new string(buffer); -#else - fixed (char* t = buffer) - return new string(t, 0, buffer.Length); -#endif - } - } -} \ No newline at end of file diff --git a/test/AET.Testing/ReferenceEqualityComparer.cs b/test/AET.Testing/ReferenceEqualityComparer.cs deleted file mode 100644 index 22bfb8d2..00000000 --- a/test/AET.Testing/ReferenceEqualityComparer.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -#if !NET5_0_OR_GREATER -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace AET.Testing; - -/// -/// An that uses reference equality () -/// instead of value equality() when comparing two object instances. -/// -/// -/// The type cannot be instantiated. -/// Instead, use the property to access the singleton instance of this type. -/// -public sealed class ReferenceEqualityComparer : IEqualityComparer, IEqualityComparer -{ - /// - /// Gets the singleton instance. - /// - public static ReferenceEqualityComparer Instance { get; } = new(); - - private ReferenceEqualityComparer() - { - } - - /// - /// Determines whether two object references refer to the same object instance. - /// - /// The first object to compare. - /// The second object to compare. - /// - /// if both and - /// refer to the same object instance or if both are ; otherwise, . - /// - public new bool Equals(object? x, object? y) => ReferenceEquals(x, y); - - /// - /// Returns a hash code for the specified object. The returned hash code is based on the object identity, not on the contents of the object. - /// - /// The object for which to retrieve the hash code. - /// A hash code for the identity of . - public int GetHashCode(object? obj) - { - return RuntimeHelpers.GetHashCode(obj!); - } -} -#endif \ No newline at end of file diff --git a/test/AET.Testing/TestBaseWithFileSystem.cs b/test/AET.Testing/TestBaseWithFileSystem.cs deleted file mode 100644 index faab29d1..00000000 --- a/test/AET.Testing/TestBaseWithFileSystem.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.IO.Abstractions; -using System.Threading; -using Microsoft.Extensions.DependencyInjection; -using Testably.Abstractions.Testing; - -namespace AET.Testing; - -/// -/// A test base that automatically registers an as service. -/// -public abstract class TestBaseWithFileSystem : TestBaseWithServiceProvider -{ - /// - /// Gets the file system abstraction used for testing purposes. - /// This property provides access to an instance, which is lazily initialized - /// and can be overridden by derived classes to customize the file system behavior. - /// - /// - /// The file system is initialized using the method. If the initialization - /// fails or returns null, an is thrown. - /// - [field: MaybeNull, AllowNull] - protected IFileSystem FileSystem => LazyInitializer.EnsureInitialized(ref field, CreateFileSystem) - ?? throw new InvalidOperationException("Creation of file system must not return null."); - - /// - /// Initializes a new instance of the class and configures the service provider. - /// - /// - /// This constructor creates a new service collection, invokes the method to allow - /// derived classes to register services, and then builds the service provider. Derived classes should override - /// SetupServices to customize service registration. - /// - protected TestBaseWithFileSystem() - { - } - - /// - /// Creates and returns a new instance of the file system abstraction for testing purposes. - /// - /// - /// This method is invoked to initialize the property. By default, it returns - /// a instance, but derived classes can override this method to provide - /// a custom implementation of . - /// - /// - /// An instance of representing the file system abstraction to be used in tests. - /// - protected virtual IFileSystem CreateFileSystem() - { - return new MockFileSystem(); - } - - - /// - protected override void SetupServices(IServiceCollection serviceCollection) - { - base.SetupServices(serviceCollection); - serviceCollection.AddSingleton(FileSystem); - } -} \ No newline at end of file diff --git a/test/AET.Testing/TestBaseWithServiceProvider.cs b/test/AET.Testing/TestBaseWithServiceProvider.cs deleted file mode 100644 index a9eb74f2..00000000 --- a/test/AET.Testing/TestBaseWithServiceProvider.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using Microsoft.Extensions.DependencyInjection; -using System; - -namespace AET.Testing; - -/// -/// Provides a base class for test fixtures that provides and for dependency injection. -/// -/// Derive from this class to set up and access services using dependency injection in test scenarios. -/// Override to register custom services required for your -/// tests. -public abstract class TestBaseWithServiceProvider -{ - /// - /// Provides access to the application's service provider for resolving dependencies within derived classes. - /// - protected readonly IServiceProvider ServiceProvider; - - /// - /// Initializes a new instance of the class and configures the service provider. - /// - /// - /// This constructor creates a new service collection, invokes the method to allow - /// derived classes to register services, and then builds the service provider. Derived classes should override - /// SetupServices to customize service registration. - /// - protected TestBaseWithServiceProvider() - { - var sc = new ServiceCollection(); - // ReSharper disable once VirtualMemberCallInConstructor - SetupServices(sc); - ServiceProvider = sc.BuildServiceProvider(); - } - - /// - /// Configures test services by adding them to the specified . - /// - /// The to which services will be added. - protected virtual void SetupServices(IServiceCollection serviceCollection) - { - } -} \ No newline at end of file diff --git a/test/AET.Testing/TestingHelpers.cs b/test/AET.Testing/TestingHelpers.cs deleted file mode 100644 index 2decdd7b..00000000 --- a/test/AET.Testing/TestingHelpers.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Alamo Engine Tools and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for details. - -using System; -using System.IO; - -namespace AET.Testing; - -/// -/// Provides common helper methods useful creating test code. -/// -public class TestingHelpers -{ - /// - /// Retrieves an embedded resource stream from the specified assembly and path. - /// - /// - /// Embedded resources are expected to be located in the "Resources" folder of the assembly. - /// - /// A from the assembly containing the embedded resource. - /// The relative path of the embedded resource within the assembly. - /// A representing the embedded resource. - /// Thrown when the specified embedded resource cannot be found. - public static Stream GetEmbeddedResource(Type type, string path) - { - var assembly = type.Assembly; - var resourcePath = $"{assembly.GetName().Name}.Resources.{path}"; - return assembly.GetManifestResourceStream(resourcePath) ?? - throw new IOException($"Could not find embedded resource: '{resourcePath}'"); - } - - /// - /// Retrieves an embedded resource as a byte array from the specified assembly and path. - /// - /// - /// Embedded resources are expected to be located in the "Resources" folder of the assembly. - /// - /// A from the assembly containing the embedded resource. - /// The relative path of the embedded resource within the assembly. - /// A byte array containing the content of the embedded resource. - /// Thrown when the specified embedded resource cannot be found. - public static byte[] GetEmbeddedResourceAsByteArray(Type type, string path) - { - using var stream = GetEmbeddedResource(type, path); - using var ms = new MemoryStream(); - stream.CopyTo(ms); - ms.Position = 0; - return ms.ToArray(); - } -} \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs index ed489a85..d00b01b1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/SteamPetroglyphStarWarsGameClientTest.cs @@ -13,7 +13,7 @@ using System; using System.Collections.Generic; using System.Runtime.Versioning; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Xunit; using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs index a1afcdc6..cc296db5 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/ArgumentValueSerializerTest.cs @@ -1,5 +1,5 @@ using System; -using AET.Testing.Attributes; +using AnakinRaW.CommonUtilities.Testing.Attributes; using PG.StarWarsGame.Infrastructure.Clients.Arguments.CommandLine; using PG.StarWarsGame.Infrastructure.Clients.Arguments.GameArguments; using Testably.Abstractions.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs index 049acd91..626b2265 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/FlagArgumentTest.cs @@ -1,5 +1,5 @@ using System; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs index 8c954540..fdd98db2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTest.cs @@ -1,5 +1,5 @@ using System; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs index cdb76fa1..3f896070 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestBase.cs @@ -7,7 +7,7 @@ using System.IO.Abstractions; using System.Linq; using System.Runtime.InteropServices; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Testably.Abstractions.Testing; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs index 56661e57..4a3f0b81 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/GameArgumentTestClasses.cs @@ -1,7 +1,7 @@ using PG.StarWarsGame.Infrastructure.Clients.Arguments; using PG.StarWarsGame.Infrastructure.Clients.Arguments.CommandLine; using System; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; namespace PG.StarWarsGame.Infrastructure.Test.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs index 4a9a5b5b..1368ab0e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/Arguments/NamedArgumentTest.cs @@ -1,6 +1,6 @@ using System; -using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.FileSystem.Normalization; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Clients.Arguments; using Testably.Abstractions.Testing; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs index ff3bc380..44697711 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Clients/PetroglyphStarWarsGameClientTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using AET.Modinfo.Spec; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Clients; using PG.StarWarsGame.Infrastructure.Clients.Arguments; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs index 87d0021e..34eeb87e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameExceptionTest.cs @@ -1,6 +1,6 @@ -using System; -using AET.Testing; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; +using System; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; @@ -11,23 +11,23 @@ public static class GameExceptionTest public static void Ctor() { var exception = new GameException(); - ExceptionHelpers.ValidateExceptionProperties(exception, validateMessage: false); + Assert.Exception(exception, validateMessage: false); } [Fact] public static void Ctor_String() { - var message = "game error"; + const string message = "game error"; var exception = new GameException(message); - ExceptionHelpers.ValidateExceptionProperties(exception, message: message); + Assert.Exception(exception, message: message); } [Fact] public static void Ctor_String_Exception() { - var message = "game error"; + const string message = "game error"; var innerException = new Exception("Inner exception"); var exception = new GameException(message, innerException); - ExceptionHelpers.ValidateExceptionProperties(exception, innerException: innerException, message: message); + Assert.Exception(exception, innerException, message); } } \ No newline at end of file diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs index 3865e78d..8450d716 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameIdentityTest.cs @@ -1,6 +1,6 @@ using PG.StarWarsGame.Infrastructure.Games; using System; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs index 087fd837..ccbb0946 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/GameFactoryTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs index f139ec15..901a6407 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/GameServices/SteamGameHelpersTest.cs @@ -1,6 +1,6 @@ using System; -using AET.Testing.Extensions; using AnakinRaW.CommonUtilities.FileSystem.Normalization; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Steam; using PG.StarWarsGame.Infrastructure.Testing.TestBases; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs index 7ba3bed5..f25fbac3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/Games/Registry/GameRegistryIntegrationTest.cs @@ -1,8 +1,8 @@ using System; using System.IO.Abstractions; -using AET.Testing.Attributes; using AnakinRaW.CommonUtilities.Registry; using AnakinRaW.CommonUtilities.Registry.Windows; +using AnakinRaW.CommonUtilities.Testing.Attributes; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Games.Registry; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs index 79a240af..686f4b23 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModBaseTest.cs @@ -3,7 +3,7 @@ using System.Linq; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Games; using Xunit; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs index c5d72146..b187279e 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModEqualityComparerTest.cs @@ -1,12 +1,12 @@ using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.TestBases; using System; using System.Collections.Generic; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs index 9fbf39e8..c8aaf0d2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyGraphBuilderTest.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing.TestBases; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs index b628af7e..a58e72af 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/Dependencies/ModDependencyTraverserTest.cs @@ -1,6 +1,6 @@ using System; using AET.Modinfo.Spec; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Mods; using PG.StarWarsGame.Infrastructure.Services.Dependencies; using PG.StarWarsGame.Infrastructure.Testing.TestBases; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs index f15c481f..1e8e6dc2 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFactoryTest.cs @@ -9,7 +9,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs index 8785a301..c1c22429 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModFinderTest.cs @@ -7,7 +7,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Mods; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs index 715abe8f..2f0ff539 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/ModGameTypeResolverTestBase.cs @@ -6,7 +6,7 @@ using AET.Modinfo.Spec; using AET.Modinfo.Spec.Steam; using AET.Modinfo.Utilities; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs index 578f2093..27e06965 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/ModServices/OnlineModGameTypeResolverTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using AET.Modinfo.Spec; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Services.Detection; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj index a0624957..d6e0a262 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Test/PG.StarWarsGame.Infrastructure.Test.csproj @@ -30,7 +30,6 @@ - diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs index fabf010f..62ca5850 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PetroglyphStarWarsGameTest.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using AET.Modinfo.Spec; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing; using PG.StarWarsGame.Infrastructure.Testing.Installations; diff --git a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs index 3826ae7e..2d4a4be4 100644 --- a/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs +++ b/test/PG.StarWarsGame.Infrastructure.Test/PlayableModContainerTest.cs @@ -7,7 +7,7 @@ #if NET5_0_OR_GREATER using System.Collections.Generic; #else -using AET.Testing; +using AnakinRaW.CommonUtilities.Testing.EqualityComparers; #endif namespace PG.StarWarsGame.Infrastructure.Test; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs index 0ae9ca2d..6677b6be 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/GITestUtilities.cs @@ -8,7 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; -using AET.Testing.Extensions; +using AnakinRaW.CommonUtilities.Testing.Extensions; using Xunit; namespace PG.StarWarsGame.Infrastructure.Testing; diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index caee0ad5..e1d3f56a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -26,6 +26,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -34,6 +35,5 @@ - diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs index 80f23c06..7c497e7a 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs +++ b/test/PG.StarWarsGame.Infrastructure.Testing/TestBases/GameInfrastructureTestBase.cs @@ -3,13 +3,13 @@ using AET.Modinfo.Model; using AET.Modinfo.Spec; -using AET.Testing; using Microsoft.Extensions.DependencyInjection; using PG.StarWarsGame.Infrastructure.Games; using PG.StarWarsGame.Infrastructure.Testing.Installations; using PG.StarWarsGame.Infrastructure.Testing.Installations.Game; using PG.StarWarsGame.Infrastructure.Testing.Installations.Mods; using System.Collections.Generic; +using AnakinRaW.CommonUtilities.Testing; namespace PG.StarWarsGame.Infrastructure.Testing.TestBases; From b364154fef446ff80f1732d8aa3634a573cafd18 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sat, 24 Jan 2026 12:02:19 +0100 Subject: [PATCH 68/71] update deps --- src/AET.SteamAbstraction/AET.SteamAbstraction.csproj | 6 +++--- .../PG.StarWarsGame.Infrastructure.csproj | 8 ++++---- .../AET.SteamAbstraction.Testing.csproj | 2 +- ....StarWarsGame.Infrastructure.Clients.Steam.Test.csproj | 2 +- .../PG.StarWarsGame.Infrastructure.Testing.csproj | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj index b994e61f..37458ded 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj @@ -21,9 +21,9 @@ true - - - + + + diff --git a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj index c6941d12..7003a9d7 100644 --- a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj +++ b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj @@ -22,10 +22,10 @@ true - - - - + + + + diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index 5147426d..ad275f8e 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj index 91704cd2..a12919b3 100644 --- a/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test/PG.StarWarsGame.Infrastructure.Clients.Steam.Test.csproj @@ -15,7 +15,7 @@ - + diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index e1d3f56a..020234e1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From f7b66aad31d6d06d9ac083ea4212828cb1f5ab95 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sat, 24 Jan 2026 17:22:48 +0100 Subject: [PATCH 69/71] fix doc --- .../Services/Detection/Games/CompositeGameDetector.cs | 7 +++++-- .../Services/Detection/Games/GameDetectorBase.cs | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/CompositeGameDetector.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/CompositeGameDetector.cs index 0634c9b8..6ef268ab 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/CompositeGameDetector.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/CompositeGameDetector.cs @@ -29,7 +29,7 @@ public sealed class CompositeGameDetector : IGameDetector /// The sorted list of detectors which shall get used. /// The service provider. /// - /// When after a detector was used, it will get disposed if it implements . + /// If , a detector that implements gets disposed after usage. /// Default is /// public CompositeGameDetector(IList sortedDetectors, IServiceProvider serviceProvider, bool disposeDetectors = false) @@ -49,7 +49,10 @@ public CompositeGameDetector(IList sortedDetectors, IServiceProvi /// The game type to detect. /// Collection of the platforms to search for. /// Data which holds the game's location or error information. - /// + /// + /// All exceptions that occurred during an unsuccessful game detection. + /// The exception is not thrown when any detector returns an installed game result. + /// public GameDetectionResult Detect(GameType gameType, params ICollection platforms) { var errors = new List(); diff --git a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/GameDetectorBase.cs b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/GameDetectorBase.cs index 8dafee05..3f6cced8 100644 --- a/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/GameDetectorBase.cs +++ b/src/PG.StarWarsGame.Infrastructure/Services/Detection/Games/GameDetectorBase.cs @@ -151,7 +151,6 @@ internal static bool DataAndMegaFilesXmlExists(IDirectoryInfo directory) /// /// The game type to detect. /// Information about a found game installation. - /// This method may throw arbitrary exceptions. protected abstract GameLocationData FindGameLocation(GameType gameType); private static bool MatchesOptionsPlatform(ICollection platforms, GamePlatform identifiedPlatform) From 4a285c9aae9b5b3dbfdb5b794d682aff3e412a04 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sat, 24 Jan 2026 17:48:55 +0100 Subject: [PATCH 70/71] update deps --- src/AET.SteamAbstraction/AET.SteamAbstraction.csproj | 6 +++--- .../PG.StarWarsGame.Infrastructure.csproj | 8 ++++---- .../AET.SteamAbstraction.Testing.csproj | 2 +- .../PG.StarWarsGame.Infrastructure.Testing.csproj | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj index 37458ded..64387ab8 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.csproj @@ -21,9 +21,9 @@ true - - - + + + diff --git a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj index 7003a9d7..b736e5ab 100644 --- a/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj +++ b/src/PG.StarWarsGame.Infrastructure/PG.StarWarsGame.Infrastructure.csproj @@ -22,10 +22,10 @@ true - - - - + + + + diff --git a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj index ad275f8e..d5942647 100644 --- a/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj +++ b/test/AET.SteamAbstraction.Testing/AET.SteamAbstraction.Testing.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj index 020234e1..9d2100c1 100644 --- a/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj +++ b/test/PG.StarWarsGame.Infrastructure.Testing/PG.StarWarsGame.Infrastructure.Testing.csproj @@ -26,7 +26,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 30c48b7a33dbfd1ea614cd7adba322dd8fa4a791 Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sat, 24 Jan 2026 17:57:01 +0100 Subject: [PATCH 71/71] update version --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 7ba42803..25568e50 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "4.1", + "version": "5.0", "publicReleaseRefSpec": [ "^refs/heads/main" ],