From aac9c968eb82446fe1acdb494d705910c85ef339 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 8 Dec 2022 03:06:31 +0200 Subject: [PATCH] Use raw string literals --- .../CommandMustBeAnnotatedAnalyzerSpecs.cs | 50 +- ...mandMustImplementInterfaceAnalyzerSpecs.cs | 40 +- .../OptionMustBeInsideCommandAnalyzerSpecs.cs | 62 +- ...ionMustHaveNameOrShortNameAnalyzerSpecs.cs | 78 +- .../OptionMustHaveUniqueNameAnalyzerSpecs.cs | 90 ++- ...ionMustHaveUniqueShortNameAnalyzerSpecs.cs | 116 +-- ...tionMustHaveValidConverterAnalyzerSpecs.cs | 188 ++--- .../OptionMustHaveValidNameAnalyzerSpecs.cs | 98 +-- ...tionMustHaveValidShortNameAnalyzerSpecs.cs | 78 +- ...ionMustHaveValidValidatorsAnalyzerSpecs.cs | 128 +-- ...rameterMustBeInsideCommandAnalyzerSpecs.cs | 66 +- ...terMustBeLastIfNonRequiredAnalyzerSpecs.cs | 96 +-- ...meterMustBeLastIfNonScalarAnalyzerSpecs.cs | 96 +-- ...rMustBeSingleIfNonRequiredAnalyzerSpecs.cs | 96 +-- ...terMustBeSingleIfNonScalarAnalyzerSpecs.cs | 96 +-- ...arameterMustHaveUniqueNameAnalyzerSpecs.cs | 70 +- ...rameterMustHaveUniqueOrderAnalyzerSpecs.cs | 70 +- ...eterMustHaveValidConverterAnalyzerSpecs.cs | 188 ++--- ...terMustHaveValidValidatorsAnalyzerSpecs.cs | 128 +-- ...stemConsoleShouldBeAvoidedAnalyzerSpecs.cs | 127 +-- CliFx.Tests/CancellationSpecs.cs | 44 +- CliFx.Tests/ConsoleSpecs.cs | 93 +-- CliFx.Tests/ConversionSpecs.cs | 728 ++++++++++-------- CliFx.Tests/DirectivesSpecs.cs | 15 +- CliFx.Tests/EnvironmentSpecs.cs | 137 ++-- CliFx.Tests/ErrorReportingSpecs.cs | 85 +- CliFx.Tests/HelpTextSpecs.cs | 642 +++++++-------- CliFx.Tests/OptionBindingSpecs.cs | 521 +++++++------ CliFx.Tests/ParameterBindingSpecs.cs | 174 +++-- CliFx.Tests/RoutingSpecs.cs | 177 ++--- CliFx.Tests/TypeActivationSpecs.cs | 112 +-- 31 files changed, 2513 insertions(+), 2176 deletions(-) diff --git a/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs index 8b5567b..f7b51ea 100644 --- a/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/CommandMustBeAnnotatedAnalyzerSpecs.cs @@ -13,11 +13,13 @@ public class CommandMustBeAnnotatedAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -28,12 +30,14 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public abstract class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public abstract class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -44,11 +48,13 @@ public abstract class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public abstract class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public abstract class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -59,11 +65,13 @@ public abstract class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class Foo -{ - public int Bar { get; set; } = 5; -}"; + const string code = + """ + public class Foo + { + public int Bar { get; set; } = 5; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs index 65b9449..47bc3b7 100644 --- a/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/CommandMustImplementInterfaceAnalyzerSpecs.cs @@ -13,12 +13,14 @@ public class CommandMustImplementInterfaceAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -29,12 +31,14 @@ public class MyCommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -45,11 +49,13 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class Foo -{ - public int Bar { get; set; } = 5; -}"; + const string code = + """ + public class Foo + { + public int Bar { get; set; } = 5; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs index 5db9e69..bc249a4 100644 --- a/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustBeInsideCommandAnalyzerSpecs.cs @@ -13,12 +13,14 @@ public class OptionMustBeInsideCommandAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyClass -{ - [CommandOption(""foo"")] - public string Foo { get; set; } -}"; + const string code = + """ + public class MyClass + { + [CommandOption("foo")] + public string Foo { get; set; } + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -29,15 +31,17 @@ public class MyClass { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -48,12 +52,14 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public abstract class MyCommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } -}"; + const string code = + """ + public abstract class MyCommand + { + [CommandOption("foo")] + public string Foo { get; set; } + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -64,14 +70,16 @@ public abstract class MyCommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs index dce4010..570cf6f 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveNameOrShortNameAnalyzerSpecs.cs @@ -13,15 +13,17 @@ public class OptionMustHaveNameOrShortNameAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(null)] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption(null)] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -32,15 +34,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -51,15 +55,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -70,14 +76,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs index 18a4837..40d7bc3 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveUniqueNameAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - [CommandOption(""foo"")] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + [CommandOption("foo")] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - [CommandOption(""bar"")] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + [CommandOption("bar")] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,15 +61,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -76,14 +82,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs index 80a2177..0030805 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveUniqueShortNameAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - [CommandOption('f')] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + [CommandOption('f')] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - [CommandOption('b')] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + [CommandOption('b')] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,18 +61,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - [CommandOption('F')] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + [CommandOption('F')] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -79,15 +85,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -98,14 +106,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs index 73788b6..3a4d933 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidConverterAnalyzerSpecs.cs @@ -13,20 +13,22 @@ public class OptionMustHaveValidConverterAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyConverter -{ - public string Convert(string rawValue) => rawValue; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Converter = typeof(MyConverter))] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter + { + public string Convert(string rawValue) => rawValue; + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Converter = typeof(MyConverter))] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -37,20 +39,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override int Convert(string rawValue) => 42; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Converter = typeof(MyConverter))] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override int Convert(string rawValue) => 42; + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Converter = typeof(MyConverter))] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -61,20 +65,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override string Convert(string rawValue) => rawValue; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Converter = typeof(MyConverter))] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override string Convert(string rawValue) => rawValue; + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Converter = typeof(MyConverter))] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -85,20 +91,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override int Convert(string rawValue) => 42; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Converter = typeof(MyConverter))] - public int? Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override int Convert(string rawValue) => 42; + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Converter = typeof(MyConverter))] + public int? Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -109,20 +117,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override string Convert(string rawValue) => rawValue; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Converter = typeof(MyConverter))] - public IReadOnlyList Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override string Convert(string rawValue) => rawValue; + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Converter = typeof(MyConverter))] + public IReadOnlyList Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -133,15 +143,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -152,14 +164,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs index 665ede0..a8b4ca5 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidNameAnalyzerSpecs.cs @@ -13,15 +13,17 @@ public class OptionMustHaveValidNameAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""f"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("f")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -32,15 +34,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""1foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("1foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -51,15 +55,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -70,15 +76,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -89,14 +97,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs index 1e3eea8..8f2fe94 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidShortNameAnalyzerSpecs.cs @@ -13,15 +13,17 @@ public class OptionMustHaveValidShortNameAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('1')] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('1')] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -32,15 +34,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -51,15 +55,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -70,14 +76,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs index c9ae82a..05ea6e4 100644 --- a/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/OptionMustHaveValidValidatorsAnalyzerSpecs.cs @@ -13,20 +13,22 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyValidator -{ - public void Validate(string value) {} -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyValidator + { + public void Validate(string value) {} + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Validators = new[] {typeof(MyValidator)})] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -37,20 +39,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyValidator : BindingValidator -{ - public override BindingValidationError Validate(int value) => Ok(); -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyValidator : BindingValidator + { + public override BindingValidationError Validate(int value) => Ok(); + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Validators = new[] {typeof(MyValidator)})] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -61,20 +65,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyValidator : BindingValidator -{ - public override BindingValidationError Validate(string value) => Ok(); -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyValidator : BindingValidator + { + public override BindingValidationError Validate(string value) => Ok(); + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Validators = new[] {typeof(MyValidator)})] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -85,15 +91,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -104,14 +112,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs index d436230..6f336f9 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeInsideCommandAnalyzerSpecs.cs @@ -13,12 +13,14 @@ public class ParameterMustBeInsideCommandAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyClass -{ - [CommandParameter(0)] - public string Foo { get; set; } -}"; + const string code = + """ + public class MyClass + { + [CommandParameter(0)] + public string Foo { get; set; } + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -29,15 +31,17 @@ public class MyClass { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -48,12 +52,14 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public abstract class MyCommand -{ - [CommandParameter(0)] - public string Foo { get; set; } -}"; + const string code = + """ + public abstract class MyCommand + { + [CommandParameter(0)] + public string Foo { get; set; } + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -64,14 +70,16 @@ public abstract class MyCommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs index da48dba..ff240df 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonRequiredAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Name = ""foo"", IsRequired = false)] - public string Foo { get; set; } - - [CommandParameter(1, Name = ""bar"")] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Name = "foo", IsRequired = false)] + public string Foo { get; set; } + + [CommandParameter(1, Name = "bar")] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Name = ""foo"")] - public string Foo { get; set; } - - [CommandParameter(1, Name = ""bar"", IsRequired = false)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Name = "foo")] + public string Foo { get; set; } + + [CommandParameter(1, Name = "bar", IsRequired = false)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,18 +61,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Name = ""foo"")] - public string Foo { get; set; } - - [CommandParameter(1, Name = ""bar"", IsRequired = true)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Name = "foo")] + public string Foo { get; set; } + + [CommandParameter(1, Name = "bar", IsRequired = true)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -79,14 +85,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs index 13fa257..711f815 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeLastIfNonScalarAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string[] Foo { get; set; } - - [CommandParameter(1)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string[] Foo { get; set; } + + [CommandParameter(1)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1)] - public string[] Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1)] + public string[] Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,18 +61,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -79,14 +85,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs index 9de264e..bcdaa71 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonRequiredAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, IsRequired = false)] - public string Foo { get; set; } - - [CommandParameter(1, IsRequired = false)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, IsRequired = false)] + public string Foo { get; set; } + + [CommandParameter(1, IsRequired = false)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1, IsRequired = false)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1, IsRequired = false)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,18 +61,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1, IsRequired = true)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1, IsRequired = true)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -79,14 +85,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs index 0718cc0..053968d 100644 --- a/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustBeSingleIfNonScalarAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string[] Foo { get; set; } - - [CommandParameter(1)] - public string[] Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string[] Foo { get; set; } + + [CommandParameter(1)] + public string[] Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1)] - public string[] Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1)] + public string[] Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,18 +61,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -79,14 +85,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs index 2529b98..f9b86af 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueNameAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class ParameterMustHaveUniqueNameAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Name = ""foo"")] - public string Foo { get; set; } - - [CommandParameter(1, Name = ""foo"")] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Name = "foo")] + public string Foo { get; set; } + + [CommandParameter(1, Name = "foo")] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Name = ""foo"")] - public string Foo { get; set; } - - [CommandParameter(1, Name = ""bar"")] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Name = "foo")] + public string Foo { get; set; } + + [CommandParameter(1, Name = "bar")] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,14 +61,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs index c09257d..27a26cb 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveUniqueOrderAnalyzerSpecs.cs @@ -13,18 +13,20 @@ public class ParameterMustHaveUniqueOrderAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(0)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(0)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -35,18 +37,20 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - [CommandParameter(1)] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1)] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -57,14 +61,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs index 8df0bc6..43471c4 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveValidConverterAnalyzerSpecs.cs @@ -13,20 +13,22 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyConverter -{ - public string Convert(string rawValue) => rawValue; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Converter = typeof(MyConverter))] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter + { + public string Convert(string rawValue) => rawValue; + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Converter = typeof(MyConverter))] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -37,20 +39,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override int Convert(string rawValue) => 42; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Converter = typeof(MyConverter))] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override int Convert(string rawValue) => 42; + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Converter = typeof(MyConverter))] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert @@ -62,20 +66,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override string Convert(string rawValue) => rawValue; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Converter = typeof(MyConverter))] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override string Convert(string rawValue) => rawValue; + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Converter = typeof(MyConverter))] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -86,20 +92,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override int Convert(string rawValue) => 42; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandOption(""foo"", Converter = typeof(MyConverter))] - public int? Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override int Convert(string rawValue) => 42; + } + + [Command] + public class MyCommand : ICommand + { + [CommandOption("foo", Converter = typeof(MyConverter))] + public int? Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -110,20 +118,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyConverter : BindingConverter -{ - public override string Convert(string rawValue) => rawValue; -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Converter = typeof(MyConverter))] - public IReadOnlyList Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyConverter : BindingConverter + { + public override string Convert(string rawValue) => rawValue; + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Converter = typeof(MyConverter))] + public IReadOnlyList Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -134,15 +144,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -153,14 +165,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs index 921fc25..abd9ebc 100644 --- a/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/ParameterMustHaveValidValidatorsAnalyzerSpecs.cs @@ -13,20 +13,22 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs { // Arrange // language=cs - const string code = @" -public class MyValidator -{ - public void Validate(string value) {} -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Validators = new[] {typeof(MyValidator)})] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyValidator + { + public void Validate(string value) {} + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Validators = new[] {typeof(MyValidator)})] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -37,20 +39,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyValidator : BindingValidator -{ - public override BindingValidationError Validate(int value) => Ok(); -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Validators = new[] {typeof(MyValidator)})] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyValidator : BindingValidator + { + public override BindingValidationError Validate(int value) => Ok(); + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Validators = new[] {typeof(MyValidator)})] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -61,20 +65,22 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -public class MyValidator : BindingValidator -{ - public override BindingValidationError Validate(string value) => Ok(); -} - -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0, Validators = new[] {typeof(MyValidator)})] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + public class MyValidator : BindingValidator + { + public override BindingValidationError Validate(string value) => Ok(); + } + + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0, Validators = new[] {typeof(MyValidator)})] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -85,15 +91,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -104,14 +112,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public string Foo { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs b/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs index b6d2647..9123660 100644 --- a/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs +++ b/CliFx.Analyzers.Tests/SystemConsoleShouldBeAvoidedAnalyzerSpecs.cs @@ -13,16 +13,18 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - Console.WriteLine(""Hello world""); - return default; - } -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + Console.WriteLine("Hello world"); + return default; + } + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -33,16 +35,19 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - Console.ForegroundColor = ConsoleColor.Black; - return default; - } -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + Console.ForegroundColor = ConsoleColor.Black; + return default; + } + } + """; + // Act & assert Analyzer.Should().ProduceDiagnostics(code); } @@ -52,16 +57,18 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - Console.Error.WriteLine(""Hello world""); - return default; - } -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + Console.Error.WriteLine("Hello world"); + return default; + } + } + """; // Act & assert Analyzer.Should().ProduceDiagnostics(code); @@ -72,16 +79,18 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Hello world""); - return default; - } -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Hello world"); + return default; + } + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -92,14 +101,16 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public void SomeOtherMethod() => Console.WriteLine(""Test""); - - public ValueTask ExecuteAsync(IConsole console) => default; -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public void SomeOtherMethod() => Console.WriteLine("Test"); + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); @@ -110,15 +121,17 @@ public class MyCommand : ICommand { // Arrange // language=cs - const string code = @" -[Command] -public class MyCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - return default; - } -}"; + const string code = + """ + [Command] + public class MyCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + return default; + } + } + """; // Act & assert Analyzer.Should().NotProduceDiagnostics(code); diff --git a/CliFx.Tests/CancellationSpecs.cs b/CliFx.Tests/CancellationSpecs.cs index 8abff3e..82aea15 100644 --- a/CliFx.Tests/CancellationSpecs.cs +++ b/CliFx.Tests/CancellationSpecs.cs @@ -21,28 +21,30 @@ public class CancellationSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public async ValueTask ExecuteAsync(IConsole console) - { - try - { - await Task.Delay( - TimeSpan.FromSeconds(3), - console.RegisterCancellationHandler() - ); + """ + [Command] + public class Command : ICommand + { + public async ValueTask ExecuteAsync(IConsole console) + { + try + { + await Task.Delay( + TimeSpan.FromSeconds(3), + console.RegisterCancellationHandler() + ); - console.Output.WriteLine(""Completed successfully""); - } - catch (OperationCanceledException) - { - console.Output.WriteLine(""Cancelled""); - throw; - } - } -}"); + console.Output.WriteLine("Completed successfully"); + } + catch (OperationCanceledException) + { + console.Output.WriteLine("Cancelled"); + throw; + } + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/ConsoleSpecs.cs b/CliFx.Tests/ConsoleSpecs.cs index c389dfd..84e4e6f 100644 --- a/CliFx.Tests/ConsoleSpecs.cs +++ b/CliFx.Tests/ConsoleSpecs.cs @@ -48,27 +48,28 @@ public class ConsoleSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.ResetColor(); - console.ForegroundColor = ConsoleColor.DarkMagenta; - console.BackgroundColor = ConsoleColor.DarkMagenta; - console.WindowWidth = 100; - console.WindowHeight = 25; - console.CursorLeft = 42; - console.CursorTop = 24; + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.ResetColor(); + console.ForegroundColor = ConsoleColor.DarkMagenta; + console.BackgroundColor = ConsoleColor.DarkMagenta; + console.WindowWidth = 100; + console.WindowHeight = 25; + console.CursorLeft = 42; + console.CursorTop = 24; - console.Output.WriteLine(""Hello ""); - console.Error.WriteLine(""world!""); + console.Output.WriteLine("Hello "); + console.Error.WriteLine("world!"); - return default; - } -} -"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -108,20 +109,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - var input = console.Input.ReadToEnd(); - console.Output.WriteLine(input); - console.Error.WriteLine(input); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + var input = console.Input.ReadToEnd(); + console.Output.WriteLine(input); + console.Error.WriteLine(input); - return default; - } -} -"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -151,20 +153,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(console.ReadKey().Key); - console.Output.WriteLine(console.ReadKey().Key); - console.Output.WriteLine(console.ReadKey().Key); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(console.ReadKey().Key); + console.Output.WriteLine(console.ReadKey().Key); + console.Output.WriteLine(console.ReadKey().Key); - return default; - } -} -"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/ConversionSpecs.cs b/CliFx.Tests/ConversionSpecs.cs index 4cf7358..4ccbb96 100644 --- a/CliFx.Tests/ConversionSpecs.cs +++ b/CliFx.Tests/ConversionSpecs.cs @@ -21,20 +21,22 @@ public class ConversionSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -59,20 +61,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public object Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public object Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -97,25 +101,27 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public bool Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public bool Foo { get; set; } - [CommandOption('b')] - public bool Bar { get; set; } + [CommandOption('b')] + public bool Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -143,20 +149,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public bool Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public bool Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -181,20 +189,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public int Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public int Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -219,20 +229,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public double Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public double Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo.ToString(CultureInfo.InvariantCulture)); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo.ToString(CultureInfo.InvariantCulture)); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -257,20 +269,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public DateTimeOffset Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public DateTimeOffset Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo.ToString("u", CultureInfo.InvariantCulture)); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo.ToString(""u"", CultureInfo.InvariantCulture)); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -295,20 +309,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public TimeSpan Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public TimeSpan Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo.ToString(null, CultureInfo.InvariantCulture)); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo.ToString(null, CultureInfo.InvariantCulture)); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -333,22 +349,24 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One = 1, Two = 2, Three = 3 } + """ + public enum CustomEnum { One = 1, Two = 2, Three = 3 } -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomEnum Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomEnum Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine((int) Foo); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine((int) Foo); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -373,25 +391,27 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public int? Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public int? Foo { get; set; } - [CommandOption('b')] - public int? Bar { get; set; } + [CommandOption('b')] + public int? Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -419,27 +439,29 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One = 1, Two = 2, Three = 3 } + """ + public enum CustomEnum { One = 1, Two = 2, Three = 3 } -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomEnum? Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomEnum? Foo { get; set; } - [CommandOption('b')] - public CustomEnum? Bar { get; set; } + [CommandOption('b')] + public CustomEnum? Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + (int?) Foo); - console.Output.WriteLine(""Bar = "" + (int?) Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + (int?) Foo); + console.Output.WriteLine("Bar = " + (int?) Bar); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -467,27 +489,29 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class CustomType -{ - public string Value { get; } + """ + public class CustomType + { + public string Value { get; } - public CustomType(string value) => Value = value; -} + public CustomType(string value) => Value = value; + } -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomType Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomType Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo.Value); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo.Value); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -512,45 +536,47 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class CustomTypeA -{ - public string Value { get; } + """ + public class CustomTypeA + { + public string Value { get; } - private CustomTypeA(string value) => Value = value; + private CustomTypeA(string value) => Value = value; - public static CustomTypeA Parse(string value) => - new CustomTypeA(value); -} + public static CustomTypeA Parse(string value) => + new CustomTypeA(value); + } -public class CustomTypeB -{ - public string Value { get; } + public class CustomTypeB + { + public string Value { get; } - private CustomTypeB(string value) => Value = value; + private CustomTypeB(string value) => Value = value; - public static CustomTypeB Parse(string value, IFormatProvider formatProvider) => - new CustomTypeB(value); -} + public static CustomTypeB Parse(string value, IFormatProvider formatProvider) => + new CustomTypeB(value); + } -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomTypeA Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomTypeA Foo { get; set; } - [CommandOption('b')] - public CustomTypeB Bar { get; set; } + [CommandOption('b')] + public CustomTypeB Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo.Value); - console.Output.WriteLine(""Bar = "" + Bar.Value); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo.Value); + console.Output.WriteLine("Bar = " + Bar.Value); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -578,26 +604,28 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class CustomConverter : BindingConverter -{ - public override int Convert(string rawValue) => - rawValue.Length; -} + """ + public class CustomConverter : BindingConverter + { + public override int Convert(string rawValue) => + rawValue.Length; + } -[Command] -public class Command : ICommand -{ - [CommandOption('f', Converter = typeof(CustomConverter))] - public int Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f', Converter = typeof(CustomConverter))] + public int Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -622,22 +650,24 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public string[] Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public string[] Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -666,22 +696,24 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -710,22 +742,24 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public List Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public List Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -754,22 +788,24 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public int[] Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public int[] Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); + + return default; + } + } + """ + ); - return default; - } -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -798,16 +834,18 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public int Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public int Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -832,18 +870,20 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class CustomType {} + """ + public class CustomType {} -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomType Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomType Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -868,23 +908,25 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class CustomType : IEnumerable -{ - public IEnumerator GetEnumerator() => Enumerable.Empty().GetEnumerator(); + """ + public class CustomType : IEnumerable + { + public IEnumerator GetEnumerator() => Enumerable.Empty().GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); -} + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomType Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomType Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -909,26 +951,28 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class ValidatorA : BindingValidator -{ - public override BindingValidationError Validate(int value) => Ok(); -} + """ + public class ValidatorA : BindingValidator + { + public override BindingValidationError Validate(int value) => Ok(); + } -public class ValidatorB : BindingValidator -{ - public override BindingValidationError Validate(int value) => Error(""Hello world""); -} + public class ValidatorB : BindingValidator + { + public override BindingValidationError Validate(int value) => Error("Hello world"); + } -[Command] -public class Command : ICommand -{ - [CommandOption('f', Validators = new[] {typeof(ValidatorA), typeof(ValidatorB)})] - public int Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f', Validators = new[] {typeof(ValidatorA), typeof(ValidatorB)})] + public int Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) @@ -953,25 +997,27 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public class CustomType -{ - public string Value { get; } + """ + public class CustomType + { + public string Value { get; } - private CustomType(string value) => Value = value; + private CustomType(string value) => Value = value; - public static CustomType Parse(string value) => throw new Exception(""Hello world""); -} + public static CustomType Parse(string value) => throw new Exception("Hello world"); + } -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public CustomType Foo { get; set; } + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public CustomType Foo { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); var application = new CliApplicationBuilder() .AddCommand(commandType) .UseConsole(FakeConsole) diff --git a/CliFx.Tests/DirectivesSpecs.cs b/CliFx.Tests/DirectivesSpecs.cs index 60d6c15..e897f7b 100644 --- a/CliFx.Tests/DirectivesSpecs.cs +++ b/CliFx.Tests/DirectivesSpecs.cs @@ -75,13 +75,14 @@ public class DirectivesSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command(""cmd"")] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """ + [Command("cmd")] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/EnvironmentSpecs.cs b/CliFx.Tests/EnvironmentSpecs.cs index 58d1e43..fb8cbf7 100644 --- a/CliFx.Tests/EnvironmentSpecs.cs +++ b/CliFx.Tests/EnvironmentSpecs.cs @@ -25,20 +25,21 @@ public class EnvironmentSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", IsRequired = true, EnvironmentVariable = ""ENV_FOO"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", IsRequired = true, EnvironmentVariable = "ENV_FOO")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -67,20 +68,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", EnvironmentVariable = "ENV_FOO")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -109,22 +111,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", EnvironmentVariable = "ENV_FOO")] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); - return default; - } -} -"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -156,20 +159,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", EnvironmentVariable = "ENV_FOO")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -198,20 +202,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", EnvironmentVariable = "ENV_FOO")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -} -"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/ErrorReportingSpecs.cs b/CliFx.Tests/ErrorReportingSpecs.cs index 3b7251f..96c402a 100644 --- a/CliFx.Tests/ErrorReportingSpecs.cs +++ b/CliFx.Tests/ErrorReportingSpecs.cs @@ -22,14 +22,15 @@ public class ErrorReportingSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => - throw new Exception(""Something went wrong""); -} -"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => + throw new Exception("Something went wrong"); + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -60,14 +61,15 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => - throw new Exception(""Something went wrong"", new Exception(""Another exception"")); -} -"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => + throw new Exception("Something went wrong", new Exception("Another exception")); + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -99,14 +101,15 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => - throw new CommandException(""Something went wrong"", 69); -} -"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => + throw new CommandException("Something went wrong", 69); + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -134,14 +137,15 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => - throw new CommandException("""", 69); -} -"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => + throw new CommandException("", 69); + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -172,14 +176,15 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => - throw new CommandException(""Something went wrong"", 69, true); -} -"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => + throw new CommandException("Something went wrong", 69, true); + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/HelpTextSpecs.cs b/CliFx.Tests/HelpTextSpecs.cs index 96541b7..dcfa852 100644 --- a/CliFx.Tests/HelpTextSpecs.cs +++ b/CliFx.Tests/HelpTextSpecs.cs @@ -44,13 +44,14 @@ public class HelpTextSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """ + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -77,19 +78,20 @@ public class DefaultCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command(""cmd"")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + [Command("cmd")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd child"")] -public class NamedChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + [Command("cmd child")] + public class NamedChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -116,25 +118,26 @@ public class NamedChildCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd"", Description = ""Description of a named command."")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + [Command("cmd", Description = "Description of a named command.")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd child"")] -public class NamedChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + [Command("cmd child")] + public class NamedChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -160,25 +163,26 @@ public class NamedChildCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd"")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + [Command("cmd")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd child"", Description = ""Description of a named child command."")] -public class NamedChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + [Command("cmd child", Description = "Description of a named child command.")] + public class NamedChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -257,13 +261,15 @@ public class NamedChildCommand : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command(Description = ""Description of the default command."")] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """ + + [Command(Description = "Description of the default command.")] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -292,19 +298,21 @@ public class DefaultCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd"")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -333,22 +341,24 @@ public class NamedCommand : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + [CommandParameter(1)] + public string Bar { get; set; } + + [CommandParameter(2)] + public IReadOnlyList Baz { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } - [CommandParameter(1)] - public string Bar { get; set; } - - [CommandParameter(2)] - public IReadOnlyList Baz { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -378,28 +388,30 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -// Base members appear last in reflection order -public abstract class CommandBase : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + + // Base members appear last in reflection order + public abstract class CommandBase : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } + + public abstract ValueTask ExecuteAsync(IConsole console); + } + + [Command] + public class Command : CommandBase + { + [CommandParameter(2)] + public IReadOnlyList Baz { get; set; } + + [CommandParameter(1)] + public string Bar { get; set; } + + public override ValueTask ExecuteAsync(IConsole console) => default; + } - public abstract ValueTask ExecuteAsync(IConsole console); -} - -[Command] -public class Command : CommandBase -{ - [CommandParameter(2)] - public IReadOnlyList Baz { get; set; } - - [CommandParameter(1)] - public string Bar { get; set; } - - public override ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -428,22 +440,24 @@ public class Command : CommandBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", IsRequired = true)] - public string Foo { get; set; } + """ + + [Command] + public class Command : ICommand + { + [CommandOption("foo", IsRequired = true)] + public string Foo { get; set; } + + [CommandOption("bar")] + public string Bar { get; set; } + + [CommandOption("baz", IsRequired = true)] + public IReadOnlyList Baz { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } - [CommandOption(""bar"")] - public string Bar { get; set; } - - [CommandOption(""baz"", IsRequired = true)] - public IReadOnlyList Baz { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -472,19 +486,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0, Name = ""foo"", Description = ""Description of foo."")] - public string Foo { get; set; } + """ + + [Command] + public class Command : ICommand + { + [CommandParameter(0, Name = "foo", Description = "Description of foo.")] + public string Foo { get; set; } + + [CommandOption("bar", Description = "Description of bar.")] + public string Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } - [CommandOption(""bar"", Description = ""Description of bar."")] - public string Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -515,13 +531,15 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """ + + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -551,13 +569,15 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command(""cmd"")] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """ + + [Command("cmd")] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -589,21 +609,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One, Two, Three } + """ + + public enum CustomEnum { One, Two, Three } + + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public CustomEnum Foo { get; set; } + + [CommandOption("bar")] + public CustomEnum Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public CustomEnum Foo { get; set; } - - [CommandOption(""bar"")] - public CustomEnum Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -634,21 +656,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One, Two, Three } + """ + + public enum CustomEnum { One, Two, Three } + + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public IReadOnlyList Foo { get; set; } + + [CommandOption("bar")] + public IReadOnlyList Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public IReadOnlyList Foo { get; set; } - - [CommandOption(""bar"")] - public IReadOnlyList Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -679,21 +703,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One, Two, Three } + """ + + public enum CustomEnum { One, Two, Three } + + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public CustomEnum? Foo { get; set; } + + [CommandOption("bar")] + public IReadOnlyList Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public CustomEnum? Foo { get; set; } - - [CommandOption(""bar"")] - public IReadOnlyList Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -724,21 +750,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One, Two, Three } + """ + + public enum CustomEnum { One, Two, Three } + + [Command] + public class Command : ICommand + { + [CommandOption("foo", EnvironmentVariable = "ENV_FOO")] + public CustomEnum Foo { get; set; } + + [CommandOption("bar", EnvironmentVariable = "ENV_BAR")] + public CustomEnum Bar { get; set; } + + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")] - public CustomEnum Foo { get; set; } - - [CommandOption(""bar"", EnvironmentVariable = ""ENV_BAR"")] - public CustomEnum Bar { get; set; } - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -768,39 +796,41 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public enum CustomEnum { One, Two, Three } + """ + + public enum CustomEnum { One, Two, Three } + + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public object Foo { get; set; } = 42; + + [CommandOption("bar")] + public string Bar { get; set; } = "hello"; + + [CommandOption("baz")] + public IReadOnlyList Baz { get; set; } = new[] {"one", "two", "three"}; + + [CommandOption("qwe")] + public bool Qwe { get; set; } = true; + + [CommandOption("qop")] + public int? Qop { get; set; } = 1337; + + [CommandOption("zor")] + public TimeSpan Zor { get; set; } = TimeSpan.FromMinutes(123); + + [CommandOption("lol")] + public CustomEnum Lol { get; set; } = CustomEnum.Two; + + [CommandOption("hmm", IsRequired = true)] + public string Hmm { get; set; } = "not printed"; + + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public object Foo { get; set; } = 42; - - [CommandOption(""bar"")] - public string Bar { get; set; } = ""hello""; - - [CommandOption(""baz"")] - public IReadOnlyList Baz { get; set; } = new[] {""one"", ""two"", ""three""}; - - [CommandOption(""qwe"")] - public bool Qwe { get; set; } = true; - - [CommandOption(""qop"")] - public int? Qop { get; set; } = 1337; - - [CommandOption(""zor"")] - public TimeSpan Zor { get; set; } = TimeSpan.FromMinutes(123); - - [CommandOption(""lol"")] - public CustomEnum Lol { get; set; } = CustomEnum.Two; - - [CommandOption(""hmm"", IsRequired = true)] - public string Hmm { get; set; } = ""not printed""; - - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -836,25 +866,27 @@ public class Command : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command(""cmd1"", Description = ""Description of one command."")] -public class FirstCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + + [Command("cmd1", Description = "Description of one command.")] + public class FirstCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2", Description = "Description of another command.")] + public class SecondCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2 child", Description = "Description of another command's child command.")] + public class SecondCommandChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd2"", Description = ""Description of another command."")] -public class SecondCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} - -[Command(""cmd2 child"", Description = ""Description of another command's child command."")] -public class SecondCommandChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -890,37 +922,39 @@ public class SecondCommandChildCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command(""cmd1"")] -public class FirstCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + + [Command("cmd1")] + public class FirstCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd1 child1")] + public class FirstCommandFirstChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2")] + public class SecondCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2 child11")] + public class SecondCommandFirstChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2 child2")] + public class SecondCommandSecondChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd1 child1"")] -public class FirstCommandFirstChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} - -[Command(""cmd2"")] -public class SecondCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} - -[Command(""cmd2 child11"")] -public class SecondCommandFirstChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} - -[Command(""cmd2 child2"")] -public class SecondCommandSecondChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -950,25 +984,27 @@ public class SecondCommandSecondChildCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command(""cmd1"")] -public class FirstCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} + """ + + [Command("cmd1")] + public class FirstCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2 child1")] + public class SecondCommandFirstChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } + + [Command("cmd2 child2")] + public class SecondCommandSecondChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) => default; + } -[Command(""cmd2 child1"")] -public class SecondCommandFirstChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} - -[Command(""cmd2 child2"")] -public class SecondCommandSecondChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) => default; -} -"); + """); var application = new CliApplicationBuilder() .AddCommands(commandTypes) diff --git a/CliFx.Tests/OptionBindingSpecs.cs b/CliFx.Tests/OptionBindingSpecs.cs index d6a0a29..0a51d9c 100644 --- a/CliFx.Tests/OptionBindingSpecs.cs +++ b/CliFx.Tests/OptionBindingSpecs.cs @@ -22,19 +22,21 @@ public class OptionBindingSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public bool Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public bool Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -}"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -60,19 +62,21 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public bool Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public bool Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); - return default; - } -}"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -98,24 +102,26 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } - [CommandOption(""bar"")] - public string Bar { get; set; } + [CommandOption("bar")] + public string Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -144,24 +150,26 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } - [CommandOption('b')] - public string Bar { get; set; } + [CommandOption('b')] + public string Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -190,24 +198,26 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public string Foo { get; set; } - [CommandOption('b')] - public string Bar { get; set; } + [CommandOption('b')] + public string Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -236,21 +246,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""Foo"")] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("Foo")] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -280,21 +292,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -324,21 +338,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -368,21 +384,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption('f')] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption('f')] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -412,21 +430,23 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", 'f')] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", 'f')] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - foreach (var i in Foo) - console.Output.WriteLine(i); + public ValueTask ExecuteAsync(IConsole console) + { + foreach (var i in Foo) + console.Output.WriteLine(i); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -456,24 +476,26 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } - [CommandOption(""bar"")] - public string Bar { get; set; } = ""hello""; + [CommandOption("bar")] + public string Bar { get; set; } = "hello"; - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -502,55 +524,56 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -public static class SharedContext -{ - public static int Foo { get; set; } + """ + public static class SharedContext + { + public static int Foo { get; set; } - public static bool Bar { get; set; } -} + public static bool Bar { get; set; } + } -public interface IHasFoo : ICommand -{ - [CommandOption(""foo"")] - public int Foo - { - get => SharedContext.Foo; - set => SharedContext.Foo = value; - } -} + public interface IHasFoo : ICommand + { + [CommandOption("foo")] + public int Foo + { + get => SharedContext.Foo; + set => SharedContext.Foo = value; + } + } -public interface IHasBar : ICommand -{ - [CommandOption(""bar"")] - public bool Bar - { - get => SharedContext.Bar; - set => SharedContext.Bar = value; - } -} + public interface IHasBar : ICommand + { + [CommandOption("bar")] + public bool Bar + { + get => SharedContext.Bar; + set => SharedContext.Bar = value; + } + } -public interface IHasBaz : ICommand -{ - public string Baz { get; set; } -} + public interface IHasBaz : ICommand + { + public string Baz { get; set; } + } -[Command] -public class Command : IHasFoo, IHasBar, IHasBaz -{ - [CommandOption(""baz"")] - public string Baz { get; set; } + [Command] + public class Command : IHasFoo, IHasBar, IHasBaz + { + [CommandOption("baz")] + public string Baz { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + SharedContext.Foo); - console.Output.WriteLine(""Bar = "" + SharedContext.Bar); - console.Output.WriteLine(""Baz = "" + Baz); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + SharedContext.Foo); + console.Output.WriteLine("Bar = " + SharedContext.Bar); + console.Output.WriteLine("Baz = " + Baz); - return default; - } -} -"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -579,20 +602,22 @@ public class Command : IHasFoo, IHasBar, IHasBaz // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(Foo); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(Foo); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -618,15 +643,17 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", IsRequired = true)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", IsRequired = true)] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -652,15 +679,17 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", IsRequired = true)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", IsRequired = true)] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -686,15 +715,17 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"", IsRequired = true)] - public IReadOnlyList Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo", IsRequired = true)] + public IReadOnlyList Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -720,15 +751,17 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -754,15 +787,17 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandOption(""foo"")] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandOption("foo")] + public string Foo { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/ParameterBindingSpecs.cs b/CliFx.Tests/ParameterBindingSpecs.cs index de92e91..5ecbb1a 100644 --- a/CliFx.Tests/ParameterBindingSpecs.cs +++ b/CliFx.Tests/ParameterBindingSpecs.cs @@ -21,24 +21,26 @@ public class ParameterBindingSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } - [CommandParameter(1)] - public string Bar { get; set; } + [CommandParameter(1)] + public string Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -67,33 +69,35 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } - [CommandParameter(1)] - public string Bar { get; set; } + [CommandParameter(1)] + public string Bar { get; set; } - [CommandParameter(2)] - public IReadOnlyList Baz { get; set; } + [CommandParameter(2)] + public IReadOnlyList Baz { get; set; } - [CommandOption(""boo"")] - public string Boo { get; set; } + [CommandOption("boo")] + public string Boo { get; set; } - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - foreach (var i in Baz) - console.Output.WriteLine(""Baz = "" + i); + foreach (var i in Baz) + console.Output.WriteLine("Baz = " + i); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -125,24 +129,26 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } - [CommandParameter(1, IsRequired = false)] - public string Bar { get; set; } = ""xyz""; + [CommandParameter(1, IsRequired = false)] + public string Bar { get; set; } = "xyz"; - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""Foo = "" + Foo); - console.Output.WriteLine(""Bar = "" + Bar); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("Foo = " + Foo); + console.Output.WriteLine("Bar = " + Bar); - return default; - } -}"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -171,18 +177,20 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } - [CommandParameter(1)] - public string Bar { get; set; } + [CommandParameter(1)] + public string Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -208,18 +216,20 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } - [CommandParameter(1)] - public IReadOnlyList Bar { get; set; } + [CommandParameter(1)] + public IReadOnlyList Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -245,18 +255,20 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - [CommandParameter(0)] - public string Foo { get; set; } + """ + [Command] + public class Command : ICommand + { + [CommandParameter(0)] + public string Foo { get; set; } - [CommandParameter(1)] - public string Bar { get; set; } + [CommandParameter(1)] + public string Bar { get; set; } - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) diff --git a/CliFx.Tests/RoutingSpecs.cs b/CliFx.Tests/RoutingSpecs.cs index 4a6da1a..1618b19 100644 --- a/CliFx.Tests/RoutingSpecs.cs +++ b/CliFx.Tests/RoutingSpecs.cs @@ -21,37 +21,38 @@ public class RoutingSpecs : SpecsBase // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""default""); - return default; - } -} + """ + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("default"); + return default; + } + } -[Command(""cmd"")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""cmd""); - return default; - } -} + [Command("cmd")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("cmd"); + return default; + } + } -[Command(""cmd child"")] -public class NamedChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""cmd child""); - return default; - } -} -"); + [Command("cmd child")] + public class NamedChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("cmd child"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -77,37 +78,38 @@ public class NamedChildCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""default""); - return default; - } -} + """ + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("default"); + return default; + } + } -[Command(""cmd"")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""cmd""); - return default; - } -} + [Command("cmd")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("cmd"); + return default; + } + } -[Command(""cmd child"")] -public class NamedChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""cmd child""); - return default; - } -} -"); + [Command("cmd child")] + public class NamedChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("cmd child"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommands(commandTypes) @@ -133,37 +135,38 @@ public class NamedChildCommand : ICommand // Arrange var commandTypes = DynamicCommandBuilder.CompileMany( // language=cs - @" -[Command] -public class DefaultCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""default""); - return default; - } -} + """ + [Command] + public class DefaultCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("default"); + return default; + } + } -[Command(""cmd"")] -public class NamedCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""cmd""); - return default; - } -} + [Command("cmd")] + public class NamedCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("cmd"); + return default; + } + } -[Command(""cmd child"")] -public class NamedChildCommand : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""cmd child""); - return default; - } -} -"); + [Command("cmd child")] + public class NamedChildCommand : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("cmd child"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommands(commandTypes) diff --git a/CliFx.Tests/TypeActivationSpecs.cs b/CliFx.Tests/TypeActivationSpecs.cs index 4e1e6c7..09eb523 100644 --- a/CliFx.Tests/TypeActivationSpecs.cs +++ b/CliFx.Tests/TypeActivationSpecs.cs @@ -23,16 +23,18 @@ public class TypeActivationSpecs : SpecsBase // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""foo""); - return default; - } -}"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("foo"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -59,14 +61,16 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public Command(string foo) {} + """ + [Command] + public class Command : ICommand + { + public Command(string foo) {} - public ValueTask ExecuteAsync(IConsole console) => default; -}"); + public ValueTask ExecuteAsync(IConsole console) => default; + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -93,20 +97,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - private readonly string _foo; + """ + [Command] + public class Command : ICommand + { + private readonly string _foo; - public Command(string foo) => _foo = foo; + public Command(string foo) => _foo = foo; - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(_foo); - return default; - } -}"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(_foo); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType) @@ -133,20 +139,22 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - private readonly string _foo; + """ + [Command] + public class Command : ICommand + { + private readonly string _foo; - public Command(string foo) => _foo = foo; + public Command(string foo) => _foo = foo; - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(_foo); - return default; - } -}"); + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine(_foo); + return default; + } + } + """ + ); var serviceProvider = new ServiceCollection() .AddSingleton(commandType, Activator.CreateInstance(commandType, "Hello world")!) @@ -177,16 +185,18 @@ public class Command : ICommand // Arrange var commandType = DynamicCommandBuilder.Compile( // language=cs - @" -[Command] -public class Command : ICommand -{ - public ValueTask ExecuteAsync(IConsole console) - { - console.Output.WriteLine(""foo""); - return default; - } -}"); + """ + [Command] + public class Command : ICommand + { + public ValueTask ExecuteAsync(IConsole console) + { + console.Output.WriteLine("foo"); + return default; + } + } + """ + ); var application = new CliApplicationBuilder() .AddCommand(commandType)