Skip to content

Commit f282a1f

Browse files
committed
added tests that are similar to those used in SqlClient when adding the LegacyRowVersionNullBehavior functionality
1 parent 8a93ea3 commit f282a1f

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

NullRowVersionIssue/Tests.cs

+37
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,43 @@ public async Task Customer_without_default_address_uses_first_address_using_data
172172
Assert.Null(ex);
173173
}
174174

175+
[Fact]
176+
public void GetValues_null_rowversion_returns_empty_byte_array()
177+
{
178+
var con = GetConnection();
179+
using var command = con.CreateCommand();
180+
command.CommandText = "select cast(null as rowversion) rv";
181+
using var reader = command.ExecuteReader();
182+
reader.Read();
183+
var data = new object[1];
184+
reader.GetValues(data);
185+
Assert.True(data[0] is byte[] {Length: 0});
186+
}
187+
188+
[Fact]
189+
public void GetValue_null_rowversion_returns_empty_byte_array()
190+
{
191+
var con = GetConnection();
192+
using var command = con.CreateCommand();
193+
command.CommandText = "select cast(null as rowversion) rv";
194+
using var reader = command.ExecuteReader();
195+
reader.Read();
196+
var value = reader.GetValue(0);
197+
Assert.True(value is byte[] {Length: 0});
198+
}
199+
200+
[Fact]
201+
public void GetFieldValue_null_rowversion_does_not_throw_invalid_cast()
202+
{
203+
var con = GetConnection();
204+
using var command = con.CreateCommand();
205+
command.CommandText = "select cast(null as rowversion) rv";
206+
using var reader = command.ExecuteReader();
207+
reader.Read();
208+
var ex = Record.Exception(() => reader.GetFieldValue<byte[]>(0));
209+
Assert.Null(ex);
210+
}
211+
175212
private void AddCustomer(Customer customer)
176213
{
177214
fixture.DataContext.Customers.Add(customer);

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ The test called "Customer_without_default_address_uses_first_address" fails.
1212
The test can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from
1313
version 3.0.0 to 2.1.3 or line 156, `builder.EnableRetryOnFailure();`, is commented out.
1414

15-
The test called "Customer_without_default_address_uses_first_address_using_datareader_GetFieldValue" fails.
16-
The test can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from
17-
version 3.0.0 to 2.1.3
18-
19-
The test called "Customer_without_default_address_uses_first_address_using_datareader_GetValues" fails.
20-
The test can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from
21-
version 3.0.0 to 2.1.3
15+
The following tests fail:
16+
* "Customer_without_default_address_uses_first_address_using_datareader_GetFieldValue"
17+
* "Customer_without_default_address_uses_first_address_using_datareader_GetValues"
18+
* "GetValues_null_rowversion_returns_empty_byte_array"
19+
* "GetValue_null_rowversion_returns_empty_byte_array"
20+
* "GetFieldValue_null_rowversion_does_not_throw_invalid_cast"
21+
They can be made to pass if the version of Microsoft.Data.SqlClient is downgraded from version 3.0.0 to 2.1.3
2222

2323
# Schema generated by EF
2424

0 commit comments

Comments
 (0)