Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-723810: Add coverage for SnowflakeDb classes #786

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
sfc-gh-ext-simba-lf marked this conversation as resolved.
Show resolved Hide resolved

// Assert
Assert.AreEqual(CommandType.Text, cmd.CommandType);
Assert.AreEqual(1, cmd.ExecuteScalar());
}
}

[Test]
public void TestSimpleLargeResultSet()
{
Expand All @@ -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<NotImplementedException>(() => cmd.Prepare());
sfc-gh-ext-simba-lf marked this conversation as resolved.
Show resolved Hide resolved
}
}

/*
* Disabled to make sure that configuration changes does not cause problems with appveyor
Expand Down
117 changes: 117 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFDbDataReaderIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)));
sfc-gh-ext-simba-lf marked this conversation as resolved.
Show resolved Hide resolved

}
}
}

[Test]
public void testGetChars()
{
Expand Down Expand Up @@ -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()
{
Expand Down
36 changes: 36 additions & 0 deletions Snowflake.Data.Tests/IntegrationTests/SFDbTransactionIT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
sfc-gh-ext-simba-lf marked this conversation as resolved.
Show resolved Hide resolved

[Test]
// Test that when a transaction is disposed, rollback would be sent out
public void TestTransactionDispose()
Expand Down
Loading