Refactor with C# 12 features

This commit is contained in:
Tyrrrz
2023-12-10 22:51:57 +02:00
parent 5854f36756
commit 490398f773
68 changed files with 371 additions and 622 deletions

View File

@@ -8,11 +8,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class ApplicationSpecs : SpecsBase
public class ApplicationSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public ApplicationSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_create_an_application_with_the_default_configuration()
{

View File

@@ -12,11 +12,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class CancellationSpecs : SpecsBase
public class CancellationSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public CancellationSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact(Timeout = 15000)]
public async Task I_can_configure_the_command_to_listen_to_the_interrupt_signal()
{

View File

@@ -12,15 +12,15 @@
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.4.5" />
<PackageReference Include="CliWrap" Version="3.6.4" />
<PackageReference Include="coverlet.collector" Version="6.0.0" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.1" PrivateAssets="all" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.5" PrivateAssets="all" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="PolyShim" Version="1.8.0" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>

View File

@@ -14,11 +14,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class ConsoleSpecs : SpecsBase
public class ConsoleSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public ConsoleSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact(Timeout = 15000)]
public async Task I_can_run_the_application_with_the_default_console_implementation_to_interact_with_the_system_console()
{

View File

@@ -8,11 +8,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class ConversionSpecs : SpecsBase
public class ConversionSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public ConversionSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_bind_a_parameter_or_an_option_to_a_string_property()
{

View File

@@ -11,11 +11,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class DirectivesSpecs : SpecsBase
public class DirectivesSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public DirectivesSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact(Timeout = 15000)]
public async Task I_can_use_the_debug_directive_to_make_the_application_wait_for_the_debugger_to_attach()
{

View File

@@ -12,11 +12,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class EnvironmentSpecs : SpecsBase
public class EnvironmentSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public EnvironmentSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_configure_an_option_to_fall_back_to_an_environment_variable_if_the_user_does_not_provide_the_corresponding_argument()
{

View File

@@ -9,11 +9,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class ErrorReportingSpecs : SpecsBase
public class ErrorReportingSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public ErrorReportingSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_throw_an_exception_in_a_command_to_report_an_error_with_a_stacktrace()
{

View File

@@ -9,11 +9,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class HelpTextSpecs : SpecsBase
public class HelpTextSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public HelpTextSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_request_the_help_text_by_running_the_application_without_arguments_if_the_default_command_is_not_defined()
{

View File

@@ -9,11 +9,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class OptionBindingSpecs : SpecsBase
public class OptionBindingSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public OptionBindingSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_bind_an_option_to_a_property_and_get_the_value_from_the_corresponding_argument_by_name()
{

View File

@@ -8,11 +8,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class ParameterBindingSpecs : SpecsBase
public class ParameterBindingSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public ParameterBindingSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_bind_a_parameter_to_a_property_and_get_the_value_from_the_corresponding_argument()
{

View File

@@ -8,11 +8,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class RoutingSpecs : SpecsBase
public class RoutingSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public RoutingSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_configure_a_command_to_be_executed_by_default_when_the_user_does_not_specify_a_command_name()
{

View File

@@ -5,14 +5,12 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public abstract class SpecsBase : IDisposable
public abstract class SpecsBase(ITestOutputHelper testOutput) : IDisposable
{
public ITestOutputHelper TestOutput { get; }
public ITestOutputHelper TestOutput { get; } = testOutput;
public FakeInMemoryConsole FakeConsole { get; } = new();
protected SpecsBase(ITestOutputHelper testOutput) => TestOutput = testOutput;
public void Dispose()
{
FakeConsole.DumpToTestOutput(TestOutput);

View File

@@ -10,11 +10,8 @@ using Xunit.Abstractions;
namespace CliFx.Tests;
public class TypeActivationSpecs : SpecsBase
public class TypeActivationSpecs(ITestOutputHelper testOutput) : SpecsBase(testOutput)
{
public TypeActivationSpecs(ITestOutputHelper testOutput)
: base(testOutput) { }
[Fact]
public async Task I_can_configure_the_application_to_use_the_default_type_activator_to_initialize_types_through_parameterless_constructors()
{