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")
.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",

View File

@@ -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<T> : IEnumerable<T>
{
private readonly T[] _arr = new T[0];
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>) _arr).GetEnumerator();
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>) Array.Empty<T>()).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 CliFx.Attributes;
@@ -20,7 +21,7 @@ namespace CliFx.Tests
private class ConcatCommand : ICommand
{
[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.")]
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)
{