public void TestConvertToDecimal(string s)
        {
            decimal actual   = (decimal)SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(decimal));
            decimal expected = Convert.ToDecimal(s, CultureInfo.InvariantCulture);

            Assert.AreEqual(expected, actual);
        }
 public void TestInvalidConversionInvalidInt(string s)
 {
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(Int32)));
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(Int64)));
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(Int16)));
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(byte)));
 }
        public void TestConvertToByte(string s)
        {
            byte actual   = (byte)SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(byte));
            byte expected = Convert.ToByte(s);

            Assert.AreEqual(expected, actual);
        }
        public void TestConvertToInt16(string s)
        {
            Int16 actual   = (Int16)SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(Int16));
            Int16 expected = Convert.ToInt16(s);

            Assert.AreEqual(expected, actual);
        }
        public void TestConvertToFloat(string s)
        {
            double actualDouble   = (double)SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(double));
            double expectedDoulbe = Convert.ToDouble(s, CultureInfo.InvariantCulture);

            Assert.AreEqual(actualDouble, expectedDoulbe);

            float actualFloat   = (float)SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(float));
            float expectedFloat = Convert.ToSingle(s, CultureInfo.InvariantCulture);

            Assert.AreEqual(expectedFloat, actualFloat);
        }
        public void TestConvertDatetime(string inputTimeStr)
        {
            DateTime inputTime;

            if (inputTimeStr == null)
            {
                inputTime = DateTime.Now;
            }
            else
            {
                inputTime = DateTime.ParseExact(inputTimeStr, "yyyy-MM-dd HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
            }

            var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var tickDiff  = inputTime.Ticks - unixEpoch.Ticks;
            var inputStringAsItWasFromDatabase = (tickDiff / 10000000.0m).ToString(CultureInfo.InvariantCulture);
            var result = SFDataConverter.ConvertToCSharpVal(inputStringAsItWasFromDatabase, SFDataType.TIMESTAMP_NTZ, typeof(DateTime));

            Assert.AreEqual(inputTime, result);
        }
 public void TestInvalidConversionInvalidDecimal(string s)
 {
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(decimal)));
 }
 public void TestInvalidConversionInvalidFloat(string s)
 {
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(float)));
     Assert.Throws <FormatException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(double)));
 }
 public void TestOverflowInt64(string s)
 {
     Assert.Throws <OverflowException>(() => SFDataConverter.ConvertToCSharpVal(s, SFDataType.FIXED, typeof(Int64)));
 }
예제 #10
0
        public void TestConvertBoolean(string inputBooleanString, bool expected)
        {
            var actual = SFDataConverter.ConvertToCSharpVal(inputBooleanString, SFDataType.BOOLEAN, typeof(bool));

            Assert.AreEqual(expected, actual);
        }