From f0d0a4f8eeb132d588c0a25ef25d02f86fcc6b50 Mon Sep 17 00:00:00 2001 From: Brice SCHUMACHER Date: Sat, 27 Jun 2026 00:57:06 +0200 Subject: [PATCH 1/2] fix: Made internal package public with clear description --- CHANGELOG.md | 6 ++++++ Directory.Build.props | 2 +- DoggyDog/DoggyDog.csproj | 4 ++-- .../NotoriousTest.Internal.Runtime.csproj | 17 +++++++++++++++++ .../RuntimeConfigurationEntity.cs | 0 .../RuntimeConfigurationProvider.cs | 0 .../InfrastructureRegistryEntryEntity.cs | 0 ...toriousTest.Internal.SqlLiteRegistry.csproj | 12 ++++++++---- .../SqliteRegistryProvider.cs | 0 .../SqliteRegistryProviderConfiguration.cs | 0 .../SqliteRegistryProviderQueries.cs | 0 .../NotoriousTest.Internal.TestSettings.csproj | 18 ++++++++++++++++++ .../TestSettingsProvider.cs | 0 .../DoggyDogWatchDog.cs | 0 .../DoggyDogWatchdogConfiguration.cs | 0 .../NotoriousTest.Internal.Watchdog.csproj | 15 +++++++++++++++ NotoriousTest.NoDoggyDog.slnf | 8 ++++---- .../NotoriousTest.Runtime.csproj | 12 ------------ .../NotoriousTest.TestSettings.csproj | 14 -------------- .../NotoriousTest.UnitTests.csproj | 4 ++-- .../NotoriousTest.Watchdog.csproj | 12 ------------ NotoriousTest.slnx | 8 ++++---- NotoriousTest/NotoriousTest.csproj | 8 ++++---- 23 files changed, 81 insertions(+), 59 deletions(-) create mode 100644 NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj rename {NotoriousTest.Runtime => NotoriousTest.Internal.Runtime}/RuntimeConfigurationEntity.cs (100%) rename {NotoriousTest.Runtime => NotoriousTest.Internal.Runtime}/RuntimeConfigurationProvider.cs (100%) rename {NotoriousTest.SqlLiteRegistry => NotoriousTest.Internal.SqlLiteRegistry}/InfrastructureRegistryEntryEntity.cs (100%) rename NotoriousTest.SqlLiteRegistry/NotoriousTest.SqlLiteRegistry.csproj => NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj (53%) rename {NotoriousTest.SqlLiteRegistry => NotoriousTest.Internal.SqlLiteRegistry}/SqliteRegistryProvider.cs (100%) rename {NotoriousTest.SqlLiteRegistry => NotoriousTest.Internal.SqlLiteRegistry}/SqliteRegistryProviderConfiguration.cs (100%) rename {NotoriousTest.SqlLiteRegistry => NotoriousTest.Internal.SqlLiteRegistry}/SqliteRegistryProviderQueries.cs (100%) create mode 100644 NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj rename {NotoriousTest.TestSettings => NotoriousTest.Internal.TestSettings}/TestSettingsProvider.cs (100%) rename {NotoriousTest.Watchdog => NotoriousTest.Internal.Watchdog}/DoggyDogWatchDog.cs (100%) rename {NotoriousTest.Watchdog => NotoriousTest.Internal.Watchdog}/DoggyDogWatchdogConfiguration.cs (100%) create mode 100644 NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj delete mode 100644 NotoriousTest.Runtime/NotoriousTest.Runtime.csproj delete mode 100644 NotoriousTest.TestSettings/NotoriousTest.TestSettings.csproj delete mode 100644 NotoriousTest.Watchdog/NotoriousTest.Watchdog.csproj diff --git a/CHANGELOG.md b/CHANGELOG.md index 718e9eb..082dbee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v5.0.1 + +### 🐛 Bug Fixes + +- Fixed a bug where internal packages were not available at installation. Preventing NotoriousTest from being installed. + ## v5.0.0 ### ✨ Features diff --git a/Directory.Build.props b/Directory.Build.props index 513e3ae..739c5f4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ icon.png LICENSE.txt README.md - 5.0.0 + 5.0.1 true high all diff --git a/DoggyDog/DoggyDog.csproj b/DoggyDog/DoggyDog.csproj index 568a89c..94f9b4b 100644 --- a/DoggyDog/DoggyDog.csproj +++ b/DoggyDog/DoggyDog.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj b/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj new file mode 100644 index 0000000..ac2a73c --- /dev/null +++ b/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj @@ -0,0 +1,17 @@ + + + net8.0 + NotoriousTest.Internal.Runtime + NotoriousTest.Runtime + NotoriousTest.Runtime + [Internal] Provides the runtime configuration layer for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + + + diff --git a/NotoriousTest.Runtime/RuntimeConfigurationEntity.cs b/NotoriousTest.Internal.Runtime/RuntimeConfigurationEntity.cs similarity index 100% rename from NotoriousTest.Runtime/RuntimeConfigurationEntity.cs rename to NotoriousTest.Internal.Runtime/RuntimeConfigurationEntity.cs diff --git a/NotoriousTest.Runtime/RuntimeConfigurationProvider.cs b/NotoriousTest.Internal.Runtime/RuntimeConfigurationProvider.cs similarity index 100% rename from NotoriousTest.Runtime/RuntimeConfigurationProvider.cs rename to NotoriousTest.Internal.Runtime/RuntimeConfigurationProvider.cs diff --git a/NotoriousTest.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs b/NotoriousTest.Internal.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs similarity index 100% rename from NotoriousTest.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs rename to NotoriousTest.Internal.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs diff --git a/NotoriousTest.SqlLiteRegistry/NotoriousTest.SqlLiteRegistry.csproj b/NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj similarity index 53% rename from NotoriousTest.SqlLiteRegistry/NotoriousTest.SqlLiteRegistry.csproj rename to NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj index ced8265..3a92a09 100644 --- a/NotoriousTest.SqlLiteRegistry/NotoriousTest.SqlLiteRegistry.csproj +++ b/NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj @@ -1,9 +1,13 @@ - + net8.0 - false - - + NotoriousTest.Internal.SqlLiteRegistry + NotoriousTest.SqlLiteRegistry + NotoriousTest.SqlLiteRegistry + [Internal] SQLite-backed infrastructure registry for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + diff --git a/NotoriousTest.SqlLiteRegistry/SqliteRegistryProvider.cs b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProvider.cs similarity index 100% rename from NotoriousTest.SqlLiteRegistry/SqliteRegistryProvider.cs rename to NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProvider.cs diff --git a/NotoriousTest.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs similarity index 100% rename from NotoriousTest.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs rename to NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs diff --git a/NotoriousTest.SqlLiteRegistry/SqliteRegistryProviderQueries.cs b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderQueries.cs similarity index 100% rename from NotoriousTest.SqlLiteRegistry/SqliteRegistryProviderQueries.cs rename to NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderQueries.cs diff --git a/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj b/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj new file mode 100644 index 0000000..a3e3ac9 --- /dev/null +++ b/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj @@ -0,0 +1,18 @@ + + + net8.0 + NotoriousTest.Internal.TestSettings + NotoriousTest.TestSettings + NotoriousTest.Core.Settings + [Internal] JSON-based test settings provider for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + + + + diff --git a/NotoriousTest.TestSettings/TestSettingsProvider.cs b/NotoriousTest.Internal.TestSettings/TestSettingsProvider.cs similarity index 100% rename from NotoriousTest.TestSettings/TestSettingsProvider.cs rename to NotoriousTest.Internal.TestSettings/TestSettingsProvider.cs diff --git a/NotoriousTest.Watchdog/DoggyDogWatchDog.cs b/NotoriousTest.Internal.Watchdog/DoggyDogWatchDog.cs similarity index 100% rename from NotoriousTest.Watchdog/DoggyDogWatchDog.cs rename to NotoriousTest.Internal.Watchdog/DoggyDogWatchDog.cs diff --git a/NotoriousTest.Watchdog/DoggyDogWatchdogConfiguration.cs b/NotoriousTest.Internal.Watchdog/DoggyDogWatchdogConfiguration.cs similarity index 100% rename from NotoriousTest.Watchdog/DoggyDogWatchdogConfiguration.cs rename to NotoriousTest.Internal.Watchdog/DoggyDogWatchdogConfiguration.cs diff --git a/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj b/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj new file mode 100644 index 0000000..f5e8eb8 --- /dev/null +++ b/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj @@ -0,0 +1,15 @@ + + + net8.0 + NotoriousTest.Internal.Watchdog + NotoriousTest.Watchdog + NotoriousTest.Watchdog + [Internal] Watchdog service for detecting and recovering stale test environments in NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + diff --git a/NotoriousTest.NoDoggyDog.slnf b/NotoriousTest.NoDoggyDog.slnf index 5e472c9..a5a07f6 100644 --- a/NotoriousTest.NoDoggyDog.slnf +++ b/NotoriousTest.NoDoggyDog.slnf @@ -3,10 +3,10 @@ "path": "NotoriousTest.slnx", "projects": [ "NotoriousTest.Core\\NotoriousTest.Core.csproj", - "NotoriousTest.Runtime\\NotoriousTest.Runtime.csproj", - "NotoriousTest.SqlLiteRegistry\\NotoriousTest.SqlLiteRegistry.csproj", - "NotoriousTest.TestSettings\\NotoriousTest.TestSettings.csproj", - "NotoriousTest.Watchdog\\NotoriousTest.Watchdog.csproj", + "NotoriousTest.Internal.Runtime\\NotoriousTest.Internal.Runtime.csproj", + "NotoriousTest.Internal.SqlLiteRegistry\\NotoriousTest.Internal.SqlLiteRegistry.csproj", + "NotoriousTest.Internal.TestSettings\\NotoriousTest.Internal.TestSettings.csproj", + "NotoriousTest.Internal.Watchdog\\NotoriousTest.Internal.Watchdog.csproj", "NotoriousTest\\NotoriousTest.csproj", "NotoriousTest.MSTest\\NotoriousTest.MSTest.csproj", "NotoriousTest.NUnit\\NotoriousTest.NUnit.csproj", diff --git a/NotoriousTest.Runtime/NotoriousTest.Runtime.csproj b/NotoriousTest.Runtime/NotoriousTest.Runtime.csproj deleted file mode 100644 index 5ca8149..0000000 --- a/NotoriousTest.Runtime/NotoriousTest.Runtime.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - net8.0 - false - - - - - - - - diff --git a/NotoriousTest.TestSettings/NotoriousTest.TestSettings.csproj b/NotoriousTest.TestSettings/NotoriousTest.TestSettings.csproj deleted file mode 100644 index 6b02e26..0000000 --- a/NotoriousTest.TestSettings/NotoriousTest.TestSettings.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - net8.0 - false - - - - - - - - - - diff --git a/NotoriousTest.UnitTests/NotoriousTest.UnitTests.csproj b/NotoriousTest.UnitTests/NotoriousTest.UnitTests.csproj index fc50592..2644a4a 100644 --- a/NotoriousTest.UnitTests/NotoriousTest.UnitTests.csproj +++ b/NotoriousTest.UnitTests/NotoriousTest.UnitTests.csproj @@ -24,8 +24,8 @@ - - + + diff --git a/NotoriousTest.Watchdog/NotoriousTest.Watchdog.csproj b/NotoriousTest.Watchdog/NotoriousTest.Watchdog.csproj deleted file mode 100644 index e695800..0000000 --- a/NotoriousTest.Watchdog/NotoriousTest.Watchdog.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - net8.0 - false - - - - - - - - diff --git a/NotoriousTest.slnx b/NotoriousTest.slnx index ab48a9d..3d21f2e 100644 --- a/NotoriousTest.slnx +++ b/NotoriousTest.slnx @@ -23,10 +23,10 @@ - - - - + + + + diff --git a/NotoriousTest/NotoriousTest.csproj b/NotoriousTest/NotoriousTest.csproj index 5b9c055..d7993f8 100644 --- a/NotoriousTest/NotoriousTest.csproj +++ b/NotoriousTest/NotoriousTest.csproj @@ -18,10 +18,10 @@ - - - - + + + + From 1a1e3224a26780a7a60486720c5ec32c80a65c29 Mon Sep 17 00:00:00 2001 From: Brice SCHUMACHER Date: Sat, 27 Jun 2026 01:26:42 +0200 Subject: [PATCH 2/2] fix: Made internal package downloable but with internal classes --- CHANGELOG.md | 2 + DoggyDog/DoggyDogRecoveryWatchdog.cs | 2 +- DoggyDog/Program.cs | 2 +- .../DoggyDog/DoggyDogTestFramework.cs | 2 +- .../InfrastructureLifecycleTestsBase.cs | 2 +- .../NotoriousTest.Internal.Runtime.csproj | 31 +-- .../RuntimeConfigurationEntity.cs | 19 +- .../RuntimeConfigurationProvider.cs | 122 +++++------ .../InfrastructureRegistryEntryEntity.cs | 97 ++++----- ...oriousTest.Internal.SqlLiteRegistry.csproj | 46 ++--- .../SqliteRegistryProvider.cs | 193 +++++++++--------- .../SqliteRegistryProviderConfiguration.cs | 9 +- .../SqliteRegistryProviderQueries.cs | 24 +-- ...NotoriousTest.Internal.TestSettings.csproj | 33 +-- .../TestSettingsProvider.cs | 61 +++--- .../DoggyDogWatchDog.cs | 148 +++++++------- .../DoggyDogWatchdogConfiguration.cs | 2 +- .../NotoriousTest.Internal.Watchdog.csproj | 26 +-- .../InfrastructureRegistryEntryEntityTests.cs | 2 +- .../DI/DependencyInjectionConfigurator.cs | 7 +- 20 files changed, 411 insertions(+), 419 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 082dbee..bd80964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### 🐛 Bug Fixes - Fixed a bug where internal packages were not available at installation. Preventing NotoriousTest from being installed. +- All internal packages are now available to download from Nuget.org, but every class is internal. Which makes them + impossible to use. ## v5.0.0 diff --git a/DoggyDog/DoggyDogRecoveryWatchdog.cs b/DoggyDog/DoggyDogRecoveryWatchdog.cs index 4adf86a..761eb72 100644 --- a/DoggyDog/DoggyDogRecoveryWatchdog.cs +++ b/DoggyDog/DoggyDogRecoveryWatchdog.cs @@ -4,7 +4,7 @@ using NotoriousTest.Core; using NotoriousTest.Core.Infrastructures.Cleaner; using NotoriousTest.Core.Registry; -using NotoriousTest.Watchdog; +using NotoriousTest.Internal.Watchdog; using System.Diagnostics; using System.Reflection; diff --git a/DoggyDog/Program.cs b/DoggyDog/Program.cs index 1940a72..c910339 100644 --- a/DoggyDog/Program.cs +++ b/DoggyDog/Program.cs @@ -4,7 +4,7 @@ using Microsoft.Data.Sqlite; -using NotoriousTest.SqlLiteRegistry; +using NotoriousTest.Internal.SqlLiteRegistry; Logger logger = Logger.Instance; diff --git a/NotoriousTest.IntegrationTests/DoggyDog/DoggyDogTestFramework.cs b/NotoriousTest.IntegrationTests/DoggyDog/DoggyDogTestFramework.cs index a95806f..fc71130 100644 --- a/NotoriousTest.IntegrationTests/DoggyDog/DoggyDogTestFramework.cs +++ b/NotoriousTest.IntegrationTests/DoggyDog/DoggyDogTestFramework.cs @@ -9,7 +9,7 @@ using NotoriousTest.Core.Logger; using NotoriousTest.Core.Registry; using NotoriousTest.Sqlite; -using NotoriousTest.SqlLiteRegistry; +using NotoriousTest.Internal.SqlLiteRegistry; using System.Diagnostics; using System.Runtime.InteropServices; diff --git a/NotoriousTest.IntegrationTests/Infrastructure/InfrastructureLifecycleTestsBase.cs b/NotoriousTest.IntegrationTests/Infrastructure/InfrastructureLifecycleTestsBase.cs index 32bcc3e..84a3677 100644 --- a/NotoriousTest.IntegrationTests/Infrastructure/InfrastructureLifecycleTestsBase.cs +++ b/NotoriousTest.IntegrationTests/Infrastructure/InfrastructureLifecycleTestsBase.cs @@ -3,7 +3,7 @@ using NotoriousTest.Core; using NotoriousTest.Core.Logger; using NotoriousTest.IntegrationTests.SystemUnderTest; -using NotoriousTest.SqlLiteRegistry; +using NotoriousTest.Internal.SqlLiteRegistry; using NotoriousTest.XUnit; namespace NotoriousTest.IntegrationTests.Infrastructure; diff --git a/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj b/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj index ac2a73c..11ea6a6 100644 --- a/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj +++ b/NotoriousTest.Internal.Runtime/NotoriousTest.Internal.Runtime.csproj @@ -1,17 +1,18 @@ - - net8.0 - NotoriousTest.Internal.Runtime - NotoriousTest.Runtime - NotoriousTest.Runtime - [Internal] Provides the runtime configuration layer for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. - true - true - - - - - - - + + net8.0 + NotoriousTest.Internal.Runtime + [Internal] Provides the runtime configuration layer for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + + + + + diff --git a/NotoriousTest.Internal.Runtime/RuntimeConfigurationEntity.cs b/NotoriousTest.Internal.Runtime/RuntimeConfigurationEntity.cs index afd7cba..eab5ac6 100644 --- a/NotoriousTest.Internal.Runtime/RuntimeConfigurationEntity.cs +++ b/NotoriousTest.Internal.Runtime/RuntimeConfigurationEntity.cs @@ -1,12 +1,11 @@ -namespace NotoriousTest.Runtime -{ - public record RuntimeConfigurationEntity(RuntimeOptions RuntimeOptions); +namespace NotoriousTest.Internal.Runtime; - public record RuntimeOptions( - string Tfm, - FrameworkEntry? Framework, - FrameworkEntry[]? Frameworks - ); +internal record RuntimeConfigurationEntity(RuntimeOptions RuntimeOptions); - public record FrameworkEntry(string Name, string Version); -} +internal record RuntimeOptions( + string Tfm, + FrameworkEntry? Framework, + FrameworkEntry[]? Frameworks +); + +internal record FrameworkEntry(string Name, string Version); diff --git a/NotoriousTest.Internal.Runtime/RuntimeConfigurationProvider.cs b/NotoriousTest.Internal.Runtime/RuntimeConfigurationProvider.cs index 1db7dfb..e4b1b03 100644 --- a/NotoriousTest.Internal.Runtime/RuntimeConfigurationProvider.cs +++ b/NotoriousTest.Internal.Runtime/RuntimeConfigurationProvider.cs @@ -1,88 +1,88 @@ -using NotoriousTest.Core.Logger; -using NotoriousTest.Core.Runtime; - -using System.Diagnostics; +using System.Diagnostics; using System.Reflection; using System.Text.Json; +using NotoriousTest.Core.Logger; +using NotoriousTest.Core.Runtime; + +namespace NotoriousTest.Internal.Runtime; -namespace NotoriousTest.Runtime +internal class RuntimeConfigurationProvider : IRuntime { - public class RuntimeConfigurationProvider : IRuntime - { - private const string RuntimeFile = "runtimeconfig.json"; - private readonly ITestLogger _logger; - private RuntimeConfiguration? _cache = null; + private const string RuntimeFile = "runtimeconfig.json"; + private readonly ITestLogger _logger; - private readonly JsonSerializerOptions JSON_OPTIONS = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; - public RuntimeConfigurationProvider(ITestLogger logger) - { - _logger = logger; - } + private readonly JsonSerializerOptions JSON_OPTIONS = new() { PropertyNameCaseInsensitive = true }; + private RuntimeConfiguration? _cache; - public RuntimeConfiguration? GetSupportedRuntimes(Assembly executingAssembly) - { - if (_cache != null) return _cache; + public RuntimeConfigurationProvider(ITestLogger logger) + { + _logger = logger; + } - string assemblyPath = executingAssembly.Location; - string runtimePath = Path.ChangeExtension(assemblyPath, RuntimeFile); + public RuntimeConfiguration? GetSupportedRuntimes(Assembly executingAssembly) + { + if (_cache != null) return _cache; + + string assemblyPath = executingAssembly.Location; + string runtimePath = Path.ChangeExtension(assemblyPath, RuntimeFile); - if (!File.Exists(runtimePath)) - return null; + if (!File.Exists(runtimePath)) + return null; - string json = File.ReadAllText(runtimePath); + string json = File.ReadAllText(runtimePath); - RuntimeConfigurationEntity? entity = JsonSerializer.Deserialize(json, JSON_OPTIONS); - if (entity == null) - return null; + RuntimeConfigurationEntity? entity = JsonSerializer.Deserialize(json, JSON_OPTIONS); + if (entity == null) + return null; - FrameworkEntry[]? frameworkEntries = entity.RuntimeOptions.Frameworks ?? [entity.RuntimeOptions.Framework!]; - SupportedFramework[]? frameworks = frameworkEntries.Select(ToDomain).ToArray(); + FrameworkEntry[]? frameworkEntries = entity.RuntimeOptions.Frameworks ?? [entity.RuntimeOptions.Framework!]; + SupportedFramework[]? frameworks = frameworkEntries.Select(ToDomain).ToArray(); - var result = new RuntimeConfiguration(entity.RuntimeOptions.Tfm, frameworks); - _cache = result; - return result; - } + var result = new RuntimeConfiguration(entity.RuntimeOptions.Tfm, frameworks); + _cache = result; + return result; + } - private SupportedFramework ToDomain(FrameworkEntry entry) => new(entry.Name, entry.Version, GetNearestVersionDirectory(entry)); + private SupportedFramework ToDomain(FrameworkEntry entry) => + new(entry.Name, entry.Version, GetNearestVersionDirectory(entry)); - private string? GetNearestVersionDirectory(FrameworkEntry framework) - { - string dotnetRoot = GetDotnetRoot(); + private string? GetNearestVersionDirectory(FrameworkEntry framework) + { + string dotnetRoot = GetDotnetRoot(); - string frameworkPath = $"{dotnetRoot}/shared/{framework.Name}"; + string frameworkPath = $"{dotnetRoot}/shared/{framework.Name}"; - string prefix = $"{new Version(framework.Version).Major}.{new Version(framework.Version).Minor}."; - // Find the nearest version - string? best = Directory.GetDirectories(frameworkPath) - .Where(d => Path.GetFileName(d).StartsWith(prefix)) - .OrderByDescending(d => new Version(Path.GetFileName(d))) - .FirstOrDefault(); + string prefix = $"{new Version(framework.Version).Major}.{new Version(framework.Version).Minor}."; + // Find the nearest version + string? best = Directory.GetDirectories(frameworkPath) + .Where(d => Path.GetFileName(d).StartsWith(prefix)) + .OrderByDescending(d => new Version(Path.GetFileName(d))) + .FirstOrDefault(); - return best; - } - private string GetDotnetRoot() - { + return best; + } - string? dotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT"); + private string GetDotnetRoot() + { + string? dotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT"); - if (!string.IsNullOrWhiteSpace(dotnetRoot)) - return dotnetRoot; + if (!string.IsNullOrWhiteSpace(dotnetRoot)) + return dotnetRoot; - string mainModule = Process.GetCurrentProcess().MainModule!.FileName; + string mainModule = Process.GetCurrentProcess().MainModule!.FileName; - // If the test project is self-contained (wich is rare), the main module will be the test executable itself. - bool isNotSelfContained = Path.GetFileNameWithoutExtension(mainModule) - .Equals("dotnet", StringComparison.OrdinalIgnoreCase); + // If the test project is self-contained (wich is rare), the main module will be the test executable itself. + bool isNotSelfContained = Path.GetFileNameWithoutExtension(mainModule) + .Equals("dotnet", StringComparison.OrdinalIgnoreCase); - if (isNotSelfContained) - return Path.GetDirectoryName(mainModule)!; + if (isNotSelfContained) + return Path.GetDirectoryName(mainModule)!; - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), - "dotnet" - ); - } + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), + "dotnet" + ); } } diff --git a/NotoriousTest.Internal.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs b/NotoriousTest.Internal.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs index c5ea2be..dd45349 100644 --- a/NotoriousTest.Internal.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs +++ b/NotoriousTest.Internal.SqlLiteRegistry/InfrastructureRegistryEntryEntity.cs @@ -1,64 +1,55 @@ -using NotoriousTest.Core.Registry; - -using System.Globalization; +using System.Globalization; using System.Text.Json; +using NotoriousTest.Core.Registry; + +namespace NotoriousTest.Internal.SqlLiteRegistry; -namespace NotoriousTest.SqlLiteRegistry +internal class InfrastructureRegistryEntryEntity { - internal class InfrastructureRegistryEntryEntity - { - public string InfrastructureId { get; set; } - public string InfrastructureType { get; set; } - public string EnvironmentId { get; set; } - public int ProcessID { get; set; } - public string? Metadata { get; set; } - public string? MetadataType { get; set; } - public string? LastResetDate { get; set; } - public string CreationDate { get; set; } - public string UpdateDate { get; set; } + public string InfrastructureId { get; set; } + public string InfrastructureType { get; set; } + public string EnvironmentId { get; set; } + public int ProcessID { get; set; } + public string? Metadata { get; set; } + public string? MetadataType { get; set; } + public string? LastResetDate { get; set; } + public string CreationDate { get; set; } + public string UpdateDate { get; set; } - internal static InfrastructureRegistryEntryEntity? FromDomain(InfrastuctureRegistryEntry entry) + internal static InfrastructureRegistryEntryEntity? FromDomain(InfrastuctureRegistryEntry entry) => + new() { - return new InfrastructureRegistryEntryEntity() - { - InfrastructureId = entry.InfrastructureId.ToString(), - InfrastructureType = entry.InfrastructureType.AssemblyQualifiedName, - EnvironmentId = entry.EnvironmentId.ToString(), - ProcessID = entry.ProcessID, - Metadata = JsonSerializer.Serialize(entry.Metadata), - MetadataType = entry.Metadata?.GetType().AssemblyQualifiedName, - LastResetDate = entry.LastResetDate?.ToString("O") - }; - } + InfrastructureId = entry.InfrastructureId.ToString(), + InfrastructureType = entry.InfrastructureType.AssemblyQualifiedName, + EnvironmentId = entry.EnvironmentId.ToString(), + ProcessID = entry.ProcessID, + Metadata = JsonSerializer.Serialize(entry.Metadata), + MetadataType = entry.Metadata?.GetType().AssemblyQualifiedName, + LastResetDate = entry.LastResetDate?.ToString("O") + }; - internal InfrastuctureRegistryEntry ToDomain() - { - Type? metadataType = null; + internal InfrastuctureRegistryEntry ToDomain() + { + Type? metadataType = null; - if (MetadataType != null) - { - metadataType = Type.GetType(MetadataType); - } + if (MetadataType != null) metadataType = Type.GetType(MetadataType); - Type? infraType = Type.GetType(InfrastructureType); - if (infraType == null) - { - throw new TypeLoadException($"Unable to load type {InfrastructureType}"); - } + var infraType = Type.GetType(InfrastructureType); + if (infraType == null) throw new TypeLoadException($"Unable to load type {InfrastructureType}"); - return new InfrastuctureRegistryEntry() - { - InfrastructureId = Guid.Parse(InfrastructureId), - InfrastructureType = Type.GetType(InfrastructureType), - EnvironmentId = Guid.Parse(EnvironmentId), - ProcessID = ProcessID, - Metadata = !(Metadata is null) && !(metadataType is null) - ? JsonSerializer.Deserialize(Metadata, metadataType) - : null, - LastResetDate = LastResetDate != null ? DateTime.Parse(LastResetDate, null, DateTimeStyles.RoundtripKind) : null, - CreationDate = DateTime.Parse(CreationDate, null, DateTimeStyles.RoundtripKind), - UpdateDate = DateTime.Parse(UpdateDate, null, DateTimeStyles.RoundtripKind), - }; - } + return new InfrastuctureRegistryEntry + { + InfrastructureId = Guid.Parse(InfrastructureId), + InfrastructureType = Type.GetType(InfrastructureType), + EnvironmentId = Guid.Parse(EnvironmentId), + ProcessID = ProcessID, + Metadata = !(Metadata is null) && !(metadataType is null) + ? JsonSerializer.Deserialize(Metadata, metadataType) + : null, + LastResetDate = + LastResetDate != null ? DateTime.Parse(LastResetDate, null, DateTimeStyles.RoundtripKind) : null, + CreationDate = DateTime.Parse(CreationDate, null, DateTimeStyles.RoundtripKind), + UpdateDate = DateTime.Parse(UpdateDate, null, DateTimeStyles.RoundtripKind) + }; } } diff --git a/NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj b/NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj index 3a92a09..62dbd5a 100644 --- a/NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj +++ b/NotoriousTest.Internal.SqlLiteRegistry/NotoriousTest.Internal.SqlLiteRegistry.csproj @@ -1,25 +1,25 @@ - - net8.0 - NotoriousTest.Internal.SqlLiteRegistry - NotoriousTest.SqlLiteRegistry - NotoriousTest.SqlLiteRegistry - [Internal] SQLite-backed infrastructure registry for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. - true - true - - - - - - - - - - - - - - - + + net8.0 + NotoriousTest.Internal.SqlLiteRegistry + [Internal] SQLite-backed infrastructure registry for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + + + + + + + + + + + + diff --git a/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProvider.cs b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProvider.cs index 76ce971..10b61fb 100644 --- a/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProvider.cs +++ b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProvider.cs @@ -1,131 +1,126 @@ -using Dapper; - +using System.Data; +using Dapper; using Microsoft.Data.Sqlite; - using NotoriousTest.Core; using NotoriousTest.Core.Registry; -namespace NotoriousTest.SqlLiteRegistry + +namespace NotoriousTest.Internal.SqlLiteRegistry; + +internal partial class SqliteRegistryProvider : IRegistry { - internal partial class SqliteRegistryProvider : IRegistry + private readonly SqliteRegistryProviderConfiguration _configuration; + + public SqliteRegistryProvider(SqliteRegistryProviderConfiguration configuration) { - private readonly SqliteRegistryProviderConfiguration _configuration; - public event Action OnInfrastructureReset; - public event Action OnInfrastructureDestroyed; - public event Action OnInfrastructureCreated; + _configuration = configuration; + } + + private SqliteConnectionStringBuilder ConnectionString => new(_configuration.ConnectionString); - public SqliteRegistryProvider(SqliteRegistryProviderConfiguration configuration) + private SqliteConnection Connection + { + get { - _configuration = configuration; + var connection = new SqliteConnection(ConnectionString.ToString()); + + if (connection.State != ConnectionState.Open) connection.Open(); + + connection.Execute("PRAGMA SYNCHRONOUS=NORMAL;PRAGMA JOURNAL_MODE=WAL;"); + return connection; } + } - private SqliteConnectionStringBuilder ConnectionString => new(_configuration.ConnectionString); + public event Action OnInfrastructureReset; + public event Action OnInfrastructureDestroyed; + public event Action OnInfrastructureCreated; - private SqliteConnection Connection - { - get - { - var connection = new SqliteConnection(ConnectionString.ToString()); - if (connection.State != System.Data.ConnectionState.Open) - { - connection.Open(); - } + public async Task Ensure() + { + string directory = Path.GetDirectoryName(ConnectionString.DataSource); + if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); - connection.Execute("PRAGMA SYNCHRONOUS=NORMAL;PRAGMA JOURNAL_MODE=WAL;"); - return connection; - } - } + await using SqliteConnection connection = Connection; + await connection.ExecuteAsync(ENSURE_REGISTRY); + } - public async Task Ensure() - { - string directory = Path.GetDirectoryName(ConnectionString.DataSource); - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } + public async Task Register(InfrastuctureRegistryEntry entry) + { + await using SqliteConnection connection = Connection; + InfrastructureRegistryEntryEntity entity = + await connection.QuerySingleAsync(REGISTER_INFRASTRUCTURE, + InfrastructureRegistryEntryEntity.FromDomain(entry)); - await using SqliteConnection connection = Connection; + return entity.ToDomain(); + } - await connection.ExecuteAsync(ENSURE_REGISTRY); - } + public async Task Remove(Guid id) + { + await using SqliteConnection connection = Connection; - public async Task Register(InfrastuctureRegistryEntry entry) - { - await using SqliteConnection connection = Connection; - InfrastructureRegistryEntryEntity entity = await connection.QuerySingleAsync(REGISTER_INFRASTRUCTURE, InfrastructureRegistryEntryEntity.FromDomain(entry)); + int deletedRows = + await connection.ExecuteAsync(REMOVE_INFRASTRUCTURE, new { InfrastructureId = id.ToString() }); + return deletedRows > 0; + } - return entity.ToDomain(); - } + public async Task NotifyReset(Guid id) + { + await using SqliteConnection connection = Connection; - public async Task Remove(Guid id) - { - await using SqliteConnection connection = Connection; + await connection.ExecuteAsync(UPDATE_INFRASTRUCTURE_RESET_DATE, new { InfrastructureId = id.ToString() }); + } - int deletedRows = await connection.ExecuteAsync(REMOVE_INFRASTRUCTURE, new { InfrastructureId = id.ToString() }); - return deletedRows > 0; - } + public async Task> GetByProcessId(int processId) + { + await using SqliteConnection connection = Connection; - public async Task NotifyReset(Guid id) - { - await using SqliteConnection connection = Connection; + IEnumerable entries = + await connection.QueryAsync(GET_BY_PROCESS_ID, + new { ProcessID = processId }); + return entries.Select(entry => entry.ToDomain()); + } - await connection.ExecuteAsync(UPDATE_INFRASTRUCTURE_RESET_DATE, new { InfrastructureId = id.ToString() }); - } + public async Task> GetByEnvironmentId(EnvironmentId environmentId) + { + await using SqliteConnection connection = Connection; - public async Task> GetByProcessId(int processId) - { - await using SqliteConnection connection = Connection; + IEnumerable entries = + await connection.QueryAsync(GET_BY_ENVIRONMENT_ID, + new { EnvironmentId = environmentId.Value.ToString() }); + return entries.Select(entry => entry.ToDomain()); + } - IEnumerable entries = await connection.QueryAsync(GET_BY_PROCESS_ID, new { ProcessID = processId }); - return entries.Select(entry => entry.ToDomain()); - } + public async Task Watch(EnvironmentId environmentId, CancellationToken ct) + { + var snapshot = (await GetByEnvironmentId(environmentId)).ToDictionary(x => x.InfrastructureId); - public async Task> GetByEnvironmentId(EnvironmentId environmentId) + do { - await using SqliteConnection connection = Connection; + IEnumerable infras = await GetByEnvironmentId(environmentId); - IEnumerable entries = await connection.QueryAsync(GET_BY_ENVIRONMENT_ID, new { EnvironmentId = environmentId.Value.ToString() }); - return entries.Select(entry => entry.ToDomain()); - } + foreach (InfrastuctureRegistryEntry infra in infras) + { + if (!snapshot.TryGetValue(infra.InfrastructureId, out InfrastuctureRegistryEntry? previous)) + OnInfrastructureCreated?.Invoke(infra); - public async Task Watch(EnvironmentId environmentId, CancellationToken ct) - { - var snapshot = (await GetByEnvironmentId(environmentId)).ToDictionary(x => x.InfrastructureId); + if (previous is not null && infra.LastResetDate != previous.LastResetDate) + OnInfrastructureReset?.Invoke(infra); + } - do + foreach ((Guid key, InfrastuctureRegistryEntry infrastructure) in snapshot) + if (!infras.Any(i => i.InfrastructureId == infrastructure.InfrastructureId)) + OnInfrastructureDestroyed?.Invoke(infrastructure); + + snapshot = infras.ToDictionary(x => x.InfrastructureId); + + try { - IEnumerable infras = await GetByEnvironmentId(environmentId); - - foreach (InfrastuctureRegistryEntry infra in infras) - { - if (!snapshot.TryGetValue(infra.InfrastructureId, out var previous)) - { - OnInfrastructureCreated?.Invoke(infra); - } - - if (previous is not null && infra.LastResetDate != previous.LastResetDate) - { - OnInfrastructureReset?.Invoke(infra); - } - } - - foreach (var (key, infrastructure) in snapshot) - { - if (!infras.Any(i => i.InfrastructureId == infrastructure.InfrastructureId)) - { - OnInfrastructureDestroyed?.Invoke(infrastructure); - } - } - - snapshot = infras.ToDictionary(x => x.InfrastructureId); - - try - { - await Task.Delay(10, ct); - } - catch (OperationCanceledException) { } - } while (!ct.IsCancellationRequested); - } + await Task.Delay(10, ct); + } + catch (OperationCanceledException) + { + } + } while (!ct.IsCancellationRequested); } } diff --git a/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs index 98c0c55..601a00a 100644 --- a/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs +++ b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderConfiguration.cs @@ -1,7 +1,6 @@ -namespace NotoriousTest.SqlLiteRegistry +namespace NotoriousTest.Internal.SqlLiteRegistry; + +internal class SqliteRegistryProviderConfiguration { - public class SqliteRegistryProviderConfiguration - { - public string ConnectionString { get; set; } - } + public string ConnectionString { get; set; } } diff --git a/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderQueries.cs b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderQueries.cs index 07262c7..2e622a9 100644 --- a/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderQueries.cs +++ b/NotoriousTest.Internal.SqlLiteRegistry/SqliteRegistryProviderQueries.cs @@ -1,9 +1,10 @@ -namespace NotoriousTest.SqlLiteRegistry +namespace NotoriousTest.Internal.SqlLiteRegistry; + +internal partial class SqliteRegistryProvider { - internal partial class SqliteRegistryProvider - { - protected const string TABLE_NAME = "InfrastructureRegistry"; - protected const string ENSURE_REGISTRY = @$" + protected const string TABLE_NAME = "InfrastructureRegistry"; + + protected const string ENSURE_REGISTRY = @$" CREATE TABLE IF NOT EXISTS {TABLE_NAME}( InfrastructureId TEXT PRIMARY KEY, InfrastructureType TEXT NOT NULL, @@ -17,30 +18,29 @@ LastResetDate TEXT ) "; - protected const string REGISTER_INFRASTRUCTURE = @$" + protected const string REGISTER_INFRASTRUCTURE = @$" INSERT INTO {TABLE_NAME}(InfrastructureId, InfrastructureType, EnvironmentId, ProcessID, Metadata, MetadataType, CreationDate, UpdateDate, LastResetDate) VALUES(@InfrastructureId, @InfrastructureType, @EnvironmentId, @ProcessID, @Metadata, @MetadataType, datetime('now', 'utc'), datetime('now', 'utc'), null) RETURNING * "; - protected const string REMOVE_INFRASTRUCTURE = @$" + protected const string REMOVE_INFRASTRUCTURE = @$" DELETE FROM {TABLE_NAME} WHERE InfrastructureId = @InfrastructureId; "; - protected const string GET_BY_PROCESS_ID = @$" + protected const string GET_BY_PROCESS_ID = @$" SELECT * FROM {TABLE_NAME} WHERE ProcessID = @ProcessID; "; - protected const string GET_BY_ENVIRONMENT_ID = @$" + protected const string GET_BY_ENVIRONMENT_ID = @$" SELECT * FROM {TABLE_NAME} WHERE EnvironmentId = @EnvironmentId; "; - protected const string GET_BY_ROWID = $@" + protected const string GET_BY_ROWID = $@" SELECT * FROM {TABLE_NAME} WHERE rowid = @rowId "; - protected const string UPDATE_INFRASTRUCTURE_RESET_DATE = @$" + protected const string UPDATE_INFRASTRUCTURE_RESET_DATE = @$" UPDATE {TABLE_NAME} SET LastResetDate = strftime('%Y-%m-%dT%H:%M:%f', 'now') WHERE InfrastructureId = @InfrastructureId "; - } } diff --git a/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj b/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj index a3e3ac9..66cc5cd 100644 --- a/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj +++ b/NotoriousTest.Internal.TestSettings/NotoriousTest.Internal.TestSettings.csproj @@ -1,18 +1,19 @@ - - net8.0 - NotoriousTest.Internal.TestSettings - NotoriousTest.TestSettings - NotoriousTest.Core.Settings - [Internal] JSON-based test settings provider for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. - true - true - - - - - - - - + + net8.0 + NotoriousTest.Internal.TestSettings + [Internal] JSON-based test settings provider for NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + + + + + + diff --git a/NotoriousTest.Internal.TestSettings/TestSettingsProvider.cs b/NotoriousTest.Internal.TestSettings/TestSettingsProvider.cs index 1fa81d1..b63a1d2 100644 --- a/NotoriousTest.Internal.TestSettings/TestSettingsProvider.cs +++ b/NotoriousTest.Internal.TestSettings/TestSettingsProvider.cs @@ -1,47 +1,42 @@ using Microsoft.Extensions.Configuration; +using NotoriousTest.Core.Settings; -namespace NotoriousTest.Core.Settings +namespace NotoriousTest.Internal.TestSettings; + +internal class TestSettingsProvider : ITestSettingsProvider { - public class TestSettingsProvider : ITestSettingsProvider + private IConfiguration _cache; + + public IConfiguration Find() { - private IConfiguration _cache; - public IConfiguration Find() + if (_cache == null) { - if (_cache == null) - { - string? settingsPath = FindFile("testsettings.json"); - - - var configurationBuilder = new ConfigurationBuilder(); - if (settingsPath != null) - { - configurationBuilder.AddJsonFile(settingsPath); + string? settingsPath = FindFile("testsettings.json"); - } - _cache = configurationBuilder.Build(); + var configurationBuilder = new ConfigurationBuilder(); + if (settingsPath != null) configurationBuilder.AddJsonFile(settingsPath); - } - - return _cache; + _cache = configurationBuilder.Build(); } - public T? Get(string key) where T : new() - { - IConfigurationSection section = Find().GetSection(key); - if (!section.Exists()) - return default; + return _cache; + } - var config = new T(); - section.Bind(config); + public T? Get(string key) where T : new() + { + IConfigurationSection section = Find().GetSection(key); + if (!section.Exists()) + return default; - return config; - } - private static string? FindFile(string fileName) - { - return Directory - .EnumerateFiles(AppContext.BaseDirectory, fileName, SearchOption.AllDirectories) - .FirstOrDefault(); - } + var config = new T(); + section.Bind(config); + + return config; } + + private static string? FindFile(string fileName) => + Directory + .EnumerateFiles(AppContext.BaseDirectory, fileName, SearchOption.AllDirectories) + .FirstOrDefault(); } diff --git a/NotoriousTest.Internal.Watchdog/DoggyDogWatchDog.cs b/NotoriousTest.Internal.Watchdog/DoggyDogWatchDog.cs index 147055b..66b2c22 100644 --- a/NotoriousTest.Internal.Watchdog/DoggyDogWatchDog.cs +++ b/NotoriousTest.Internal.Watchdog/DoggyDogWatchDog.cs @@ -1,89 +1,95 @@ -using NotoriousTest.Core; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.InteropServices; +using NotoriousTest.Core; using NotoriousTest.Core.Logger; using NotoriousTest.Core.Watchdog; -using NotoriousTest.SqlLiteRegistry; +using NotoriousTest.Internal.SqlLiteRegistry; -using System.Diagnostics; -using System.Reflection; -using System.Runtime.InteropServices; +namespace NotoriousTest.Internal.Watchdog; -namespace NotoriousTest.Watchdog +internal class DoggyDogWatchDog : IWatchDog { - public class DoggyDogWatchDog : IWatchDog - { - private readonly SqliteRegistryProviderConfiguration _registyConfiguration; - private readonly ITestLogger _logger; - private readonly DoggyDogWatchdogConfiguration _config; - - public DoggyDogWatchDog(SqliteRegistryProviderConfiguration registryConfiguration, ITestLogger logger, DoggyDogWatchdogConfiguration config) - { - _registyConfiguration = registryConfiguration; - _logger = logger; - _config = config; - } - - public Process Start(Assembly currentAssembly, int currentPid, EnvironmentId environmentId, IEnumerable? runtimePaths) - { - string assemblyPath = currentAssembly.Location; - string? runtimesParams = runtimePaths == null ? null : string.Join("|", runtimePaths); + private readonly DoggyDogWatchdogConfiguration _config; + private readonly ITestLogger _logger; + private readonly SqliteRegistryProviderConfiguration _registyConfiguration; - if (_config.ManualLaunch) - return WaitForDoggyDogToLaunch(currentPid, environmentId, assemblyPath, runtimesParams); - return LaunchDoggyDog(currentPid, environmentId, assemblyPath, runtimesParams) ?? throw new Exception("Could not launch DoggyDog"); - } + public DoggyDogWatchDog(SqliteRegistryProviderConfiguration registryConfiguration, ITestLogger logger, + DoggyDogWatchdogConfiguration config) + { + _registyConfiguration = registryConfiguration; + _logger = logger; + _config = config; + } - private Process? LaunchDoggyDog(int currentPid, EnvironmentId contextId, string assemblyPath, string? runtimesParams) - { - string watchdogPath = Path.Combine(AppContext.BaseDirectory, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "DoggyDog.exe" : "DoggyDog"); + public Process Start(Assembly currentAssembly, int currentPid, EnvironmentId environmentId, + IEnumerable? runtimePaths) + { + string assemblyPath = currentAssembly.Location; + string? runtimesParams = runtimePaths == null ? null : string.Join("|", runtimePaths); - string runtimeParameter = runtimesParams == null ? "" : $"--runtimes \"{runtimesParams}\" "; - var process = Process.Start(new ProcessStartInfo - { - FileName = watchdogPath, - Arguments = $"--pid {currentPid} " + - $"--assembly \"{assemblyPath}\" " + - $"--connectionString \"{_registyConfiguration.ConnectionString}\" " + - $"--environment {contextId.Value} " + - runtimeParameter + - "--loglevel Info", - UseShellExecute = true, - CreateNoWindow = false, - }); + if (_config.ManualLaunch) + return WaitForDoggyDogToLaunch(currentPid, environmentId, assemblyPath, runtimesParams); + return LaunchDoggyDog(currentPid, environmentId, assemblyPath, runtimesParams) ?? + throw new Exception("Could not launch DoggyDog"); + } + public void SendSuccessSignal(EnvironmentId contextId) => + File.WriteAllText(Path.Combine(Path.GetTempPath(), $"nt-{contextId.Value}.signal"), "OK"); - return process; - } + private Process? LaunchDoggyDog(int currentPid, EnvironmentId contextId, string assemblyPath, + string? runtimesParams) + { + string watchdogPath = Path.Combine(AppContext.BaseDirectory, + RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "DoggyDog.exe" : "DoggyDog"); - private Process WaitForDoggyDogToLaunch(int currentPid, EnvironmentId environmentId, string assemblyPath, string? runtimesParams) + string runtimeParameter = runtimesParams == null ? "" : $"--runtimes \"{runtimesParams}\" "; + var process = Process.Start(new ProcessStartInfo { - Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_PID", currentPid.ToString(), EnvironmentVariableTarget.User); - Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_ASSEMBLY", assemblyPath, EnvironmentVariableTarget.User); - Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_CONNECTIONSTRING", _registyConfiguration.ConnectionString, EnvironmentVariableTarget.User); - Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_ENVIRONMENT", environmentId.Value.ToString(), EnvironmentVariableTarget.User); - Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_RUNTIMES", runtimesParams, EnvironmentVariableTarget.User); - Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_LOGLEVEL", "Debug", EnvironmentVariableTarget.User); - - Process? doggyDogProcess; - do - { - _logger.Log("Waiting for DoggyDog to launch...", environmentId); - doggyDogProcess = Process.GetProcessesByName("DoggyDog")?.FirstOrDefault(); - Thread.Sleep(5000); - - } while (doggyDogProcess == null); + FileName = watchdogPath, + Arguments = $"--pid {currentPid} " + + $"--assembly \"{assemblyPath}\" " + + $"--connectionString \"{_registyConfiguration.ConnectionString}\" " + + $"--environment {contextId.Value} " + + runtimeParameter + + "--loglevel Info", + UseShellExecute = true, + CreateNoWindow = false + }); + + + return process; + } - return doggyDogProcess; - } + private Process WaitForDoggyDogToLaunch(int currentPid, EnvironmentId environmentId, string assemblyPath, + string? runtimesParams) + { + Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_PID", currentPid.ToString(), EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_ASSEMBLY", assemblyPath, EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_CONNECTIONSTRING", _registyConfiguration.ConnectionString, + EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_ENVIRONMENT", environmentId.Value.ToString(), + EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_RUNTIMES", runtimesParams, EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable("DOGGYDOG_DEBUG_LOGLEVEL", "Debug", EnvironmentVariableTarget.User); + + Process? doggyDogProcess; + do + { + _logger.Log("Waiting for DoggyDog to launch...", environmentId); + doggyDogProcess = Process.GetProcessesByName("DoggyDog")?.FirstOrDefault(); + Thread.Sleep(5000); + } while (doggyDogProcess == null); - public void SendSuccessSignal(EnvironmentId contextId) => File.WriteAllText(Path.Combine(Path.GetTempPath(), $"nt-{contextId.Value}.signal"), "OK"); + return doggyDogProcess; + } - public static bool ReadSuccessSignal(EnvironmentId contextId) - { - string path = Path.Combine(Path.GetTempPath(), $"nt-{contextId.Value}.signal"); - bool isSuccess = File.Exists(path); - if (isSuccess) File.Delete(path); + public static bool ReadSuccessSignal(EnvironmentId contextId) + { + string path = Path.Combine(Path.GetTempPath(), $"nt-{contextId.Value}.signal"); + bool isSuccess = File.Exists(path); + if (isSuccess) File.Delete(path); - return isSuccess; - } + return isSuccess; } } diff --git a/NotoriousTest.Internal.Watchdog/DoggyDogWatchdogConfiguration.cs b/NotoriousTest.Internal.Watchdog/DoggyDogWatchdogConfiguration.cs index 1d6cdaa..a65a46c 100644 --- a/NotoriousTest.Internal.Watchdog/DoggyDogWatchdogConfiguration.cs +++ b/NotoriousTest.Internal.Watchdog/DoggyDogWatchdogConfiguration.cs @@ -1,4 +1,4 @@ -namespace NotoriousTest.Core.Watchdog +namespace NotoriousTest.Internal.Watchdog { public class DoggyDogWatchdogConfiguration { diff --git a/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj b/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj index f5e8eb8..cdd92e9 100644 --- a/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj +++ b/NotoriousTest.Internal.Watchdog/NotoriousTest.Internal.Watchdog.csproj @@ -1,15 +1,17 @@ - - net8.0 - NotoriousTest.Internal.Watchdog - NotoriousTest.Watchdog - NotoriousTest.Watchdog - [Internal] Watchdog service for detecting and recovering stale test environments in NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. - true - true - - - - + + net8.0 + NotoriousTest.Internal.Watchdog + [Internal] Watchdog service for detecting and recovering stale test environments in NotoriousTest. Not intended for direct consumption — use the NotoriousTest package instead. + true + true + + + + + + + + diff --git a/NotoriousTest.UnitTests/Registry/InfrastructureRegistryEntryEntityTests.cs b/NotoriousTest.UnitTests/Registry/InfrastructureRegistryEntryEntityTests.cs index 69e110f..f02230c 100644 --- a/NotoriousTest.UnitTests/Registry/InfrastructureRegistryEntryEntityTests.cs +++ b/NotoriousTest.UnitTests/Registry/InfrastructureRegistryEntryEntityTests.cs @@ -1,7 +1,7 @@ using AwesomeAssertions; using NotoriousTest.Core.Registry; -using NotoriousTest.SqlLiteRegistry; +using NotoriousTest.Internal.SqlLiteRegistry; using System.Text.Json; diff --git a/NotoriousTest/DI/DependencyInjectionConfigurator.cs b/NotoriousTest/DI/DependencyInjectionConfigurator.cs index cc6ad08..bea5bc6 100644 --- a/NotoriousTest/DI/DependencyInjectionConfigurator.cs +++ b/NotoriousTest/DI/DependencyInjectionConfigurator.cs @@ -9,9 +9,10 @@ using NotoriousTest.Core.Settings; using NotoriousTest.Core.Watchdog; using NotoriousTest.Environments; -using NotoriousTest.Runtime; -using NotoriousTest.SqlLiteRegistry; -using NotoriousTest.Watchdog; +using NotoriousTest.Internal.Runtime; +using NotoriousTest.Internal.SqlLiteRegistry; +using NotoriousTest.Internal.TestSettings; +using NotoriousTest.Internal.Watchdog; namespace NotoriousTest.DI;