diff --git a/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs b/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs index 49e835e7c..34648dd1a 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs @@ -221,10 +221,11 @@ public void TestPutFileProvidesQueryIdOnFailure() using (var conn = new SnowflakeDbConnection(ConnectionString)) { conn.Open(); - var queryId = PutFile(conn); - + var snowflakeDbException = Assert.Throws(()=>PutFile(conn)); + var queryId = snowflakeDbException.QueryId; + // Assert - Assert.IsNotNull(queryId); + Assert.IsNotEmpty(queryId); Assert.DoesNotThrow(()=>Guid.Parse(queryId)); } } @@ -514,42 +515,42 @@ string PutFile( $"PUT file://{t_inputFilePath} {t_internalStagePath}" + $" AUTO_COMPRESS={(t_autoCompress ? "TRUE" : "FALSE")}" + $" {additionalAttribute}"; - // Upload file command.CommandText = putQuery; + var reader = command.ExecuteReader(); try { - var reader = command.ExecuteReader(); Assert.IsTrue(reader.Read()); - // Checking query id when reader succeeded - queryId = ((SnowflakeDbDataReader)reader).GetQueryId(); - // Checking if query Id is provided on the command level as well - Assert.AreEqual(queryId, ((SnowflakeDbCommand)command).GetQueryId()); - // Check file status - Assert.AreEqual(expectedStatus.ToString(), - reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.ResultStatus)); - // Check source and destination compression type - if (t_autoCompress) - { - Assert.AreEqual(t_sourceCompressionType, - reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.SourceCompressionType)); - Assert.AreEqual(t_destCompressionType, - reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.DestinationCompressionType)); - } - else - { - Assert.AreEqual(SFFileCompressionTypes.NONE.Name, - reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.SourceCompressionType)); - Assert.AreEqual(SFFileCompressionTypes.NONE.Name, - reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.DestinationCompressionType)); - } - Assert.IsNull(reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.ErrorDetails)); } catch (SnowflakeDbException e) { - queryId = e.QueryId; - Assert.AreEqual(queryId, ((SnowflakeDbCommand)command).GetQueryId()); + // to make sure in a failure case command was set properly with a failed QueryId + Assert.AreEqual(e.QueryId, ((SnowflakeDbCommand)command).GetQueryId()); + throw; + } + // Checking query id when reader succeeded + queryId = ((SnowflakeDbDataReader)reader).GetQueryId(); + // Checking if query Id is provided on the command level as well + Assert.AreEqual(queryId, ((SnowflakeDbCommand)command).GetQueryId()); + // Check file status + Assert.AreEqual(expectedStatus.ToString(), + reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.ResultStatus)); + // Check source and destination compression type + if (t_autoCompress) + { + Assert.AreEqual(t_sourceCompressionType, + reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.SourceCompressionType)); + Assert.AreEqual(t_destCompressionType, + reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.DestinationCompressionType)); + } + else + { + Assert.AreEqual(SFFileCompressionTypes.NONE.Name, + reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.SourceCompressionType)); + Assert.AreEqual(SFFileCompressionTypes.NONE.Name, + reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.DestinationCompressionType)); } + Assert.IsNull(reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.ErrorDetails)); } return queryId; } diff --git a/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs b/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs index d9210c65b..c07325a8c 100644 --- a/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs +++ b/Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs @@ -70,7 +70,7 @@ class SFFileTransferAgentTest : SFBaseTest const string FileContent = "FTAFileContent"; [SetUp] - public void BeforeTest() + public void BeforeEachTest() { // Base object's names on worker thread id var threadSuffix = TestContext.CurrentContext.WorkerId?.Replace('#', '_'); @@ -121,7 +121,7 @@ public void BeforeTest() } [TearDown] - public void AfterTest() + public void AfterEachTest() { // Delete stage directory recursively if (Directory.Exists(t_locationStage)) diff --git a/Snowflake.Data/Client/SnowflakeDbException.cs b/Snowflake.Data/Client/SnowflakeDbException.cs index f61349762..7d83eb3af 100755 --- a/Snowflake.Data/Client/SnowflakeDbException.cs +++ b/Snowflake.Data/Client/SnowflakeDbException.cs @@ -23,7 +23,7 @@ public sealed class SnowflakeDbException : DbException static private ResourceManager rm = new ResourceManager("Snowflake.Data.Core.ErrorMessages", typeof(SnowflakeDbException).Assembly); - public string SqlState { get; private set; } + public new string SqlState { get; private set; } private int VendorCode;