mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Refactor tests
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests
|
||||
{
|
||||
public partial class CliApplicationBuilderTests
|
||||
{
|
||||
[Command]
|
||||
private class TestCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class CliApplicationBuilderTests
|
||||
public class CliApplicationBuilderTests
|
||||
{
|
||||
// Make sure all builder methods work
|
||||
[Test]
|
||||
@@ -17,10 +18,10 @@ namespace CliFx.Tests
|
||||
|
||||
// Act
|
||||
builder
|
||||
.AddCommand(typeof(TestCommand))
|
||||
.AddCommandsFrom(typeof(TestCommand).Assembly)
|
||||
.AddCommands(new[] {typeof(TestCommand)})
|
||||
.AddCommandsFrom(new[] {typeof(TestCommand).Assembly})
|
||||
.AddCommand(typeof(EchoCommand))
|
||||
.AddCommandsFrom(typeof(EchoCommand).Assembly)
|
||||
.AddCommands(new[] {typeof(EchoCommand)})
|
||||
.AddCommandsFrom(new[] {typeof(EchoCommand).Assembly})
|
||||
.AddCommandsFromThisAssembly()
|
||||
.AllowDebugMode()
|
||||
.AllowPreviewMode()
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests
|
||||
{
|
||||
public partial class CliApplicationTests
|
||||
{
|
||||
[Command]
|
||||
private class DefaultCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine("DefaultCommand executed.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
[Command("cmd")]
|
||||
private class NamedCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine("NamedCommand executed.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Negative
|
||||
public partial class CliApplicationTests
|
||||
{
|
||||
[Command("faulty1")]
|
||||
private class FaultyCommand1 : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => throw new CommandException(150);
|
||||
}
|
||||
|
||||
[Command("faulty2")]
|
||||
private class FaultyCommand2 : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => throw new CommandException("FaultyCommand2 error message.", 150);
|
||||
}
|
||||
|
||||
[Command("faulty3")]
|
||||
private class FaultyCommand3 : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => throw new Exception("FaultyCommand3 error message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,38 +3,39 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class CliApplicationTests
|
||||
public class CliApplicationTests
|
||||
{
|
||||
private const string TestVersionText = "v1.0";
|
||||
|
||||
private static IEnumerable<TestCaseData> GetTestCases_RunAsync()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new string[0],
|
||||
"DefaultCommand executed."
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[] {"-m", "foo bar"},
|
||||
"foo bar"
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {"cmd"},
|
||||
"NamedCommand executed."
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"echo", "-m", "foo bar"},
|
||||
"foo bar"
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[] {"--version"},
|
||||
TestVersionText
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"--version"},
|
||||
TestVersionText
|
||||
);
|
||||
@@ -43,78 +44,68 @@ namespace CliFx.Tests
|
||||
private static IEnumerable<TestCaseData> GetTestCases_RunAsync_Smoke()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new string[0]
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[] {"-h"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[] {"--help"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[] {"--version"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {typeof(EchoCommand)},
|
||||
new string[0]
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"-h"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"--help"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"--version"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NamedCommand)},
|
||||
new[] {"cmd", "-h"}
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"echo", "-h"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand1)},
|
||||
new[] {"faulty1", "-h"}
|
||||
new[] {typeof(ExceptionCommand)},
|
||||
new[] {"exc", "-h"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand2)},
|
||||
new[] {"faulty2", "-h"}
|
||||
new[] {typeof(CommandExceptionCommand)},
|
||||
new[] {"exc", "-h"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand3)},
|
||||
new[] {"faulty3", "-h"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[] {"[preview]"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand1)},
|
||||
new[] {"faulty1", "[preview]"}
|
||||
new[] {typeof(ExceptionCommand)},
|
||||
new[] {"exc", "[preview]"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand1)},
|
||||
new[] {"faulty1", "[preview]", "-o", "value"}
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"echo", "[preview]", "-o", "value"}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,23 +117,23 @@ namespace CliFx.Tests
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(DefaultCommand)},
|
||||
new[] {typeof(EchoCommand)},
|
||||
new[] {"non-existing"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand1)},
|
||||
new[] {"faulty1"}
|
||||
new[] {typeof(ExceptionCommand)},
|
||||
new[] {"exc"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand2)},
|
||||
new[] {"faulty2"}
|
||||
new[] {typeof(CommandExceptionCommand)},
|
||||
new[] {"exc"}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(FaultyCommand3)},
|
||||
new[] {"faulty3"}
|
||||
new[] {typeof(CommandExceptionCommand)},
|
||||
new[] {"exc", "-c", "666"}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
public partial class CommandFactoryTests
|
||||
{
|
||||
[Command]
|
||||
private class TestCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,21 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class CommandFactoryTests
|
||||
public class CommandFactoryTests
|
||||
{
|
||||
private static CommandSchema GetCommandSchema(Type commandType) =>
|
||||
new CommandSchemaResolver().GetCommandSchemas(new[] {commandType}).Single();
|
||||
|
||||
private static IEnumerable<TestCaseData> GetTestCases_CreateCommand()
|
||||
{
|
||||
yield return new TestCaseData(GetCommandSchema(typeof(TestCommand)));
|
||||
yield return new TestCaseData(GetCommandSchema(typeof(EchoCommand)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
public partial class CommandInitializerTests
|
||||
{
|
||||
[Command]
|
||||
private class TestCommand : ICommand
|
||||
{
|
||||
[CommandOption("int", 'i', IsRequired = true)]
|
||||
public int Option1 { get; set; } = 24;
|
||||
|
||||
[CommandOption("str", 's')]
|
||||
public string Option2 { get; set; } = "foo bar";
|
||||
|
||||
[CommandOption('S')]
|
||||
public bool Option3 { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,14 @@ using System.Linq;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class CommandInitializerTests
|
||||
public class CommandInitializerTests
|
||||
{
|
||||
private static CommandSchema GetCommandSchema(Type commandType) =>
|
||||
new CommandSchemaResolver().GetCommandSchemas(new[] {commandType}).Single();
|
||||
@@ -18,63 +19,89 @@ namespace CliFx.Tests.Services
|
||||
private static IEnumerable<TestCaseData> GetTestCases_InitializeCommand()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
new TestCommand(),
|
||||
GetCommandSchema(typeof(TestCommand)),
|
||||
new CommandInput(new[]
|
||||
new DivideCommand(),
|
||||
GetCommandSchema(typeof(DivideCommand)),
|
||||
new CommandInput("div", new[]
|
||||
{
|
||||
new CommandOptionInput("int", "13")
|
||||
new CommandOptionInput("dividend", "13"),
|
||||
new CommandOptionInput("divisor", "8")
|
||||
}),
|
||||
new TestCommand {Option1 = 13}
|
||||
new DivideCommand {Dividend = 13, Divisor = 8}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new TestCommand(),
|
||||
GetCommandSchema(typeof(TestCommand)),
|
||||
new CommandInput(new[]
|
||||
new DivideCommand(),
|
||||
GetCommandSchema(typeof(DivideCommand)),
|
||||
new CommandInput("div", new[]
|
||||
{
|
||||
new CommandOptionInput("int", "13"),
|
||||
new CommandOptionInput("str", "hello world")
|
||||
new CommandOptionInput("dividend", "13"),
|
||||
new CommandOptionInput("d", "8")
|
||||
}),
|
||||
new TestCommand {Option1 = 13, Option2 = "hello world"}
|
||||
new DivideCommand {Dividend = 13, Divisor = 8}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new TestCommand(),
|
||||
GetCommandSchema(typeof(TestCommand)),
|
||||
new CommandInput(new[]
|
||||
new DivideCommand(),
|
||||
GetCommandSchema(typeof(DivideCommand)),
|
||||
new CommandInput("div", new[]
|
||||
{
|
||||
new CommandOptionInput("i", "13")
|
||||
new CommandOptionInput("D", "13"),
|
||||
new CommandOptionInput("d", "8")
|
||||
}),
|
||||
new TestCommand {Option1 = 13}
|
||||
new DivideCommand {Dividend = 13, Divisor = 8}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new TestCommand(),
|
||||
GetCommandSchema(typeof(TestCommand)),
|
||||
new CommandInput(new[]
|
||||
new ConcatCommand(),
|
||||
GetCommandSchema(typeof(ConcatCommand)),
|
||||
new CommandInput("concat", new[]
|
||||
{
|
||||
new CommandOptionInput("i", "13"),
|
||||
new CommandOptionInput("s", "hello world"),
|
||||
new CommandOptionInput("S")
|
||||
new CommandOptionInput("i", new[] {"foo", " ", "bar"})
|
||||
}),
|
||||
new TestCommand {Option1 = 13, Option2 = "hello world", Option3 = true}
|
||||
new ConcatCommand {Inputs = new[] {"foo", " ", "bar"}}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new ConcatCommand(),
|
||||
GetCommandSchema(typeof(ConcatCommand)),
|
||||
new CommandInput("concat", new[]
|
||||
{
|
||||
new CommandOptionInput("i", new[] {"foo", "bar"}),
|
||||
new CommandOptionInput("s", " ")
|
||||
}),
|
||||
new ConcatCommand {Inputs = new[] {"foo", "bar"}, Separator = " "}
|
||||
);
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> GetTestCases_InitializeCommand_Negative()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
new TestCommand(),
|
||||
GetCommandSchema(typeof(TestCommand)),
|
||||
CommandInput.Empty
|
||||
new DivideCommand(),
|
||||
GetCommandSchema(typeof(DivideCommand)),
|
||||
new CommandInput("div")
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new TestCommand(),
|
||||
GetCommandSchema(typeof(TestCommand)),
|
||||
new CommandInput(new[]
|
||||
new DivideCommand(),
|
||||
GetCommandSchema(typeof(DivideCommand)),
|
||||
new CommandInput("div", new[]
|
||||
{
|
||||
new CommandOptionInput("str", "hello world")
|
||||
new CommandOptionInput("D", "13")
|
||||
})
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new ConcatCommand(),
|
||||
GetCommandSchema(typeof(ConcatCommand)),
|
||||
new CommandInput("concat")
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new ConcatCommand(),
|
||||
GetCommandSchema(typeof(ConcatCommand)),
|
||||
new CommandInput("concat", new[]
|
||||
{
|
||||
new CommandOptionInput("s", "_")
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
public partial class CommandOptionInputConverterTests
|
||||
{
|
||||
private enum TestEnum
|
||||
{
|
||||
Value1,
|
||||
Value2,
|
||||
Value3
|
||||
}
|
||||
|
||||
private class TestStringConstructable
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
public TestStringConstructable(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private class TestStringParseable
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private TestStringParseable(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static TestStringParseable Parse(string value) => new TestStringParseable(value);
|
||||
}
|
||||
|
||||
private class TestStringParseableWithFormatProvider
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private TestStringParseableWithFormatProvider(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static TestStringParseableWithFormatProvider Parse(string value, IFormatProvider formatProvider) =>
|
||||
new TestStringParseableWithFormatProvider(value + " " + formatProvider);
|
||||
}
|
||||
}
|
||||
|
||||
// Negative
|
||||
public partial class CommandOptionInputConverterTests
|
||||
{
|
||||
private class NonStringParseable
|
||||
{
|
||||
public int Value { get; }
|
||||
|
||||
public NonStringParseable(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,14 @@ using System.Globalization;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCustomTypes;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class CommandOptionInputConverterTests
|
||||
public class CommandOptionInputConverterTests
|
||||
{
|
||||
private static IEnumerable<TestCaseData> GetTestCases_ConvertOptionInput()
|
||||
{
|
||||
@@ -271,7 +272,7 @@ namespace CliFx.Tests.Services
|
||||
|
||||
yield return new TestCaseData(
|
||||
new CommandOptionInput("option", "123"),
|
||||
typeof(NonStringParseable)
|
||||
typeof(TestNonStringParseable)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
public partial class CommandSchemaResolverTests
|
||||
{
|
||||
[Command("cmd", Description = "NormalCommand1 description.")]
|
||||
private class NormalCommand1 : ICommand
|
||||
{
|
||||
[CommandOption("option-a", 'a')]
|
||||
public int OptionA { get; set; }
|
||||
|
||||
[CommandOption('A')]
|
||||
public int AlmostOptionA { get; set; }
|
||||
|
||||
[CommandOption("option-b", IsRequired = true)]
|
||||
public string OptionB { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command(Description = "NormalCommand2 description.")]
|
||||
private class NormalCommand2 : ICommand
|
||||
{
|
||||
[CommandOption("option-c", Description = "OptionC description.")]
|
||||
public bool OptionC { get; set; }
|
||||
|
||||
[CommandOption("option-d", 'd')]
|
||||
public DateTimeOffset OptionD { get; set; }
|
||||
|
||||
public string NotAnOption { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
// Negative
|
||||
public partial class CommandSchemaResolverTests
|
||||
{
|
||||
[Command("conflict")]
|
||||
private class ConflictingCommand1 : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command("conflict")]
|
||||
private class ConflictingCommand2 : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command]
|
||||
private class InvalidCommand1
|
||||
{
|
||||
}
|
||||
|
||||
// No attribute
|
||||
private class InvalidCommand2 : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command]
|
||||
private class InvalidCommand3 : ICommand
|
||||
{
|
||||
[CommandOption("conflict")]
|
||||
public string ConflictingOption1 { get; set; }
|
||||
|
||||
[CommandOption("conflict")]
|
||||
public string ConflictingOption2 { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command]
|
||||
private class InvalidCommand4 : ICommand
|
||||
{
|
||||
[CommandOption('c')]
|
||||
public string ConflictingOption1 { get; set; }
|
||||
|
||||
[CommandOption('c')]
|
||||
public string ConflictingOption2 { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,37 +3,49 @@ using System.Collections.Generic;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class CommandSchemaResolverTests
|
||||
public class CommandSchemaResolverTests
|
||||
{
|
||||
private static IEnumerable<TestCaseData> GetTestCases_GetCommandSchemas()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(NormalCommand1), typeof(NormalCommand2)},
|
||||
new[] {typeof(DivideCommand), typeof(ConcatCommand)},
|
||||
new[]
|
||||
{
|
||||
new CommandSchema(typeof(NormalCommand1), "cmd", "NormalCommand1 description.",
|
||||
new CommandSchema(typeof(DivideCommand), "div", "Divide one number by another.",
|
||||
new[]
|
||||
{
|
||||
new CommandOptionSchema(typeof(NormalCommand1).GetProperty(nameof(NormalCommand1.OptionA)),
|
||||
"option-a", 'a', false, null),
|
||||
new CommandOptionSchema(typeof(NormalCommand1).GetProperty(nameof(NormalCommand1.AlmostOptionA)),
|
||||
null, 'A', false, null),
|
||||
new CommandOptionSchema(typeof(NormalCommand1).GetProperty(nameof(NormalCommand1.OptionB)),
|
||||
"option-b", null, true, null)
|
||||
new CommandOptionSchema(typeof(DivideCommand).GetProperty(nameof(DivideCommand.Dividend)),
|
||||
"dividend", 'D', true, "The number to divide."),
|
||||
new CommandOptionSchema(typeof(DivideCommand).GetProperty(nameof(DivideCommand.Divisor)),
|
||||
"divisor", 'd', true, "The number to divide by.")
|
||||
}),
|
||||
new CommandSchema(typeof(NormalCommand2), null, "NormalCommand2 description.",
|
||||
new CommandSchema(typeof(ConcatCommand), "concat", "Concatenate strings.",
|
||||
new[]
|
||||
{
|
||||
new CommandOptionSchema(typeof(NormalCommand2).GetProperty(nameof(NormalCommand2.OptionC)),
|
||||
"option-c", null, false, "OptionC description."),
|
||||
new CommandOptionSchema(typeof(NormalCommand2).GetProperty(nameof(NormalCommand2.OptionD)),
|
||||
"option-d", 'd', false, null)
|
||||
new CommandOptionSchema(typeof(ConcatCommand).GetProperty(nameof(ConcatCommand.Inputs)),
|
||||
null, 'i', true, "Input strings."),
|
||||
new CommandOptionSchema(typeof(ConcatCommand).GetProperty(nameof(ConcatCommand.Separator)),
|
||||
null, 's', false, "String separator.")
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
new[] {typeof(EchoDefaultCommand)},
|
||||
new[]
|
||||
{
|
||||
new CommandSchema(typeof(EchoDefaultCommand), null, null,
|
||||
new[]
|
||||
{
|
||||
new CommandOptionSchema(typeof(EchoDefaultCommand).GetProperty(nameof(EchoDefaultCommand.Message)),
|
||||
"message", 'm', true, null)
|
||||
})
|
||||
}
|
||||
);
|
||||
@@ -48,27 +60,27 @@ namespace CliFx.Tests.Services
|
||||
|
||||
yield return new TestCaseData(new object[]
|
||||
{
|
||||
new[] {typeof(ConflictingCommand1), typeof(ConflictingCommand2)}
|
||||
new[] {typeof(NonImplementedCommand)}
|
||||
});
|
||||
|
||||
yield return new TestCaseData(new object[]
|
||||
{
|
||||
new[] {typeof(InvalidCommand1)}
|
||||
new[] {typeof(NonAnnotatedCommand)}
|
||||
});
|
||||
|
||||
yield return new TestCaseData(new object[]
|
||||
{
|
||||
new[] {typeof(DuplicateOptionNamesCommand)}
|
||||
});
|
||||
|
||||
yield return new TestCaseData(new object[]
|
||||
{
|
||||
new[] {typeof(InvalidCommand2)}
|
||||
new[] {typeof(DuplicateOptionShortNamesCommand)}
|
||||
});
|
||||
|
||||
|
||||
yield return new TestCaseData(new object[]
|
||||
{
|
||||
new[] {typeof(InvalidCommand3)}
|
||||
});
|
||||
|
||||
yield return new TestCaseData(new object[]
|
||||
{
|
||||
new[] {typeof(InvalidCommand4)}
|
||||
new[] {typeof(ExceptionCommand), typeof(CommandExceptionCommand)}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
public partial class DelegateCommandFactoryTests
|
||||
{
|
||||
[Command]
|
||||
private class TestCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,14 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class DelegateCommandFactoryTests
|
||||
public class DelegateCommandFactoryTests
|
||||
{
|
||||
private static CommandSchema GetCommandSchema(Type commandType) =>
|
||||
new CommandSchemaResolver().GetCommandSchemas(new[] {commandType}).Single();
|
||||
@@ -18,7 +19,7 @@ namespace CliFx.Tests.Services
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
new Func<CommandSchema, ICommand>(schema => (ICommand) Activator.CreateInstance(schema.Type)),
|
||||
GetCommandSchema(typeof(TestCommand))
|
||||
GetCommandSchema(typeof(EchoCommand))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
public partial class HelpTextRendererTests
|
||||
{
|
||||
[Command(Description = "DefaultCommand description.")]
|
||||
private class DefaultCommand : ICommand
|
||||
{
|
||||
[CommandOption("option-a", 'a', Description = "OptionA description.")]
|
||||
public string OptionA { get; set; }
|
||||
|
||||
[CommandOption("option-b", 'b', Description = "OptionB description.")]
|
||||
public string OptionB { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command("cmd", Description = "NamedCommand description.")]
|
||||
private class NamedCommand : ICommand
|
||||
{
|
||||
[CommandOption("option-c", 'c', Description = "OptionC description.")]
|
||||
public string OptionC { get; set; }
|
||||
|
||||
[CommandOption("option-d", 'd', Description = "OptionD description.")]
|
||||
public string OptionD { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Command("cmd sub", Description = "NamedSubCommand description.")]
|
||||
private class NamedSubCommand : ICommand
|
||||
{
|
||||
[CommandOption("option-e", 'e', Description = "OptionE description.")]
|
||||
public string OptionE { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,14 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using CliFx.Models;
|
||||
using CliFx.Services;
|
||||
using CliFx.Tests.TestCommands;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CliFx.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public partial class HelpTextRendererTests
|
||||
public class HelpTextRendererTests
|
||||
{
|
||||
private static HelpTextSource CreateHelpTextSource(IReadOnlyList<Type> availableCommandTypes, Type targetCommandType)
|
||||
{
|
||||
@@ -27,11 +28,13 @@ namespace CliFx.Tests.Services
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
CreateHelpTextSource(
|
||||
new[] {typeof(DefaultCommand), typeof(NamedCommand), typeof(NamedSubCommand)},
|
||||
typeof(DefaultCommand)),
|
||||
new[] {typeof(HelpDefaultCommand), typeof(HelpNamedCommand), typeof(HelpSubCommand)},
|
||||
typeof(HelpDefaultCommand)),
|
||||
|
||||
new[]
|
||||
{
|
||||
"Description",
|
||||
"HelpDefaultCommand description.",
|
||||
"Usage",
|
||||
"[command]", "[options]",
|
||||
"Options",
|
||||
@@ -40,20 +43,20 @@ namespace CliFx.Tests.Services
|
||||
"-h|--help", "Shows help text.",
|
||||
"--version", "Shows version information.",
|
||||
"Commands",
|
||||
"cmd", "NamedCommand description.",
|
||||
"cmd", "HelpNamedCommand description.",
|
||||
"You can run", "to show help on a specific command."
|
||||
}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
CreateHelpTextSource(
|
||||
new[] {typeof(DefaultCommand), typeof(NamedCommand), typeof(NamedSubCommand)},
|
||||
typeof(NamedCommand)),
|
||||
new[] {typeof(HelpDefaultCommand), typeof(HelpNamedCommand), typeof(HelpSubCommand)},
|
||||
typeof(HelpNamedCommand)),
|
||||
|
||||
new[]
|
||||
{
|
||||
"Description",
|
||||
"NamedCommand description.",
|
||||
"HelpNamedCommand description.",
|
||||
"Usage",
|
||||
"cmd", "[command]", "[options]",
|
||||
"Options",
|
||||
@@ -61,20 +64,20 @@ namespace CliFx.Tests.Services
|
||||
"-d|--option-d", "OptionD description.",
|
||||
"-h|--help", "Shows help text.",
|
||||
"Commands",
|
||||
"sub", "NamedSubCommand description.",
|
||||
"sub", "HelpSubCommand description.",
|
||||
"You can run", "to show help on a specific command."
|
||||
}
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
CreateHelpTextSource(
|
||||
new[] {typeof(DefaultCommand), typeof(NamedCommand), typeof(NamedSubCommand)},
|
||||
typeof(NamedSubCommand)),
|
||||
new[] {typeof(HelpDefaultCommand), typeof(HelpNamedCommand), typeof(HelpSubCommand)},
|
||||
typeof(HelpSubCommand)),
|
||||
|
||||
new[]
|
||||
{
|
||||
"Description",
|
||||
"NamedSubCommand description.",
|
||||
"HelpSubCommand description.",
|
||||
"Usage",
|
||||
"cmd sub", "[options]",
|
||||
"Options",
|
||||
|
||||
19
CliFx.Tests/TestCommands/CommandExceptionCommand.cs
Normal file
19
CliFx.Tests/TestCommands/CommandExceptionCommand.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("exc")]
|
||||
public class CommandExceptionCommand : ICommand
|
||||
{
|
||||
[CommandOption("code", 'c')]
|
||||
public int ExitCode { get; set; } = 1337;
|
||||
|
||||
[CommandOption("msg", 'm')]
|
||||
public string Message { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => throw new CommandException(Message, ExitCode);
|
||||
}
|
||||
}
|
||||
23
CliFx.Tests/TestCommands/ConcatCommand.cs
Normal file
23
CliFx.Tests/TestCommands/ConcatCommand.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("concat", Description = "Concatenate strings.")]
|
||||
public class ConcatCommand : ICommand
|
||||
{
|
||||
[CommandOption('i', IsRequired = true, Description = "Input strings.")]
|
||||
public IReadOnlyList<string> Inputs { get; set; }
|
||||
|
||||
[CommandOption('s', Description = "String separator.")]
|
||||
public string Separator { get; set; } = "";
|
||||
|
||||
public Task ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(string.Join(Separator, Inputs));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
25
CliFx.Tests/TestCommands/DivideCommand.cs
Normal file
25
CliFx.Tests/TestCommands/DivideCommand.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("div", Description = "Divide one number by another.")]
|
||||
public class DivideCommand : ICommand
|
||||
{
|
||||
[CommandOption("dividend", 'D', IsRequired = true, Description = "The number to divide.")]
|
||||
public double Dividend { get; set; }
|
||||
|
||||
[CommandOption("divisor", 'd', IsRequired = true, Description = "The number to divide by.")]
|
||||
public double Divisor { get; set; }
|
||||
|
||||
// This property should be ignored by resolver
|
||||
public bool NotAnOption { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Dividend / Divisor);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
CliFx.Tests/TestCommands/DuplicateOptionNamesCommand.cs
Normal file
18
CliFx.Tests/TestCommands/DuplicateOptionNamesCommand.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command]
|
||||
public class DuplicateOptionNamesCommand : ICommand
|
||||
{
|
||||
[CommandOption("fruits")]
|
||||
public string Apples { get; set; }
|
||||
|
||||
[CommandOption("fruits")]
|
||||
public string Oranges { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
18
CliFx.Tests/TestCommands/DuplicateOptionShortNamesCommand.cs
Normal file
18
CliFx.Tests/TestCommands/DuplicateOptionShortNamesCommand.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command]
|
||||
public class DuplicateOptionShortNamesCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Apples { get; set; }
|
||||
|
||||
[CommandOption('f')]
|
||||
public string Oranges { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
19
CliFx.Tests/TestCommands/EchoCommand.cs
Normal file
19
CliFx.Tests/TestCommands/EchoCommand.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("echo")]
|
||||
public class EchoCommand : ICommand
|
||||
{
|
||||
[CommandOption("message", 'm', IsRequired = true)]
|
||||
public string Message { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Message);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
CliFx.Tests/TestCommands/EchoDefaultCommand.cs
Normal file
9
CliFx.Tests/TestCommands/EchoDefaultCommand.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using CliFx.Attributes;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command]
|
||||
public class EchoDefaultCommand : EchoCommand
|
||||
{
|
||||
}
|
||||
}
|
||||
16
CliFx.Tests/TestCommands/ExceptionCommand.cs
Normal file
16
CliFx.Tests/TestCommands/ExceptionCommand.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("exc")]
|
||||
public class ExceptionCommand : ICommand
|
||||
{
|
||||
[CommandOption("msg", 'm')]
|
||||
public string Message { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => throw new Exception(Message);
|
||||
}
|
||||
}
|
||||
18
CliFx.Tests/TestCommands/HelpDefaultCommand.cs
Normal file
18
CliFx.Tests/TestCommands/HelpDefaultCommand.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command(Description = "HelpDefaultCommand description.")]
|
||||
public class HelpDefaultCommand : ICommand
|
||||
{
|
||||
[CommandOption("option-a", 'a', Description = "OptionA description.")]
|
||||
public string OptionA { get; set; }
|
||||
|
||||
[CommandOption("option-b", 'b', Description = "OptionB description.")]
|
||||
public string OptionB { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
18
CliFx.Tests/TestCommands/HelpNamedCommand.cs
Normal file
18
CliFx.Tests/TestCommands/HelpNamedCommand.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("cmd", Description = "HelpNamedCommand description.")]
|
||||
public class HelpNamedCommand : ICommand
|
||||
{
|
||||
[CommandOption("option-c", 'c', Description = "OptionC description.")]
|
||||
public string OptionC { get; set; }
|
||||
|
||||
[CommandOption("option-d", 'd', Description = "OptionD description.")]
|
||||
public string OptionD { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
15
CliFx.Tests/TestCommands/HelpSubCommand.cs
Normal file
15
CliFx.Tests/TestCommands/HelpSubCommand.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command("cmd sub", Description = "HelpSubCommand description.")]
|
||||
public class HelpSubCommand : ICommand
|
||||
{
|
||||
[CommandOption("option-e", 'e', Description = "OptionE description.")]
|
||||
public string OptionE { get; set; }
|
||||
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
10
CliFx.Tests/TestCommands/NonAnnotatedCommand.cs
Normal file
10
CliFx.Tests/TestCommands/NonAnnotatedCommand.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using CliFx.Services;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
public class NonAnnotatedCommand : ICommand
|
||||
{
|
||||
public Task ExecuteAsync(IConsole console) => Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
9
CliFx.Tests/TestCommands/NonImplementedCommand.cs
Normal file
9
CliFx.Tests/TestCommands/NonImplementedCommand.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using CliFx.Attributes;
|
||||
|
||||
namespace CliFx.Tests.TestCommands
|
||||
{
|
||||
[Command]
|
||||
public class NonImplementedCommand
|
||||
{
|
||||
}
|
||||
}
|
||||
9
CliFx.Tests/TestCustomTypes/TestEnum.cs
Normal file
9
CliFx.Tests/TestCustomTypes/TestEnum.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace CliFx.Tests.TestCustomTypes
|
||||
{
|
||||
public enum TestEnum
|
||||
{
|
||||
Value1,
|
||||
Value2,
|
||||
Value3
|
||||
}
|
||||
}
|
||||
12
CliFx.Tests/TestCustomTypes/TestNonStringParseable.cs
Normal file
12
CliFx.Tests/TestCustomTypes/TestNonStringParseable.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace CliFx.Tests.TestCustomTypes
|
||||
{
|
||||
public class TestNonStringParseable
|
||||
{
|
||||
public int Value { get; }
|
||||
|
||||
public TestNonStringParseable(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
CliFx.Tests/TestCustomTypes/TestStringConstructable.cs
Normal file
12
CliFx.Tests/TestCustomTypes/TestStringConstructable.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace CliFx.Tests.TestCustomTypes
|
||||
{
|
||||
public class TestStringConstructable
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
public TestStringConstructable(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
CliFx.Tests/TestCustomTypes/TestStringParseable.cs
Normal file
14
CliFx.Tests/TestCustomTypes/TestStringParseable.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace CliFx.Tests.TestCustomTypes
|
||||
{
|
||||
public class TestStringParseable
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private TestStringParseable(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static TestStringParseable Parse(string value) => new TestStringParseable(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace CliFx.Tests.TestCustomTypes
|
||||
{
|
||||
public class TestStringParseableWithFormatProvider
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
private TestStringParseableWithFormatProvider(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public static TestStringParseableWithFormatProvider Parse(string value, IFormatProvider formatProvider) =>
|
||||
new TestStringParseableWithFormatProvider(value + " " + formatProvider);
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ namespace CliFx
|
||||
// Keep track whether there was an error in the input
|
||||
var isError = false;
|
||||
|
||||
// If target command isn't defined, find its parent
|
||||
// If target command isn't defined, find its contextual replacement
|
||||
if (targetCommandSchema == null)
|
||||
{
|
||||
// If command was specified, inform the user that it's not defined
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using CliFx.Models;
|
||||
using CliFx.Models;
|
||||
|
||||
namespace CliFx.Services
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user