From 6af8eb04d5a3ef7098d0e70a167dfc5e01be0764 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Fri, 6 Oct 2023 15:42:44 -0700 Subject: [PATCH 1/4] SNOW-723810: Add coverage for SnowflakeDb classes --- .../IntegrationTests/SFDbCommandIT.cs | 34 +++++ .../IntegrationTests/SFDbDataReaderIT.cs | 117 ++++++++++++++++++ .../IntegrationTests/SFDbTransactionIT.cs | 36 ++++++ 3 files changed, 187 insertions(+) diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs index 98e9af7c1..c2655b4d6 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs @@ -203,6 +203,24 @@ public void TestSimpleCommand() } } + [Test] + public void TestSimpleCommandWithConnectionAndCommandText() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + // Act + IDbCommand cmd = new SnowflakeDbCommand((SnowflakeDbConnection)conn, "select 1"); + + // Assert + Assert.AreEqual(CommandType.Text, cmd.CommandType); + Assert.AreEqual(1, cmd.ExecuteScalar()); + } + } + [Test] public void TestSimpleLargeResultSet() { @@ -228,6 +246,22 @@ public void TestSimpleLargeResultSet() } } + [Test] + public void TestCommandPrepareThrowsNotImplemented() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + // Act + IDbCommand cmd = conn.CreateCommand(); + + // Assert + Assert.Throws(() => cmd.Prepare()); + } + } /* * Disabled to make sure that configuration changes does not cause problems with appveyor diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs index 158abc7f0..e9985e6c1 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs @@ -562,6 +562,47 @@ public void testGetBoolean() } } + [Test] + public void testGetByte() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + CreateOrReplaceTable(conn, TableName, new[] + { + "col1 BINARY", + }); + + byte[] testBytes = Encoding.UTF8.GetBytes("TEST_GET_BINARAY"); + + IDbCommand cmd = conn.CreateCommand(); + + var p1 = cmd.CreateParameter(); + p1.ParameterName = "1"; + p1.DbType = DbType.Binary; + p1.Value = testBytes; + + cmd.Parameters.Add(p1); + cmd.CommandText = $"insert into {TableName} values (?)"; + cmd.ExecuteNonQuery(); + cmd.CommandText = $"select * from {TableName}"; + + // Act + using (IDataReader reader = cmd.ExecuteReader()) + { + int index = 0; + while (reader.Read()) + { + // Assert + Assert.AreEqual(testBytes[index++], reader.GetByte(0)); + } + } + } + } + [Test] public void testGetBinary() { @@ -705,6 +746,38 @@ public void testGetBinary() } } + [Test] + public void testGetChar() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + CreateOrReplaceTable(conn, TableName, new[] + { + "col1 VARCHAR(50)", + }); + + char testChar = 'T'; + + IDbCommand cmd = conn.CreateCommand(); + cmd.CommandText = $"insert into {TableName} values ('{testChar}')"; + cmd.ExecuteNonQuery(); + cmd.CommandText = $"select * from {TableName}"; + + // Act + using (IDataReader reader = cmd.ExecuteReader()) + { + // Assert + Assert.IsTrue(reader.Read()); + Assert.IsTrue(testChar.Equals(reader.GetChar(0))); + + } + } + } + [Test] public void testGetChars() { @@ -850,6 +923,50 @@ public void testGetChars() } } + [Test] + public void testGetDataTypeName() + { + using (IDbConnection conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + CreateOrReplaceTable(conn, TableName, new[] + { + "col1 VARCHAR(50)", + "col2 BINARY", + "col3 DOUBLE" + }); + + string testChars = "TEST_GET_CHARS"; + byte[] testBytes = Encoding.UTF8.GetBytes("TEST_GET_BINARY"); + double testDouble = 1.2345678; + + IDbCommand cmd = conn.CreateCommand(); + + var p1 = cmd.CreateParameter(); + p1.ParameterName = "1"; + p1.DbType = DbType.Binary; + p1.Value = testBytes; + + cmd.Parameters.Add(p1); + cmd.CommandText = $"insert into {TableName} values ('{testChars}', ?, {testDouble.ToString()})"; + cmd.ExecuteNonQuery(); + cmd.CommandText = $"select * from {TableName}"; + + // Act + using (DbDataReader reader = (DbDataReader)cmd.ExecuteReader()) + { + // Assert + Assert.IsTrue(reader.Read()); + Assert.AreEqual("TEXT", reader.GetDataTypeName(0)); + Assert.AreEqual("BINARY", reader.GetDataTypeName(1)); + Assert.AreEqual("REAL", reader.GetDataTypeName(2)); + } + } + } + [Test] public void testGetStream() { diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbTransactionIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbTransactionIT.cs index c0b571f98..2786d8226 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbTransactionIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbTransactionIT.cs @@ -15,6 +15,42 @@ namespace Snowflake.Data.Tests.IntegrationTests [TestFixture] class SFDbTransactionIT : SFBaseTest { + [Test] + public void TestTransactionDbConnection() + { + using (var conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + // Act + using (IDbTransaction t1 = conn.BeginTransaction()) + { + // Assert + Assert.AreEqual(conn, t1.Connection); + } + } + } + + [Test] + public void TestTransactionIsolationLevel() + { + using (var conn = new SnowflakeDbConnection()) + { + // Arrange + conn.ConnectionString = ConnectionString; + conn.Open(); + + // Act + using (IDbTransaction t1 = conn.BeginTransaction()) + { + // Assert + Assert.AreEqual(IsolationLevel.ReadCommitted, t1.IsolationLevel); + } + } + } + [Test] // Test that when a transaction is disposed, rollback would be sent out public void TestTransactionDispose() From cfbe8873763cd64107205f586e3e6800a3d13464 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Wed, 18 Oct 2023 12:22:05 -0700 Subject: [PATCH 2/4] SNOW-723810: Modify tests --- .../IntegrationTests/SFDbCommandIT.cs | 35 --------------- .../IntegrationTests/SFDbDataReaderIT.cs | 3 +- .../UnitTests/SFDbCommandTest.cs | 43 +++++++++++++++++++ 3 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 Snowflake.Data.Tests/UnitTests/SFDbCommandTest.cs diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs index c2655b4d6..7cc317bd6 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs @@ -203,24 +203,6 @@ public void TestSimpleCommand() } } - [Test] - public void TestSimpleCommandWithConnectionAndCommandText() - { - using (IDbConnection conn = new SnowflakeDbConnection()) - { - // Arrange - conn.ConnectionString = ConnectionString; - conn.Open(); - - // Act - IDbCommand cmd = new SnowflakeDbCommand((SnowflakeDbConnection)conn, "select 1"); - - // Assert - Assert.AreEqual(CommandType.Text, cmd.CommandType); - Assert.AreEqual(1, cmd.ExecuteScalar()); - } - } - [Test] public void TestSimpleLargeResultSet() { @@ -246,23 +228,6 @@ public void TestSimpleLargeResultSet() } } - [Test] - public void TestCommandPrepareThrowsNotImplemented() - { - using (IDbConnection conn = new SnowflakeDbConnection()) - { - // Arrange - conn.ConnectionString = ConnectionString; - conn.Open(); - - // Act - IDbCommand cmd = conn.CreateCommand(); - - // Assert - Assert.Throws(() => cmd.Prepare()); - } - } - /* * Disabled to make sure that configuration changes does not cause problems with appveyor */ diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs index e9985e6c1..4f2d74bbc 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs @@ -772,8 +772,7 @@ public void testGetChar() { // Assert Assert.IsTrue(reader.Read()); - Assert.IsTrue(testChar.Equals(reader.GetChar(0))); - + Assert.AreEqual(testChar, reader.GetValue(0)); } } } diff --git a/Snowflake.Data.Tests/UnitTests/SFDbCommandTest.cs b/Snowflake.Data.Tests/UnitTests/SFDbCommandTest.cs new file mode 100644 index 000000000..e4350cd61 --- /dev/null +++ b/Snowflake.Data.Tests/UnitTests/SFDbCommandTest.cs @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. + */ + +namespace Snowflake.Data.Tests.UnitTests +{ + using NUnit.Framework; + using Snowflake.Data.Client; + using System; + + [TestFixture] + class SFDbCommandTest + { + SnowflakeDbCommand command; + + [SetUp] + public void BeforeTest() + { + command = new SnowflakeDbCommand(); + } + + [Test] + public void TestCommandWithConnectionAndCommandText() + { + // Arrange + SnowflakeDbConnection conn = new SnowflakeDbConnection(); + string commandText = "select 1"; + + // Act + command = new SnowflakeDbCommand(conn, commandText); + + // Assert + Assert.AreEqual(conn, command.Connection); + Assert.AreEqual(commandText, command.CommandText); + } + + [Test] + public void TestCommandPrepareThrowsNotImplemented() + { + Assert.Throws(() => command.Prepare()); + } + } +} From 2177327e567d0113f2d9ebff9d35df01406d9a9f Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Wed, 18 Oct 2023 12:23:19 -0700 Subject: [PATCH 3/4] SNOW-723810: Modify tests --- Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs index 4f2d74bbc..4a80e6ca0 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs @@ -772,7 +772,7 @@ public void testGetChar() { // Assert Assert.IsTrue(reader.Read()); - Assert.AreEqual(testChar, reader.GetValue(0)); + Assert.AreEqual(testChar, reader.GetChar(0)); } } } From 38f43e206d262eadd85a9cad2b213d6bc3d5a24b Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-lf Date: Wed, 18 Oct 2023 12:24:14 -0700 Subject: [PATCH 4/4] SNOW-723810: Modify tests --- Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs index 7cc317bd6..98e9af7c1 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs @@ -228,6 +228,7 @@ public void TestSimpleLargeResultSet() } } + /* * Disabled to make sure that configuration changes does not cause problems with appveyor */