Пример #1
0
        public void Resolve_NullPropertyInfo_ArgumentNullException()
        {
            var ex = Assert.Throws <ArgumentNullException>(
                () => ArgumentConverterResolver.Resolve(null));

            Assert.That(ex.ParamName, Is.EqualTo(ResolvePropertyInfoParam));
        }
Пример #2
0
        public void Resolve_ImplicitOperatorProperty_FindImplicitArgumentConverter()
        {
            var argumentConverter = ArgumentConverterResolver.Resolve(
                typeof(CommandStub).GetProperty(nameof(CommandStub.ImplicitOperatorStubProperty)));

            Assert.That(argumentConverter, Is.Not.Null);
            Assert.That(argumentConverter, Is.TypeOf <ImplicitArgumentConverter>());
        }
Пример #3
0
        public void Resolve_TypeConverterProperty_FindTypeConverterArgumentConverter()
        {
            var argumentConverter = ArgumentConverterResolver.Resolve(
                typeof(CommandStub).GetProperty(nameof(CommandStub.TypeConverterProperty)));

            Assert.That(argumentConverter, Is.Not.Null);
            Assert.That(argumentConverter, Is.TypeOf <TypeConverterArgumentConverter>());
        }
Пример #4
0
        public void Resolve_StringProperty_FindDefaultArgumentConverter()
        {
            var argumentConverter = ArgumentConverterResolver.Resolve(
                typeof(CommandStub).GetProperty(nameof(CommandStub.StringProperty)));

            Assert.That(argumentConverter, Is.Not.Null);
            Assert.That(argumentConverter, Is.TypeOf <DefaultArgumentConverter>());
        }
Пример #5
0
        public void Resolve_CannotResolveProperty_ArgumentConverterResolveException()
        {
            const string PropertyName = nameof(CommandStub.CannotResolveProperty);
            var          ex           = Assert.Throws <ArgumentConverterResolveException>(
                () => ArgumentConverterResolver.Resolve(
                    typeof(CommandStub).GetProperty(PropertyName)));

            Assert.That(ex.ArgumentName, Is.EqualTo(PropertyName));
        }
 /// <summary>
 /// Creates a <see cref="CommandParameterMetadata"/> instance from this
 /// <see cref="CommandParameterAttribute"/>.
 /// </summary>
 /// <param name="targetPropertyInfo">The <see cref="PropertyInfo"/> of the target of this
 /// <see cref="CommandParameterAttribute"/>.
 /// </param>
 /// <returns>An instance of <see cref="CommandParameterMetadata"/>.</returns>
 internal CommandParameterMetadata GetMetadata(PropertyInfo targetPropertyInfo)
 {
     return(new CommandParameterMetadata
     {
         Index = this.Index,
         Name = this.Name,
         HelpText = this.HelpText,
         Required = this.Required,
         DefaultValue = this.DefaultValue,
         Converter = ArgumentConverterResolver.Resolve(targetPropertyInfo),
         PropertyInfo = targetPropertyInfo
     });
 }