示例#1
0
        /// <summary>
        /// Maps the specified <paramref name="arguments"/> to a command within the <paramref name="commandList"/>.
        /// </summary>
        /// <typeparam name="TCommand">The type of the t command.</typeparam>
        /// <param name="parser">The parser.</param>
        /// <param name="arguments">The argument array.</param>
        /// <param name="commandList">The command list.</param>
        /// <param name="onSuccess">The action invoked when a command is found.</param>
        /// <param name="onParsingError">The action invoked when a parsing error occurs.</param>
        /// <exception cref="ArgumentException"><typeparamref name="TCommand"/> is not assignable from the mapped object command.</exception>
        public static void Map <TCommand>(this Parser parser, string[] arguments, IEnumerable <Type> commandList, Action <TCommand> onSuccess, Action <string> onParsingError)
        {
            foreach (Type type in commandList)
            {
                parser.Add(CommandInfo.ConvertFrom(type));
            }

            if (parser.TryMap(arguments, out CommandInfo command, out string error))
            {
                if (command.IsInternal) /* DO NOTHING; IT'S ALREADY HANDLED. */ } {
示例#2
0
 public void ConvertFrom_should_create_command_from_a_type()
 {
     foreach (var sample in new Type[]
     {
         typeof(MutableCommand),
         typeof(ImmutableCommand),
         typeof(NonDecoratedCommand)
     })
     {
         using (ApprovalResults.ForScenario(sample.Name))
         {
             var result = CommandInfo.ConvertFrom(sample);
             Approvals.VerifyJson(result.ToJson(showType: true));
         }
     }
 }
示例#3
0
        public void ConvertFrom_should_threw_exception_when_null_is_passed()
        {
            Type type = null;

            Should.Throw <ArgumentNullException>(() => { CommandInfo.ConvertFrom(type); });
        }