public void ConvertToStringTest()
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.String, true, true);

            Assert.IsNull(conv.ConvertToString(DBNull.Value));

            Assert.IsNull(conv.ConvertToString(null));

            const string test = "Test";

            Assert.AreEqual(test, conv.ConvertToString(test));
        }
示例#2
0
        public void CreateConverterTest8(bool throwsOnParseErrors)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.ByteArray, false, false, throwOnParseErrors: throwsOnParseErrors);

            Assert.IsInstanceOfType(conv, typeof(Base64Converter));
            Assert.AreEqual(typeof(byte[]), conv.Type);
            Assert.AreEqual(throwsOnParseErrors, conv.ThrowsOnParseErrors);

            if (conv.FallbackValue is byte[] bts)
            {
                Assert.AreEqual(0, bts.Length);
            }
            else
            {
                Assert.Fail();
            }

            var test1 = new byte[] { 17, 24, 42 };

            string?s = conv.ConvertToString(test1);

            byte[]? test2 = (byte[]?)conv.Parse(s);

            CollectionAssert.AreEqual(test1, test2);
        }
示例#3
0
        public void RoundtripTest10(bool throwOnParseErrors, bool ignoreCase, bool nullable)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateEnumConverter <CsvTypeCode>(nullable, true, throwOnParseErrors, ignoreCase);

            string?s = conv.ConvertToString(DBNull.Value);

            Assert.IsNull(s);

            Assert.IsTrue(Convert.IsDBNull(conv.Parse(s)));
        }
        public void ConvertToStringTest2()
        {
            var dt = new DateTime(1972, 01, 31);
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.DateTime);

            //dt = dt.ToLocalTime();

            string?s = conv.ConvertToString(dt);

            Assert.IsNotNull(s);
        }
示例#5
0
        public void RoundtripTest8(bool throwOnParseErrors, bool ignoreCase)
        {
            CsvTypeCode?val = null;

            ICsvTypeConverter conv = CsvConverterFactory.CreateEnumConverter <CsvTypeCode>(true, false, throwOnParseErrors, ignoreCase);

            string?s = conv.ConvertToString(val);

            Assert.IsNull(s);

            Assert.IsNull(conv.Parse(s));
        }
        public void RoundtripTest1()
        {
            double d = 72.81;

            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.Double);

            string?s = conv.ConvertToString(d);

            Assert.IsNotNull(s);

            double?d2 = (double?)conv.Parse(s);

            Assert.AreEqual(d, d2);
        }
        public void RoundtripTest2()
        {
            int i = 123456789;

            ICsvTypeConverter conv = CsvConverterFactory.CreateHexConverter(CsvTypeCode.Int32);

            string?s = conv.ConvertToString(i)?.ToLowerInvariant();

            Assert.IsNotNull(s);

            var i2 = (int?)conv.Parse(s);

            Assert.AreEqual(i, i2);
        }
        public void Roundtrip1()
        {
            TimeSpan now = DateTime.UtcNow.TimeOfDay;

            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.TimeSpan);

            string?tmp = conv.ConvertToString(now);

            Assert.IsNotNull(tmp);

            var now2 = (TimeSpan?)conv.Parse(tmp);

            Assert.AreEqual(now, now2);
        }
示例#9
0
        public void Roundtrip1()
        {
            var guid = Guid.NewGuid();

            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.Guid);

            string?tmp = conv.ConvertToString(guid);

            Assert.IsNotNull(tmp);

            var now2 = (Guid?)conv.Parse(tmp);

            Assert.AreEqual(guid, now2);
        }
示例#10
0
        public void RoundtripTest2()
        {
            CsvTypeCode val = CsvTypeCode.DateTimeOffset;

            ICsvTypeConverter conv = CsvConverterFactory.CreateEnumConverter <CsvTypeCode>("F");

            string?s = conv.ConvertToString(val);

            Assert.IsNotNull(s);

            var val2 = (CsvTypeCode?)conv.Parse(s);

            Assert.AreEqual(val, val2);
        }
示例#11
0
        public void RoundtripTest6()
        {
            CsvTypeCode val = CsvTypeCode.DateTimeOffset;

            ICsvTypeConverter conv = CsvConverterFactory.CreateEnumConverter <CsvTypeCode>("F", ignoreCase: false, throwOnParseErrors: true);

            string?s = conv.ConvertToString(val);

            Assert.IsNotNull(s);

            s = s !.ToUpperInvariant();


            _ = (CsvTypeCode?)conv.Parse(s);
        }
示例#12
0
        public void Roundtrip1()
        {
            DateTimeOffset now = new DateTime(2021, 3, 1, 17, 25, 38, DateTimeKind.Local);

            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.DateTimeOffset);

            string?tmp = conv.ConvertToString(now);

            Assert.IsNotNull(tmp);

            var now2 = (DateTimeOffset?)conv.Parse(tmp);


            Assert.AreEqual(now, now2);
        }
示例#13
0
        public void RoundtripTest3()
        {
            CsvTypeCode val = CsvTypeCode.DateTimeOffset;

            ICsvTypeConverter conv = CsvConverterFactory.CreateEnumConverter <CsvTypeCode>(ignoreCase: true);

            string?s = conv.ConvertToString(val);

            Assert.IsNotNull(s);

            s = s !.ToUpperInvariant();

            var val2 = (CsvTypeCode?)conv.Parse(s);

            Assert.AreEqual(val, val2);
        }
示例#14
0
        public void DateTimeOffsetConverterTest0()
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.DateTimeOffset);

            Assert.IsInstanceOfType(conv, typeof(DateTimeOffsetConverter));

            var dt = new DateTime(1975, 07, 14);

            string?s = conv.ConvertToString(new DateTimeOffset(dt));

            Assert.IsNotNull(s);

            var dto = (DateTimeOffset)conv.Parse(s) !;

            Assert.AreEqual(dt, dto.DateTime);
        }
示例#15
0
        public void CreateConverterTest9(bool throwsOnParseErrors)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.Guid, false, false, throwOnParseErrors: throwsOnParseErrors);

            Assert.IsInstanceOfType(conv, typeof(GuidConverter));
            Assert.AreEqual(typeof(Guid), conv.Type);
            Assert.AreEqual(throwsOnParseErrors, conv.ThrowsOnParseErrors);
            Assert.AreEqual(conv.FallbackValue, default(Guid));

            var test1 = Guid.NewGuid();

            string?s = conv.ConvertToString(test1);

            var test2 = (Guid?)conv.Parse(s);

            Assert.AreEqual(test1, test2);
        }
        public void RoundtripTest1()
        {
            var bytes = new byte[7];

            using var rnd = RandomNumberGenerator.Create();
            rnd.GetBytes(bytes);

            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.ByteArray);

            string?s = conv.ConvertToString(bytes);

            Assert.IsNotNull(s);

            var bytes2 = (byte[]?)conv.Parse(s);

            CollectionAssert.AreEqual(bytes, bytes2);
        }
示例#17
0
        public void CreateConverterTest12(bool throwsOnParseErrors)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.DateTime, false, false, CultureInfo.InvariantCulture, throwOnParseErrors: throwsOnParseErrors);

            Assert.IsInstanceOfType(conv, typeof(DateTimeConverter));
            Assert.AreEqual(typeof(DateTime), conv.Type);
            Assert.AreEqual(default(DateTime), conv.FallbackValue);
            Assert.AreEqual(throwsOnParseErrors, conv.ThrowsOnParseErrors);

            var    test = new DateTime(1956, 12, 24, 14, 27, 32);
            string?s    = conv.ConvertToString(test);

            Assert.IsNotNull(s);

            var test2 = (DateTime?)conv.Parse(s);

            Assert.AreEqual(test, test2);
        }
示例#18
0
        public void CreateConverterTest15(bool throwsOnParseErrors)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.DateTimeOffset, false, false, CultureInfo.CreateSpecificCulture("de-DE"), throwOnParseErrors: throwsOnParseErrors);

            Assert.IsInstanceOfType(conv, typeof(DateTimeOffsetConverter));
            Assert.AreEqual(typeof(DateTimeOffset), conv.Type);
            Assert.AreEqual(default(DateTimeOffset), conv.FallbackValue);
            Assert.AreEqual(throwsOnParseErrors, conv.ThrowsOnParseErrors);

            var    test = new DateTimeOffset(1956, 12, 24, 14, 27, 32, TimeSpan.FromHours(3));
            string?s    = conv.ConvertToString(test);

            Assert.IsNotNull(s);

            var test2 = (DateTimeOffset?)conv.Parse(s);

            Assert.AreEqual(test, test2);
        }
示例#19
0
        public void CreateConverterTest7(bool throwsOnParseErrors)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.Decimal, false, false, CultureInfo.CreateSpecificCulture("de-DE"), throwOnParseErrors: throwsOnParseErrors);

            Assert.IsInstanceOfType(conv, typeof(NumberConverter <decimal>));
            Assert.AreEqual(typeof(decimal), conv.Type);
            Assert.AreEqual(default(decimal), conv.FallbackValue);
            Assert.AreEqual(throwsOnParseErrors, conv.ThrowsOnParseErrors);

            decimal test = 57.839m;
            string? s    = conv.ConvertToString(test);

            Assert.IsNotNull(s);

            decimal?test2 = (decimal?)conv.Parse(s);

            Assert.AreEqual(test, test2);
        }
示例#20
0
        public void CreateConverterTest17(bool throwsOnParseErrors)
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.TimeSpan, false, false, CultureInfo.CreateSpecificCulture("de-DE"), throwOnParseErrors: throwsOnParseErrors);

            Assert.IsInstanceOfType(conv, typeof(TimeSpanConverter));
            Assert.AreEqual(typeof(TimeSpan), conv.Type);
            Assert.AreEqual(default(TimeSpan), conv.FallbackValue);
            Assert.AreEqual(throwsOnParseErrors, conv.ThrowsOnParseErrors);

            var    test = new TimeSpan(16, 24, 53);
            string?s    = conv.ConvertToString(test);

            Assert.IsNotNull(s);

            var test2 = (TimeSpan?)conv.Parse(s);

            Assert.AreEqual(test, test2);
        }
        public void MyTestMethod()
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.ByteArray);

            _ = conv.ConvertToString(4711);
        }
        public void ConvertToStringTest_ThrowOnDBNull()
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.String);

            _ = conv.ConvertToString(DBNull.Value);
        }
        public void ConvertToStringTest_ThrowOnInvalidType()
        {
            ICsvTypeConverter conv = CsvConverterFactory.CreateConverter(CsvTypeCode.String);

            _ = conv.ConvertToString(4711);
        }