mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
Add new test framework for consoles
This commit is contained in:
parent
f5a9c0ca26
commit
04efd1719c
@ -1,17 +1,3 @@
|
||||
root = false
|
||||
|
||||
[*.cs]
|
||||
# CS1591: Missing XML comment for publicly visible type or member
|
||||
dotnet_diagnostic.CS1591.severity = none
|
||||
|
||||
# SA1600: Elements should be documented
|
||||
dotnet_diagnostic.SA1600.severity = none
|
||||
|
||||
# SA1200: Using directives should be placed correctly
|
||||
dotnet_diagnostic.SA1200.severity = none
|
||||
|
||||
# Default severity for analyzer diagnostics with category 'StyleCop.CSharp.OrderingRules'
|
||||
dotnet_analyzer_diagnostic.category-StyleCop.CSharp.OrderingRules.severity = none
|
||||
|
||||
# CA1819: Properties should not return arrays
|
||||
dotnet_diagnostic.CA1819.severity = none
|
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ICommandInterceptor"/> that triggers a callback when invoked.
|
||||
/// </summary>
|
||||
public sealed class CallbackCommandInterceptor : ICommandInterceptor
|
||||
{
|
||||
private readonly Action<CommandContext, CommandSettings> _callback;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CallbackCommandInterceptor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback to call when the interceptor is invoked.</param>
|
||||
public CallbackCommandInterceptor(Action<CommandContext, CommandSettings> callback)
|
||||
{
|
||||
_callback = callback ?? throw new ArgumentNullException(nameof(callback));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Intercept(CommandContext context, CommandSettings settings)
|
||||
{
|
||||
_callback(context, settings);
|
||||
}
|
||||
}
|
||||
}
|
29
src/Spectre.Console.Testing/Cli/CommandAppFailure.cs
Normal file
29
src/Spectre.Console.Testing/Cli/CommandAppFailure.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a <see cref="CommandApp"/> runtime failure.
|
||||
/// </summary>
|
||||
public sealed class CommandAppFailure
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the exception that was thrown.
|
||||
/// </summary>
|
||||
public Exception Exception { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the console output.
|
||||
/// </summary>
|
||||
public string Output { get; }
|
||||
|
||||
internal CommandAppFailure(Exception exception, string output)
|
||||
{
|
||||
Exception = exception ?? throw new ArgumentNullException(nameof(exception));
|
||||
Output = output.NormalizeLineEndings()
|
||||
.TrimLines()
|
||||
.Trim();
|
||||
}
|
||||
}
|
||||
}
|
43
src/Spectre.Console.Testing/Cli/CommandAppResult.cs
Normal file
43
src/Spectre.Console.Testing/Cli/CommandAppResult.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the result of a completed <see cref="CommandApp"/> run.
|
||||
/// </summary>
|
||||
public sealed class CommandAppResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the exit code.
|
||||
/// </summary>
|
||||
public int ExitCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the console output.
|
||||
/// </summary>
|
||||
public string Output { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command context.
|
||||
/// </summary>
|
||||
public CommandContext? Context { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command settings.
|
||||
/// </summary>
|
||||
public CommandSettings? Settings { get; }
|
||||
|
||||
internal CommandAppResult(int exitCode, string output, CommandContext? context, CommandSettings? settings)
|
||||
{
|
||||
ExitCode = exitCode;
|
||||
Output = output ?? string.Empty;
|
||||
Context = context;
|
||||
Settings = settings;
|
||||
|
||||
Output = Output
|
||||
.NormalizeLineEndings()
|
||||
.TrimLines()
|
||||
.Trim();
|
||||
}
|
||||
}
|
||||
}
|
112
src/Spectre.Console.Testing/Cli/CommandAppTester.cs
Normal file
112
src/Spectre.Console.Testing/Cli/CommandAppTester.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="CommandApp"/> test harness.
|
||||
/// </summary>
|
||||
public sealed class CommandAppTester
|
||||
{
|
||||
private Action<CommandApp>? _appConfiguration;
|
||||
private Action<IConfigurator>? _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default command.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The default command type.</typeparam>
|
||||
public void SetDefaultCommand<T>()
|
||||
where T : class, ICommand
|
||||
{
|
||||
_appConfiguration = (app) => app.SetDefaultCommand<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the command application.
|
||||
/// </summary>
|
||||
/// <param name="action">The configuration action.</param>
|
||||
public void Configure(Action<IConfigurator> action)
|
||||
{
|
||||
if (_configuration != null)
|
||||
{
|
||||
throw new InvalidOperationException("The command app harnest have already been configured.");
|
||||
}
|
||||
|
||||
_configuration = action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the command application and expects an exception of a specific type to be thrown.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The expected exception type.</typeparam>
|
||||
/// <param name="args">The arguments.</param>
|
||||
/// <returns>The information about the failure.</returns>
|
||||
public CommandAppFailure RunAndCatch<T>(params string[] args)
|
||||
where T : Exception
|
||||
{
|
||||
var console = new TestConsole().Width(int.MaxValue);
|
||||
|
||||
try
|
||||
{
|
||||
Run(args, console, c => c.PropagateExceptions());
|
||||
throw new InvalidOperationException("Expected an exception to be thrown, but there was none.");
|
||||
}
|
||||
catch (T ex)
|
||||
{
|
||||
return new CommandAppFailure(ex, console.Output);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Expected an exception of type '{typeof(T).FullName}' to be thrown, "
|
||||
+ $"but received {ex.GetType().FullName}.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the command application.
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments.</param>
|
||||
/// <returns>The result.</returns>
|
||||
public CommandAppResult Run(params string[] args)
|
||||
{
|
||||
var console = new TestConsole().Width(int.MaxValue);
|
||||
return Run(args, console);
|
||||
}
|
||||
|
||||
private CommandAppResult Run(string[] args, TestConsole console, Action<IConfigurator>? config = null)
|
||||
{
|
||||
CommandContext? context = null;
|
||||
CommandSettings? settings = null;
|
||||
|
||||
var app = new CommandApp();
|
||||
_appConfiguration?.Invoke(app);
|
||||
|
||||
if (_configuration != null)
|
||||
{
|
||||
app.Configure(_configuration);
|
||||
}
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
app.Configure(config);
|
||||
}
|
||||
|
||||
app.Configure(c => c.ConfigureConsole(console));
|
||||
app.Configure(c => c.SetInterceptor(new CallbackCommandInterceptor((ctx, s) =>
|
||||
{
|
||||
context = ctx;
|
||||
settings = s;
|
||||
})));
|
||||
|
||||
var result = app.Run(args);
|
||||
|
||||
var output = console.Output
|
||||
.NormalizeLineEndings()
|
||||
.TrimLines()
|
||||
.Trim();
|
||||
|
||||
return new CommandAppResult(result, output, context, settings);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class CommandAppFixture
|
||||
{
|
||||
private Action<CommandApp> _appConfiguration = _ => { };
|
||||
private Action<IConfigurator> _configuration;
|
||||
|
||||
public CommandAppFixture()
|
||||
{
|
||||
_configuration = (_) => { };
|
||||
}
|
||||
|
||||
public CommandAppFixture WithDefaultCommand<T>()
|
||||
where T : class, ICommand
|
||||
{
|
||||
_appConfiguration = (app) => app.SetDefaultCommand<T>();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Configure(Action<IConfigurator> action)
|
||||
{
|
||||
_configuration = action;
|
||||
}
|
||||
|
||||
public (string Message, string Output) RunAndCatch<T>(params string[] args)
|
||||
where T : Exception
|
||||
{
|
||||
CommandContext context = null;
|
||||
CommandSettings settings = null;
|
||||
|
||||
using var console = new FakeConsole();
|
||||
|
||||
var app = new CommandApp();
|
||||
_appConfiguration?.Invoke(app);
|
||||
|
||||
app.Configure(_configuration);
|
||||
app.Configure(c => c.ConfigureConsole(console));
|
||||
app.Configure(c => c.SetInterceptor(new FakeCommandInterceptor((ctx, s) =>
|
||||
{
|
||||
context = ctx;
|
||||
settings = s;
|
||||
})));
|
||||
|
||||
try
|
||||
{
|
||||
app.Run(args);
|
||||
}
|
||||
catch (T ex)
|
||||
{
|
||||
var output = console.Output
|
||||
.NormalizeLineEndings()
|
||||
.TrimLines()
|
||||
.Trim();
|
||||
|
||||
return (ex.Message, output);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("No exception was thrown");
|
||||
}
|
||||
|
||||
public (int ExitCode, string Output, CommandContext Context, CommandSettings Settings) Run(params string[] args)
|
||||
{
|
||||
CommandContext context = null;
|
||||
CommandSettings settings = null;
|
||||
|
||||
using var console = new FakeConsole(width: int.MaxValue);
|
||||
|
||||
var app = new CommandApp();
|
||||
_appConfiguration?.Invoke(app);
|
||||
|
||||
app.Configure(_configuration);
|
||||
app.Configure(c => c.ConfigureConsole(console));
|
||||
app.Configure(c => c.SetInterceptor(new FakeCommandInterceptor((ctx, s) =>
|
||||
{
|
||||
context = ctx;
|
||||
settings = s;
|
||||
})));
|
||||
|
||||
var result = app.Run(args);
|
||||
|
||||
var output = console.Output
|
||||
.NormalizeLineEndings()
|
||||
.TrimLines()
|
||||
.Trim();
|
||||
|
||||
return (result, output, context, settings);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Shouldly;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
public static class ShouldlyExtensions
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
public static T And<T>(this T item, Action<T> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
action(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static void As<T>(this T item, Action<T> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
action(item);
|
||||
}
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static void As<T>(this object item, Action<T> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
action((T)item);
|
||||
}
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static void ShouldBe<T>(this Type item)
|
||||
{
|
||||
item.ShouldBe(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Spectre.Console
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extensions for <see cref="string"/>.
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
private static readonly Regex _lineNumberRegex = new Regex(":\\d+", RegexOptions.Singleline);
|
||||
private static readonly Regex _filenameRegex = new Regex("\\sin\\s.*cs:nn", RegexOptions.Multiline);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new string with all lines trimmed of trailing whitespace.
|
||||
/// </summary>
|
||||
/// <param name="value">The string to trim.</param>
|
||||
/// <returns>A new string with all lines trimmed of trailing whitespace.</returns>
|
||||
public static string TrimLines(this string value)
|
||||
{
|
||||
if (value is null)
|
||||
@ -16,24 +21,19 @@ namespace Spectre.Console
|
||||
}
|
||||
|
||||
var result = new List<string>();
|
||||
var lines = value.Split(new[] { '\n' });
|
||||
|
||||
foreach (var line in lines)
|
||||
foreach (var line in value.Split(new[] { '\n' }))
|
||||
{
|
||||
var current = line.TrimEnd();
|
||||
if (string.IsNullOrWhiteSpace(current))
|
||||
{
|
||||
result.Add(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(current);
|
||||
}
|
||||
result.Add(line.TrimEnd());
|
||||
}
|
||||
|
||||
return string.Join("\n", result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new string with normalized line endings.
|
||||
/// </summary>
|
||||
/// <param name="value">The string to normalize line endings for.</param>
|
||||
/// <returns>A new string with normalized line endings.</returns>
|
||||
public static string NormalizeLineEndings(this string value)
|
||||
{
|
||||
if (value != null)
|
||||
@ -44,36 +44,5 @@ namespace Spectre.Console
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static string NormalizeStackTrace(this string text)
|
||||
{
|
||||
text = _lineNumberRegex.Replace(text, match =>
|
||||
{
|
||||
return ":nn";
|
||||
});
|
||||
|
||||
return _filenameRegex.Replace(text, match =>
|
||||
{
|
||||
var value = match.Value;
|
||||
var index = value.LastIndexOfAny(new[] { '\\', '/' });
|
||||
var filename = value.Substring(index + 1, value.Length - index - 1);
|
||||
|
||||
return $" in /xyz/{filename}";
|
||||
});
|
||||
}
|
||||
|
||||
internal static string ReplaceExact(this string text, string oldValue, string newValue)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(newValue))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
#if NET5_0
|
||||
return text.Replace(oldValue, newValue, StringComparison.Ordinal);
|
||||
#else
|
||||
return text.Replace(oldValue, newValue);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,17 @@
|
||||
namespace Spectre.Console.Tests
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extensions for <see cref="Style"/>.
|
||||
/// </summary>
|
||||
public static class StyleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the foreground or background color of the specified style.
|
||||
/// </summary>
|
||||
/// <param name="style">The style.</param>
|
||||
/// <param name="color">The color.</param>
|
||||
/// <param name="foreground">Whether or not to set the foreground color.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Style SetColor(this Style style, Color color, bool foreground)
|
||||
{
|
||||
if (foreground)
|
||||
|
@ -1,69 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
public static class XmlElementExtensions
|
||||
{
|
||||
public static void SetNullableAttribute(this XmlElement element, string name, string value)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
|
||||
element.SetAttribute(name, value ?? "NULL");
|
||||
}
|
||||
|
||||
public static void SetNullableAttribute(this XmlElement element, string name, IEnumerable<string> values)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
|
||||
if (values?.Any() != true)
|
||||
{
|
||||
element.SetAttribute(name, "NULL");
|
||||
}
|
||||
|
||||
element.SetAttribute(name, string.Join(",", values));
|
||||
}
|
||||
|
||||
public static void SetBooleanAttribute(this XmlElement element, string name, bool value)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
|
||||
element.SetAttribute(name, value ? "true" : "false");
|
||||
}
|
||||
|
||||
public static void SetEnumAttribute(this XmlElement element, string name, Enum value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(element));
|
||||
}
|
||||
|
||||
var field = value.GetType().GetField(value.ToString());
|
||||
var attribute = field.GetCustomAttribute<DescriptionAttribute>(false);
|
||||
if (attribute == null)
|
||||
{
|
||||
throw new InvalidOperationException("Enum is missing description.");
|
||||
}
|
||||
|
||||
element.SetAttribute(name, attribute.Description);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeAnsiConsole : IDisposable, IAnsiConsole
|
||||
{
|
||||
private readonly StringWriter _writer;
|
||||
private readonly IAnsiConsole _console;
|
||||
private readonly FakeExclusivityMode _exclusivityLock;
|
||||
|
||||
public string Output => _writer.ToString();
|
||||
|
||||
public Profile Profile => _console.Profile;
|
||||
public IAnsiConsoleCursor Cursor => _console.Cursor;
|
||||
public FakeConsoleInput Input { get; }
|
||||
public IExclusivityMode ExclusivityMode => _exclusivityLock;
|
||||
public RenderPipeline Pipeline => _console.Pipeline;
|
||||
|
||||
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||
|
||||
public FakeAnsiConsole(
|
||||
ColorSystem colors,
|
||||
AnsiSupport ansi = AnsiSupport.Yes,
|
||||
int width = 80)
|
||||
{
|
||||
_exclusivityLock = new FakeExclusivityMode();
|
||||
_writer = new StringWriter();
|
||||
|
||||
var factory = new AnsiConsoleFactory();
|
||||
_console = factory.Create(new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = ansi,
|
||||
ColorSystem = (ColorSystemSupport)colors,
|
||||
Out = new AnsiConsoleOutput(_writer),
|
||||
Enrichment = new ProfileEnrichment
|
||||
{
|
||||
UseDefaultEnrichers = false,
|
||||
},
|
||||
});
|
||||
|
||||
_console.Profile.Width = width;
|
||||
_console.Profile.Capabilities.Unicode = true;
|
||||
|
||||
Input = new FakeConsoleInput();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_writer?.Dispose();
|
||||
}
|
||||
|
||||
public void Clear(bool home)
|
||||
{
|
||||
_console.Clear(home);
|
||||
}
|
||||
|
||||
public void Write(IRenderable renderable)
|
||||
{
|
||||
_console.Write(renderable);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeCapabilities : IReadOnlyCapabilities
|
||||
{
|
||||
public ColorSystem ColorSystem { get; set; } = ColorSystem.TrueColor;
|
||||
|
||||
public bool Ansi { get; set; }
|
||||
|
||||
public bool Links { get; set; }
|
||||
|
||||
public bool Legacy { get; set; }
|
||||
|
||||
public bool IsTerminal { get; set; }
|
||||
|
||||
public bool Interactive { get; set; }
|
||||
|
||||
public bool Unicode { get; set; }
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeCommandInterceptor : ICommandInterceptor
|
||||
{
|
||||
private readonly Action<CommandContext, CommandSettings> _action;
|
||||
|
||||
public FakeCommandInterceptor(Action<CommandContext, CommandSettings> action)
|
||||
{
|
||||
_action = action ?? throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
public void Intercept(CommandContext context, CommandSettings settings)
|
||||
{
|
||||
_action(context, settings);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeConsole : IAnsiConsole, IDisposable
|
||||
{
|
||||
public Profile Profile { get; }
|
||||
public IAnsiConsoleCursor Cursor => new FakeAnsiConsoleCursor();
|
||||
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||
public IExclusivityMode ExclusivityMode { get; }
|
||||
public RenderPipeline Pipeline { get; }
|
||||
|
||||
public FakeConsoleInput Input { get; }
|
||||
public string Output => Profile.Out.Writer.ToString();
|
||||
public IReadOnlyList<string> Lines => Output.TrimEnd('\n').Split(new char[] { '\n' });
|
||||
|
||||
public FakeConsole(
|
||||
int width = 80, int height = 9000, Encoding encoding = null,
|
||||
bool supportsAnsi = true, ColorSystem colorSystem = ColorSystem.Standard,
|
||||
bool legacyConsole = false, bool interactive = true)
|
||||
{
|
||||
Input = new FakeConsoleInput();
|
||||
ExclusivityMode = new FakeExclusivityMode();
|
||||
Pipeline = new RenderPipeline();
|
||||
|
||||
Profile = new Profile(new AnsiConsoleOutput(new StringWriter()), encoding ?? Encoding.UTF8);
|
||||
Profile.Width = width;
|
||||
Profile.Height = height;
|
||||
Profile.Capabilities.ColorSystem = colorSystem;
|
||||
Profile.Capabilities.Ansi = supportsAnsi;
|
||||
Profile.Capabilities.Legacy = legacyConsole;
|
||||
Profile.Capabilities.Interactive = interactive;
|
||||
Profile.Capabilities.Links = true;
|
||||
Profile.Capabilities.Unicode = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Profile.Out.Writer.Dispose();
|
||||
}
|
||||
|
||||
public void Clear(bool home)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(IRenderable renderable)
|
||||
{
|
||||
foreach (var segment in renderable.GetSegments(this))
|
||||
{
|
||||
Profile.Out.Writer.Write(segment.Text);
|
||||
}
|
||||
}
|
||||
|
||||
public string WriteNormalizedException(Exception ex, ExceptionFormats formats = ExceptionFormats.Default)
|
||||
{
|
||||
this.WriteException(ex, formats);
|
||||
return string.Join("\n", Output.NormalizeStackTrace()
|
||||
.NormalizeLineEndings()
|
||||
.Split(new char[] { '\n' })
|
||||
.Select(line => line.TrimEnd()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeConsoleInput : IAnsiConsoleInput
|
||||
{
|
||||
private readonly Queue<ConsoleKeyInfo> _input;
|
||||
|
||||
public FakeConsoleInput()
|
||||
{
|
||||
_input = new Queue<ConsoleKeyInfo>();
|
||||
}
|
||||
|
||||
public void PushText(string input)
|
||||
{
|
||||
if (input is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
|
||||
foreach (var character in input)
|
||||
{
|
||||
PushCharacter(character);
|
||||
}
|
||||
}
|
||||
|
||||
public void PushTextWithEnter(string input)
|
||||
{
|
||||
PushText(input);
|
||||
PushKey(ConsoleKey.Enter);
|
||||
}
|
||||
|
||||
public void PushCharacter(char character)
|
||||
{
|
||||
var control = char.IsUpper(character);
|
||||
_input.Enqueue(new ConsoleKeyInfo(character, (ConsoleKey)character, false, false, control));
|
||||
}
|
||||
|
||||
public void PushKey(ConsoleKey key)
|
||||
{
|
||||
_input.Enqueue(new ConsoleKeyInfo((char)key, key, false, false, false));
|
||||
}
|
||||
|
||||
public ConsoleKeyInfo ReadKey(bool intercept)
|
||||
{
|
||||
if (_input.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No input available.");
|
||||
}
|
||||
|
||||
return _input.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeTypeResolver : ITypeResolver
|
||||
{
|
||||
private readonly IDictionary<Type, object> _lookup;
|
||||
|
||||
public FakeTypeResolver()
|
||||
{
|
||||
_lookup = new Dictionary<Type, object>();
|
||||
}
|
||||
|
||||
public void Register<T>(T instance)
|
||||
{
|
||||
_lookup[typeof(T)] = instance;
|
||||
}
|
||||
|
||||
public object Resolve(Type type)
|
||||
{
|
||||
if (_lookup.TryGetValue(type, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return Activator.CreateInstance(type);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeAnsiConsoleCursor : IAnsiConsoleCursor
|
||||
internal sealed class NoopCursor : IAnsiConsoleCursor
|
||||
{
|
||||
public void Move(CursorDirection direction, int steps)
|
||||
{
|
@ -3,7 +3,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeExclusivityMode : IExclusivityMode
|
||||
internal sealed class NoopExclusivityMode : IExclusivityMode
|
||||
{
|
||||
public T Run<T>(Func<T> func)
|
||||
{
|
@ -1,18 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0</TargetFrameworks>
|
||||
<TargetFrameworks>net5.0;netstandard2.0</TargetFrameworks>
|
||||
<IsTestProject>false</IsTestProject>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Description>Contains testing utilities for Spectre.Console.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\stylecop.json" Link="Properties/stylecop.json" />
|
||||
<None Include="../../resources/gfx/small-logo.png" Pack="true" PackagePath="\" Link="Properties/small-logo.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Label="Project References">
|
||||
<ProjectReference Include="..\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Shouldly" Version="4.0.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,5 +0,0 @@
|
||||
<ProjectConfiguration>
|
||||
<Settings>
|
||||
<XUnit2Enabled>False</XUnit2Enabled>
|
||||
</Settings>
|
||||
</ProjectConfiguration>
|
40
src/Spectre.Console.Testing/TestCapabilities.cs
Normal file
40
src/Spectre.Console.Testing/TestCapabilities.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents fake capabilities useful in tests.
|
||||
/// </summary>
|
||||
public sealed class TestCapabilities : IReadOnlyCapabilities
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public ColorSystem ColorSystem { get; set; } = ColorSystem.TrueColor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Ansi { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Links { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Legacy { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsTerminal { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Interactive { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool Unicode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RenderContext"/> with the same capabilities as this instace.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="RenderContext"/> with the same capabilities as this instace.</returns>
|
||||
public RenderContext CreateRenderContext()
|
||||
{
|
||||
return new RenderContext(this);
|
||||
}
|
||||
}
|
||||
}
|
122
src/Spectre.Console.Testing/TestConsole.cs
Normal file
122
src/Spectre.Console.Testing/TestConsole.cs
Normal file
@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// A testable console.
|
||||
/// </summary>
|
||||
public sealed class TestConsole : IAnsiConsole, IDisposable
|
||||
{
|
||||
private readonly IAnsiConsole _console;
|
||||
private readonly StringWriter _writer;
|
||||
private IAnsiConsoleCursor? _cursor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Profile Profile => _console.Profile;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IExclusivityMode ExclusivityMode => _console.ExclusivityMode;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the console input.
|
||||
/// </summary>
|
||||
public TestConsoleInput Input { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public RenderPipeline Pipeline => _console.Pipeline;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IAnsiConsoleCursor Cursor => _cursor ?? _console.Cursor;
|
||||
|
||||
/// <inheritdoc/>
|
||||
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the console output.
|
||||
/// </summary>
|
||||
public string Output => _writer.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the console output lines.
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> Lines => Output.NormalizeLineEndings().TrimEnd('\n').Split(new char[] { '\n' });
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not VT/ANSI sequences
|
||||
/// should be emitted to the console.
|
||||
/// </summary>
|
||||
public bool EmitAnsiSequences { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TestConsole"/> class.
|
||||
/// </summary>
|
||||
public TestConsole()
|
||||
{
|
||||
_writer = new StringWriter();
|
||||
_cursor = new NoopCursor();
|
||||
|
||||
Input = new TestConsoleInput();
|
||||
EmitAnsiSequences = false;
|
||||
|
||||
var factory = new AnsiConsoleFactory();
|
||||
_console = factory.Create(new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = AnsiSupport.Yes,
|
||||
ColorSystem = (ColorSystemSupport)ColorSystem.TrueColor,
|
||||
Out = new AnsiConsoleOutput(_writer),
|
||||
Interactive = InteractionSupport.No,
|
||||
ExclusivityMode = new NoopExclusivityMode(),
|
||||
Enrichment = new ProfileEnrichment
|
||||
{
|
||||
UseDefaultEnrichers = false,
|
||||
},
|
||||
});
|
||||
|
||||
_console.Profile.Width = 80;
|
||||
_console.Profile.Height = 24;
|
||||
_console.Profile.Capabilities.Ansi = true;
|
||||
_console.Profile.Capabilities.Unicode = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
_writer.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Clear(bool home)
|
||||
{
|
||||
_console.Clear(home);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Write(IRenderable renderable)
|
||||
{
|
||||
if (EmitAnsiSequences)
|
||||
{
|
||||
_console.Write(renderable);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var segment in renderable.GetSegments(this))
|
||||
{
|
||||
if (segment.IsControlCode)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Profile.Out.Writer.Write(segment.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetCursor(IAnsiConsoleCursor? cursor)
|
||||
{
|
||||
_cursor = cursor;
|
||||
}
|
||||
}
|
||||
}
|
55
src/Spectre.Console.Testing/TestConsoleExtensions.cs
Normal file
55
src/Spectre.Console.Testing/TestConsoleExtensions.cs
Normal file
@ -0,0 +1,55 @@
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extensions for <see cref="TestConsole"/>.
|
||||
/// </summary>
|
||||
public static class TestConsoleExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the console's color system.
|
||||
/// </summary>
|
||||
/// <param name="console">The console.</param>
|
||||
/// <param name="colors">The color system to use.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TestConsole Colors(this TestConsole console, ColorSystem colors)
|
||||
{
|
||||
console.Profile.Capabilities.ColorSystem = colors;
|
||||
return console;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the console interactive.
|
||||
/// </summary>
|
||||
/// <param name="console">The console.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TestConsole Interactive(this TestConsole console)
|
||||
{
|
||||
console.Profile.Capabilities.Interactive = true;
|
||||
return console;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the console width.
|
||||
/// </summary>
|
||||
/// <param name="console">The console.</param>
|
||||
/// <param name="width">The console width.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TestConsole Width(this TestConsole console, int width)
|
||||
{
|
||||
console.Profile.Width = width;
|
||||
return console;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turns on emitting of VT/ANSI sequences.
|
||||
/// </summary>
|
||||
/// <param name="console">The console.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static TestConsole EmitAnsiSequences(this TestConsole console)
|
||||
{
|
||||
console.SetCursor(null);
|
||||
console.EmitAnsiSequences = true;
|
||||
return console;
|
||||
}
|
||||
}
|
||||
}
|
78
src/Spectre.Console.Testing/TestConsoleInput.cs
Normal file
78
src/Spectre.Console.Testing/TestConsoleInput.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a testable console input mechanism.
|
||||
/// </summary>
|
||||
public sealed class TestConsoleInput : IAnsiConsoleInput
|
||||
{
|
||||
private readonly Queue<ConsoleKeyInfo> _input;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TestConsoleInput"/> class.
|
||||
/// </summary>
|
||||
public TestConsoleInput()
|
||||
{
|
||||
_input = new Queue<ConsoleKeyInfo>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes the specified text to the input queue.
|
||||
/// </summary>
|
||||
/// <param name="input">The input string.</param>
|
||||
public void PushText(string input)
|
||||
{
|
||||
if (input is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
|
||||
foreach (var character in input)
|
||||
{
|
||||
PushCharacter(character);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes the specified text followed by 'Enter' to the input queue.
|
||||
/// </summary>
|
||||
/// <param name="input">The input.</param>
|
||||
public void PushTextWithEnter(string input)
|
||||
{
|
||||
PushText(input);
|
||||
PushKey(ConsoleKey.Enter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes the specified character to the input queue.
|
||||
/// </summary>
|
||||
/// <param name="input">The input.</param>
|
||||
public void PushCharacter(char input)
|
||||
{
|
||||
var control = char.IsUpper(input);
|
||||
_input.Enqueue(new ConsoleKeyInfo(input, (ConsoleKey)input, false, false, control));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes the specified key to the input queue.
|
||||
/// </summary>
|
||||
/// <param name="input">The input.</param>
|
||||
public void PushKey(ConsoleKey input)
|
||||
{
|
||||
_input.Enqueue(new ConsoleKeyInfo((char)input, input, false, false, false));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ConsoleKeyInfo ReadKey(bool intercept)
|
||||
{
|
||||
if (_input.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No input available.");
|
||||
}
|
||||
|
||||
return _input.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class DummySpinner1 : Spinner
|
||||
{
|
||||
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
|
||||
public override bool IsUnicode => true;
|
||||
public override IReadOnlyList<string> Frames => new List<string> { "*", };
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class DummySpinner2 : Spinner
|
||||
{
|
||||
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
|
||||
public override bool IsUnicode => true;
|
||||
public override IReadOnlyList<string> Frames => new List<string> { "-", };
|
||||
}
|
||||
}
|
@ -34,7 +34,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.TrueColor)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(128, 0, 128), foreground));
|
||||
@ -49,7 +51,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Eight_Bit_Ansi_Code_For_Known_Colors(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.TrueColor)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(Color.Purple, foreground));
|
||||
@ -67,7 +71,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.EightBit);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.EightBit)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(Color.Olive, foreground));
|
||||
@ -82,7 +88,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Map_TrueColor_To_Nearest_Eight_Bit_Color_If_Possible(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.EightBit);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.EightBit)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(128, 128, 0), foreground));
|
||||
@ -97,7 +105,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Estimate_TrueColor_To_Nearest_Eight_Bit_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.EightBit);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.EightBit)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(126, 127, 0), foreground));
|
||||
@ -115,7 +125,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(Color.Olive, foreground));
|
||||
@ -135,7 +147,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
@ -155,7 +169,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
@ -173,7 +189,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Code_For_Known_Color(bool foreground, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Legacy);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Legacy)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(Color.Olive, foreground));
|
||||
@ -193,7 +211,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Legacy);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Legacy)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
@ -213,7 +233,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Legacy);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Legacy)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello", new Style().SetColor(new Color(r, g, b), foreground));
|
||||
|
@ -18,7 +18,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Ansi_Code(CursorDirection direction, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole().EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello");
|
||||
@ -36,7 +36,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Return_Correct_Ansi_Code()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole().EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello");
|
||||
|
@ -15,7 +15,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Output_Expected_Ansi_For_Markup(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Markup(markup);
|
||||
@ -28,7 +30,8 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Output_Expected_Ansi_For_Link_With_Url_And_Text()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Markup("[link=https://patriksvensson.se]Click to visit my blog[/]");
|
||||
@ -41,7 +44,8 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Output_Expected_Ansi_For_Link_With_Only_Url()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Markup("[link]https://patriksvensson.se[/]");
|
||||
@ -55,7 +59,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Be_Able_To_Escape_Tags(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Markup(markup);
|
||||
@ -72,7 +78,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Encounters_Malformed_Tag(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => console.Markup(markup));
|
||||
@ -86,7 +92,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Tags_Are_Unbalanced()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => console.Markup("[yellow][blue]Hello[/]"));
|
||||
@ -100,7 +106,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Encounters_Closing_Tag()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => console.Markup("Hello[/]World"));
|
||||
|
@ -19,7 +19,8 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Write_Decorated_Text_Correctly(Decoration decoration, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor);
|
||||
var console = new TestConsole()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello World", new Style().Decoration(decoration));
|
||||
@ -34,7 +35,8 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Write_Text_With_Multiple_Decorations_Correctly(Decoration decoration, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor);
|
||||
var console = new TestConsole()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello World", new Style().Decoration(decoration));
|
||||
|
@ -13,7 +13,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Clear_Screen(bool home, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write("Hello");
|
||||
@ -28,7 +30,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Combine_Decoration_And_Colors()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write(
|
||||
@ -46,7 +50,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Not_Include_Foreground_If_Set_To_Default_Color()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write(
|
||||
@ -64,7 +70,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Not_Include_Background_If_Set_To_Default_Color()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write(
|
||||
@ -82,7 +90,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Not_Include_Decoration_If_Set_To_None()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.Write(
|
||||
@ -102,7 +112,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Reset_Colors_Correctly_After_Line_Break()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.WriteLine("Hello", new Style().Background(ConsoleColor.Red));
|
||||
@ -117,7 +129,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Reset_Colors_Correctly_After_Line_Break_In_Text()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
// When
|
||||
console.WriteLine("Hello\nWorld", new Style().Background(ConsoleColor.Red));
|
||||
|
@ -15,7 +15,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new BarChart()
|
||||
@ -34,7 +34,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly_2()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new BarChart()
|
||||
|
@ -33,7 +33,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var panel = Fixture.GetPanel().NoBorder();
|
||||
|
||||
// When
|
||||
@ -65,7 +65,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var panel = Fixture.GetPanel().AsciiBorder();
|
||||
|
||||
// When
|
||||
@ -97,7 +97,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var panel = Fixture.GetPanel().DoubleBorder();
|
||||
|
||||
// When
|
||||
@ -129,7 +129,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var panel = Fixture.GetPanel().HeavyBorder();
|
||||
|
||||
// When
|
||||
@ -158,7 +158,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var panel = Fixture.GetPanel().RoundedBorder();
|
||||
|
||||
// When
|
||||
@ -187,7 +187,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var panel = Fixture.GetPanel().SquareBorder();
|
||||
|
||||
// When
|
||||
|
@ -15,7 +15,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart();
|
||||
|
||||
// When
|
||||
@ -30,7 +30,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_With_Specific_Width()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart().Width(60);
|
||||
|
||||
// When
|
||||
@ -45,7 +45,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly_With_Specific_Value_Formatter()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart()
|
||||
.Width(60)
|
||||
.Culture("sv-SE")
|
||||
@ -63,7 +63,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly_Without_Tags()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart().Width(60).HideTags();
|
||||
|
||||
// When
|
||||
@ -78,7 +78,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly_Without_Tag_Values()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart().Width(60).HideTagValues();
|
||||
|
||||
// When
|
||||
@ -93,7 +93,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correctly_With_Specific_Culture()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart().Width(60).Culture("sv-SE");
|
||||
|
||||
// When
|
||||
@ -108,7 +108,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_FullSize_Mode_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var chart = Fixture.GetChart().Width(60).FullSize();
|
||||
|
||||
// When
|
||||
@ -123,7 +123,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Correct_Ansi()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.EightBit, width: 80);
|
||||
var console = new TestConsole().EmitAnsiSequences();
|
||||
var chart = Fixture.GetChart().Width(60).FullSize();
|
||||
|
||||
// When
|
||||
|
@ -16,7 +16,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Calendar_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var calendar = new Calendar(2020, 10)
|
||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
||||
@ -34,7 +34,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Center_Calendar_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var calendar = new Calendar(2020, 10)
|
||||
.Centered()
|
||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||
@ -53,7 +53,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Left_Align_Calendar_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var calendar = new Calendar(2020, 10)
|
||||
.LeftAligned()
|
||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||
@ -72,7 +72,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Right_Align_Calendar_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var calendar = new Calendar(2020, 10)
|
||||
.RightAligned()
|
||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||
@ -91,7 +91,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Calendar_Correctly_For_Specific_Culture()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var calendar = new Calendar(2020, 10, 15)
|
||||
.Culture("de-DE")
|
||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||
|
@ -42,7 +42,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Canvas_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var canvas = new Canvas(width: 5, height: 5);
|
||||
canvas.SetPixel(0, 0, Color.Red);
|
||||
canvas.SetPixel(4, 0, Color.Green);
|
||||
@ -61,7 +64,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Simple_Measure()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var panel = new Panel(new Canvas(width: 2, height: 2)
|
||||
.SetPixel(0, 0, Color.Aqua)
|
||||
.SetPixel(1, 1, Color.Grey));
|
||||
@ -78,7 +84,11 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Scale_Down_Canvas_Is_Bigger_Than_Terminal()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, width: 10);
|
||||
var console = new TestConsole()
|
||||
.Width(10)
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var canvas = new Canvas(width: 20, height: 10);
|
||||
canvas.SetPixel(0, 0, Color.Aqua);
|
||||
canvas.SetPixel(19, 9, Color.Grey);
|
||||
@ -95,7 +105,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Scale_Down_Canvas_If_MaxWidth_Is_Set()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, width: 80);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var canvas = new Canvas(width: 20, height: 10) { MaxWidth = 10 };
|
||||
canvas.SetPixel(0, 0, Color.Aqua);
|
||||
canvas.SetPixel(19, 9, Color.Aqua);
|
||||
@ -111,7 +124,11 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Not_Render_Canvas_If_Canvas_Cannot_Be_Scaled_Down()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, width: 10);
|
||||
var console = new TestConsole()
|
||||
.Width(10)
|
||||
.Colors(ColorSystem.Standard)
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var canvas = new Canvas(width: 20, height: 2);
|
||||
canvas.SetPixel(0, 0, Color.Aqua);
|
||||
canvas.SetPixel(19, 1, Color.Grey);
|
||||
|
@ -79,7 +79,7 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public static string Run<TSettings>(params string[] args)
|
||||
where TSettings : CommandSettings
|
||||
{
|
||||
using (var writer = new FakeConsole())
|
||||
using (var writer = new TestConsole())
|
||||
{
|
||||
var app = new CommandApp();
|
||||
app.Configure(c => c.ConfigureConsole(writer));
|
||||
|
@ -26,11 +26,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Encountered unexpected character '$'.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Encountered unexpected character '$'.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,11 +48,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Encountered unterminated value name 'BAR'.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Encountered unterminated value name 'BAR'.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,11 +70,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Options without name are not allowed.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Options without name are not allowed.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,11 +92,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Option names cannot start with a digit.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Option names cannot start with a digit.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,11 +114,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Encountered invalid character '$' in option name.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Encountered invalid character '$' in option name.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,11 +136,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Long option names must consist of more than one character.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Long option names must consist of more than one character.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,11 +158,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Short option names can not be longer than one character.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Short option names can not be longer than one character.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,11 +180,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Multiple option values are not supported.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Multiple option values are not supported.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,11 +202,11 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("Encountered invalid character '$' in value name.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("Encountered invalid character '$' in value name.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,23 +224,22 @@ namespace Spectre.Console.Tests.Unit.Cli.Annotations
|
||||
public Task Should_Return_Correct_Text()
|
||||
{
|
||||
// Given, When
|
||||
var (message, result) = Fixture.Run<Settings>();
|
||||
var result = Fixture.Run<Settings>();
|
||||
|
||||
// Then
|
||||
message.ShouldBe("No long or short name for option has been specified.");
|
||||
return Verifier.Verify(result);
|
||||
result.Exception.Message.ShouldBe("No long or short name for option has been specified.");
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Fixture
|
||||
{
|
||||
public static (string Message, string Output) Run<TSettings>(params string[] args)
|
||||
public static CommandAppFailure Run<TSettings>(params string[] args)
|
||||
where TSettings : CommandSettings
|
||||
{
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(c =>
|
||||
{
|
||||
c.PropagateExceptions();
|
||||
c.AddCommand<GenericCommand<TSettings>>("foo");
|
||||
});
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Shouldly;
|
||||
using Shouldly;
|
||||
using Spectre.Console.Cli;
|
||||
using Spectre.Console.Testing;
|
||||
using Xunit;
|
||||
@ -42,10 +42,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Nullable_objects_in_settings_are_populated_properly()
|
||||
public void Should_Populate_Nullable_Objects_In_Settings()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -53,19 +53,21 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, _, _, settings) = fixture.Run("null");
|
||||
var nullableSettings = (NullableSettings)settings;
|
||||
var result = fixture.Run("null");
|
||||
|
||||
// Then
|
||||
nullableSettings.Detailed.ShouldBeNull();
|
||||
nullableSettings.Extra.ShouldBeNull();
|
||||
result.Settings.ShouldBeOfType<NullableSettings>().And(settings =>
|
||||
{
|
||||
settings.Detailed.ShouldBeNull();
|
||||
settings.Extra.ShouldBeNull();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Nullable_objects_with_init_in_settings_are_populated_properly()
|
||||
public void Should_Populate_Nullable_Objects_With_Init_In_Settings()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -73,19 +75,21 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, _, _, settings) = fixture.Run("null");
|
||||
var nullableSettings = (NullableWithInitSettings)settings;
|
||||
var result = fixture.Run("null");
|
||||
|
||||
// Then
|
||||
nullableSettings.Detailed.ShouldBeNull();
|
||||
nullableSettings.Extra.ShouldBeNull();
|
||||
result.Settings.ShouldBeOfType<NullableWithInitSettings>().And(settings =>
|
||||
{
|
||||
settings.Detailed.ShouldBeNull();
|
||||
settings.Extra.ShouldBeNull();
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Regular_settings_are_populated_properly()
|
||||
public void Should_Populate_Regular_Settings()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -93,12 +97,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, _, _, settings) = fixture.Run("null", "-d", "true", "first-item");
|
||||
var nullableSettings = (NullableSettings)settings;
|
||||
var result = fixture.Run("null", "-d", "true", "first-item");
|
||||
|
||||
// Then
|
||||
nullableSettings.Detailed.ShouldBe(true);
|
||||
nullableSettings.Extra.ShouldBe(new[] { "first-item" });
|
||||
result.Settings.ShouldBeOfType<NullableSettings>().And(settings =>
|
||||
{
|
||||
settings.Detailed.ShouldBe(true);
|
||||
settings.Extra.ShouldBe(new[] { "first-item" });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -66,7 +66,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Set_Flag_And_Value_If_Both_Were_Provided()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -74,14 +74,11 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
{
|
||||
"foo", "--serve", "123",
|
||||
});
|
||||
var result = app.Run(new[] { "foo", "--serve", "123", });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<FlagSettings>().And(flag =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<FlagSettings>().And(flag =>
|
||||
{
|
||||
flag.Serve.IsSet.ShouldBeTrue();
|
||||
flag.Serve.Value.ShouldBe(123);
|
||||
@ -92,7 +89,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Only_Set_Flag_If_No_Value_Was_Provided()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -100,14 +97,11 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
{
|
||||
"foo", "--serve",
|
||||
});
|
||||
var result = app.Run(new[] { "foo", "--serve" });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<FlagSettings>().And(flag =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<FlagSettings>().And(flag =>
|
||||
{
|
||||
flag.Serve.IsSet.ShouldBeTrue();
|
||||
flag.Serve.Value.ShouldBe(0);
|
||||
@ -118,7 +112,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Set_Value_To_Default_Value_If_None_Was_Explicitly_Set()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -126,14 +120,11 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
{
|
||||
"foo", "--serve",
|
||||
});
|
||||
var result = app.Run(new[] { "foo", "--serve" });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<FlagSettingsWithDefaultValue>().And(flag =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<FlagSettingsWithDefaultValue>().And(flag =>
|
||||
{
|
||||
flag.Serve.IsSet.ShouldBeTrue();
|
||||
flag.Serve.Value.ShouldBe(987);
|
||||
@ -144,7 +135,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Create_Unset_Instance_If_Flag_Was_Not_Set()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -152,14 +143,11 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
{
|
||||
"foo",
|
||||
});
|
||||
var result = app.Run(new[] { "foo" });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<FlagSettings>().And(flag =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<FlagSettings>().And(flag =>
|
||||
{
|
||||
flag.Serve.IsSet.ShouldBeFalse();
|
||||
flag.Serve.Value.ShouldBe(0);
|
||||
@ -170,7 +158,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Create_Unset_Instance_With_Null_For_Nullable_Value_Type_If_Flag_Was_Not_Set()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -178,14 +166,11 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
{
|
||||
"foo",
|
||||
});
|
||||
var result = app.Run(new[] { "foo" });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<FlagSettingsWithNullableValueType>().And(flag =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<FlagSettingsWithNullableValueType>().And(flag =>
|
||||
{
|
||||
flag.Serve.IsSet.ShouldBeFalse();
|
||||
flag.Serve.Value.ShouldBeNull();
|
||||
@ -201,9 +186,11 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var flag = new FlagValue<string>();
|
||||
flag.Value = value;
|
||||
flag.IsSet = isSet;
|
||||
var flag = new FlagValue<string>
|
||||
{
|
||||
Value = value,
|
||||
IsSet = isSet,
|
||||
};
|
||||
|
||||
// When
|
||||
var result = flag.ToString();
|
||||
@ -220,8 +207,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
string expected)
|
||||
{
|
||||
// Given
|
||||
var flag = new FlagValue<string>();
|
||||
flag.IsSet = isSet;
|
||||
var flag = new FlagValue<string>
|
||||
{
|
||||
IsSet = isSet,
|
||||
};
|
||||
|
||||
// When
|
||||
var result = flag.ToString();
|
||||
|
@ -19,7 +19,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Root_Correctly()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -29,10 +29,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -40,7 +40,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Skip_Hidden_Commands()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -52,10 +52,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -63,7 +63,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Command_Correctly()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -75,10 +75,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("cat", "--help");
|
||||
var result = fixture.Run("cat", "--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -86,7 +86,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Leaf_Correctly()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -98,10 +98,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("cat", "lion", "--help");
|
||||
var result = fixture.Run("cat", "lion", "--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -109,18 +109,18 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Default_Command_Correctly()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
fixture.WithDefaultCommand<LionCommand>();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<LionCommand>();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -128,7 +128,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Root_Examples_Defined_On_Root()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -139,10 +139,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -150,7 +150,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -161,10 +161,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -172,7 +172,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Root_Examples_Defined_On_Leaves_If_No_Other_Examples_Are_Found()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -187,10 +187,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -198,7 +198,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Only_Output_Command_Examples_Defined_On_Command()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -215,10 +215,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("animal", "--help");
|
||||
var result = fixture.Run("animal", "--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -226,8 +226,8 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
fixture.WithDefaultCommand<LionCommand>();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<LionCommand>();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -235,10 +235,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -246,7 +246,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
@ -254,10 +254,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -265,18 +265,18 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_List_Arguments_In_Correct_Order()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
fixture.WithDefaultCommand<GenericCommand<ArgumentOrderSettings>>();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<GenericCommand<ArgumentOrderSettings>>();
|
||||
fixture.Configure(configurator =>
|
||||
{
|
||||
configurator.SetApplicationName("myapp");
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run("--help");
|
||||
var result = fixture.Run("--help");
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Inject_Parameters()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
var dependency = new FakeDependency();
|
||||
|
||||
app.WithDefaultCommand<GenericCommand<InjectSettings>>();
|
||||
app.SetDefaultCommand<GenericCommand<InjectSettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.Settings.Registrar.RegisterInstance(dependency);
|
||||
@ -46,15 +46,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--name", "foo",
|
||||
"--age", "35",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<InjectSettings>().And(injected =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<InjectSettings>().And(injected =>
|
||||
{
|
||||
injected.ShouldNotBeNull();
|
||||
injected.Fake.ShouldBeSameAs(dependency);
|
||||
|
@ -127,15 +127,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Map_Pairs_To_Pair_Deconstructable_Collection_Using_Default_Deconstructort()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<DefaultPairDeconstructorSettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<DefaultPairDeconstructorSettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--var", "foo=1",
|
||||
"--var", "foo=3",
|
||||
@ -143,8 +143,8 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DefaultPairDeconstructorSettings>().And(pair =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DefaultPairDeconstructorSettings>().And(pair =>
|
||||
{
|
||||
pair.Values.ShouldNotBeNull();
|
||||
pair.Values.Count.ShouldBe(2);
|
||||
@ -160,41 +160,41 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
string input, string expected)
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<DefaultPairDeconstructorSettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<DefaultPairDeconstructorSettings>>();
|
||||
|
||||
// When
|
||||
var (result, output, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--var", input,
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(-1);
|
||||
output.ShouldBe(expected);
|
||||
result.ExitCode.ShouldBe(-1);
|
||||
result.Output.ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Map_Lookup_Values()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<LookupSettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<LookupSettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--var", "foo=bar",
|
||||
"--var", "foo=qux",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<LookupSettings>().And(pair =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<LookupSettings>().And(pair =>
|
||||
{
|
||||
pair.Values.ShouldNotBeNull();
|
||||
pair.Values.Count.ShouldBe(1);
|
||||
@ -206,23 +206,23 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Map_Dictionary_Values()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<DictionarySettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<DictionarySettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--var", "foo=bar",
|
||||
"--var", "baz=qux",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DictionarySettings>().And(pair =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DictionarySettings>().And(pair =>
|
||||
{
|
||||
pair.Values.ShouldNotBeNull();
|
||||
pair.Values.Count.ShouldBe(2);
|
||||
@ -235,23 +235,23 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Map_Latest_Value_Of_Same_Key_When_Mapping_To_Dictionary()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<DictionarySettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<DictionarySettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--var", "foo=bar",
|
||||
"--var", "foo=qux",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DictionarySettings>().And(pair =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DictionarySettings>().And(pair =>
|
||||
{
|
||||
pair.Values.ShouldNotBeNull();
|
||||
pair.Values.Count.ShouldBe(1);
|
||||
@ -263,23 +263,23 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Map_ReadOnly_Dictionary_Values()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<ReadOnlyDictionarySettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<ReadOnlyDictionarySettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"--var", "foo=bar",
|
||||
"--var", "baz=qux",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<ReadOnlyDictionarySettings>().And(pair =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<ReadOnlyDictionarySettings>().And(pair =>
|
||||
{
|
||||
pair.Values.ShouldNotBeNull();
|
||||
pair.Values.Count.ShouldBe(2);
|
||||
|
@ -657,7 +657,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
|
||||
public string Run(params string[] args)
|
||||
{
|
||||
using (var console = new FakeConsole())
|
||||
using (var console = new TestConsole())
|
||||
{
|
||||
var app = new CommandApp();
|
||||
_appConfiguration?.Invoke(app);
|
||||
|
@ -14,7 +14,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Register_Remaining_Parsed_Arguments_With_Context()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -25,7 +25,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12", "--",
|
||||
"--foo", "bar", "--foo", "baz",
|
||||
@ -34,18 +34,18 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.Remaining.Parsed.Count.ShouldBe(4);
|
||||
ctx.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" });
|
||||
ctx.ShouldHaveRemainingArgument("b", values: new[] { (string)null });
|
||||
ctx.ShouldHaveRemainingArgument("a", values: new[] { (string)null });
|
||||
ctx.ShouldHaveRemainingArgument("r", values: new[] { (string)null });
|
||||
result.Context.Remaining.Parsed.Count.ShouldBe(4);
|
||||
result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" });
|
||||
result.Context.ShouldHaveRemainingArgument("b", values: new[] { (string)null });
|
||||
result.Context.ShouldHaveRemainingArgument("a", values: new[] { (string)null });
|
||||
result.Context.ShouldHaveRemainingArgument("r", values: new[] { (string)null });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Register_Remaining_Raw_Arguments_With_Context()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -56,7 +56,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12", "--",
|
||||
"--foo", "bar", "-bar", "\"baz\"", "qux",
|
||||
@ -64,13 +64,13 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.Remaining.Raw.Count.ShouldBe(6);
|
||||
ctx.Remaining.Raw[0].ShouldBe("--foo");
|
||||
ctx.Remaining.Raw[1].ShouldBe("bar");
|
||||
ctx.Remaining.Raw[2].ShouldBe("-bar");
|
||||
ctx.Remaining.Raw[3].ShouldBe("baz");
|
||||
ctx.Remaining.Raw[4].ShouldBe("qux");
|
||||
ctx.Remaining.Raw[5].ShouldBe("foo bar baz qux");
|
||||
result.Context.Remaining.Raw.Count.ShouldBe(6);
|
||||
result.Context.Remaining.Raw[0].ShouldBe("--foo");
|
||||
result.Context.Remaining.Raw[1].ShouldBe("bar");
|
||||
result.Context.Remaining.Raw[2].ShouldBe("-bar");
|
||||
result.Context.Remaining.Raw[3].ShouldBe("baz");
|
||||
result.Context.Remaining.Raw[4].ShouldBe("qux");
|
||||
result.Context.Remaining.Raw[5].ShouldBe("foo bar baz qux");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Treat_Commands_As_Case_Sensitive_If_Specified()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandApp();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.UseStrictParsing();
|
||||
@ -39,7 +39,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Treat_Long_Options_As_Case_Sensitive_If_Specified()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandApp();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.UseStrictParsing();
|
||||
@ -66,7 +66,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Treat_Short_Options_As_Case_Sensitive()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandApp();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.UseStrictParsing();
|
||||
@ -92,7 +92,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Suppress_Case_Sensitivity_If_Specified()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.UseStrictParsing();
|
||||
@ -102,14 +102,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"Command", "--Foo", "bar",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<StringOptionSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<StringOptionSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.ShouldBe("bar");
|
||||
});
|
||||
|
@ -14,7 +14,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Bind_Using_Custom_Type_Converter_If_Specified()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -22,15 +22,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"cat", "--name", "Tiger",
|
||||
"--agility", "FOOBAR",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<CatSettings>().And(cat =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<CatSettings>().And(cat =>
|
||||
{
|
||||
cat.Agility.ShouldBe(6);
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Can_Mix_Safe_And_Unsafe_Configurators()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -31,15 +31,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "--alive", "mammal", "--name",
|
||||
"Rufus", "dog", "12", "--good-boy",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Age.ShouldBe(12);
|
||||
dog.GoodBoy.ShouldBe(true);
|
||||
@ -52,7 +52,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Can_Turn_Safety_On_After_Turning_It_Off_For_Branch()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -69,15 +69,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "--alive", "mammal", "--name",
|
||||
"Rufus", "dog", "12", "--good-boy",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Age.ShouldBe(12);
|
||||
dog.GoodBoy.ShouldBe(true);
|
||||
@ -112,7 +112,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_1()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -128,15 +128,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "--alive", "mammal", "--name",
|
||||
"Rufus", "dog", "12", "--good-boy",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Age.ShouldBe(12);
|
||||
dog.GoodBoy.ShouldBe(true);
|
||||
@ -149,7 +149,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_2()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -157,15 +157,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"dog", "12", "4", "--good-boy",
|
||||
"--name", "Rufus", "--alive",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Legs.ShouldBe(12);
|
||||
dog.Age.ShouldBe(4);
|
||||
@ -179,7 +179,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_3()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -191,15 +191,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "dog", "12", "--good-boy",
|
||||
"--name", "Rufus",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Age.ShouldBe(12);
|
||||
dog.GoodBoy.ShouldBe(true);
|
||||
@ -212,7 +212,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_4()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -223,15 +223,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12",
|
||||
"--good-boy", "--name", "Rufus",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Legs.ShouldBe(4);
|
||||
dog.Age.ShouldBe(12);
|
||||
@ -245,7 +245,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_5()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -253,14 +253,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"multi", "--foo", "a", "--foo", "b", "--bar", "1", "--foo", "c", "--bar", "2",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.Length.ShouldBe(3);
|
||||
vec.Foo.ShouldBe(new[] { "a", "b", "c" });
|
||||
@ -273,7 +273,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_6()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -281,14 +281,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"multi", "a", "b", "c",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<ArgumentVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<ArgumentVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.Length.ShouldBe(3);
|
||||
vec.Foo.ShouldBe(new[] { "a", "b", "c" });
|
||||
|
@ -56,7 +56,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Assign_Values_To_Argument_Vector()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -64,14 +64,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"multi", "a", "b", "c",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<ArgumentVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<ArgumentVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.Length.ShouldBe(3);
|
||||
vec.Foo[0].ShouldBe("a");
|
||||
@ -84,7 +84,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Assign_Values_To_Option_Vector()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -92,15 +92,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"cmd", "--foo", "red",
|
||||
"--bar", "4", "--foo", "blue",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.ShouldBe(new string[] { "red", "blue" });
|
||||
vec.Bar.ShouldBe(new int[] { 4 });
|
||||
|
@ -13,7 +13,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Output_The_Version_To_The_Console()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddBranch<AnimalSettings>("animal", animal =>
|
||||
@ -27,10 +27,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.VersionCommand);
|
||||
var result = fixture.Run(Constants.VersionCommand);
|
||||
|
||||
// Then
|
||||
output.ShouldStartWith("Spectre.Cli version ");
|
||||
result.Output.ShouldStartWith("Spectre.Cli version ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Dump_Correct_Model_For_Case_1()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -34,10 +34,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.XmlDocCommand);
|
||||
var result = fixture.Run(Constants.XmlDocCommand);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -45,17 +45,17 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Dump_Correct_Model_For_Case_2()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddCommand<DogCommand>("dog");
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.XmlDocCommand);
|
||||
var result = fixture.Run(Constants.XmlDocCommand);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -63,7 +63,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Dump_Correct_Model_For_Case_3()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddBranch<AnimalSettings>("animal", animal =>
|
||||
@ -74,10 +74,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.XmlDocCommand);
|
||||
var result = fixture.Run(Constants.XmlDocCommand);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -85,7 +85,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Dump_Correct_Model_For_Case_4()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddBranch<AnimalSettings>("animal", animal =>
|
||||
@ -95,10 +95,10 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.XmlDocCommand);
|
||||
var result = fixture.Run(Constants.XmlDocCommand);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -106,17 +106,17 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Dump_Correct_Model_For_Case_5()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddCommand<OptionVectorCommand>("cmd");
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.XmlDocCommand);
|
||||
var result = fixture.Run(Constants.XmlDocCommand);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -124,17 +124,18 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public Task Should_Dump_Correct_Model_For_Model_With_Default_Command()
|
||||
{
|
||||
// Given
|
||||
var fixture = new CommandAppFixture().WithDefaultCommand<DogCommand>();
|
||||
var fixture = new CommandAppTester();
|
||||
fixture.SetDefaultCommand<DogCommand>();
|
||||
fixture.Configure(config =>
|
||||
{
|
||||
config.AddCommand<HorseCommand>("horse");
|
||||
});
|
||||
|
||||
// When
|
||||
var (_, output, _, _) = fixture.Run(Constants.XmlDocCommand);
|
||||
var result = fixture.Run(Constants.XmlDocCommand);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(output);
|
||||
return Verifier.Verify(result.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_1()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -28,15 +28,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "--alive", "mammal", "--name",
|
||||
"Rufus", "dog", "12", "--good-boy",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Age.ShouldBe(12);
|
||||
dog.GoodBoy.ShouldBe(true);
|
||||
@ -49,7 +49,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_2()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -57,15 +57,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"dog", "12", "4", "--good-boy",
|
||||
"--name", "Rufus", "--alive",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Legs.ShouldBe(12);
|
||||
dog.Age.ShouldBe(4);
|
||||
@ -79,7 +79,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_3()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -91,15 +91,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "dog", "12", "--good-boy",
|
||||
"--name", "Rufus",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Age.ShouldBe(12);
|
||||
dog.GoodBoy.ShouldBe(true);
|
||||
@ -112,7 +112,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_4()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -123,15 +123,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12", "--good-boy",
|
||||
"--name", "Rufus",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Legs.ShouldBe(4);
|
||||
dog.Age.ShouldBe(12);
|
||||
@ -145,7 +145,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_5()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -153,15 +153,15 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"multi", "--foo", "a", "--foo", "b",
|
||||
"--bar", "1", "--foo", "c", "--bar", "2",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.Length.ShouldBe(3);
|
||||
vec.Foo.ShouldBe(new[] { "a", "b", "c" });
|
||||
@ -174,7 +174,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Pass_Case_6()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -182,14 +182,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"multi", "a", "b", "c",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<ArgumentVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<ArgumentVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.Length.ShouldBe(3);
|
||||
vec.Foo.ShouldBe(new[] { "a", "b", "c" });
|
||||
@ -200,7 +200,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Be_Able_To_Use_Command_Alias()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -208,14 +208,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"multiple", "--foo", "a",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<OptionVectorSettings>().And(vec =>
|
||||
{
|
||||
vec.Foo.Length.ShouldBe(1);
|
||||
vec.Foo.ShouldBe(new[] { "a" });
|
||||
@ -226,19 +226,19 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Assign_Default_Value_To_Optional_Argument()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<OptionalArgumentWithDefaultValueSettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<OptionalArgumentWithDefaultValueSettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(Array.Empty<string>());
|
||||
var result = app.Run(Array.Empty<string>());
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<OptionalArgumentWithDefaultValueSettings>().And(settings =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<OptionalArgumentWithDefaultValueSettings>().And(settings =>
|
||||
{
|
||||
settings.Greeting.ShouldBe("Hello World");
|
||||
});
|
||||
@ -248,19 +248,19 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Assign_Default_Value_To_Optional_Argument_Using_Converter_If_Necessary()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<OptionalArgumentWithDefaultValueAndTypeConverterSettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<OptionalArgumentWithDefaultValueAndTypeConverterSettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(Array.Empty<string>());
|
||||
var result = app.Run(Array.Empty<string>());
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<OptionalArgumentWithDefaultValueAndTypeConverterSettings>().And(settings =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<OptionalArgumentWithDefaultValueAndTypeConverterSettings>().And(settings =>
|
||||
{
|
||||
settings.Greeting.ShouldBe(5);
|
||||
});
|
||||
@ -270,8 +270,8 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Throw_If_Required_Argument_Have_Default_Value()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<GenericCommand<RequiredArgumentWithDefaultValueSettings>>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<GenericCommand<RequiredArgumentWithDefaultValueSettings>>();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -385,35 +385,6 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("True", true)]
|
||||
[InlineData("false", false)]
|
||||
[InlineData("False", false)]
|
||||
public void Should_Accept_Explicit_Boolan_Flag(string value, bool expected)
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
config.AddCommand<DogCommand>("dog");
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
{
|
||||
"dog", "12", "4", "--alive", value,
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.IsAlive.ShouldBe(expected);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Can_Register_Command_Settings_When_Configuring_Application()
|
||||
{
|
||||
@ -447,6 +418,35 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
registrar.Registrations[typeof(MammalSettings)].ShouldContain(typeof(MammalSettings));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("True", true)]
|
||||
[InlineData("false", false)]
|
||||
[InlineData("False", false)]
|
||||
public void Should_Accept_Explicit_Boolan_Flag(string value, bool expected)
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
config.AddCommand<DogCommand>("dog");
|
||||
});
|
||||
|
||||
// When
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"dog", "12", "4", "--alive", value,
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.IsAlive.ShouldBe(expected);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_When_Encountering_Unknown_Option_In_Strict_Mode()
|
||||
{
|
||||
@ -473,7 +473,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Add_Unknown_Option_To_Remaining_Arguments_In_Relaxed_Mode()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -484,23 +484,23 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12",
|
||||
"--foo", "bar",
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.ShouldNotBeNull();
|
||||
ctx.Remaining.Parsed.Count.ShouldBe(1);
|
||||
ctx.ShouldHaveRemainingArgument("foo", values: new[] { "bar" });
|
||||
result.Context.ShouldNotBeNull();
|
||||
result.Context.Remaining.Parsed.Count.ShouldBe(1);
|
||||
result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Add_Unknown_Boolean_Option_To_Remaining_Arguments_In_Relaxed_Mode()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -511,33 +511,33 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12", "--foo",
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.ShouldNotBeNull();
|
||||
ctx.Remaining.Parsed.Count.ShouldBe(1);
|
||||
ctx.ShouldHaveRemainingArgument("foo", values: new[] { (string)null });
|
||||
result.Context.ShouldNotBeNull();
|
||||
result.Context.Remaining.Parsed.Count.ShouldBe(1);
|
||||
result.Context.ShouldHaveRemainingArgument("foo", values: new[] { (string)null });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Be_Able_To_Set_The_Default_Command()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
app.WithDefaultCommand<DogCommand>();
|
||||
var app = new CommandAppTester();
|
||||
app.SetDefaultCommand<DogCommand>();
|
||||
|
||||
// When
|
||||
var (result, _, _, settings) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"4", "12", "--good-boy", "--name", "Rufus",
|
||||
});
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
result.ExitCode.ShouldBe(0);
|
||||
result.Settings.ShouldBeOfType<DogSettings>().And(dog =>
|
||||
{
|
||||
dog.Legs.ShouldBe(4);
|
||||
dog.Age.ShouldBe(12);
|
||||
@ -550,7 +550,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Set_Command_Name_In_Context()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -561,21 +561,21 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12",
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.ShouldNotBeNull();
|
||||
ctx.Name.ShouldBe("dog");
|
||||
result.Context.ShouldNotBeNull();
|
||||
result.Context.Name.ShouldBe("dog");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Pass_Command_Data_In_Context()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -586,14 +586,14 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12",
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.ShouldNotBeNull();
|
||||
ctx.Data.ShouldBe(123);
|
||||
result.Context.ShouldNotBeNull();
|
||||
result.Context.Data.ShouldBe(123);
|
||||
}
|
||||
|
||||
public sealed class Delegate_Commands
|
||||
@ -670,7 +670,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Register_Remaining_Parsed_Arguments_With_Context()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -681,7 +681,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12", "--",
|
||||
"--foo", "bar", "--foo", "baz",
|
||||
@ -689,18 +689,18 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.Remaining.Parsed.Count.ShouldBe(4);
|
||||
ctx.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" });
|
||||
ctx.ShouldHaveRemainingArgument("b", values: new[] { (string)null });
|
||||
ctx.ShouldHaveRemainingArgument("a", values: new[] { (string)null });
|
||||
ctx.ShouldHaveRemainingArgument("r", values: new[] { (string)null });
|
||||
result.Context.Remaining.Parsed.Count.ShouldBe(4);
|
||||
result.Context.ShouldHaveRemainingArgument("foo", values: new[] { "bar", "baz" });
|
||||
result.Context.ShouldHaveRemainingArgument("b", values: new[] { (string)null });
|
||||
result.Context.ShouldHaveRemainingArgument("a", values: new[] { (string)null });
|
||||
result.Context.ShouldHaveRemainingArgument("r", values: new[] { (string)null });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Register_Remaining_Raw_Arguments_With_Context()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.PropagateExceptions();
|
||||
@ -711,19 +711,19 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, ctx, _) = app.Run(new[]
|
||||
var result = app.Run(new[]
|
||||
{
|
||||
"animal", "4", "dog", "12", "--",
|
||||
"--foo", "bar", "-bar", "\"baz\"", "qux",
|
||||
});
|
||||
|
||||
// Then
|
||||
ctx.Remaining.Raw.Count.ShouldBe(5);
|
||||
ctx.Remaining.Raw[0].ShouldBe("--foo");
|
||||
ctx.Remaining.Raw[1].ShouldBe("bar");
|
||||
ctx.Remaining.Raw[2].ShouldBe("-bar");
|
||||
ctx.Remaining.Raw[3].ShouldBe("baz");
|
||||
ctx.Remaining.Raw[4].ShouldBe("qux");
|
||||
result.Context.Remaining.Raw.Count.ShouldBe(5);
|
||||
result.Context.Remaining.Raw[0].ShouldBe("--foo");
|
||||
result.Context.Remaining.Raw[1].ShouldBe("bar");
|
||||
result.Context.Remaining.Raw[2].ShouldBe("-bar");
|
||||
result.Context.Remaining.Raw[3].ShouldBe("baz");
|
||||
result.Context.Remaining.Raw[4].ShouldBe("qux");
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,7 +733,7 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
public void Should_Not_Propagate_Runtime_Exceptions_If_Not_Explicitly_Told_To_Do_So()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddBranch<AnimalSettings>("animal", animal =>
|
||||
@ -744,27 +744,27 @@ namespace Spectre.Console.Tests.Unit.Cli
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, _) = app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" });
|
||||
var result = app.Run(new[] { "animal", "4", "dog", "101", "--name", "Rufus" });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(-1);
|
||||
result.ExitCode.ShouldBe(-1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Not_Propagate_Exceptions_If_Not_Explicitly_Told_To_Do_So()
|
||||
{
|
||||
// Given
|
||||
var app = new CommandAppFixture();
|
||||
var app = new CommandAppTester();
|
||||
app.Configure(config =>
|
||||
{
|
||||
config.AddCommand<ThrowingCommand>("throw");
|
||||
});
|
||||
|
||||
// When
|
||||
var (result, _, _, _) = app.Run(new[] { "throw" });
|
||||
var result = app.Run(new[] { "throw" });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(-1);
|
||||
result.ExitCode.ShouldBe(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Columns_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 61);
|
||||
var console = new TestConsole().Width(61);
|
||||
var users = new[]
|
||||
{
|
||||
new User { Name = "Savannah Thompson", Country = "Australia" },
|
||||
|
@ -10,7 +10,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Substitute_Emoji_Shortcodes_In_Markdown()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Markup("Hello :globe_showing_europe_africa:!");
|
||||
@ -57,7 +57,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Can_Handle_Different_Combinations(string markup, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Markup(markup);
|
||||
@ -70,7 +70,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Leave_Single_Colons()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Markup("Hello :globe_showing_europe_africa:! Output: good");
|
||||
@ -80,10 +80,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unknown_emojis_should_remain()
|
||||
public void Unknown_emojis_should_remain_unchanged()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Markup("Hello :globe_showing_flat_earth:!");
|
||||
|
@ -17,7 +17,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Write_Exception()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 1024);
|
||||
var console = new TestConsole().Width(1024);
|
||||
var dex = GetException(() => TestExceptions.MethodThatThrows(null));
|
||||
|
||||
// When
|
||||
@ -32,7 +32,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Write_Exception_With_Shortened_Types()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 1024);
|
||||
var console = new TestConsole().Width(1024);
|
||||
var dex = GetException(() => TestExceptions.MethodThatThrows(null));
|
||||
|
||||
// When
|
||||
@ -47,7 +47,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Write_Exception_With_Shortened_Methods()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 1024);
|
||||
var console = new TestConsole().Width(1024);
|
||||
var dex = GetException(() => TestExceptions.MethodThatThrows(null));
|
||||
|
||||
// When
|
||||
@ -62,7 +62,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Write_Exception_With_Inner_Exception()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 1024);
|
||||
var console = new TestConsole().Width(1024);
|
||||
var dex = GetException(() => TestExceptions.ThrowWithInnerException());
|
||||
|
||||
// When
|
||||
@ -77,7 +77,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Write_Exceptions_With_Generic_Type_Parameters_In_Callsite_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 1024);
|
||||
var console = new TestConsole().Width(1024);
|
||||
var dex = GetException(() => TestExceptions.ThrowWithGenericInnerException());
|
||||
|
||||
// When
|
||||
|
@ -15,7 +15,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Load_Font_From_Stream()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 180);
|
||||
var console = new TestConsole().Width(180);
|
||||
var font = FigletFont.Load(EmbeddedResourceReader.LoadResourceStream("Spectre.Console.Tests/Data/starwars.flf"));
|
||||
var text = new FigletText(font, "Patrik was here");
|
||||
|
||||
@ -31,7 +31,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Text_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 70);
|
||||
var console = new TestConsole().Width(70);
|
||||
var text = new FigletText(FigletFont.Default, "Patrik was here");
|
||||
|
||||
// When
|
||||
@ -46,7 +46,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Wrapped_Text_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 70);
|
||||
var console = new TestConsole().Width(70);
|
||||
var text = new FigletText(FigletFont.Default, "Spectre.Console");
|
||||
|
||||
// When
|
||||
@ -61,7 +61,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Left_Aligned_Text_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 120);
|
||||
var console = new TestConsole().Width(120);
|
||||
var text = new FigletText(FigletFont.Default, "Spectre.Console")
|
||||
.Alignment(Justify.Left);
|
||||
|
||||
@ -77,7 +77,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Centered_Text_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 120);
|
||||
var console = new TestConsole().Width(120);
|
||||
var text = new FigletText(FigletFont.Default, "Spectre.Console")
|
||||
.Alignment(Justify.Center);
|
||||
|
||||
@ -93,7 +93,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public async Task Should_Render_Right_Aligned_Text_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 120);
|
||||
var console = new TestConsole().Width(120);
|
||||
var text = new FigletText(FigletFont.Default, "Spectre.Console")
|
||||
.Alignment(Justify.Right);
|
||||
|
||||
|
@ -87,7 +87,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Add_Empty_Row()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var grid = new Grid();
|
||||
grid.AddColumns(2);
|
||||
grid.AddRow("Foo", "Bar");
|
||||
@ -108,7 +108,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Grid_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var grid = new Grid();
|
||||
grid.AddColumn();
|
||||
grid.AddColumn();
|
||||
@ -127,7 +127,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
[Expectation("Render_2")]
|
||||
public Task Should_Render_Grid_Correctly_2()
|
||||
{
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var grid = new Grid();
|
||||
grid.AddColumn(new GridColumn { NoWrap = true });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(2, 0, 0, 0) });
|
||||
@ -147,7 +147,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Grid_Column_Alignment_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var grid = new Grid();
|
||||
grid.AddColumn(new GridColumn { Alignment = Justify.Right });
|
||||
grid.AddColumn(new GridColumn { Alignment = Justify.Center });
|
||||
@ -168,7 +168,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Use_Default_Padding()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var grid = new Grid();
|
||||
grid.AddColumns(3);
|
||||
grid.AddRow("Foo", "Bar", "Baz");
|
||||
@ -187,7 +187,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Explicit_Grid_Column_Padding_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var grid = new Grid();
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(3, 0, 0, 0) });
|
||||
grid.AddColumn(new GridColumn { Padding = new Padding(0, 0, 0, 0) });
|
||||
|
@ -47,7 +47,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Closing_Tag_Is_Not_Properly_Escaped(string input)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => new Markup(input));
|
||||
@ -62,7 +62,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Escape_Markup_Blocks_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var markup = new Markup("Hello [[ World ]] !");
|
||||
|
||||
// When
|
||||
@ -78,7 +78,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Render_Links_As_Expected(string input, string output)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var markup = new Markup(input);
|
||||
|
||||
// When
|
||||
@ -89,10 +89,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_not_fail_with_brackets_on_calls_without_args()
|
||||
public void Should_Not_Fail_With_Brackets_On_Calls_Without_Args()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.MarkupLine("{");
|
||||
|
@ -15,7 +15,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Padded_Object_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 60);
|
||||
var console = new TestConsole().Width(60);
|
||||
var table = new Table();
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar");
|
||||
@ -34,7 +34,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Expanded_Padded_Object_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 60);
|
||||
var console = new TestConsole().Width(60);
|
||||
var table = new Table();
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar");
|
||||
@ -55,7 +55,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Padded_Object_Correctly_When_Nested_Within_Other_Object()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 60);
|
||||
var console = new TestConsole().Width(60);
|
||||
var table = new Table();
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0));
|
||||
|
@ -17,7 +17,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Text("Hello World")));
|
||||
@ -31,7 +31,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Padding_Set_To_Zero()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Text("Hello World"))
|
||||
@ -48,7 +48,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Padding()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Text("Hello World"))
|
||||
@ -65,7 +65,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Header()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel("Hello World")
|
||||
@ -84,7 +84,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Left_Aligned_Header()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel("Hello World")
|
||||
@ -102,7 +102,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Centered_Header()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel("Hello World")
|
||||
@ -120,7 +120,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Right_Aligned_Header()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel("Hello World")
|
||||
@ -138,7 +138,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Collapse_Header_If_It_Will_Not_Fit()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 10);
|
||||
var console = new TestConsole().Width(10);
|
||||
|
||||
// When
|
||||
console.Write(new Panel("Hello World")
|
||||
@ -156,7 +156,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Unicode_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Text(" \n💩\n ")));
|
||||
@ -170,7 +170,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_With_Multiple_Lines()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Text("Hello World\nFoo Bar")));
|
||||
@ -184,7 +184,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Preserve_Explicit_Line_Ending()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var text = new Panel(
|
||||
new Markup("I heard [underline on blue]you[/] like 📦\n\n\n\nSo I put a 📦 in a 📦"));
|
||||
|
||||
@ -200,7 +200,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Expand_Panel_If_Enabled()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Text("Hello World"))
|
||||
@ -217,7 +217,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Justify_Child_To_Right_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 25);
|
||||
var console = new TestConsole().Width(25);
|
||||
|
||||
// When
|
||||
console.Write(
|
||||
@ -235,7 +235,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Center_Child_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 25);
|
||||
var console = new TestConsole().Width(25);
|
||||
|
||||
// When
|
||||
console.Write(
|
||||
@ -253,7 +253,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Panel_Inside_Panel_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Panel(new Panel(new Text("Hello World"))));
|
||||
@ -267,7 +267,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Wrap_Content_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 84);
|
||||
var console = new TestConsole().Width(84);
|
||||
var rows = new List<IRenderable>();
|
||||
var grid = new Grid();
|
||||
grid.AddColumn(new GridColumn().PadLeft(2).PadRight(0));
|
||||
@ -292,7 +292,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Wrap_Table_With_CJK_Tables_In_Panel_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
var table = new Table();
|
||||
table.AddColumn("测试");
|
||||
|
@ -19,7 +19,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
|
||||
public string Render()
|
||||
{
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var context = new RenderContext(console.Profile.Capabilities);
|
||||
console.Write(Column.Render(context, Task, TimeSpan.Zero));
|
||||
return console.Output;
|
||||
|
@ -15,7 +15,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Render_Task_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);
|
||||
var console = new TestConsole()
|
||||
.Width(10)
|
||||
.Interactive()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
@ -40,7 +43,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Not_Auto_Clear_If_Specified()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);
|
||||
var console = new TestConsole()
|
||||
.Width(10)
|
||||
.Interactive()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
@ -66,7 +72,9 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Reduce_Width_If_Needed()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 20);
|
||||
var console = new TestConsole()
|
||||
.Width(20)
|
||||
.Interactive();
|
||||
|
||||
var progress = new Progress(console)
|
||||
.Columns(new ProgressColumn[]
|
||||
@ -96,8 +104,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole()
|
||||
.Interactive();
|
||||
|
||||
var task = default(ProgressTask);
|
||||
var console = new FakeConsole();
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
.AutoRefresh(false)
|
||||
@ -120,8 +130,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Setting_Value_Should_Override_Incremented_Value()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole()
|
||||
.Interactive();
|
||||
|
||||
var task = default(ProgressTask);
|
||||
var console = new FakeConsole();
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
.AutoRefresh(false)
|
||||
@ -144,8 +156,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Setting_Value_To_MaxValue_Should_Finish_Task()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole()
|
||||
.Interactive();
|
||||
|
||||
var task = default(ProgressTask);
|
||||
var console = new FakeConsole();
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
.AutoRefresh(false)
|
||||
@ -166,8 +180,10 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Increment_Manually_Set_Value()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole()
|
||||
.Interactive();
|
||||
|
||||
var task = default(ProgressTask);
|
||||
var console = new FakeConsole();
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
.AutoRefresh(false)
|
||||
@ -189,10 +205,14 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Hide_Completed_Tasks()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole()
|
||||
.Width(10)
|
||||
.Interactive()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var taskFinished = default(ProgressTask);
|
||||
var taskInProgress1 = default(ProgressTask);
|
||||
var taskInProgress2 = default(ProgressTask);
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);
|
||||
|
||||
var progress = new Progress(console)
|
||||
.Columns(new[] { new ProgressBarColumn() })
|
||||
|
@ -17,7 +17,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Return_Validation_Error_If_Value_Cannot_Be_Converted()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushTextWithEnter("ninety-nine");
|
||||
console.Input.PushTextWithEnter("99");
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Chose_Default_Value_If_Nothing_Is_Entered()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
|
||||
// When
|
||||
@ -52,7 +52,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Return_Error_If_An_Invalid_Choice_Is_Made()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushTextWithEnter("Apple");
|
||||
console.Input.PushTextWithEnter("Banana");
|
||||
|
||||
@ -72,7 +72,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Accept_Choice_In_List()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushTextWithEnter("Orange");
|
||||
|
||||
// When
|
||||
@ -91,7 +91,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Auto_Complete_To_First_Choice_If_Pressing_Tab_On_Empty_String()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushKey(ConsoleKey.Tab);
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
|
||||
@ -111,7 +111,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Auto_Complete_To_Best_Match()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushText("Band");
|
||||
console.Input.PushKey(ConsoleKey.Tab);
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
@ -132,7 +132,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Auto_Complete_To_Next_Choice_When_Pressing_Tab_On_A_Match()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushText("Apple");
|
||||
console.Input.PushKey(ConsoleKey.Tab);
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
@ -153,7 +153,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Return_Error_If_Custom_Validation_Fails()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushTextWithEnter("22");
|
||||
console.Input.PushTextWithEnter("102");
|
||||
console.Input.PushTextWithEnter("ABC");
|
||||
@ -186,7 +186,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Use_Custom_Converter()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushTextWithEnter("Banana");
|
||||
|
||||
// When
|
||||
@ -206,7 +206,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Chose_Masked_Default_Value_If_Nothing_Is_Entered_And_Prompt_Is_Secret()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Input.PushKey(ConsoleKey.Enter);
|
||||
|
||||
// When
|
||||
|
@ -15,7 +15,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Export_Text_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var recorder = new Recorder(console);
|
||||
|
||||
recorder.Write(new Table()
|
||||
@ -35,7 +35,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Export_Html_Text_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var recorder = new Recorder(console);
|
||||
|
||||
recorder.Write(new Table()
|
||||
|
@ -21,7 +21,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Inject_Renderable_Before_Writing_To_Console()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
console.Pipeline.Attach(new HelloRenderHook());
|
||||
|
||||
// When
|
||||
|
@ -16,7 +16,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Rows()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 60);
|
||||
var console = new TestConsole().Width(60);
|
||||
var rows = new Rows(
|
||||
new IRenderable[]
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Rows_Correctly_Inside_Other_Widget()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 60);
|
||||
var console = new TestConsole().Width(60);
|
||||
var table = new Table()
|
||||
.AddColumns("Foo", "Bar")
|
||||
.AddRow("HELLO WORLD")
|
||||
@ -62,7 +62,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Rows_Correctly_Inside_Other_Widget_When_Expanded()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 60);
|
||||
var console = new TestConsole().Width(60);
|
||||
var table = new Table()
|
||||
.AddColumns("Foo", "Bar")
|
||||
.AddRow("HELLO WORLD")
|
||||
|
@ -16,7 +16,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Default_Rule_Without_Title()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule());
|
||||
@ -30,7 +30,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Default_Rule_With_Specified_Border()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule().DoubleBorder());
|
||||
@ -44,7 +44,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_With_Specified_Box()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule("Hello World").DoubleBorder());
|
||||
@ -58,7 +58,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Default_Rule_With_Title_Centered_By_Default()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule("Hello World"));
|
||||
@ -72,7 +72,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Default_Rule_With_Title_Left_Aligned()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule("Hello World")
|
||||
@ -89,7 +89,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Default_Rule_With_Title_Right_Aligned()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule("Hello World")
|
||||
@ -106,7 +106,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Convert_Line_Breaks_In_Title_To_Spaces()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule("Hello\nWorld\r\n!"));
|
||||
@ -120,7 +120,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Truncate_Title()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 40);
|
||||
var console = new TestConsole().Width(40);
|
||||
|
||||
// When
|
||||
console.Write(new Rule(" Hello World "));
|
||||
@ -145,7 +145,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Truncate_Too_Long_Title(int width, string input, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width);
|
||||
var console = new TestConsole().Width(width);
|
||||
|
||||
// When
|
||||
console.Write(new Rule(input));
|
||||
|
@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Spectre.Console.Testing;
|
||||
using Spectre.Verify.Extensions;
|
||||
@ -10,16 +12,36 @@ namespace Spectre.Console.Tests.Unit
|
||||
[ExpectationPath("Widgets/Status")]
|
||||
public sealed class StatusTests
|
||||
{
|
||||
public sealed class DummySpinner1 : Spinner
|
||||
{
|
||||
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
|
||||
public override bool IsUnicode => true;
|
||||
public override IReadOnlyList<string> Frames => new List<string> { "*", };
|
||||
}
|
||||
|
||||
public sealed class DummySpinner2 : Spinner
|
||||
{
|
||||
public override TimeSpan Interval => TimeSpan.FromMilliseconds(100);
|
||||
public override bool IsUnicode => true;
|
||||
public override IReadOnlyList<string> Frames => new List<string> { "-", };
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Render")]
|
||||
public Task Should_Render_Status_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeAnsiConsole(ColorSystem.TrueColor, width: 10);
|
||||
var console = new TestConsole()
|
||||
.Colors(ColorSystem.TrueColor)
|
||||
.Width(10)
|
||||
.Interactive()
|
||||
.EmitAnsiSequences();
|
||||
|
||||
var status = new Status(console);
|
||||
status.AutoRefresh = false;
|
||||
status.Spinner = new DummySpinner1();
|
||||
var status = new Status(console)
|
||||
{
|
||||
AutoRefresh = false,
|
||||
Spinner = new DummySpinner1(),
|
||||
};
|
||||
|
||||
// When
|
||||
status.Start("foo", ctx =>
|
||||
|
@ -43,7 +43,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().NoBorder();
|
||||
|
||||
// When
|
||||
@ -85,7 +85,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().AsciiBorder();
|
||||
|
||||
// When
|
||||
@ -127,7 +127,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().Ascii2Border();
|
||||
|
||||
// When
|
||||
@ -169,7 +169,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().AsciiDoubleHeadBorder();
|
||||
|
||||
// When
|
||||
@ -211,7 +211,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().SquareBorder();
|
||||
|
||||
// When
|
||||
@ -253,7 +253,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().RoundedBorder();
|
||||
|
||||
// When
|
||||
@ -295,7 +295,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().MinimalBorder();
|
||||
|
||||
// When
|
||||
@ -337,7 +337,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().MinimalHeavyHeadBorder();
|
||||
|
||||
// When
|
||||
@ -379,7 +379,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().MinimalDoubleHeadBorder();
|
||||
|
||||
// When
|
||||
@ -421,7 +421,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().SimpleBorder();
|
||||
|
||||
// When
|
||||
@ -463,7 +463,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().HorizontalBorder();
|
||||
|
||||
// When
|
||||
@ -505,7 +505,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().SimpleHeavyBorder();
|
||||
|
||||
// When
|
||||
@ -547,7 +547,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().HeavyBorder();
|
||||
|
||||
// When
|
||||
@ -589,7 +589,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().HeavyEdgeBorder();
|
||||
|
||||
// When
|
||||
@ -631,7 +631,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().HeavyHeadBorder();
|
||||
|
||||
// When
|
||||
@ -673,7 +673,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().DoubleBorder();
|
||||
|
||||
// When
|
||||
@ -715,7 +715,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().DoubleEdgeBorder();
|
||||
|
||||
// When
|
||||
@ -757,7 +757,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable().MarkdownBorder();
|
||||
|
||||
// When
|
||||
@ -772,7 +772,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Left_Aligned_Table_Columns_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable(header2: Justify.Left).MarkdownBorder();
|
||||
|
||||
// When
|
||||
@ -787,7 +787,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Center_Aligned_Table_Columns_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable(header2: Justify.Center).MarkdownBorder();
|
||||
|
||||
// When
|
||||
@ -802,7 +802,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Right_Aligned_Table_Columns_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole();
|
||||
var console = new TestConsole();
|
||||
var table = Fixture.GetTable(header2: Justify.Right).MarkdownBorder();
|
||||
|
||||
// When
|
||||
|
@ -131,7 +131,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
@ -151,7 +151,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
@ -169,7 +169,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_With_Footers_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn(new TableColumn("Foo").Footer("Oof").RightAligned());
|
||||
table.AddColumn("Bar");
|
||||
@ -189,7 +189,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Left_Align_Table_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.Alignment = Justify.Left;
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
@ -208,7 +208,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Center_Table_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.Alignment = Justify.Center;
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
@ -227,7 +227,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Right_Align_Table_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.Alignment = Justify.Right;
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
@ -246,7 +246,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_Nested_In_Panels_Correctly()
|
||||
{
|
||||
// A simple table
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table() { Border = TableBorder.Rounded };
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn("Bar");
|
||||
@ -269,7 +269,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_With_Column_Justification_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn(new TableColumn("Foo") { Alignment = Justify.Left });
|
||||
table.AddColumn(new TableColumn("Bar") { Alignment = Justify.Right });
|
||||
@ -289,7 +289,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Expand_Table_To_Available_Space_If_Specified()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table() { Expand = true };
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux", "Corgi", "Waldo");
|
||||
@ -307,7 +307,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_With_Multiple_Rows_In_Cell_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar", "Baz");
|
||||
table.AddRow("Qux\nQuuux", "Corgi", "Waldo");
|
||||
@ -325,7 +325,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_With_Cell_Padding_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar");
|
||||
table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) });
|
||||
@ -344,7 +344,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_Without_Rows()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumns("Foo", "Bar");
|
||||
table.AddColumn(new TableColumn("Baz") { Padding = new Padding(3, 0, 2, 0) });
|
||||
@ -361,7 +361,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Not_Draw_Tables_That_Are_Impossible_To_Draw()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 25);
|
||||
var console = new TestConsole().Width(25);
|
||||
|
||||
var first = new Table().Border(TableBorder.Rounded).BorderColor(Color.Red);
|
||||
first.AddColumn(new TableColumn("[u]PS1[/]").Centered());
|
||||
@ -399,7 +399,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Table_With_Title_And_Caption_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table { Border = TableBorder.Rounded };
|
||||
table.Title = new TableTitle("Hello World");
|
||||
table.Caption = new TableTitle("Goodbye World");
|
||||
@ -419,7 +419,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Left_Align_Table_With_Title_And_Caption_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table { Border = TableBorder.Rounded };
|
||||
table.LeftAligned();
|
||||
table.Title = new TableTitle("Hello World");
|
||||
@ -440,7 +440,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Center_Table_With_Title_And_Caption_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table { Border = TableBorder.Rounded };
|
||||
table.Centered();
|
||||
table.Title = new TableTitle("Hello World");
|
||||
@ -461,7 +461,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Right_Align_Table_With_Title_And_Caption_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var table = new Table { Border = TableBorder.Rounded };
|
||||
table.RightAligned();
|
||||
table.Title = new TableTitle("Hello World");
|
||||
|
@ -11,11 +11,11 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Consider_The_Longest_Word_As_Minimum_Width()
|
||||
{
|
||||
// Given
|
||||
var caps = new FakeCapabilities { Unicode = true };
|
||||
var caps = new TestCapabilities { Unicode = true };
|
||||
var text = new Text("Foo Bar Baz\nQux\nLol mobile");
|
||||
|
||||
// When
|
||||
var result = ((IRenderable)text).Measure(new RenderContext(caps), 80);
|
||||
var result = ((IRenderable)text).Measure(caps.CreateRenderContext(), 80);
|
||||
|
||||
// Then
|
||||
result.Min.ShouldBe(6);
|
||||
@ -25,11 +25,11 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Consider_The_Longest_Line_As_Maximum_Width()
|
||||
{
|
||||
// Given
|
||||
var caps = new FakeCapabilities { Unicode = true };
|
||||
var caps = new TestCapabilities { Unicode = true };
|
||||
var text = new Text("Foo Bar Baz\nQux\nLol mobile");
|
||||
|
||||
// When
|
||||
var result = ((IRenderable)text).Measure(new RenderContext(caps), 80);
|
||||
var result = ((IRenderable)text).Measure(caps.CreateRenderContext(), 80);
|
||||
|
||||
// Then
|
||||
result.Max.ShouldBe(11);
|
||||
@ -39,7 +39,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Render_Unstyled_Text_As_Expected()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var text = new Text("Hello World");
|
||||
|
||||
// When
|
||||
@ -55,7 +55,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Write_Line_Breaks(string input)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 5);
|
||||
var console = new TestConsole();
|
||||
var text = new Text(input);
|
||||
|
||||
// When
|
||||
@ -69,7 +69,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Render_Panel_2()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
// When
|
||||
console.Write(new Markup("[b]Hello World[/]\n[yellow]Hello World[/]"));
|
||||
@ -87,7 +87,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
int width, string input, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width);
|
||||
var console = new TestConsole().Width(width);
|
||||
var text = new Text(input);
|
||||
|
||||
// When
|
||||
@ -106,7 +106,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Overflow_Text_Correctly(Overflow overflow, string expected)
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(14);
|
||||
var console = new TestConsole().Width(14);
|
||||
var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux")
|
||||
.Overflow(overflow);
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Tree_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
var tree = new Tree(new Text("Root node")).Guide(TreeGuide.DoubleLine);
|
||||
|
||||
@ -48,7 +48,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public Task Should_Render_Tree_With_No_Child_Nodes_Correctly()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
var tree = new Tree(new Text("Root node"));
|
||||
|
||||
// When
|
||||
@ -62,7 +62,7 @@ namespace Spectre.Console.Tests.Unit
|
||||
public void Should_Throw_If_Tree_Contains_Cycles()
|
||||
{
|
||||
// Given
|
||||
var console = new FakeConsole(width: 80);
|
||||
var console = new TestConsole();
|
||||
|
||||
var child2 = new TreeNode(new Text("child 2"));
|
||||
var child3 = new TreeNode(new Text("child 3"));
|
||||
|
@ -14,7 +14,7 @@ namespace Spectre.Console.Tests
|
||||
}
|
||||
|
||||
var assembly = Assembly.GetCallingAssembly();
|
||||
resourceName = resourceName.ReplaceExact("/", ".");
|
||||
resourceName = resourceName.Replace("/", ".");
|
||||
|
||||
return assembly.GetManifestResourceStream(resourceName);
|
||||
}
|
||||
@ -31,7 +31,7 @@ namespace Spectre.Console.Tests
|
||||
throw new ArgumentNullException(nameof(resourceName));
|
||||
}
|
||||
|
||||
resourceName = resourceName.ReplaceExact("/", ".");
|
||||
resourceName = resourceName.Replace("/", ".");
|
||||
return assembly.GetManifestResourceStream(resourceName);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
public static class ShouldlyExtensions
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
public static T And<T>(this T item, Action<T> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
}
|
||||
|
||||
action(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Spectre.Console.Testing;
|
||||
|
||||
namespace Spectre.Console.Tests
|
||||
{
|
||||
public static class TestConsoleExtensions
|
||||
{
|
||||
private static readonly Regex _lineNumberRegex = new Regex(":\\d+", RegexOptions.Singleline);
|
||||
private static readonly Regex _filenameRegex = new Regex("\\sin\\s.*cs:nn", RegexOptions.Multiline);
|
||||
|
||||
public static string WriteNormalizedException(this TestConsole console, Exception ex, ExceptionFormats formats = ExceptionFormats.Default)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(console.Output))
|
||||
{
|
||||
throw new InvalidOperationException("Output buffer is not empty.");
|
||||
}
|
||||
|
||||
console.WriteException(ex, formats);
|
||||
return string.Join("\n", NormalizeStackTrace(console.Output)
|
||||
.NormalizeLineEndings()
|
||||
.Split(new char[] { '\n' })
|
||||
.Select(line => line.TrimEnd()));
|
||||
}
|
||||
|
||||
public static string NormalizeStackTrace(string text)
|
||||
{
|
||||
text = _lineNumberRegex.Replace(text, match =>
|
||||
{
|
||||
return ":nn";
|
||||
});
|
||||
|
||||
return _filenameRegex.Replace(text, match =>
|
||||
{
|
||||
var value = match.Value;
|
||||
var index = value.LastIndexOfAny(new[] { '\\', '/' });
|
||||
var filename = value.Substring(index + 1, value.Length - index - 1);
|
||||
|
||||
return $" in /xyz/{filename}";
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -6,13 +6,11 @@ namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeTypeRegistrar : ITypeRegistrar
|
||||
{
|
||||
private readonly ITypeResolver _resolver;
|
||||
public Dictionary<Type, List<Type>> Registrations { get; }
|
||||
public Dictionary<Type, List<object>> Instances { get; }
|
||||
|
||||
public FakeTypeRegistrar(ITypeResolver resolver = null)
|
||||
public FakeTypeRegistrar()
|
||||
{
|
||||
_resolver = resolver;
|
||||
Registrations = new Dictionary<Type, List<Type>>();
|
||||
Instances = new Dictionary<Type, List<object>>();
|
||||
}
|
||||
@ -52,7 +50,7 @@ namespace Spectre.Console.Testing
|
||||
|
||||
public ITypeResolver Build()
|
||||
{
|
||||
return _resolver;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -86,6 +86,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{A0C772BA-C
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "..\examples\Shared\Shared.csproj", "{8428A7DD-29FC-4417-9CA0-B90D34B26AB2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Internal", "Internal", "{0FC844AD-FCBB-4B2F-9AEC-6CB5505E49E3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
Loading…
x
Reference in New Issue
Block a user