From 0e47036bac9fecebdaad1f797662baaf0659e955 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Mon, 2 Mar 2026 12:54:07 +0100 Subject: [PATCH 1/3] feat: add configuration support with JSON file integration - Introduced `TryAddJsonFile` method in `ConfigurationBuilderExtensions` to conditionally add JSON configuration files. - Added new `CreativeCoders.Configuration` project to the solution with necessary dependencies. - Enhanced `ICliHostBuilder` with `UseConfiguration` method for customizable configuration setups. - Updated `Core.sln` and `CreativeCoders.Cli.Hosting` to incorporate new configuration capabilities. --- Core.sln | 10 ++++++++++ .../CreativeCoders.Cli.Hosting.csproj | 6 ++++-- .../DefaultCliHostBuilder.cs | 18 ++++++++++++++++++ .../ICliHostBuilder.cs | 12 ++++++++++++ .../ConfigurationBuilderExtensions.cs | 14 ++++++++++++++ .../CreativeCoders.Configuration.csproj | 18 ++++++++++++++++++ 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 source/Configuration/CreativeCoders.Configuration/ConfigurationBuilderExtensions.cs create mode 100644 source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj diff --git a/Core.sln b/Core.sln index 4370305c..ebd6e91a 100644 --- a/Core.sln +++ b/Core.sln @@ -262,6 +262,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.IO.Ports", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.CakeBuild.Tests", "tests\CreativeCoders.CakeBuild.Tests\CreativeCoders.CakeBuild.Tests.csproj", "{A081DDB3-A9DB-498F-824B-C605ACFDB43A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configuration", "Configuration", "{2568D059-EB13-4489-8F12-769EB4DD449F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreativeCoders.Configuration", "source\Configuration\CreativeCoders.Configuration\CreativeCoders.Configuration.csproj", "{86E41188-7778-415E-A783-2CEF2DADB21A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -588,6 +592,10 @@ Global {A081DDB3-A9DB-498F-824B-C605ACFDB43A}.Debug|Any CPU.Build.0 = Debug|Any CPU {A081DDB3-A9DB-498F-824B-C605ACFDB43A}.Release|Any CPU.ActiveCfg = Release|Any CPU {A081DDB3-A9DB-498F-824B-C605ACFDB43A}.Release|Any CPU.Build.0 = Release|Any CPU + {86E41188-7778-415E-A783-2CEF2DADB21A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86E41188-7778-415E-A783-2CEF2DADB21A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86E41188-7778-415E-A783-2CEF2DADB21A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86E41188-7778-415E-A783-2CEF2DADB21A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -698,6 +706,8 @@ Global {EC120660-306E-4E48-8FBB-43D9F3962CEE} = {F31389F0-613B-48B1-AA99-6BFC3D8D7D1A} {C34426F1-E40C-498D-8FDE-D4ECEB3E49D4} = {F31389F0-613B-48B1-AA99-6BFC3D8D7D1A} {A081DDB3-A9DB-498F-824B-C605ACFDB43A} = {5A3FFD14-2258-4007-AC77-BAFB3B3EB26F} + {2568D059-EB13-4489-8F12-769EB4DD449F} = {2A7105AA-05B6-469A-93F5-719723A4D90D} + {86E41188-7778-415E-A783-2CEF2DADB21A} = {2568D059-EB13-4489-8F12-769EB4DD449F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EE24476B-9A4C-4146-B982-3461FAF8B3B0} diff --git a/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj b/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj index e5f99f0e..225bd357 100644 --- a/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj +++ b/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj @@ -13,8 +13,10 @@ - - + + + + diff --git a/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs b/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs index ba16ac83..20445a44 100644 --- a/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs +++ b/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs @@ -6,6 +6,7 @@ using CreativeCoders.Cli.Hosting.Commands.Validation; using CreativeCoders.Cli.Hosting.Help; using CreativeCoders.Core; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -123,6 +124,23 @@ public ICliHostBuilder RegisterPostProcessor(Action? configure = null) return ConfigureServices(x => x.AddSingleton()); } + public ICliHostBuilder UseConfiguration(Action configure) + { + Ensure.NotNull(configure); + + return ConfigureServices(x => + { + var configurationBuilder = new ConfigurationBuilder(); + + configure(configurationBuilder); + + var configuration = configurationBuilder.Build(); + + x.AddSingleton(configuration); + x.AddSingleton(configuration); + }); + } + [SuppressMessage("Performance", "CA1859:Use concrete types when possible for improved performance")] private IServiceProvider BuildServiceProvider() { diff --git a/source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs b/source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs index 6dca7d9a..de45a6bf 100644 --- a/source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs +++ b/source/Cli/CreativeCoders.Cli.Hosting/ICliHostBuilder.cs @@ -2,6 +2,7 @@ using CreativeCoders.Cli.Core; using CreativeCoders.Cli.Hosting.Help; using JetBrains.Annotations; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace CreativeCoders.Cli.Hosting; @@ -95,6 +96,17 @@ ICliHostBuilder UseContext(Action? configu /// The same instance. ICliHostBuilder RegisterPostProcessor(Action? configure = null) where T : class, ICliPostProcessor; + /// + /// Configures the application using a custom configuration setup. + /// + /// + /// An action to configure the . The action allows adding sources, + /// modifying settings, or otherwise adjusting the configuration behavior. + /// + /// The same instance, enabling method chaining. + /// Thrown if the parameter is null. + ICliHostBuilder UseConfiguration(Action configure); + /// /// Builds and creates an instance of configured through the current builder. /// diff --git a/source/Configuration/CreativeCoders.Configuration/ConfigurationBuilderExtensions.cs b/source/Configuration/CreativeCoders.Configuration/ConfigurationBuilderExtensions.cs new file mode 100644 index 00000000..e33dba18 --- /dev/null +++ b/source/Configuration/CreativeCoders.Configuration/ConfigurationBuilderExtensions.cs @@ -0,0 +1,14 @@ +using CreativeCoders.Core.IO; +using Microsoft.Extensions.Configuration; + +namespace CreativeCoders.Configuration; + +public static class ConfigurationBuilderExtensions +{ + public static IConfigurationBuilder TryAddJsonFile(this IConfigurationBuilder builder, string path) + { + return FileSys.File.Exists(path) + ? builder.AddJsonFile(path) + : builder; + } +} diff --git a/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj b/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj new file mode 100644 index 00000000..6e9431b2 --- /dev/null +++ b/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj @@ -0,0 +1,18 @@ + + + + enable + enable + + + + + + + + + + + + + From d6cf0d7c4b1b753277763e5918cb97e3fb850752 Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Mon, 2 Mar 2026 13:00:24 +0100 Subject: [PATCH 2/3] chore: update package dependencies to latest versions - Upgraded multiple NuGet package references across source, sample, and test projects for consistency and security improvements. - Updated dependencies include `Microsoft.Extensions.*`, `FakeItEasy`, `AwesomeAssertions`, `coverlet.collector`, `xunit.runner.visualstudio`, and others. --- .../BlazorWebAssemblySampleApp.csproj | 6 +++--- samples/CakeBuildSample/CakeBuildSample.csproj | 2 +- samples/NetSampleApp/NetSampleApp.csproj | 2 +- .../ProcessUtilsSampleApp.csproj | 4 ++-- samples/WebApiSampleApp/WebApiSampleApp.csproj | 2 +- .../CreativeCoders.AspNetCore.Blazor.csproj | 6 +++--- ...ativeCoders.AspNetCore.TokenAuth.Jwt.csproj | 4 ++-- ...veCoders.AspNetCore.TokenAuthApi.Jwt.csproj | 2 +- .../CreativeCoders.AspNetCore.csproj | 2 +- .../CreativeCoders.CakeBuild.csproj | 4 ++-- .../CreativeCoders.Cli.Hosting.csproj | 8 ++++---- .../CreativeCoders.Config.csproj | 2 +- .../CreativeCoders.Configuration.csproj | 4 ++-- .../CreativeCoders.Core.csproj | 4 ++-- .../CreativeCoders.Daemon.Linux.csproj | 2 +- .../CreativeCoders.Daemon.Windows.csproj | 2 +- .../CreativeCoders.Daemon.csproj | 2 +- ...CreativeCoders.Data.EfCore.SqlServer.csproj | 2 +- .../CreativeCoders.Data.EfCore.csproj | 4 ++-- .../CreativeCoders.Data.Nhibernate.csproj | 2 +- .../CreativeCoders.Data.NoSql.csproj | 2 +- .../CreativeCoders.DependencyInjection.csproj | 4 ++-- .../CreativeCoders.IO.Archives.csproj | 2 +- .../CreativeCoders.IO.Ports.csproj | 2 +- .../CreativeCoders.Localization.csproj | 2 +- .../CreativeCoders.Net.JsonRpc.csproj | 2 +- .../CreativeCoders.Net.csproj | 4 ++-- .../CreativeCoders.Options.Core.csproj | 2 +- .../CreativeCoders.SysConsole.App.csproj | 6 +++--- ...reativeCoders.SysConsole.Cli.Parsing.csproj | 2 +- .../CreativeCoders.SysConsole.Core.csproj | 2 +- .../CreativeCoders.UnitTests.csproj | 6 +++--- ...veCoders.AspNetCore.Blazor.UnitTests.csproj | 8 ++++---- .../CreativeCoders.AspNetCore.Tests.csproj | 16 ++++++++-------- .../CreativeCoders.CakeBuild.Tests.csproj | 12 ++++++------ .../CreativeCoders.Cli.Tests.csproj | 10 +++++----- ...tiveCoders.CodeCompilation.UnitTests.csproj | 6 +++--- .../CreativeCoders.Core.UnitTests.csproj | 14 +++++++------- ...eativeCoders.Data.NoSql.LiteDb.Tests.csproj | 18 +++++++++--------- ...Coders.DependencyInjection.UnitTests.csproj | 12 ++++++------ .../CreativeCoders.IO.UnitTests.csproj | 12 ++++++------ ...reativeCoders.Localization.UnitTests.csproj | 14 +++++++------- .../CreativeCoders.Messaging.UnitTests.csproj | 6 +++--- .../CreativeCoders.MiscTest.UnitTests.csproj | 10 +++++----- .../CreativeCoders.Net.UnitTests.csproj | 10 +++++----- .../CreativeCoders.Reactive.UnitTests.csproj | 8 ++++---- .../CreativeCoders.Scripting.UnitTests.csproj | 8 ++++---- ...ativeCoders.SysConsole.App.UnitTests.csproj | 10 +++++----- ...ers.SysConsole.Cli.Actions.UnitTests.csproj | 16 ++++++++-------- ...ers.SysConsole.Cli.Parsing.UnitTests.csproj | 12 ++++++------ ...rs.SysConsole.CliArguments.UnitTests.csproj | 12 ++++++------ .../CreativeCoders.SysConsole.UnitTests.csproj | 10 +++++----- 52 files changed, 163 insertions(+), 163 deletions(-) diff --git a/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj b/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj index 3fc58281..7e8b615e 100644 --- a/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj +++ b/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj @@ -5,9 +5,9 @@ - - - + + + diff --git a/samples/CakeBuildSample/CakeBuildSample.csproj b/samples/CakeBuildSample/CakeBuildSample.csproj index d9b57ee9..3c4d09d0 100644 --- a/samples/CakeBuildSample/CakeBuildSample.csproj +++ b/samples/CakeBuildSample/CakeBuildSample.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/NetSampleApp/NetSampleApp.csproj b/samples/NetSampleApp/NetSampleApp.csproj index f455010b..cc635ea2 100644 --- a/samples/NetSampleApp/NetSampleApp.csproj +++ b/samples/NetSampleApp/NetSampleApp.csproj @@ -6,7 +6,7 @@ - + diff --git a/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj b/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj index d83e26c7..0830cd43 100644 --- a/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj +++ b/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/samples/WebApiSampleApp/WebApiSampleApp.csproj b/samples/WebApiSampleApp/WebApiSampleApp.csproj index 7385823e..aa8bb3c1 100644 --- a/samples/WebApiSampleApp/WebApiSampleApp.csproj +++ b/samples/WebApiSampleApp/WebApiSampleApp.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj index 8ac2b29c..2ecd4107 100644 --- a/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj +++ b/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj index db97aea3..ce7d6366 100644 --- a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj +++ b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj index 9710e1fa..1c8e8b2e 100644 --- a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj +++ b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj @@ -8,7 +8,7 @@ - + diff --git a/source/AspNetCore/CreativeCoders.AspNetCore/CreativeCoders.AspNetCore.csproj b/source/AspNetCore/CreativeCoders.AspNetCore/CreativeCoders.AspNetCore.csproj index 2b622ced..f94c535d 100644 --- a/source/AspNetCore/CreativeCoders.AspNetCore/CreativeCoders.AspNetCore.csproj +++ b/source/AspNetCore/CreativeCoders.AspNetCore/CreativeCoders.AspNetCore.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj b/source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj index 32004047..ee9f4957 100644 --- a/source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj +++ b/source/CakeBuild/CreativeCoders.CakeBuild/CreativeCoders.CakeBuild.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj b/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj index 225bd357..9f106a54 100644 --- a/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj +++ b/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj @@ -13,10 +13,10 @@ - - - - + + + + diff --git a/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj b/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj index 4fded7a2..c3190728 100644 --- a/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj +++ b/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj b/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj index 6e9431b2..a894e8ee 100644 --- a/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj +++ b/source/Configuration/CreativeCoders.Configuration/CreativeCoders.Configuration.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj b/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj index 4b7c18f0..221e8e76 100644 --- a/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj +++ b/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj b/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj index 8d844bca..2e4a8486 100644 --- a/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj +++ b/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj b/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj index 848c41e7..dc165188 100644 --- a/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj +++ b/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj b/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj index 4c1a82f0..8278679e 100644 --- a/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj +++ b/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj @@ -8,7 +8,7 @@ - + diff --git a/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj b/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj index 99f63b4d..1d25ee3c 100644 --- a/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj +++ b/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj b/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj index 34221f6c..f1a86cac 100644 --- a/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj +++ b/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj b/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj index 09bb7859..0ff2f305 100644 --- a/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj +++ b/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj b/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj index 72459f62..3bf9a5f7 100644 --- a/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj +++ b/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj @@ -8,7 +8,7 @@ - + diff --git a/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj b/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj index 8d94c9c6..fb52a3a1 100644 --- a/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj +++ b/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/source/IO/CreativeCoders.IO.Archives/CreativeCoders.IO.Archives.csproj b/source/IO/CreativeCoders.IO.Archives/CreativeCoders.IO.Archives.csproj index 8ef18b86..6232f010 100644 --- a/source/IO/CreativeCoders.IO.Archives/CreativeCoders.IO.Archives.csproj +++ b/source/IO/CreativeCoders.IO.Archives/CreativeCoders.IO.Archives.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/IO/CreativeCoders.IO.Ports/CreativeCoders.IO.Ports.csproj b/source/IO/CreativeCoders.IO.Ports/CreativeCoders.IO.Ports.csproj index 83d2209e..4b2465e0 100644 --- a/source/IO/CreativeCoders.IO.Ports/CreativeCoders.IO.Ports.csproj +++ b/source/IO/CreativeCoders.IO.Ports/CreativeCoders.IO.Ports.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj b/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj index d8831c3f..219d2e1d 100644 --- a/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj +++ b/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj b/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj index 08573ab0..ed861ecf 100644 --- a/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj +++ b/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj @@ -12,7 +12,7 @@ - + diff --git a/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj b/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj index d2420a43..bacc8caa 100644 --- a/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj +++ b/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj @@ -6,9 +6,9 @@ - + - + diff --git a/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj b/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj index 919ffdd9..c07c53b6 100644 --- a/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj +++ b/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj b/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj index a9815d62..a2f8a463 100644 --- a/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj +++ b/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj index 22e11379..13ec4e99 100644 --- a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj +++ b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj @@ -6,7 +6,7 @@ - + diff --git a/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj b/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj index e5f8ff50..59bb26b2 100644 --- a/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj +++ b/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj b/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj index 3c7f57c5..73863f11 100644 --- a/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj +++ b/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj b/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj index 7f098e87..c37439a6 100644 --- a/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj +++ b/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj @@ -5,19 +5,19 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj b/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj index fd48092a..81a0232a 100644 --- a/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj +++ b/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj @@ -7,23 +7,23 @@ - - + + - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.CakeBuild.Tests/CreativeCoders.CakeBuild.Tests.csproj b/tests/CreativeCoders.CakeBuild.Tests/CreativeCoders.CakeBuild.Tests.csproj index 4609ffff..af872225 100644 --- a/tests/CreativeCoders.CakeBuild.Tests/CreativeCoders.CakeBuild.Tests.csproj +++ b/tests/CreativeCoders.CakeBuild.Tests/CreativeCoders.CakeBuild.Tests.csproj @@ -10,23 +10,23 @@ - - - + + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj b/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj index 81b25691..ead5f805 100644 --- a/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj +++ b/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj @@ -6,22 +6,22 @@ - - + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj b/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj index b482c848..eafd70a8 100644 --- a/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj +++ b/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj @@ -5,17 +5,17 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj b/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj index b51018e0..7f9b4205 100644 --- a/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj +++ b/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj @@ -5,22 +5,22 @@ - - + + - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj b/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj index ee6ff5f8..24e3eb3e 100644 --- a/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj +++ b/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj @@ -7,23 +7,23 @@ - - - - - - - + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj b/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj index 54b34b79..d0d5e06d 100644 --- a/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj +++ b/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj @@ -7,20 +7,20 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj b/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj index bd4edd14..13ab176d 100644 --- a/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj +++ b/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj @@ -6,21 +6,21 @@ - - + + - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj b/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj index aa5f39d9..a55d1884 100644 --- a/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj +++ b/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj @@ -5,21 +5,21 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj b/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj index a2ac5f21..818e4761 100644 --- a/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj +++ b/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj @@ -6,17 +6,17 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj b/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj index c6287dab..04f5edaa 100644 --- a/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj +++ b/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj @@ -7,21 +7,21 @@ - - + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj b/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj index 94a46fb9..1330e5f4 100644 --- a/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj +++ b/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj @@ -5,19 +5,19 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj b/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj index 98a6c101..fd52523e 100644 --- a/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj +++ b/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj @@ -5,19 +5,19 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj b/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj index e5823eb7..83705971 100644 --- a/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj +++ b/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj @@ -5,18 +5,18 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj b/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj index 8a77f2d1..26377e55 100644 --- a/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj +++ b/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj @@ -6,19 +6,19 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj b/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj index 16a3b071..1db70d40 100644 --- a/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj +++ b/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj @@ -10,22 +10,22 @@ - - - - - - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj index 488f35b8..6199f883 100644 --- a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj +++ b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj @@ -6,20 +6,20 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj b/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj index 1590ee63..479eb479 100644 --- a/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj +++ b/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj @@ -6,20 +6,20 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj b/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj index c98979df..6261acee 100644 --- a/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj +++ b/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj @@ -7,19 +7,19 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + From 243ef5559e220d48beb283aafc679425b563283c Mon Sep 17 00:00:00 2001 From: darthsharp <48331467+darthsharp@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:25:35 +0100 Subject: [PATCH 3/3] feat(cli hosting): add configuration support to unit tests and integration tests - Introduced tests for `UseConfiguration` extension in `DefaultCliHostBuilder` to validate service registration. - Added integration test to ensure commands can access configuration settings at runtime. - Enhanced CLI framework with configuration sample commands for testing. --- .../Hosting/CliHostingIntegrationTests.cs | 66 +++++++++++++ .../Hosting/DefaultCliHostBuilderTests.cs | 92 +++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/tests/CreativeCoders.Cli.Tests/Hosting/CliHostingIntegrationTests.cs b/tests/CreativeCoders.Cli.Tests/Hosting/CliHostingIntegrationTests.cs index 1ac5fd04..0ef9fcd3 100644 --- a/tests/CreativeCoders.Cli.Tests/Hosting/CliHostingIntegrationTests.cs +++ b/tests/CreativeCoders.Cli.Tests/Hosting/CliHostingIntegrationTests.cs @@ -5,6 +5,7 @@ using CreativeCoders.Cli.Hosting.Help; using CreativeCoders.SysConsole.Cli.Parsing; using JetBrains.Annotations; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Spectre.Console; using Xunit; @@ -129,6 +130,29 @@ public async Task RunAsync_WhenCommandConstructionFails_ReturnsConstructionFaile await output.DisposeAsync(); } + [Fact] + public async Task RunAsync_WhenConfigurationIsUsed_CommandCanAccessConfiguration() + { + // Arrange + var host = CreateHostWithConfiguration(out var output); + + // Act + var result = await host.RunAsync(["int", "config"]); + + // Assert + result.ExitCode + .Should() + .Be(CliExitCodes.Success); + + output.ToString() + .Should() + .Contain("AppName: TestApp") + .And + .Contain("Version: 1.0.0"); + + await output.DisposeAsync(); + } + private static ICliHost CreateHostWithOutput(out StringWriter output) { var writer = new StringWriter(); @@ -150,6 +174,35 @@ private static ICliHost CreateHostWithOutput(out StringWriter output) .Build(); } + private static ICliHost CreateHostWithConfiguration(out StringWriter output) + { + var writer = new StringWriter(); + Console.SetOut(writer); + output = writer; + + return CliHostBuilder.Create() + .SkipScanEntryAssembly() + .ScanAssemblies(Assembly.GetExecutingAssembly()) + .EnableHelp(HelpCommandKind.Command) + .UseConfiguration(config => + { + config.AddInMemoryCollection(new Dictionary + { + { "AppName", "TestApp" }, + { "Version", "1.0.0" } + }); + }) + .ConfigureServices(services => + { + services.AddSingleton(_ => + AnsiConsole.Create(new AnsiConsoleSettings + { + Out = new AnsiConsoleOutput(writer) + })); + }) + .Build(); + } + [UsedImplicitly] [CliCommand(["int", "simple"], Description = "simple command")] private sealed class SimpleCommand(IAnsiConsole ansiConsole) : ICliCommand @@ -203,4 +256,17 @@ public Task ExecuteAsync() return Task.FromResult(new CommandResult()); } } + + [UsedImplicitly] + [CliCommand(["int", "config"], Description = "configuration command")] + private sealed class ConfigCommand(IAnsiConsole ansiConsole, IConfiguration configuration) : ICliCommand + { + public Task ExecuteAsync() + { + ansiConsole.WriteLine($"AppName: {configuration["AppName"]}"); + ansiConsole.WriteLine($"Version: {configuration["Version"]}"); + + return Task.FromResult(new CommandResult { ExitCode = CliExitCodes.Success }); + } + } } diff --git a/tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostBuilderTests.cs b/tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostBuilderTests.cs index 37196103..7c7bac87 100644 --- a/tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostBuilderTests.cs +++ b/tests/CreativeCoders.Cli.Tests/Hosting/DefaultCliHostBuilderTests.cs @@ -8,6 +8,7 @@ using CreativeCoders.Cli.Hosting.Help; using FakeItEasy; using JetBrains.Annotations; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -331,6 +332,97 @@ public void DontUseValidation_SettingsNotAddedToServicesOrSettingsUseValidationI .Should().NotBe(true); } + [Fact] + public void UseConfiguration_AddsConfigurationToServices() + { + // Arrange + var builder = CreateBuilder(); + + builder.SkipScanEntryAssembly(); + + builder.UseConfiguration(config => + { + config.AddInMemoryCollection(new Dictionary + { + { "TestKey", "TestValue" }, + { "TestNumber", "42" } + }); + }); + + var commandScanner = A.Fake(); + var commandStore = A.Fake(); + var validator = A.Fake(); + var cliHost = A.Fake(); + + A.CallTo(() => commandScanner.ScanForCommands(A.Ignored)) + .Returns(CreateScanResult()); + + SubstituteServices(builder, commandScanner, commandStore, validator, cliHost); + + var services = GetBuiltServiceProvider(builder); + + // Act + builder.Build(); + + // Assert + var configuration = services.GetRequiredService(); + + configuration + .Should() + .NotBeNull(); + + configuration["TestKey"] + .Should() + .Be("TestValue"); + + configuration["TestNumber"] + .Should() + .Be("42"); + } + + [Fact] + public void UseConfiguration_AddsConfigurationRootToServices() + { + // Arrange + var builder = CreateBuilder(); + + builder.SkipScanEntryAssembly(); + + builder.UseConfiguration(config => + { + config.AddInMemoryCollection(new Dictionary + { + { "Key", "Value" } + }); + }); + + var commandScanner = A.Fake(); + var commandStore = A.Fake(); + var validator = A.Fake(); + var cliHost = A.Fake(); + + A.CallTo(() => commandScanner.ScanForCommands(A.Ignored)) + .Returns(CreateScanResult()); + + SubstituteServices(builder, commandScanner, commandStore, validator, cliHost); + + var services = GetBuiltServiceProvider(builder); + + // Act + builder.Build(); + + // Assert + var configurationRoot = services.GetRequiredService(); + + configurationRoot + .Should() + .NotBeNull(); + + configurationRoot["Key"] + .Should() + .Be("Value"); + } + private static DefaultCliHostBuilder CreateBuilder() { return new DefaultCliHostBuilder();