public void NullConverterAttributeException()
            {
                // Arrange
                ConverterKeyValueAttribute converterAttribute = null;
                var expectedExceptionMessage = SourceParameterName;

                // Act
                var actualException = Assert.Throws <ArgumentNullException>(() => converterAttribute.BuildKeyConverter());

                // Assert
                Assert.Equal(expectedExceptionMessage, actualException.ParamName);
            }
コード例 #2
0
            public void DefaultStringConverterActivation()
            {
                // Arrange
                var expected           = typeof(Int32Converter);
                var converterAttribute = new ConverterKeyValueAttribute(expected);

                // Act
                var actual = converterAttribute.BuildValueConverter();

                // Assert
                Assert.NotNull(actual);
                Assert.IsType <Int32Converter>(actual);
            }
コード例 #3
0
            public void NullConverterAttributeException()
            {
                // Arrange
                ConverterKeyValueAttribute converterAttribute = null;
                var expectedExceptionMessage = SourceParameterName;

                // Act
                var actualException =
                    // ReSharper disable once ExpressionIsAlwaysNull
                    Assert.Throws <ArgumentNullException>(() => converterAttribute.BuildValueConverter());

                // Assert
                Assert.Equal(expectedExceptionMessage, actualException.ParamName);
            }
            public void Int32ConverterActivation()
            {
                // Arrange
                var expected           = typeof(Int32Converter);
                var valueConverterType = typeof(GuidConverter);
                var converterAttribute = new ConverterKeyValueAttribute(valueConverterType, expected);

                // Act
                var actual = converterAttribute.BuildKeyConverter();

                // Assert
                Assert.NotNull(actual);
                Assert.IsType <Int32Converter>(actual);
            }
コード例 #5
0
        private static IConverter GetKeyConverter(PropertyInfo propertyInfo, string optionName, string commandName, ConverterKeyValueAttribute converterKeyValuePairAttribute)
        {
            var keyType      = propertyInfo.PropertyType.GetUnderlyingDictionaryType(true);
            var keyConverter = converterKeyValuePairAttribute.BuildKeyConverter();

            if (!keyType.IsType(keyConverter.TargetType))
            {
                throw new CommandLineParserException(Constants.ExceptionMessages.ParserExtractKeyConverterIsNotValid(optionName, commandName, keyType, keyConverter.TargetType));
            }

            return(keyConverter);
        }
コード例 #6
0
        private static IConverter GetValueConverter(PropertyInfo propertyInfo, string optionName, string commandName, ConverterKeyValueAttribute converterKeyValuePairAttribute)
        {
            var valueType      = propertyInfo.PropertyType.GetUnderlyingDictionaryType(false);
            var valueConverter = converterKeyValuePairAttribute.BuildValueConverter();

            if (!valueType.IsAssignableFrom(valueConverter.TargetType))
            {
                throw new CommandLineParserException(Constants.ExceptionMessages.ParserExtractValueConverterIsNotValid(optionName, commandName, valueType, valueConverter.TargetType));
            }
            return(valueConverter);
        }