public void CommandPathMatchTest() { var path = new CommandPath("alpha", "bravo", "charly", "delta"); Assert.IsTrue(path.Matches("alpha bravo charly delta")); Assert.IsFalse(path.Matches("alpha b charly delta")); Assert.IsFalse(path.Matches("alpha bravo charly")); Assert.IsFalse(path.Matches("alpha bravo")); Assert.IsFalse(path.Matches("alpha")); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultCommand" /> class. /// </summary> /// <param name="names">The names.</param> /// <param name="displayName">The display name.</param> /// <param name="ignoreCase">if set to <c>true</c> ignore the case of the command.</param> /// <param name="permissionCheckers">The permission checkers.</param> /// <param name="method">The method.</param> /// <param name="usageMessage">The usage message.</param> public DefaultCommand(CommandPath[] names, string displayName, bool ignoreCase, IPermissionChecker[] permissionCheckers, MethodInfo method, string usageMessage) { if (names == null) throw new ArgumentNullException(nameof(names)); if (method == null) throw new ArgumentNullException(nameof(method)); if (names.Length == 0) throw new ArgumentException("Must contain at least 1 name", nameof(names)); if (!IsValidCommandMethod(method)) throw new ArgumentException("Method unsuitable as command", nameof(method)); IsMethodMemberOfPlayer = typeof (BasePlayer).IsAssignableFrom(method.DeclaringType); var skipCount = IsMethodMemberOfPlayer ? 0 : 1; var index = 0; var count = method.GetParameters().Length - skipCount; Names = names; _displayName = displayName; IsCaseIgnored = ignoreCase; Method = method; UsageMessage = string.IsNullOrWhiteSpace(usageMessage) ? null : usageMessage; Parameters = Method.GetParameters() .Skip(skipCount) .Select( p => { var type = GetParameterType(p, index++, count); return type == null ? null : new CommandParameterInfo(p.Name, type, p.HasDefaultValue, p.DefaultValue); }) .ToArray(); if (Parameters.Any(v => v == null)) { throw new ArgumentException("Method has parameter of unknown type", nameof(method)); } PermissionCheckers = (permissionCheckers?.Where(p => p != null).ToArray() ?? new IPermissionChecker[0]); }
/// <summary> /// Creates a command. /// </summary> /// <param name="commandPaths">The command paths.</param> /// <param name="displayName">The display name.</param> /// <param name="ignoreCase">if set to <c>true</c> ignore the case the command.</param> /// <param name="permissionCheckers">The permission checkers.</param> /// <param name="method">The method.</param> /// <param name="usageMessage">The usage message.</param> /// <returns>The created command</returns> protected override ICommand CreateCommand(CommandPath[] commandPaths, string displayName, bool ignoreCase, IPermissionChecker[] permissionCheckers, MethodInfo method, string usageMessage) { return new MyCommand(commandPaths, displayName, ignoreCase, permissionCheckers, method, usageMessage); }
public void CommandPathLengthTest() { var path = new CommandPath("alpha", "bravo", "charly", "delta"); Assert.AreEqual("alpha bravo charly delta".Length, path.Length); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultCommand" /> class. /// </summary> /// <param name="names">The names.</param> /// <param name="displayName">The display name.</param> /// <param name="ignoreCase">if set to <c>true</c> ignore the case of the command.</param> /// <param name="permissionCheckers">The permission checkers.</param> /// <param name="method">The method.</param> /// <param name="usageMessage">The usage message.</param> public MyCommand(CommandPath[] names, string displayName, bool ignoreCase, IPermissionChecker[] permissionCheckers, MethodInfo method, string usageMessage) : base(names, displayName, ignoreCase, permissionCheckers, method, usageMessage) { }