From 1dab27de551c8fcb5abd2656b5372c0091a77eb5 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Mon, 20 Apr 2020 17:20:17 +0300 Subject: [PATCH] Fix warnings in tests --- CliFx.Tests/ApplicationSpecs.cs | 6 +++--- CliFx.Tests/ArgumentBindingSpecs.Types.cs | 19 ++++--------------- CliFx.Tests/RoutingSpecs.Commands.cs | 9 +++++---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/CliFx.Tests/ApplicationSpecs.cs b/CliFx.Tests/ApplicationSpecs.cs index cd94fc7..00f0fea 100644 --- a/CliFx.Tests/ApplicationSpecs.cs +++ b/CliFx.Tests/ApplicationSpecs.cs @@ -43,7 +43,7 @@ namespace CliFx.Tests .UseVersionText("test") .UseDescription("test") .UseConsole(new VirtualConsole(Stream.Null)) - .UseTypeActivator(Activator.CreateInstance) + .UseTypeActivator(Activator.CreateInstance!) .Build(); // Assert @@ -212,7 +212,7 @@ namespace CliFx.Tests new[] { new CommandParameterSchema( - typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Parameter)), + typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Parameter))!, 13, "param", "Param description") @@ -220,7 +220,7 @@ namespace CliFx.Tests new[] { new CommandOptionSchema( - typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Option)), + typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Option))!, "option", 'o', "ENV", diff --git a/CliFx.Tests/ArgumentBindingSpecs.Types.cs b/CliFx.Tests/ArgumentBindingSpecs.Types.cs index ea83bb5..7d751ae 100644 --- a/CliFx.Tests/ArgumentBindingSpecs.Types.cs +++ b/CliFx.Tests/ArgumentBindingSpecs.Types.cs @@ -17,20 +17,14 @@ namespace CliFx.Tests { public string Value { get; } - public StringConstructable(string value) - { - Value = value; - } + public StringConstructable(string value) => Value = value; } private class StringParseable { public string Value { get; } - private StringParseable(string value) - { - Value = value; - } + private StringParseable(string value) => Value = value; public static StringParseable Parse(string value) => new StringParseable(value); } @@ -39,10 +33,7 @@ namespace CliFx.Tests { public string Value { get; } - private StringParseableWithFormatProvider(string value) - { - Value = value; - } + private StringParseableWithFormatProvider(string value) => Value = value; public static StringParseableWithFormatProvider Parse(string value, IFormatProvider formatProvider) => new StringParseableWithFormatProvider(value + " " + formatProvider); @@ -54,9 +45,7 @@ namespace CliFx.Tests public class CustomEnumerable : IEnumerable { - private readonly T[] _arr = new T[0]; - - public IEnumerator GetEnumerator() => ((IEnumerable) _arr).GetEnumerator(); + public IEnumerator GetEnumerator() => ((IEnumerable) Array.Empty()).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } diff --git a/CliFx.Tests/RoutingSpecs.Commands.cs b/CliFx.Tests/RoutingSpecs.Commands.cs index 3b61921..f4d5bd1 100644 --- a/CliFx.Tests/RoutingSpecs.Commands.cs +++ b/CliFx.Tests/RoutingSpecs.Commands.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using CliFx.Attributes; @@ -20,7 +21,7 @@ namespace CliFx.Tests private class ConcatCommand : ICommand { [CommandOption('i', IsRequired = true, Description = "Input strings.")] - public IReadOnlyList Inputs { get; set; } + public IReadOnlyList Inputs { get; set; } = Array.Empty(); [CommandOption('s', Description = "String separator.")] public string Separator { get; set; } = ""; @@ -36,10 +37,10 @@ namespace CliFx.Tests private class DivideCommand : ICommand { [CommandOption("dividend", 'D', IsRequired = true, Description = "The number to divide.")] - public double Dividend { get; set; } + public double Dividend { get; set; } = 0; [CommandOption("divisor", 'd', IsRequired = true, Description = "The number to divide by.")] - public double Divisor { get; set; } + public double Divisor { get; set; } = 0; public ValueTask ExecuteAsync(IConsole console) {