From 465726bcd8cc11f0396d1724230d685edc685bd9 Mon Sep 17 00:00:00 2001 From: mauricel Date: Tue, 30 Mar 2021 14:29:58 +0100 Subject: [PATCH] #13 - Fix tests - add stubs for FileSystem. --- CliFx.Tests/ApplicationSpecs.cs | 7 ++++-- CliFx.Tests/CancellationSpecs.cs | 1 + CliFx.Tests/ConsoleSpecs.cs | 2 ++ CliFx.Tests/ConversionSpecs.cs | 22 +++++++++++++++++ CliFx.Tests/DirectivesSpecs.cs | 1 + CliFx.Tests/EnvironmentSpecs.cs | 5 ++++ CliFx.Tests/ErrorReportingSpecs.cs | 5 ++++ CliFx.Tests/HelpTextSpecs.cs | 21 ++++++++++++++++ CliFx.Tests/OptionBindingSpecs.cs | 17 +++++++++++++ CliFx.Tests/ParameterBindingSpecs.cs | 5 ++++ CliFx.Tests/RoutingSpecs.cs | 3 +++ CliFx.Tests/SpecsBase.cs | 2 ++ CliFx.Tests/SuggestDirectiveSpecs.cs | 3 ++- CliFx.Tests/TypeActivationSpecs.cs | 4 ++++ CliFx/CliApplicationBuilder.cs | 2 +- CliFx/Infrastructure/FakeFileSystem.cs | 33 ++++++++++++++++++++++++++ CliFx/Infrastructure/FileSystem.cs | 2 ++ CliFx/Infrastructure/NullFileSystem.cs | 27 +++++++++++++++++++++ 18 files changed, 158 insertions(+), 4 deletions(-) create mode 100644 CliFx/Infrastructure/FakeFileSystem.cs create mode 100644 CliFx/Infrastructure/NullFileSystem.cs diff --git a/CliFx.Tests/ApplicationSpecs.cs b/CliFx.Tests/ApplicationSpecs.cs index ad469fce..390fa93c 100644 --- a/CliFx.Tests/ApplicationSpecs.cs +++ b/CliFx.Tests/ApplicationSpecs.cs @@ -22,6 +22,7 @@ public async Task Application_can_be_created_with_minimal_configuration() var app = new CliApplicationBuilder() .AddCommandsFromThisAssembly() .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); var exitCode = await app.RunAsync( @@ -40,8 +41,8 @@ public async Task Application_can_be_created_with_a_fully_customized_configurati var app = new CliApplicationBuilder() .AddCommand() .AddCommandsFrom(typeof(NoOpCommand).Assembly) - .AddCommands(new[] {typeof(NoOpCommand)}) - .AddCommandsFrom(new[] {typeof(NoOpCommand).Assembly}) + .AddCommands(new[] { typeof(NoOpCommand) }) + .AddCommandsFrom(new[] { typeof(NoOpCommand).Assembly }) .AddCommandsFromThisAssembly() .AllowDebugMode() .AllowPreviewMode() @@ -50,6 +51,7 @@ public async Task Application_can_be_created_with_a_fully_customized_configurati .SetVersion("test") .SetDescription("test") .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .UseTypeActivator(Activator.CreateInstance!) .Build(); @@ -69,6 +71,7 @@ public async Task Application_configuration_fails_if_an_invalid_command_is_regis var app = new CliApplicationBuilder() .AddCommand(typeof(ApplicationSpecs)) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); var exitCode = await app.RunAsync( diff --git a/CliFx.Tests/CancellationSpecs.cs b/CliFx.Tests/CancellationSpecs.cs index 4bbc166f..eca79a3d 100644 --- a/CliFx.Tests/CancellationSpecs.cs +++ b/CliFx.Tests/CancellationSpecs.cs @@ -47,6 +47,7 @@ public async ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/ConsoleSpecs.cs b/CliFx.Tests/ConsoleSpecs.cs index 7b7715aa..f1d8ee03 100644 --- a/CliFx.Tests/ConsoleSpecs.cs +++ b/CliFx.Tests/ConsoleSpecs.cs @@ -66,6 +66,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -117,6 +118,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/ConversionSpecs.cs b/CliFx.Tests/ConversionSpecs.cs index b58c5507..61d7e325 100644 --- a/CliFx.Tests/ConversionSpecs.cs +++ b/CliFx.Tests/ConversionSpecs.cs @@ -38,6 +38,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -76,6 +77,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -119,6 +121,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -160,6 +163,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -198,6 +202,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -236,6 +241,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -274,6 +280,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -312,6 +319,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -352,6 +360,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -395,6 +404,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -443,6 +453,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -491,6 +502,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -554,6 +566,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -601,6 +614,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -641,6 +655,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -685,6 +700,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -729,6 +745,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -773,6 +790,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -811,6 +829,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -847,6 +866,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -888,6 +908,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -932,6 +953,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/DirectivesSpecs.cs b/CliFx.Tests/DirectivesSpecs.cs index d4707ac9..9969b563 100644 --- a/CliFx.Tests/DirectivesSpecs.cs +++ b/CliFx.Tests/DirectivesSpecs.cs @@ -85,6 +85,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .AllowPreviewMode() .Build(); diff --git a/CliFx.Tests/EnvironmentSpecs.cs b/CliFx.Tests/EnvironmentSpecs.cs index fea1f263..1777da9a 100644 --- a/CliFx.Tests/EnvironmentSpecs.cs +++ b/CliFx.Tests/EnvironmentSpecs.cs @@ -43,6 +43,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -85,6 +86,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -129,6 +131,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -174,6 +177,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -216,6 +220,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/ErrorReportingSpecs.cs b/CliFx.Tests/ErrorReportingSpecs.cs index ea34eb8b..35846b7b 100644 --- a/CliFx.Tests/ErrorReportingSpecs.cs +++ b/CliFx.Tests/ErrorReportingSpecs.cs @@ -34,6 +34,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -72,6 +73,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -111,6 +113,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -146,6 +149,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -184,6 +188,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .SetDescription("This will be in help text") .Build(); diff --git a/CliFx.Tests/HelpTextSpecs.cs b/CliFx.Tests/HelpTextSpecs.cs index 3fcba112..346440d2 100644 --- a/CliFx.Tests/HelpTextSpecs.cs +++ b/CliFx.Tests/HelpTextSpecs.cs @@ -22,6 +22,7 @@ public async Task Help_text_is_printed_if_no_arguments_are_provided_and_the_defa // Arrange var application = new CliApplicationBuilder() .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .SetDescription("This will be in help text") .Build(); @@ -55,6 +56,7 @@ public class DefaultCommand : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .SetDescription("This will be in help text") .Build(); @@ -94,6 +96,7 @@ public class NamedChildCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .SetDescription("This will be in help text") .Build(); @@ -139,6 +142,7 @@ public class NamedChildCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -183,6 +187,7 @@ public class NamedChildCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -205,6 +210,7 @@ public async Task Help_text_is_printed_on_invalid_user_input() var application = new CliApplicationBuilder() .AddCommand() .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .SetDescription("This will be in help text") .Build(); @@ -229,6 +235,7 @@ public async Task Help_text_shows_application_metadata() // Arrange var application = new CliApplicationBuilder() .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .SetTitle("App title") .SetDescription("App description") .SetVersion("App version") @@ -268,6 +275,7 @@ public class DefaultCommand : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -309,6 +317,7 @@ public class NamedCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -353,6 +362,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -397,6 +407,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -438,6 +449,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -475,6 +487,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -511,6 +524,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -557,6 +571,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -602,6 +617,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -664,6 +680,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -718,6 +735,7 @@ public class SecondCommandChildCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -784,6 +802,7 @@ public class SecondCommandSecondChildCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -832,6 +851,7 @@ public class SecondCommandSecondChildCommand : ICommand var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -860,6 +880,7 @@ public async Task Version_text_is_printed_if_provided_arguments_contain_the_vers .AddCommand() .SetVersion("v6.9") .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/OptionBindingSpecs.cs b/CliFx.Tests/OptionBindingSpecs.cs index e61a8945..0c06439d 100644 --- a/CliFx.Tests/OptionBindingSpecs.cs +++ b/CliFx.Tests/OptionBindingSpecs.cs @@ -39,6 +39,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -77,6 +78,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -120,6 +122,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -166,6 +169,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -212,6 +216,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -255,6 +260,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -299,6 +305,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -343,6 +350,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -387,6 +395,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -431,6 +440,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -478,6 +488,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -520,6 +531,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -554,6 +566,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -588,6 +601,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -622,6 +636,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -656,6 +671,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -690,6 +706,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/ParameterBindingSpecs.cs b/CliFx.Tests/ParameterBindingSpecs.cs index 3b4a3989..b2925ae4 100644 --- a/CliFx.Tests/ParameterBindingSpecs.cs +++ b/CliFx.Tests/ParameterBindingSpecs.cs @@ -43,6 +43,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -98,6 +99,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -141,6 +143,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -178,6 +181,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -215,6 +219,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/RoutingSpecs.cs b/CliFx.Tests/RoutingSpecs.cs index b989285f..2a8aed08 100644 --- a/CliFx.Tests/RoutingSpecs.cs +++ b/CliFx.Tests/RoutingSpecs.cs @@ -56,6 +56,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -112,6 +113,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act @@ -168,6 +170,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommands(commandTypes) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .Build(); // Act diff --git a/CliFx.Tests/SpecsBase.cs b/CliFx.Tests/SpecsBase.cs index 035b6b9d..ed6d4185 100644 --- a/CliFx.Tests/SpecsBase.cs +++ b/CliFx.Tests/SpecsBase.cs @@ -11,6 +11,8 @@ public abstract class SpecsBase : IDisposable public FakeInMemoryConsole FakeConsole { get; } = new(); + public NullFileSystem NullFileSystem { get; } = new(); + protected SpecsBase(ITestOutputHelper testOutput) => TestOutput = testOutput; diff --git a/CliFx.Tests/SuggestDirectiveSpecs.cs b/CliFx.Tests/SuggestDirectiveSpecs.cs index 19812744..c14a74ef 100644 --- a/CliFx.Tests/SuggestDirectiveSpecs.cs +++ b/CliFx.Tests/SuggestDirectiveSpecs.cs @@ -44,7 +44,8 @@ public CliApplicationBuilder TestApplicationFactory(params string[] commandClass builder = builder.AddCommand(commandType); }); - return builder.UseConsole(FakeConsole); + return builder.UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem); } [Theory] diff --git a/CliFx.Tests/TypeActivationSpecs.cs b/CliFx.Tests/TypeActivationSpecs.cs index 40924b7f..29760e20 100644 --- a/CliFx.Tests/TypeActivationSpecs.cs +++ b/CliFx.Tests/TypeActivationSpecs.cs @@ -36,6 +36,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .UseTypeActivator(new DefaultTypeActivator()) .Build(); @@ -70,6 +71,7 @@ public class Command : ICommand var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .UseTypeActivator(new DefaultTypeActivator()) .Build(); @@ -110,6 +112,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .UseTypeActivator(type => Activator.CreateInstance(type, "hello world")!) .Build(); @@ -146,6 +149,7 @@ public ValueTask ExecuteAsync(IConsole console) var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) + .UseFileSystem(NullFileSystem) .UseTypeActivator(_ => null!) .Build(); diff --git a/CliFx/CliApplicationBuilder.cs b/CliFx/CliApplicationBuilder.cs index e0947a5c..e647fa7d 100644 --- a/CliFx/CliApplicationBuilder.cs +++ b/CliFx/CliApplicationBuilder.cs @@ -182,7 +182,7 @@ public CliApplicationBuilder UseConsole(IConsole console) /// /// Configures the application to use the specified implementation of . /// - CliApplicationBuilder UseFileSystem(IFileSystem fileSystem) + public CliApplicationBuilder UseFileSystem(IFileSystem fileSystem) { _fileSystem = fileSystem; return this; diff --git a/CliFx/Infrastructure/FakeFileSystem.cs b/CliFx/Infrastructure/FakeFileSystem.cs new file mode 100644 index 00000000..9e0451dc --- /dev/null +++ b/CliFx/Infrastructure/FakeFileSystem.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CliFx.Infrastructure +{ + public class FakeSystem : IFileSystem + { + public Dictionary Files => new Dictionary(); + + public void Copy(string sourceFileName, string destFileName) + { + Files[destFileName] = Files[sourceFileName]; + } + + public bool Exists(string path) + { + return Files.ContainsKey(path); + } + + public string ReadAllText(string path) + { + return Files[path]; + } + + public void WriteAllText(string path, string content) + { + Files[path] = content; + } + } + + +} diff --git a/CliFx/Infrastructure/FileSystem.cs b/CliFx/Infrastructure/FileSystem.cs index 4b81291a..006988f8 100644 --- a/CliFx/Infrastructure/FileSystem.cs +++ b/CliFx/Infrastructure/FileSystem.cs @@ -24,4 +24,6 @@ public void WriteAllText(string path, string content) File.WriteAllText(path, content); } } + + } diff --git a/CliFx/Infrastructure/NullFileSystem.cs b/CliFx/Infrastructure/NullFileSystem.cs new file mode 100644 index 00000000..8e7a1713 --- /dev/null +++ b/CliFx/Infrastructure/NullFileSystem.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CliFx.Infrastructure +{ + public class NullFileSystem : IFileSystem + { + public void Copy(string sourceFileName, string destFileName) + { + } + + public bool Exists(string path) + { + return false; + } + + public string ReadAllText(string path) + { + return ""; + } + + public void WriteAllText(string path, string content) + { + } + } +}