Skip to content

Commit

Permalink
SNOW-1729244 tests for wrong conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dstempniak committed Oct 9, 2024
1 parent 93f3cc5 commit 70cba5f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Snowflake.Data.Tests/UnitTests/SFDataConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System;
using System.Text;
using Snowflake.Data.Client;
using Snowflake.Data.Tests.Util;

namespace Snowflake.Data.Tests.UnitTests
{
Expand Down Expand Up @@ -36,7 +38,7 @@ public void TestConvertBindToSFValFinlandLocale()

Thread.CurrentThread.CurrentCulture = ci;

System.Tuple<string, string> t =
System.Tuple<string, string> t =
SFDataConverter.csharpTypeValToSfTypeVal(System.Data.DbType.Double, 1.2345);

Assert.AreEqual("REAL", t.Item1);
Expand Down Expand Up @@ -109,7 +111,7 @@ public void TestConvertTimeSpan(string inputTimeStr)
var tickDiff = val.Ticks;
var inputStringAsItComesBackFromDatabase = (tickDiff / 10000000.0m).ToString(CultureInfo.InvariantCulture);
inputStringAsItComesBackFromDatabase += inputTimeStr.Substring(8, inputTimeStr.Length - 8);

// Run the conversion
var result = SFDataConverter.ConvertToCSharpVal(ConvertToUTF8Buffer(inputStringAsItComesBackFromDatabase), SFDataType.TIME, typeof(TimeSpan));

Expand Down Expand Up @@ -326,5 +328,21 @@ public void TestInvalidConversionInvalidDecimal(string s)
Assert.Throws<FormatException>(() => SFDataConverter.ConvertToCSharpVal(ConvertToUTF8Buffer(s), SFDataType.FIXED, typeof(decimal)));
}

[Test]
[TestCase(SFDataType.TIMESTAMP_LTZ, typeof(DateTime))]
[TestCase(SFDataType.TIMESTAMP_TZ, typeof(DateTime))]
[TestCase(SFDataType.TIMESTAMP_NTZ, typeof(DateTimeOffset))]
[TestCase(SFDataType.TIME, typeof(DateTimeOffset))]
[TestCase(SFDataType.DATE, typeof(DateTimeOffset))]
public void TestInvalidTimestampConversion(SFDataType dataType, Type unsupportedType)
{
object unsupportedObject;
if (unsupportedType == typeof(DateTimeOffset))
unsupportedObject = new DateTimeOffset();
else
unsupportedObject = new DateTime();
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => SFDataConverter.csharpValToSfVal(dataType, unsupportedObject));
SnowflakeDbExceptionAssert.HasErrorCode(ex, SFError.INVALID_DATA_CONVERSION);
}
}
}

0 comments on commit 70cba5f

Please sign in to comment.