Ejemplo n.º 1
0
        public void TryConvert_TypeConverter_ConvertFrom_NoMatchingTypeConverter()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("", cultureInfo, out Dummy value);

            Assert.AreEqual(false, converted);
        }
        public void TryConvert_StringToInt32_02()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("", cultureInfo, out int value);

            Assert.AreEqual(false, converted);
        }
Ejemplo n.º 3
0
        public void TryConvert_StringToByteArray_Base64_Invalid()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("AQIDBA=", cultureInfo, out byte[] _);

            Assert.False(converted);
        }
Ejemplo n.º 4
0
        public void TryConvert_StringToCultureInfo_InvalidCulture()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("dfgnksdfklgfg", cultureInfo, out CultureInfo _);

            Assert.False(converted);
        }
        public void TryConvert_DbNullToInt32()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(DBNull.Value, cultureInfo, out int _);

            Assert.False(converted);
        }
Ejemplo n.º 6
0
        public void TryConvert_StringToInt32_EmptyString()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("", cultureInfo, out int _);

            Assert.False(converted);
        }
        public void TryConvert_CultureInfo_InvalidCulture()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("dfgnksdfklgfg", cultureInfo, out CultureInfo value);

            Assert.AreEqual(false, converted);
        }
        public void TryConvert_StringToNullableLong_01()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("3000000000", cultureInfo, out long?value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(3000000000L, value);
        }
        public void TryConvert_StringToGuid_01()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("afa523e478df4b2da8c86d6b43c48e3e", cultureInfo, out Guid value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(Guid.Parse("afa523e478df4b2da8c86d6b43c48e3e"), value);
        }
        public void TryConvert_StringToEnum_CommaSeparatedStringAndInt()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("Option1, 2", cultureInfo, out SampleEnum value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(SampleEnum.Option1 | SampleEnum.Option2, value);
        }
Ejemplo n.º 11
0
        public void TryConvert_StringToDateTimeOffset()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("2018/06/24 14:21:01+0230", cultureInfo, out DateTimeOffset value);

            Assert.True(converted);
            Assert.Equal(new DateTimeOffset(2018, 06, 24, 14, 21, 01, new TimeSpan(2, 30, 0)), value);
        }
        public void TryConvert_DbNullToString()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(DBNull.Value, cultureInfo, out string value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(null, value);
        }
        public void TryConvert_Uri_02()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("test.png", cultureInfo, out Uri value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(new Uri("test.png", UriKind.Relative), value);
        }
        public void TryConvert_CultureInfo_EmptyString()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("", cultureInfo, out CultureInfo value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(CultureInfo.InvariantCulture, value);
        }
Ejemplo n.º 15
0
        public void TryConvert_TypeConverter_ConvertTo()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(new Dummy(), cultureInfo, out int value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(10, value);
        }
Ejemplo n.º 16
0
        public void TryConvert_DateTimeToDateTimeOffset()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.CurrentCulture;
            var converted   = converter.TryChangeType("6/12/2018 12:00:00 AM -05:00", cultureInfo, out DateTimeOffset value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(new DateTimeOffset(2018, 06, 12, 0, 0, 0, TimeSpan.FromHours(-5)), value);
        }
Ejemplo n.º 17
0
        public void TryConvert_StringToNullableInt32_EmptyString()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("", cultureInfo, out int?value);

            Assert.True(converted);
            Assert.Null(value);
        }
Ejemplo n.º 18
0
        public void TryConvert_StringToBoolean_FalseValue(string text)
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(text, cultureInfo, out bool value);

            Assert.True(converted);
            Assert.False(value);
        }
Ejemplo n.º 19
0
        public void TryConvert_StringToByteArray_Base16Prefixed()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("0x0d01", cultureInfo, out byte[] value);

            Assert.True(converted);
            Assert.Equal(new byte[] { 0x0d, 0x01 }, value);
        }
        public void TryConvert_CultureInfo_LcidAsString()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("1033", cultureInfo, out CultureInfo value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual("en-US", value.Name);
        }
Ejemplo n.º 21
0
        public void TryConvert_TypeConverter_ConvertFrom()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(1, cultureInfo, out Dummy value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(CustomTypeConverter.Instance, value);
        }
        public void TryConvert_StringToNullableInt32_01()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("42", cultureInfo, out int?value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(42, value);
        }
        public void TryConvert_CultureInfo_NullValue()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType <CultureInfo>(null, null, out var value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(null, value);
        }
Ejemplo n.º 24
0
        public void TryConvert_StringToDecimal()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("42.24", cultureInfo, out decimal value);

            Assert.True(converted);
            Assert.Equal(42.24m, value);
        }
        public void TryConvert_Uri_03()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("http://meziantou.net", cultureInfo, out Uri value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(new Uri("http://meziantou.net", UriKind.Absolute), value);
        }
        public void TryConvert_StringToEnum_ValueAsString()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("2", cultureInfo, out SampleEnum value);

            Assert.AreEqual(true, converted);
            Assert.AreEqual(SampleEnum.Option2, value);
        }
Ejemplo n.º 27
0
        public void TryConvert_StringToGuid()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("2d8a54aa-569b-404f-933b-693918885dba", cultureInfo, out Guid value);

            Assert.True(converted);
            Assert.Equal(new Guid("2d8a54aa-569b-404f-933b-693918885dba"), value);
        }
Ejemplo n.º 28
0
        public void TryConvert_StringToDateTime()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType("2018/06/24 14:21:01", cultureInfo, out DateTime value);

            Assert.True(converted);
            Assert.Equal(new DateTime(2018, 06, 24, 14, 21, 01), value);
        }
Ejemplo n.º 29
0
        public void TryConvert_ImplicitConverter_01()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(new ImplicitConverter(), cultureInfo, out int value);

            Assert.True(converted);
            Assert.Equal(1, value);
        }
Ejemplo n.º 30
0
        public void TryConvert_ByteArrayToString_Base64()
        {
            var converter   = new DefaultConverter();
            var cultureInfo = CultureInfo.InvariantCulture;
            var converted   = converter.TryChangeType(new byte[] { 1, 2, 3, 4 }, cultureInfo, out string value);

            Assert.True(converted);
            Assert.Equal("AQIDBA==", value);
        }