public void ConstructAssignsAppCommandAsDefault() { var appRuntime = new Mock <IRuntimeCommand>(); var testInstance = new AggregatedRuntimeCommand(new ParseContext(Array.Empty <string>()), appRuntime.Object, Enumerable.Empty <ICommandLineConfiguration>()); testInstance.SelectedRuntime.ShouldBeSameAs(appRuntime.Object); }
public void ConstructFindsCommand() { var cmd = MockSubConfiguration("test"); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), new Mock <IRuntimeCommand>().Object, new[] { cmd }); testInstance.SelectedRuntime.ShouldBe(cmd.GetRuntimeCommand()); }
public void TemplateReturnsCommandTemplate() { var cmd = MockSubConfiguration("test"); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), new Mock <IRuntimeCommand>().Object, new[] { cmd }); testInstance.SelectedRuntime.Template.Tokens.Single().ShouldBe(new Token(TokenType.NonTemplateValue, "test")); testInstance.Template.Tokens.Single().ShouldBe(new Token(TokenType.NonTemplateValue, "test")); }
public void ConstructIgnoresCommandForNonMatchingTemplate() { var cmd = MockSubConfiguration("ignore"); var appRuntime = new Mock <IRuntimeCommand>(); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), appRuntime.Object, new[] { cmd }); testInstance.SelectedRuntime.ShouldBeSameAs(appRuntime.Object); }
public void GetOptionsReturnsCommandInstance() { var options = new object(); var cmd = MockSubConfiguration("test", runtimeCmdConfig: m => m.Setup(c => c.GetOptions()).Returns(options)); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), new Mock <IRuntimeCommand>().Object, new[] { cmd }); testInstance.GetOptions().ShouldBe(options); }
public void GetHelpContentProviderReturnsCommandInstance() { var provider = new Mock <IProvider <IReadOnlyCollection <string> > >().Object; var cmd = MockSubConfiguration("test", runtimeCmdConfig: m => m.Setup(c => c.HelpContentProvider).Returns(provider)); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), new Mock <IRuntimeCommand>().Object, new[] { cmd }); testInstance.HelpContentProvider.ShouldBe(provider); }
public void InvokeCallsCommand() { Mock <IRuntimeCommand> cmdMock = null; var cmd = MockSubConfiguration("test", runtimeCmdConfig: m => { cmdMock = m; m.Setup(c => c.Invoke(It.IsAny <object>())).Verifiable(); }); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), new Mock <IRuntimeCommand>().Object, new[] { cmd }); testInstance.Invoke(new object()); cmdMock.Verify(c => c.Invoke(It.IsAny <object>()), Times.Once); }
public async Task InvokeAsyncCallsCommand() { Mock <IRuntimeCommand> cmdMock = null; var cmd = MockSubConfiguration("test", runtimeCmdConfig: m => { cmdMock = m; m.Setup(c => c.InvokeAsync(It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask) .Verifiable(); }); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "test" }), new Mock <IRuntimeCommand>().Object, new[] { cmd }); await testInstance.InvokeAsync(new object(), CancellationToken.None); cmdMock.Verify(c => c.InvokeAsync(It.IsAny <object>(), It.IsAny <CancellationToken>()), Times.Once); }
public void MapArgumentsCallsCommand() { var parseContext = new ParseContext(new[] { "test", "arg" }); var parserType = ParserType.Option; var options = new object(); Mock <IRuntimeCommand> cmdMock = null; var cmd = MockSubConfiguration("test", runtimeCmdConfig: m => { cmdMock = m; m.Setup(c => c.MapArguments(parseContext, options, parserType)).Verifiable(); }); var testInstance = new AggregatedRuntimeCommand(parseContext, new Mock <IRuntimeCommand>().Object, new[] { cmd }); testInstance.MapArguments(parseContext, options, parserType); cmdMock.Verify(c => c.MapArguments(parseContext, options, parserType), Times.Once); }
public async Task InvokeAsyncCallsAppWithGivenCancellationToken() { using var cancelTokenSource = new CancellationTokenSource(); var cancellationToken = cancelTokenSource.Token; Mock <IRuntimeCommand> cmdMock = null; var cmd = MockSubConfiguration("test", runtimeCmdConfig: m => { cmdMock = m; m.Setup(c => c.InvokeAsync(It.IsAny <object>(), cancellationToken)) .Returns(Task.CompletedTask) .Verifiable(); }); var appMock = new Mock <IRuntimeCommand>(); appMock.Setup(m => m.InvokeAsync(It.IsAny <object>(), cancellationToken)).Returns(Task.CompletedTask).Verifiable(); var testInstance = new AggregatedRuntimeCommand(new ParseContext(new[] { "app" }), appMock.Object, new[] { cmd }); await testInstance.InvokeAsync(new object(), cancellationToken); cmdMock.Verify(c => c.InvokeAsync(It.IsAny <object>(), cancellationToken), Times.Never); appMock.Verify(c => c.InvokeAsync(It.IsAny <object>(), cancellationToken), Times.Once); }