public void CannotWriteHelpUnlessConfigured() { var resolver = new CommandResolver(); Assert.Throws<InvalidCommandException>(() => resolver.Resolve("help")); Assert.Throws<InvalidCommandException>(() => resolver.Resolve("help test")); }
public async Task ReceivedMessageAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { try { var activity = await argument as Activity; // 現在の会話のユーザーIDを得る if (_currentUser == null) { var usecase = new UserUsecase(); var userId = await activity.GetFirstMember(); _currentUser = await usecase.GetUser(userId); } var message = await argument; Trace.WriteLine($"{_currentUser?.UserId ?? "unknown user"} posted '{message.Text}'."); var resolver = new CommandResolver(); var command = resolver.Resolve(message.Text); Trace.WriteLine($"Resolved command is {command.Type} with {command.Message}"); await CommandAsync(context, command); } catch (Exception ex) { Trace.WriteLine($"ReceivedMessageAsync failed - {ex.Message} - {ex.StackTrace}"); await context.PostAsync($"ReceivedMessageAsync failed - {ex.Message}"); context.Wait(ReceivedMessageAsync); } }
public void CommandResolver_Valid_SimpleTest() { var path = new[] { new ValueBindingExpression(vm => ((dynamic)vm[0]).A[0], "A()[0]") }; var commandId = "someCommand"; var command = new CommandBindingExpression(vm => ((TestA)vm[0]).Test(((TestA)vm[0]).StringToPass, ((dynamic)vm[1]).NumberToPass), commandId); var testObject = new { A = new[] { new TestA() { StringToPass = "******" } }, NumberToPass = 16 }; var viewRoot = new DotvvmView() { DataContext = testObject }; viewRoot.SetBinding(Controls.Validation.TargetProperty, new ValueBindingExpression(vm => vm.Last(), "$root")); var placeholder = new HtmlGenericControl("div"); placeholder.SetBinding(DotvvmBindableObject.DataContextProperty, path[0]); viewRoot.Children.Add(placeholder); var button = new Button(); button.SetBinding(ButtonBase.ClickProperty, command); placeholder.Children.Add(button); var resolver = new CommandResolver(); var context = new DotvvmRequestContext() { ViewModel = testObject }; context.ModelState.ValidationTargetPath = KnockoutHelper.GetValidationTargetExpression(button); resolver.GetFunction(viewRoot, context, path.Select(v => v.Javascript).ToArray(), commandId).Action(); Assert.AreEqual(testObject.NumberToPass, testObject.A[0].ResultInt); Assert.AreEqual(testObject.A[0].ResultString, testObject.A[0].ResultString); }
public void CannotSelectCorrectGeneratorWhenFoundMultiple() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "test1 a"); resolver.Register(() => new SampleDateTimeList(), "test1"); resolver.Resolve("test1 a (test)", true); }
public static ApplicationBehavior Resolve(ApplicationSchemaDefinition application) { var platformSpecificNamespace = string.Format("{0}.{1}", PlatformSpecificProbingNamespace, application.ApplicationName); var applicationSpecificNamespace = string.Format("{0}.{1}", typeof(NamespaceAnchor).Namespace, application.ApplicationName); // Let's probe for all custom commands // eligible for this application behavior. var commands = CommandResolver.Resolve(new[] { platformSpecificNamespace, applicationSpecificNamespace }); // Do we have a behavior specific for this // application and platform? e.g. workorder // on iOS. // ReSharper disable once PossibleMultipleEnumeration var platformSpecificBehavior = Instantiate(platformSpecificNamespace, application.ApplicationName, commands); if (null != platformSpecificBehavior) { return(platformSpecificBehavior); } // Do we have a behavior specific for this // application, but platform-independent? // ReSharper disable once PossibleMultipleEnumeration var applicationSpecificBehavior = Instantiate(applicationSpecificNamespace, application.ApplicationName, commands); if (null != applicationSpecificBehavior) { return(applicationSpecificBehavior); } // Damn it, no luck. Let's return the // base application behavior then. // ReSharper disable once PossibleMultipleEnumeration return(new ApplicationBehavior(commands)); }
private void SubmitInput() { // get current input Input input = GetCurrentInput(); // update command history if (_submitHistory.Count == 0 || !_submitHistory.LastOrDefault().Equals(input.ToString().Trim())) { _submitHistory.Add(input.ToString().TrimEnd()); _submitHistoryIndex = _submitHistory.Count; } Out.Standard.WriteLine(); // resolve command CommandResolver resolver = new CommandResolver(input, Commands); if (resolver.HasErrors) // if resolution failed with errors, output errors here { foreach (var err in resolver.Errors) { Out.Error.WriteLine(err); } CommandExecutionComplete(null); } else { var cmd = new CommandActivator().Create(resolver, this); InputFilters.SetFilterMode(FilterMode.Execution); _invoker.Invoke(cmd, false, CommandExecutionComplete); } }
public List <string> GetOptions(Input input, InputNode currentNode) { CommandResolver resolver = new CommandResolver(input, _hostInterface.Commands); if (string.IsNullOrWhiteSpace(input.ToString()) || currentNode.ElementType == InputNodeType.Command) // node is in leading white space or at very beginning of command or is the command node { return(GetCommandsAutoComplete(input, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.NamedParameter) { return(GetNamedParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.NamedParameterValue) { return(GetParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.Empty) { return(GetParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.OrdinalParameterValue) { return(GetParameterAutoComplete(resolver, currentNode)); } else if (resolver.CommandDefinition != null && currentNode.ElementType == InputNodeType.Switch) { return(GetSwitchAutoComplete(resolver, currentNode)); } return(null); }
public void TryResolveUnknownCommandTest() { var commandResolver = new CommandResolver("adfkghskdjfgh"); var command = commandResolver.GetCommand(); Assert.IsNull(command); }
public void ResolveMessageCommandNotValidJsonTest() { var commandResolver = new CommandResolver("telemetrydata {\"Temperature\": }"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(TelemetryDataCommand)); Assert.IsFalse(command.IsValid); }
static void PrintHelp(CommandResolver commandResolver) { Console.WriteLine($"Usage: GitHelp command <arguments>\n"); Console.WriteLine("Available commands:"); foreach (var helpInstance in commandResolver.Help()) { Console.WriteLine($"{helpInstance.name} \t\t {helpInstance.description}"); } }
public void TryResolveLoginCommandTest() { var commandResolver = new CommandResolver("login deviceid"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(LoginCommand)); Assert.IsFalse(command.IsValid); }
public void ResolveUbsubscribeCommandTest() { var commandResolver = new CommandResolver("unsubscribe"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(UnsubscribeCommand)); Assert.IsTrue(command.IsValid); }
public void ResolveHeartbeatCommandTest() { var commandResolver = new CommandResolver("heartbeat"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(HeartbeatCommand)); Assert.IsTrue(command.IsValid); }
public void ResolveCloseCommandTest() { var commandResolver = new CommandResolver("close"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(CloseCommand)); Assert.IsTrue(command.IsValid); }
public void TryResolveSendToCommandTest() { var commandResolver = new CommandResolver("sendto deviceIdmsg"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(SendToCommand)); Assert.IsFalse(command.IsValid); }
public void BeforeTest() { var commandFactoryMock = new Mock <CommandFactory>(); this.commandGroupMetadataFactoryMock = new Mock <CommandGroupMetadataFactory>(); this.commandResolver = new CommandResolver(commandFactoryMock.Object); this.commandLoop = new CommandLoop( this.commandResolver, this.commandGroupMetadataFactoryMock.Object); }
public void ResolveSubscribeCommandTest() { var commandResolver = new CommandResolver("subscribe receiveandforget"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(SubscribeCommand)); Assert.AreEqual(SubscriptionType.ReceiveAndForget, ((SubscribeCommand)command).SubscriptionType); Assert.IsTrue(command.IsValid); }
public CommandViewModel(IAppServices appServices, CommandResolver commandResolver) { _eventAggregator = appServices.EventAggregator; _log = appServices.Log; _appServices = appServices; _commandResolver = commandResolver; _eventAggregator.Subscribe(this); _matchedItems = new BindableCollection <MatchResult>(); DisplayName = "Command"; }
public void CanBindIntNullableListWithMultipleParameters() { var resolver = new CommandResolver(); resolver.Register(() => new SampleIntNullableList(), "sample") .WithArgumentList(null, x => x.TestList); var generator = resolver.Resolve("sample 1, 2, 3"); generator.Should().Be.OfType<SampleIntNullableList>() .And.Value.TestList.Should().Have.SameSequenceAs(new int?[] { 1, 2, 3 }); }
public void CanBindIntNullable() { var resolver = new CommandResolver(); resolver.Register(() => new SampleSingleIntNullable(), "sample") .WithArgument(null, x => x.Test); var generator = resolver.Resolve("sample 1"); generator.Should().Be.OfType<SampleSingleIntNullable>() .And.Value.Test.Should().Be(1); }
public void CanBindIntNullableListWithNoParameters() { var resolver = new CommandResolver(); resolver.Register(() => new SampleIntNullableList(), "sample") .WithArgumentList(null, x => x.TestList); var generator = resolver.Resolve("sample"); generator.Should().Be.OfType<SampleIntNullableList>() .And.Value.TestList.Should().Be.Empty(); }
public void Write(CommandResolver resolver) { Writer.WriteLine("Available commands: (say 'help <commands>' for more info)"); foreach (var command in resolver.GetMeta()) { Blank(); WriteCommandName(command.Command, command.Parser); Writer.WriteLine("> Generator: {0}", command.Parser.GeneratorType); } }
public void ResolveSendToCommandTest() { var commandResolver = new CommandResolver("sendto deviceId msg"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(SendToCommand)); Assert.AreEqual("deviceId", ((SendToCommand)command).DeviceId); Assert.AreEqual("msg", ((SendToCommand)command).Message); Assert.IsTrue(command.IsValid); }
public void CanBindBooleanWithoutPassingItsValue() { var resolver = new CommandResolver(); resolver.Register(() => new SampleBoolean(), "sample") .WithOption("lasers", x => x.Test); var generator = resolver.Resolve("sample"); generator.Should().Be.OfType<SampleBoolean>() .And.Value.Test.Should().Be.False(); }
public void CanBindBoolList() { var resolver = new CommandResolver(); resolver.Register(() => new SampleBoolList(), "sample") .WithOptionList("lasers", x => x.Test); var generator = resolver.Resolve("sample lasers=t,f,y,n,yes,no,1,0,true,false"); generator.Should().Be.OfType<SampleBoolList>() .And.Value.Test.Should().Have.SameSequenceAs(true, false, true, false, true, false, true, false, true, false); }
public void ResolveCommand_IsRequired_Test(CommandOptionSet commandOptionSet) { // Arrange var typeProvider = new TypeProvider(typeof(TestCommand)); var optionConverter = new CommandOptionConverter(); var resolver = new CommandResolver(typeProvider, optionConverter); // Act & Assert Assert.Throws <CommandResolveException>(() => resolver.ResolveCommand(commandOptionSet)); }
public void ResolveLoginCommandTest() { var commandResolver = new CommandResolver("login deviceid apikey"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(LoginCommand)); Assert.AreEqual("deviceid", ((LoginCommand)command).DeviceId); Assert.AreEqual("apikey", ((LoginCommand)command).ApiKey); Assert.IsTrue(command.IsValid); }
public void ResolveMessageCommandTest() { long tickts = DateTime.UtcNow.Ticks; var commandResolver = new CommandResolver("telemetrydata {\"Temperature\": 24, \"Time\":" + tickts + "}"); var command = commandResolver.GetCommand(); Assert.IsInstanceOfType(command, typeof(TelemetryDataCommand)); Assert.AreEqual("{\"Temperature\":24,\"Time\":" + tickts + "}", ((TelemetryDataCommand)command).TelemetryData.ToString(Formatting.None)); Assert.IsTrue(command.IsValid); }
public static void Initialize(TestContext ctx) { var registry = new CommandRegistry(); registry.RegisterCommand <Command>(); registry.RegisterCommand <CommandWithNameAttribute>(); registry.RegisterCommand <CommandWithArgument>(); registry.RegisterCommand <CommandWithAlias>(); registry.RegisterCommand <MultipleArgumentsAndAliases>(); _resolver = new CommandResolver(registry); }
protected override CommandResolver Configure() { var resolver = new CommandResolver().WithHelp() .RegisterCommands(Configurator.IsProduction); InternalConfigure(DefaultEnvironment); if (!Configurator.IsProduction) InternalConfigure(Configurator.Test); return resolver; }
public void CanSelectCorrectGeneratorWithSpacedInput() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "test1 a"); resolver.Register(() => new SampleDateTimeList(), "test2 b"); var generator1 = resolver.Resolve("test1 a", true); var generator2 = resolver.Resolve("test2 b", true); generator1.Should().Be.InstanceOf<SampleStringList>(); generator2.Should().Be.InstanceOf<SampleDateTimeList>(); }
protected override CommandResolver Configure() { var resolver = new CommandResolver().WithHelp() .RegisterCommands(Configurator.IsProduction); InternalConfigure(DefaultEnvironment); if (!Configurator.IsProduction) { InternalConfigure(Configurator.Test); } return(resolver); }
public static void Initialize(TestContext ctx) { var registry = new CommandRegistry(); registry.RegisterCommand <Command>(); registry.RegisterCommand <WithArgument>(); registry.RegisterCommand <WithIntArg>(); registry.RegisterCommand <MultipleArgs>(); registry.RegisterCommand <WithAlias>(); registry.RegisterCommand <WithOption>(); _resolver = new CommandResolver(registry); _activator = new CommandActivator(); }
public SessionInformation Command(string command) { var commandDetail = CommandResolver.Resolve(command); if (commandDetail.CommandType == CommandType.Draw) { DrawTable(); } if (commandDetail.CommandType == CommandType.Undo) { if (Checkmate) { WriteError("Checkmate !!!"); } if (Checkmate == false && MovementInstructions.Keys.Count != 0) { var lastInstraction = GetLastMovement(); var lastResult = MovementInstructions[lastInstraction]; if (lastResult.Eated != null) { CurrentPlayer.Stones.Add(lastResult.Eated); PreviousPlayer.Eats.Remove(lastResult.Eated); } lastInstraction.MovingStone.ForceMove(lastInstraction.FromLocation); SetPlayerReturn(); MovementInstructions.Remove(lastInstraction); DrawTable(); SessionTimer.Restart(); } } if (commandDetail.CommandType == CommandType.Stat) { DrawStatistics(); } if (commandDetail.CommandType == CommandType.Play && Checkmate == false) { if (commandDetail.IsCorrect == false) { WriteError(commandDetail.ReturnMessage); MovementInstructions.Add(default, new MovementResult(false, null, null, null, commandDetail.ReturnMessage));
private List <string> GetNamedParameterAutoComplete(CommandResolver resolver, InputNode currentNode) { CommandParameterAnalysis analysis = new CommandParameterAnalysis(resolver); List <string> values = analysis.AvailableParameters .Where(p => p.Name.StartsWith(currentNode.Value, StringComparison.OrdinalIgnoreCase)) .Select(p => p.Name).ToList(); values.AddRange(analysis.AvailableParameters .SelectMany(p => p.Aliases) .Where(a => a.StartsWith(currentNode.Value, StringComparison.OrdinalIgnoreCase))); return(values.OrderBy(v => v).ToList()); }
protected void Init() { this.logger = Simply.Do.Log(this); try { resolver = Configure(); ConfigureLogging(); } catch (Exception e) { ConfigureLogging(); logger.Warn("Failed to configure: {0}".AsFormat(e.Message) , e); } logger.InfoFormat("Simple.Net v{0} [{1}]", Simply.Do.Version.ToString(3), ProjectText); }
public void CommandResolver_Valid_SimpleTest() { var path = new[] { ValueBindingExpression.CreateBinding <object>(bindingService, vm => ((Test1)vm[0]).A[0], (DataContextStack)null) }; var commandId = "someCommand"; var command = new CommandBindingExpression(bindingService, vm => { ((TestA)vm[0]).Test(((TestA)vm[0]).StringToPass, ((dynamic)vm[1]).NumberToPass); }, commandId); var testObject = new Test1 { A = new[] { new TestA() { StringToPass = "******" } }, NumberToPass = 16 }; var viewRoot = new DotvvmView() { DataContext = testObject }; viewRoot.SetBinding(Controls.Validation.TargetProperty, ValueBindingExpression.CreateBinding(bindingService, vm => vm.Last(), new ParametrizedCode("$root"))); var placeholder = new HtmlGenericControl("div"); placeholder.SetBinding(DotvvmBindableObject.DataContextProperty, path[0]); viewRoot.Children.Add(placeholder); var button = new Button(); button.SetBinding(ButtonBase.ClickProperty, command); placeholder.Children.Add(button); var resolver = new CommandResolver(); var context = new TestDotvvmRequestContext() { ViewModel = testObject, ModelState = new ModelState() }; context.ModelState.ValidationTargetPath = KnockoutHelper.GetValidationTargetExpression(button); resolver.GetFunction(viewRoot, context, path.Select(v => v.GetProperty <SimplePathExpressionBindingProperty>().Code.FormatKnockoutScript(button, v)).ToArray(), commandId, new Func <Type, object> [0]).Action(); Assert.AreEqual(testObject.NumberToPass, testObject.A[0].ResultInt); Assert.AreEqual(testObject.A[0].ResultString, testObject.A[0].ResultString); }
public void CommandResolver_Valid_SimpleTest() { var path = new[] { new ValueBindingExpression(vm => ((dynamic)vm[0]).A[0], "A()[0]") }; var commandId = "someCommand"; var command = new CommandBindingExpression(vm => ((TestA)vm[0]).Test(((TestA)vm[0]).StringToPass, ((dynamic)vm[1]).NumberToPass), commandId); var testObject = new { A = new[] { new TestA() { StringToPass = "******" } }, NumberToPass = 16 }; var viewRoot = new DotvvmView() { DataContext = testObject }; viewRoot.SetBinding(Validate.TargetProperty, new ValueBindingExpression(vm => vm.Last(), "$root")); var placeholder = new HtmlGenericControl("div"); placeholder.SetBinding(DotvvmBindableObject.DataContextProperty, path[0]); viewRoot.Children.Add(placeholder); var button = new Button(); button.SetBinding(ButtonBase.ClickProperty, command); placeholder.Children.Add(button); var resolver = new CommandResolver(); var context = new DotvvmRequestContext() { ViewModel = testObject }; context.ModelState.ValidationTargetPath = KnockoutHelper.GetValidationTargetExpression(button); resolver.GetFunction(viewRoot, context, path.Select(v => v.Javascript).ToArray(), commandId).Action(); Assert.AreEqual(testObject.NumberToPass, testObject.A[0].ResultInt); Assert.AreEqual(testObject.A[0].ResultString, testObject.A[0].ResultString); }
public void Resolve_does_not_care_about_case(CommandResolver commandResolver, List <ICraneCommand> commands, Type result) { "Given I have the commands init and help" ._(() => { commandResolver = new CommandResolver(); commands = new List <ICraneCommand> { B.AutoMock <Help>().Subject, B.AutoMock <Init>().Subject }; }); "When I resolve the command init" ._(() => result = commandResolver.Resolve(commands, "init")); "Then the init command is returned" ._(() => result.Should().Be(typeof(Init))); }
public dynamic SendCommand(string json) { try { dynamic command = CommandResolver.ConvertToCommand(json); dynamic handler = CommandResolver.ResolveCommandHandler(command); return(handler.Handle(command)); } catch { return(new SuccessInfoDto() { isSuccess = false }); } }
public void ResolveCommand_Test(CommandOptionSet commandOptionSet, TestCommand expectedCommand) { // Arrange var typeProvider = new TypeProvider(typeof(TestCommand)); var optionConverter = new CommandOptionConverter(); var resolver = new CommandResolver(typeProvider, optionConverter); // Act var command = resolver.ResolveCommand(commandOptionSet) as TestCommand; // Assert Assert.Multiple(() => { Assert.That(command, Is.Not.Null); Assert.That(command.StringOption, Is.EqualTo(expectedCommand.StringOption), nameof(command.StringOption)); Assert.That(command.IntOption, Is.EqualTo(expectedCommand.IntOption), nameof(command.IntOption)); }); }
private List <string> GetParameterAutoComplete(CommandResolver resolver, InputNode currentNode) { CommandResolverNode resolverNode = resolver.GetNode(currentNode); ParameterDef def = resolverNode != null ? resolverNode.Parameter : null; string validationFunctionName = null; // try to find ordinal parameter definition for an empty element if (def == null && currentNode.ElementType == InputNodeType.Empty) { int ordinalIndex = resolver.Input.InputNodes .Where(n => n.Index < currentNode.Index && n.ElementType == InputNodeType.OrdinalParameterValue).Count() + 1; def = new CommandParameterAnalysis(resolver).AvailableParameters .Where(p => p.OrdinalPosition == ordinalIndex).FirstOrDefault(); } // find validation function for a valid resolver node if (def != null) { validationFunctionName = def.AutoCompleteValuesFunction; } // execute validation values function try { if (validationFunctionName != null) { return(Util.GetParameterAutoCompleteValues(resolver, def, _hostInterface) .Where(v => v.StartsWith(currentNode.Value, StringComparison.OrdinalIgnoreCase)).ToList()); } } catch (Exception ex) { // TODO: Do something with this exception } return(null); }
public HelpTextGenerator(CommandResolver resolver, params IHelpWriter[] writers) { Resolver = resolver; Writers = writers; }
public void CanBindNamedStringListQuoted() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "sample") .WithArgumentList("asd", x => x.TestList); var generator = resolver.Resolve("sample 'test 1'"); generator.Should().Be.OfType<SampleStringList>() .And.Value.TestList.Should().Have.SameSequenceAs("test 1"); }
public void ShowErrorWhenStringOnlyStartsWithCorrectValue() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "test1"); Assert.Throws<InvalidCommandException>(() => resolver.Resolve("test1t(test)", true)); }
public CommandResolver Sample(TextWriter writer) { var r = new CommandResolver().WithHelp(writer, Console.Out); r.Register<Sample1>("cmd1 a", "cmd1 b") .WithArgumentList("cmd1_arguments", x => x.Arguments) .WithOption("opt1", x => x.Option1) .WithOption("opt2", x => x.Option2); r.Register<Sample2>("cmd2") .WithOption("opt1", x => x.Option1) .WithOption("opt2", x => x.Option2); r.Register<Sample2>("noopt"); return r; }
public void CanBindStringWithOptionAndEqualsWithoutParameter() { var resolver = new CommandResolver(); resolver.Register(() => new SampleString(), "sample") .WithOption("with", x => x.Test); var generator = resolver.Resolve("sample with=lasers"); generator.Should().Be.OfType<SampleString>() .And.Value.Test.Should().Be("lasers"); }
public void CanBindIntList() { var resolver = new CommandResolver(); resolver.Register(() => new SampleIntList(), "sample") .WithOptionList("lasers", x => x.Test); var generator = resolver.Resolve("sample lasers:1,2,3"); generator.Should().Be.InstanceOf<SampleIntList>(); generator.Should().Be.OfType<SampleIntList>() .And.Value.Test.Should().Have.SameSequenceAs(1, 2, 3); }
public void CannotBindIntWithTwoParameter() { var resolver = new CommandResolver(); resolver.Register(() => new SampleSingleInt(), "sample") .WithArgument(null, x => x.Test); resolver.Executing(x=> x.Resolve("sample 1,2")) .Throws<InvalidArgumentCountException>() .And.Exception.Message.Should().Be("Invalid argument count in ' 1,2'. Expected: 1. Found: 2"); }
public void CanBindStringListWithSpecialChars() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "sample") .WithArgumentList(null, x => x.TestList); var generator = resolver.Resolve("sample +test, @test2, t^est3"); generator.Should().Be.OfType<SampleStringList>() .And.Value.TestList.Should().Have.SameSequenceAs(new[] { "+test", "@test2", "t^est3" }); }
public void CannotBindStringToMultipleParameters() { var resolver = new CommandResolver(); resolver.Register(() => new SampleString(), "sample") .WithOption("with", x => x.Test); resolver.Executing(x => x.Resolve("sample with lasers, test ")) .Throws<InvalidArgumentCountException>(); }
public void CanBindStringListWithOneParameter() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "sample") .WithArgumentList(null, x => x.TestList); var generator = resolver.Resolve("sample test"); generator.Should().Be.OfType<SampleStringList>() .And.Value.TestList.Should().Have.SameSequenceAs(new[] { "test" }); }
public void CanBindStringListWithMultipleParametersWithParentesis() { var resolver = new CommandResolver(); resolver.Register(() => new SampleStringList(), "sample") .WithArgumentList(null, x => x.TestList); var generator = resolver.Resolve("sample (test, test2, test3)"); generator.Should().Be.OfType<SampleStringList>() .And.Value.TestList.Should().Have.SameSequenceAs("test", "test2", "test3"); }
public FrontControllerImpl(CommandResolver commandResolver) { command_resolver = commandResolver; }
public void CannotBindBooleanShorthandAndNormalAtSameTime() { var resolver = new CommandResolver(); resolver.Register(() => new SampleBoolean(), "sample") .WithOption("lasers", x => x.Test); resolver.Executing(x => x.Resolve("sample +lasers:true")) .Throws<UnrecognizedOptionsException>(); }