From f282a1f299fc99780a6e4a818241f21f7ea5f00f Mon Sep 17 00:00:00 2001 From: Andrew Pattison Date: Tue, 20 Jul 2021 11:38:06 +0100 Subject: [PATCH] added tests that are similar to those used in SqlClient when adding the LegacyRowVersionNullBehavior functionality --- NullRowVersionIssue/Tests.cs | 37 ++++++++++++++++++++++++++++++++++++ README.md | 14 +++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/NullRowVersionIssue/Tests.cs b/NullRowVersionIssue/Tests.cs index 1a96da3..e2dbaf7 100644 --- a/NullRowVersionIssue/Tests.cs +++ b/NullRowVersionIssue/Tests.cs @@ -172,6 +172,43 @@ public async Task Customer_without_default_address_uses_first_address_using_data Assert.Null(ex); } + [Fact] + public void GetValues_null_rowversion_returns_empty_byte_array() + { + var con = GetConnection(); + using var command = con.CreateCommand(); + command.CommandText = "select cast(null as rowversion) rv"; + using var reader = command.ExecuteReader(); + reader.Read(); + var data = new object[1]; + reader.GetValues(data); + Assert.True(data[0] is byte[] {Length: 0}); + } + + [Fact] + public void GetValue_null_rowversion_returns_empty_byte_array() + { + var con = GetConnection(); + using var command = con.CreateCommand(); + command.CommandText = "select cast(null as rowversion) rv"; + using var reader = command.ExecuteReader(); + reader.Read(); + var value = reader.GetValue(0); + Assert.True(value is byte[] {Length: 0}); + } + + [Fact] + public void GetFieldValue_null_rowversion_does_not_throw_invalid_cast() + { + var con = GetConnection(); + using var command = con.CreateCommand(); + command.CommandText = "select cast(null as rowversion) rv"; + using var reader = command.ExecuteReader(); + reader.Read(); + var ex = Record.Exception(() => reader.GetFieldValue(0)); + Assert.Null(ex); + } + private void AddCustomer(Customer customer) { fixture.DataContext.Customers.Add(customer); diff --git a/README.md b/README.md index 30f60c7..669102d 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ The test called "Customer_without_default_address_uses_first_address" fails. The test can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from version 3.0.0 to 2.1.3 or line 156, `builder.EnableRetryOnFailure();`, is commented out. -The test called "Customer_without_default_address_uses_first_address_using_datareader_GetFieldValue" fails. -The test can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from -version 3.0.0 to 2.1.3 - -The test called "Customer_without_default_address_uses_first_address_using_datareader_GetValues" fails. -The test can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from -version 3.0.0 to 2.1.3 +The following tests fail: +* "Customer_without_default_address_uses_first_address_using_datareader_GetFieldValue" +* "Customer_without_default_address_uses_first_address_using_datareader_GetValues" +* "GetValues_null_rowversion_returns_empty_byte_array" +* "GetValue_null_rowversion_returns_empty_byte_array" +* "GetFieldValue_null_rowversion_does_not_throw_invalid_cast" +They can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from version 3.0.0 to 2.1.3 # Schema generated by EF