Пример #1
0
        public void TryCreate_String_CanConvert()
        {
            // Act
            IConverter <string, string> converter = TToStringConverterFactory.TryCreate <string>();

            // Assert
            Assert.NotNull(converter);
            const string expected = "abc";
            string       actual   = converter.Convert(expected);

            Assert.Same(expected, actual);
        }
Пример #2
0
        public void TryCreate_UInt16_CanConvert()
        {
            // Act
            IConverter <ushort, string> converter = TToStringConverterFactory.TryCreate <ushort>();

            // Assert
            Assert.NotNull(converter);
            const ushort value    = 65535;
            string       actual   = converter.Convert(value);
            string       expected = "65535";

            Assert.Equal(expected, actual);
        }
Пример #3
0
        public void TryCreate_Byte_CanConvert()
        {
            // Act
            IConverter <byte, string> converter = TToStringConverterFactory.TryCreate <byte>();

            // Assert
            Assert.NotNull(converter);
            const byte value    = 255;
            string     actual   = converter.Convert(value);
            string     expected = "255";

            Assert.Equal(expected, actual);
        }
Пример #4
0
        public void TryCreate_Char_CanConvert()
        {
            // Act
            IConverter <char, string> converter = TToStringConverterFactory.TryCreate <char>();

            // Assert
            Assert.NotNull(converter);
            const char value    = 'a';
            string     actual   = converter.Convert(value);
            string     expected = Char.ToString(value);

            Assert.Equal(expected, actual);
        }
Пример #5
0
        public void TryCreate_Guid_CanConvert()
        {
            // Act
            IConverter <Guid, string> converter = TToStringConverterFactory.TryCreate <Guid>();

            // Assert
            Assert.NotNull(converter);
            Guid   value    = Guid.Empty;
            string actual   = converter.Convert(value);
            string expected = "00000000-0000-0000-0000-000000000000";

            Assert.Equal(expected, actual);
        }
Пример #6
0
        public void TryCreate_UInt64_CanConvert()
        {
            // Act
            IConverter <ulong, string> converter = TToStringConverterFactory.TryCreate <ulong>();

            // Assert
            Assert.NotNull(converter);
            const ulong value    = 18446744073709551615;
            string      actual   = converter.Convert(value);
            string      expected = "18446744073709551615";

            Assert.Equal(expected, actual);
        }
Пример #7
0
        public void TryCreate_UInt32_CanConvert()
        {
            // Act
            IConverter <uint, string> converter = TToStringConverterFactory.TryCreate <uint>();

            // Assert
            Assert.NotNull(converter);
            const uint value    = 4294967295;
            string     actual   = converter.Convert(value);
            string     expected = "4294967295";

            Assert.Equal(expected, actual);
        }
Пример #8
0
        public void TryCreate_Int16_CanConvert()
        {
            // Arrange
            using (new CultureInfoContext(CreateCultureWithDifferentNegativeSign()))
            {
                // Act
                IConverter <short, string> converter = TToStringConverterFactory.TryCreate <short>();

                // Assert
                Assert.NotNull(converter);
                const short value    = -32768;
                string      actual   = converter.Convert(value);
                string      expected = "-32768";
                Assert.Equal(expected, actual);
            }
        }
Пример #9
0
        public void TryCreate_Int64_CanConvert()
        {
            // Arrange
            using (new CultureInfoContext(CreateCultureWithDifferentNegativeSign()))
            {
                // Act
                IConverter <long, string> converter = TToStringConverterFactory.TryCreate <long>();

                // Assert
                Assert.NotNull(converter);
                const long value    = -9223372036854775808;
                string     actual   = converter.Convert(value);
                string     expected = "-9223372036854775808";
                Assert.Equal(expected, actual);
            }
        }
        public IArgumentBinding <TBindingData> TryCreate(ParameterInfo parameter)
        {
            if (parameter.ParameterType != typeof(string))
            {
                return(null);
            }

            IConverter <TBindingData, string> converter = TToStringConverterFactory.TryCreate <TBindingData>();

            if (converter == null)
            {
                return(null);
            }

            return(new TToStringArgumentBinding(converter));
        }