コード例 #1
0
        public void TargetType()
        {
            // Arrange
            IConverter converter = new KeyValueConverter(new StringConverter(), new Int32Converter());
            var expectedType = typeof (KeyValuePair<string, int>);

            // Act
            var actualType = converter.TargetType;

            // Assert
            Assert.Equal(expectedType, actualType);
        }
コード例 #2
0
        public void ConversionWithNullValue()
        {
            // Arrange
            IConverter converter = new KeyValueConverter(new StringConverter(), new Int32Converter());
            var value = "Test";
            var expectedKeyValue = "Test";

            // Act
            var actualValue = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actualValue);
            var actualTuple = Assert.IsAssignableFrom<Tuple<object, object>>(actualValue);
            Assert.Equal(expectedKeyValue, (string) actualTuple.Item1);
            Assert.Null(actualTuple.Item2);
        }
コード例 #3
0
        public void BadValueConversion()
        {
            // Arrange
            IConverter converter = new KeyValueConverter(new StringConverter(), new Int32Converter());
            var value = "Hello=Hello";
            var expectedExceptionMessage = Constants.ExceptionMessages.FormatConverterUnableConvert("Hello", typeof(int));
            var expectedInnerExceptionMessage = "Input string was not in a correct format.";

            // Act
            using (new LangageSwitcher("en-us"))
            {
                var actualException = Assert.Throws<CommandLineParserException>(() => converter.Convert(value, converter.TargetType));

                // Assert
                Assert.Equal(expectedExceptionMessage, actualException.Message);
                Assert.NotNull(actualException.InnerException);
                var actualInnerExecption = Assert.IsAssignableFrom<FormatException>(actualException.InnerException);
                Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message);
            }
        }
コード例 #4
0
        public void EmptyValueConverter()
        {
            // Arrange
            IConverter converter = new KeyValueConverter(new StringConverter(), new Int32Converter());
            var expectedInnerExceptionMessage = @"value";
            var value = string.Empty;

            // Act
            var actualException = Assert.Throws<ArgumentNullException>(() => converter.Convert(value, converter.TargetType));

            // Assert
            Assert.Equal(expectedInnerExceptionMessage, actualException.ParamName);
        }