コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterAttribute"/> class.
        /// </summary>
        /// <param name="parameterName">The name of the parameter to apply a known value to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="parameterName"/> is
        /// <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="parameterName"/> is empty.
        /// </exception>
        public ParameterAttribute(string parameterName)
        {
            ParameterValidation.IsNotNull(parameterName, nameof(parameterName));
            ParameterValidation.IsNotEmpty(parameterName, nameof(parameterName));

            this.ParameterName = parameterName;
        }
コード例 #2
0
        public void IsNotEmpty_EmptyValue_ArgumentNullException()
        {
            var ex = Assert.Throws <ArgumentException>(
                () => ParameterValidation.IsNotEmpty(string.Empty, TestParameterName));

            Assert.That(ex.ParamName, Is.EqualTo(TestParameterName));
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterAttribute"/> class.
        /// </summary>
        /// <param name="parameterName">The name of the parameter to apply a known value to.</param>
        /// <param name="specimenValue">The value to apply to the parameter.</param>
        /// <exception cref="ArgumentNullException"><paramref name="parameterName"/>, or
        /// <paramref name="specimenValue"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="parameterName"/> is empty.
        /// </exception>
        public ParameterAttribute(string parameterName, object specimenValue)
        {
            ParameterValidation.IsNotNull(parameterName, nameof(parameterName));
            ParameterValidation.IsNotEmpty(parameterName, nameof(parameterName));
            ParameterValidation.IsNotNull(specimenValue, nameof(specimenValue));

            this.ParameterName = parameterName;
            this.SpecimenValue = specimenValue;
        }
コード例 #4
0
        /// <summary>
        /// Removes a message from this <see cref="MessageBoard"/>.
        /// </summary>
        /// <param name="message">The message to remove from this <see cref="MessageBoard"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is
        /// <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="message"/> is empty.</exception>
        public void RemoveMessage(string message)
        {
            ParameterValidation.IsNotNull(message, nameof(message));
            ParameterValidation.IsNotEmpty(message, nameof(message));

            if (this.messages.Remove(message))
            {
                this.Notify();
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterCustomization"/> class.
        /// </summary>
        /// <param name="declaringType">The <see cref="Type"/> of the object that contains the
        /// parameter to apply a known value to.</param>
        /// <param name="parameterName">The name of the parameter to apply a known value to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="declaringType"/>, or
        /// <paramref name="parameterName"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="parameterName"/> is empty.
        /// </exception>
        public ParameterCustomization(
            Type declaringType,
            string parameterName)
        {
            ParameterValidation.IsNotNull(declaringType, nameof(declaringType));
            ParameterValidation.IsNotNull(parameterName, nameof(parameterName));
            ParameterValidation.IsNotEmpty(parameterName, nameof(parameterName));

            this.DeclaringType = declaringType;
            this.ParameterName = parameterName;
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExampleAttribute"/> class.
        /// </summary>
        /// <param name="name">the name of an <see cref="IExample"/> specified by this
        /// <see cref="ExampleAttribute"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> is
        /// <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="name"/> is empty.</exception>
        public ExampleAttribute(string name)
        {
            ParameterValidation.IsNotNull(name, nameof(name));
            ParameterValidation.IsNotEmpty(name, nameof(name));
            ParameterValidation.IsFalse(
                name.Contains(" "),
                "Value cannot contain spaces.",
                nameof(name));

            this.Name = name;
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterSpecimenBuilder"/> class.
        /// </summary>
        /// <param name="declaringType">The <see cref="Type"/> of the object that contains the
        /// parameter to apply a known value to.</param>
        /// <param name="parameterName">The name of the parameter to apply a known value to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="declaringType"/>, or
        /// <paramref name="parameterName"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="parameterName"/> is empty.
        /// </exception>
        public ParameterSpecimenBuilder(
            Type declaringType,
            string parameterName)
        {
            ParameterValidation.IsNotNull(declaringType, nameof(declaringType));
            ParameterValidation.IsNotNull(parameterName, nameof(parameterName));
            ParameterValidation.IsNotEmpty(parameterName, nameof(parameterName));

            this.DeclaringType = declaringType;
            this.ParameterName = parameterName;
        }
コード例 #8
0
        /// <summary>
        /// Resolves an instance of <see cref="ICommand"/> from the specified command group and
        /// <see cref="ParsedCommand"/>.
        /// </summary>
        /// <param name="commandGroup">The command group name the <see cref="ICommand"/> to resolve
        /// is part of.</param>
        /// <param name="parsedCommand">The <see cref="ParsedCommand"/> that describes the
        /// <see cref="ICommand"/> to resolve.</param>
        /// <returns>The created instance of <see cref="ICommand"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="commandGroup"/>, or
        /// <paramref name="parsedCommand"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="commandGroup"/> is empty.
        /// </exception>
        /// <exception cref="CommandResolveException">The arguments of
        /// <paramref name="parsedCommand"/> could not be resolved.</exception>
        /// <exception cref="CommandNotFoundException">An <see cref="ICommand"/> described by
        /// <paramref name="parsedCommand"/> could not be found.</exception>
        public ICommand Resolve(
            string commandGroup,
            ParsedCommand parsedCommand)
        {
            ParameterValidation.IsNotNull(commandGroup, nameof(commandGroup));
            ParameterValidation.IsNotEmpty(commandGroup, nameof(commandGroup));
            ParameterValidation.IsNotNull(parsedCommand, nameof(parsedCommand));

            var commandMeta = this.ResolveCommandMeta(commandGroup, parsedCommand);

            MatchArguments(commandMeta, parsedCommand);
            return(commandMeta.Value);
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExceptionBehaviorExpectation{T}"/> class.
        /// </summary>
        /// <param name="specimenBuilder">The anonymous object creation service used to workaround
        /// a problem with guard clause assertions.</param>
        /// <param name="guardClauseExtensions">An instance of helper extensions for the
        /// <see cref="GuardClauseAssertion"/> class.</param>
        /// <param name="parameterName">The name of the parameter to apply a known value to.</param>
        /// <param name="values">The values to apply to the parameter to assert the guard clause.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="specimenBuilder"/>,
        /// <paramref name="guardClauseExtensions"/>, <paramref name="parameterName"/>, or
        /// <paramref name="values"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="parameterName"/> is empty.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="values"/> is empty.</exception>
        public ExceptionBehaviorExpectation(
            ISpecimenBuilder specimenBuilder,
            IGuardClauseExtensions guardClauseExtensions,
            string parameterName,
            params object[] values)
        {
            ParameterValidation.IsNotNull(specimenBuilder, nameof(specimenBuilder));
            ParameterValidation.IsNotNull(guardClauseExtensions, nameof(guardClauseExtensions));
            ParameterValidation.IsNotNull(parameterName, nameof(parameterName));
            ParameterValidation.IsNotEmpty(parameterName, nameof(parameterName));
            ParameterValidation.IsNotNull(values, nameof(values));
            if (values.Length == 0)
            {
                throw new ArgumentException("Collection must not be empty.", nameof(values));
            }

            this.specimenBuilder       = specimenBuilder;
            this.ParameterName         = parameterName;
            this.Values                = values;
            this.guardClauseExtensions = guardClauseExtensions;
        }
コード例 #10
0
        public CommandParameterAttribute(
            int index,
            string name,
            Type resourceType,
            string helpTextResourceName)
        {
            ParameterValidation.IsGreaterThanOrEqualTo(index, 0, nameof(index));
            ParameterValidation.IsNotNull(name, nameof(name));
            ParameterValidation.IsNotEmpty(name, nameof(name));
            ParameterValidation.IsFalse(
                name.Contains(" "),
                "Value cannot contain spaces.",
                nameof(name));
            ParameterValidation.IsNotNull(resourceType, nameof(resourceType));
            ParameterValidation.IsNotNull(helpTextResourceName, nameof(helpTextResourceName));
            ParameterValidation.IsNotEmpty(helpTextResourceName, nameof(helpTextResourceName));

            this.Index    = index;
            this.Name     = name;
            this.HelpText =
                ResourceTypeResolver.ResolveResource <string>(resourceType, helpTextResourceName);
        }
コード例 #11
0
        public CommandAttribute(
            string group,
            string name,
            Type resourceType,
            string helpTextResourceName)
        {
            ParameterValidation.IsNotNull(group, nameof(group));
            ParameterValidation.IsNotEmpty(group, nameof(group));
            ParameterValidation.IsNotNull(name, nameof(name));
            ParameterValidation.IsNotEmpty(name, nameof(name));
            ParameterValidation.IsFalse(
                name.Contains(" "),
                "Value cannot contain spaces.",
                nameof(name));
            ParameterValidation.IsNotNull(resourceType, nameof(resourceType));
            ParameterValidation.IsNotNull(helpTextResourceName, nameof(helpTextResourceName));
            ParameterValidation.IsNotEmpty(helpTextResourceName, nameof(helpTextResourceName));

            this.Group    = group;
            this.Name     = name;
            this.HelpText =
                ResourceTypeResolver.ResolveResource <string>(resourceType, helpTextResourceName);
        }
コード例 #12
0
 public void IsNotEmpty_NotEmptyValue_DoesNotThrow()
 {
     Assert.DoesNotThrow(
         () => ParameterValidation.IsNotEmpty("Not Empty.", TestParameterName));
 }