Fix warnings in tests

This commit is contained in:
Alexey Golub
2020-04-20 17:20:17 +03:00
parent 698629b153
commit 1dab27de55
3 changed files with 12 additions and 22 deletions

View File

@@ -43,7 +43,7 @@ namespace CliFx.Tests
.UseVersionText("test") .UseVersionText("test")
.UseDescription("test") .UseDescription("test")
.UseConsole(new VirtualConsole(Stream.Null)) .UseConsole(new VirtualConsole(Stream.Null))
.UseTypeActivator(Activator.CreateInstance) .UseTypeActivator(Activator.CreateInstance!)
.Build(); .Build();
// Assert // Assert
@@ -212,7 +212,7 @@ namespace CliFx.Tests
new[] new[]
{ {
new CommandParameterSchema( new CommandParameterSchema(
typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Parameter)), typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Parameter))!,
13, 13,
"param", "param",
"Param description") "Param description")
@@ -220,7 +220,7 @@ namespace CliFx.Tests
new[] new[]
{ {
new CommandOptionSchema( new CommandOptionSchema(
typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Option)), typeof(HiddenPropertiesCommand).GetProperty(nameof(HiddenPropertiesCommand.Option))!,
"option", "option",
'o', 'o',
"ENV", "ENV",

View File

@@ -17,20 +17,14 @@ namespace CliFx.Tests
{ {
public string Value { get; } public string Value { get; }
public StringConstructable(string value) public StringConstructable(string value) => Value = value;
{
Value = value;
}
} }
private class StringParseable private class StringParseable
{ {
public string Value { get; } public string Value { get; }
private StringParseable(string value) private StringParseable(string value) => Value = value;
{
Value = value;
}
public static StringParseable Parse(string value) => new StringParseable(value); public static StringParseable Parse(string value) => new StringParseable(value);
} }
@@ -39,10 +33,7 @@ namespace CliFx.Tests
{ {
public string Value { get; } public string Value { get; }
private StringParseableWithFormatProvider(string value) private StringParseableWithFormatProvider(string value) => Value = value;
{
Value = value;
}
public static StringParseableWithFormatProvider Parse(string value, IFormatProvider formatProvider) => public static StringParseableWithFormatProvider Parse(string value, IFormatProvider formatProvider) =>
new StringParseableWithFormatProvider(value + " " + formatProvider); new StringParseableWithFormatProvider(value + " " + formatProvider);
@@ -54,9 +45,7 @@ namespace CliFx.Tests
public class CustomEnumerable<T> : IEnumerable<T> public class CustomEnumerable<T> : IEnumerable<T>
{ {
private readonly T[] _arr = new T[0]; public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>) Array.Empty<T>()).GetEnumerator();
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>) _arr).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using CliFx.Attributes; using CliFx.Attributes;
@@ -20,7 +21,7 @@ namespace CliFx.Tests
private class ConcatCommand : ICommand private class ConcatCommand : ICommand
{ {
[CommandOption('i', IsRequired = true, Description = "Input strings.")] [CommandOption('i', IsRequired = true, Description = "Input strings.")]
public IReadOnlyList<string> Inputs { get; set; } public IReadOnlyList<string> Inputs { get; set; } = Array.Empty<string>();
[CommandOption('s', Description = "String separator.")] [CommandOption('s', Description = "String separator.")]
public string Separator { get; set; } = ""; public string Separator { get; set; } = "";
@@ -36,10 +37,10 @@ namespace CliFx.Tests
private class DivideCommand : ICommand private class DivideCommand : ICommand
{ {
[CommandOption("dividend", 'D', IsRequired = true, Description = "The number to divide.")] [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.")] [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) public ValueTask ExecuteAsync(IConsole console)
{ {