|
9 | 9 | using System.Data.SqlTypes;
|
10 | 10 | using System.Threading;
|
11 | 11 | using Xunit;
|
| 12 | +using System.Globalization; |
| 13 | + |
12 | 14 | #if !NETFRAMEWORK
|
13 | 15 | using Microsoft.SqlServer.Types;
|
14 | 16 | using Microsoft.Data.SqlClient.Server;
|
@@ -442,6 +444,75 @@ public static void TestDateOnlyTVPDataTable_CommandSP()
|
442 | 444 | DataTestUtility.DropUserDefinedType(connection, tableTypeName);
|
443 | 445 | }
|
444 | 446 | }
|
| 447 | + |
| 448 | + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] |
| 449 | + public static void TestDateOnlyTVPSqlDataRecord_CommandSP() |
| 450 | + { |
| 451 | + string tableTypeName = "[dbo]." + DataTestUtility.GetUniqueNameForSqlServer("UDTTTestDateOnlySqlDataRecordTVP"); |
| 452 | + string spName = DataTestUtility.GetUniqueNameForSqlServer("spTestDateOnlySqlDataRecordTVP"); |
| 453 | + SqlConnection connection = new(s_connString); |
| 454 | + try |
| 455 | + { |
| 456 | + connection.Open(); |
| 457 | + using (SqlCommand cmd = connection.CreateCommand()) |
| 458 | + { |
| 459 | + cmd.CommandType = CommandType.Text; |
| 460 | + cmd.CommandText = $"CREATE TYPE {tableTypeName} AS TABLE ([DateColumn] date NULL, [TimeColumn] time NULL)"; |
| 461 | + cmd.ExecuteNonQuery(); |
| 462 | + cmd.CommandText = $"CREATE PROCEDURE {spName} (@dates {tableTypeName} READONLY) AS SELECT COUNT(*) FROM @dates"; |
| 463 | + cmd.ExecuteNonQuery(); |
| 464 | + } |
| 465 | + using (SqlCommand cmd = connection.CreateCommand()) |
| 466 | + { |
| 467 | + cmd.CommandText = spName; |
| 468 | + cmd.CommandType = CommandType.StoredProcedure; |
| 469 | + |
| 470 | + SqlMetaData[] metadata = new SqlMetaData[] |
| 471 | + { |
| 472 | + new SqlMetaData("DateColumn", SqlDbType.Date), |
| 473 | + new SqlMetaData("TimeColumn", SqlDbType.Time) |
| 474 | + }; |
| 475 | + |
| 476 | + SqlDataRecord record1 = new SqlDataRecord(metadata); |
| 477 | + record1.SetValues(new DateOnly(2023, 11, 15), new TimeOnly(12, 30, 45)); |
| 478 | + |
| 479 | + SqlDataRecord record2 = new SqlDataRecord(metadata); |
| 480 | + record2.SetValues(new DateOnly(2025, 11, 15), new TimeOnly(13, 31, 46)); |
| 481 | + |
| 482 | + IList<SqlDataRecord> featureInserts = new List<SqlDataRecord> |
| 483 | + { |
| 484 | + record1, |
| 485 | + record2, |
| 486 | + }; |
| 487 | + |
| 488 | + cmd.Parameters.Add(new SqlParameter |
| 489 | + { |
| 490 | + ParameterName = "@dates", |
| 491 | + SqlDbType = SqlDbType.Structured, |
| 492 | + TypeName = tableTypeName, |
| 493 | + Value = featureInserts, |
| 494 | + }); |
| 495 | + |
| 496 | + using var reader = cmd.ExecuteReader(); |
| 497 | + |
| 498 | + Assert.True(reader.HasRows); |
| 499 | + |
| 500 | + int count = 0; |
| 501 | + while (reader.Read()) |
| 502 | + { |
| 503 | + Assert.NotNull(reader[0]); |
| 504 | + count++; |
| 505 | + } |
| 506 | + |
| 507 | + Assert.Equal(1, count); |
| 508 | + } |
| 509 | + } |
| 510 | + finally |
| 511 | + { |
| 512 | + DataTestUtility.DropStoredProcedure(connection, spName); |
| 513 | + DataTestUtility.DropUserDefinedType(connection, tableTypeName); |
| 514 | + } |
| 515 | + } |
445 | 516 | #endif
|
446 | 517 |
|
447 | 518 | #region Scaled Decimal Parameter & TVP Test
|
@@ -471,8 +542,8 @@ public static void SqlDecimalConvertToDecimal_TestInRange(string sqlDecimalValue
|
471 | 542 | cmd.Connection = cnn;
|
472 | 543 | using SqlDataReader rdr = cmd.ExecuteReader();
|
473 | 544 | Assert.True(rdr.Read(), "SqlDataReader must have a value");
|
474 |
| - decimal retrunValue = rdr.GetDecimal(0); |
475 |
| - Assert.Equal(expectedDecimalValue, retrunValue.ToString()); |
| 545 | + decimal returnValue = rdr.GetDecimal(0); |
| 546 | + Assert.Equal(expectedDecimalValue, returnValue.ToString(CultureInfo.InvariantCulture)); |
476 | 547 | }
|
477 | 548 |
|
478 | 549 | [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
|
|
0 commit comments