Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksa1 committed Sep 3, 2024
1 parent 0405003 commit 3990a7e
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ private void ValidateSchema(SqlDataReader reader)
}
}

private void ValidateNullJson(SqlDataReader reader)
{
while (reader.Read())
{
bool IsNull = reader.IsDBNull(0);
_output.WriteLine(IsNull ? "null" : "not null");
Assert.True(IsNull);
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))]
public void TestJsonWrite()
{
Expand Down Expand Up @@ -286,5 +296,40 @@ public async Task TestJsonReadAsync()
}
}
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))]
public void TestNullJson()
{
string tableName = DataTestUtility.GetUniqueNameForSqlServer("Json_Test");

string tableCreate = "CREATE TABLE " + tableName + " (Data json)";
string tableInsert = "INSERT INTO " + tableName + " VALUES (@jsonData)";
string tableRead = "SELECT * FROM " + tableName;

using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
//Create Table
command.CommandText = tableCreate;
command.ExecuteNonQuery();

//Insert Null value
command.CommandText = tableInsert;
var parameter = new SqlParameter("@jsonData", SqlDbTypeExtensions.Json);
parameter.Value = DBNull.Value;
command.Parameters.Add(parameter);
command.ExecuteNonQuery();

//Query the table
command.CommandText = tableRead;
var reader = command.ExecuteReader();

ValidateNullJson(reader);
reader.Close();
}
}
}
}
}

0 comments on commit 3990a7e

Please sign in to comment.