diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index e83e49b79a..838f9a2d14 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -92,14 +92,6 @@ public static class DataTestUtility //SQL Server EngineEdition private static string s_sqlServerEngineEdition; - // Currently, only Azure SQL supports vectors and JSON. - // Our CI images with specific SQL Server versions lag - // behind with vector and JSON support. - // JSON Column type - public static readonly bool IsJsonSupported = !IsNotAzureServer(); - // VECTOR column type - public static readonly bool IsVectorSupported = !IsNotAzureServer(); - // Azure Synapse EngineEditionId == 6 // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname public static bool IsAzureSynapse @@ -181,7 +173,6 @@ static DataTestUtility() ManagedIdentitySupported = c.ManagedIdentitySupported; IsManagedInstance = c.IsManagedInstance; AliasName = c.AliasName; - IsJsonSupported = c.IsJsonSupported; #if NETFRAMEWORK System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; @@ -453,6 +444,11 @@ public static bool IsAADAuthorityURLSetup() return !string.IsNullOrEmpty(AADAuthorityURL); } + public static bool IsAzureServer() + { + return AreConnStringsSetup() && Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); + } + public static bool IsNotAzureServer() { return !AreConnStringsSetup() || !Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs index c92ba237b4..2ba0b80a8d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs @@ -7,18 +7,17 @@ using Newtonsoft.Json; using Xunit.Abstractions; using Xunit; -using System.Collections; namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.JsonTest { public class JsonBulkCopyTest { private readonly ITestOutputHelper _output; - private static readonly string _generatedJsonFile = DataTestUtility.GenerateRandomCharacters("randomRecords"); - private static readonly string _outputFile = DataTestUtility.GenerateRandomCharacters("serverResults"); - private static readonly string _sourceTableName = DataTestUtility.GenerateObjectName(); - private static readonly string _destinationTableName = DataTestUtility.GenerateObjectName(); - + private static readonly string _generatedJsonFile = DataTestUtility.GetUniqueName("randomRecords"); + private static readonly string _outputFile = DataTestUtility.GetUniqueName("serverResults"); + private static readonly string _sourceTableName = DataTestUtility.GetUniqueName("jsonBulkCopySrcTable", true); + private static readonly string _destinationTableName = DataTestUtility.GetUniqueName("jsonBulkCopyDestTable", true); + public JsonBulkCopyTest(ITestOutputHelper output) { _output = output; @@ -26,10 +25,10 @@ public JsonBulkCopyTest(ITestOutputHelper output) public static IEnumerable JsonBulkCopyTestData() { - yield return new object[] { CommandBehavior.Default, false, 300, 100 }; - yield return new object[] { CommandBehavior.Default, true, 300, 100 }; - yield return new object[] { CommandBehavior.SequentialAccess, false, 300, 100 }; - yield return new object[] { CommandBehavior.SequentialAccess, true, 300, 100 }; + yield return new object[] { CommandBehavior.Default, false, 30, 10 }; + yield return new object[] { CommandBehavior.Default, true, 30, 10 }; + yield return new object[] { CommandBehavior.SequentialAccess, false, 30, 10 }; + yield return new object[] { CommandBehavior.SequentialAccess, true, 30, 10 }; } private void PopulateData(int noOfRecords, int rows) @@ -87,7 +86,7 @@ private void PrintJsonDataToFileAndCompare(SqlConnection connection) try { DeleteFile(_outputFile); - using (SqlCommand command = new SqlCommand("SELECT [data] FROM [" + _destinationTableName + "]", connection)) + using (SqlCommand command = new SqlCommand("SELECT [data] FROM " + _destinationTableName, connection)) { using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { @@ -125,7 +124,7 @@ private async Task PrintJsonDataToFileAndCompareAsync(SqlConnection connection) try { DeleteFile(_outputFile); - using (SqlCommand command = new SqlCommand("SELECT [data] FROM [" + _destinationTableName + "]", connection)) + using (SqlCommand command = new SqlCommand("SELECT [data] FROM " + _destinationTableName, connection)) { using (SqlDataReader reader = await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess)) { @@ -159,7 +158,7 @@ private async Task PrintJsonDataToFileAndCompareAsync(SqlConnection connection) private void StreamJsonFileToServer(SqlConnection connection) { - using (SqlCommand cmd = new SqlCommand("INSERT INTO [" + _sourceTableName + "] (data) VALUES (@jsondata)", connection)) + using (SqlCommand cmd = new SqlCommand("INSERT INTO " + _sourceTableName + " (data) VALUES (@jsondata)", connection)) { using (StreamReader jsonFile = File.OpenText(_generatedJsonFile)) { @@ -171,7 +170,7 @@ private void StreamJsonFileToServer(SqlConnection connection) private async Task StreamJsonFileToServerAsync(SqlConnection connection) { - using (SqlCommand cmd = new SqlCommand("INSERT INTO [" + _sourceTableName + "] (data) VALUES (@jsondata)", connection)) + using (SqlCommand cmd = new SqlCommand("INSERT INTO " + _sourceTableName + " (data) VALUES (@jsondata)", connection)) { using (StreamReader jsonFile = File.OpenText(_generatedJsonFile)) { @@ -265,7 +264,7 @@ private async Task BulkCopyDataAsync(CommandBehavior cb, bool enableStraming, in } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData( nameof(JsonBulkCopyTestData) #if NETFRAMEWORK @@ -289,7 +288,7 @@ public void TestJsonBulkCopy(CommandBehavior cb, bool enableStraming, int jsonAr } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData( nameof(JsonBulkCopyTestData) #if NETFRAMEWORK diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs index a82fee1665..045efc8408 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs @@ -19,11 +19,11 @@ public class JsonRecord public string Name { get; set; } } - public class JsonStreamTest + public class JsonStreamTest { private readonly ITestOutputHelper _output; - private static readonly string _jsonFile = "randomRecords.json"; - private static readonly string _outputFile = "serverRecords.json"; + private static readonly string _jsonFile = DataTestUtility.GetUniqueName("randomRecords") + ".json"; + private static readonly string _outputFile = DataTestUtility.GetUniqueName("serverRecords") + ".json"; public JsonStreamTest(ITestOutputHelper output) { @@ -49,7 +49,7 @@ private void GenerateJsonFile(int noOfRecords, string filename) string json = JsonConvert.SerializeObject(records, Formatting.Indented); File.WriteAllText(filename, json); Assert.True(File.Exists(filename)); - _output.WriteLine("Generated JSON file "+filename); + _output.WriteLine("Generated JSON file " + filename); } private void CompareJsonFiles() @@ -157,10 +157,10 @@ private void DeleteFile(string filename) } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonStreaming() { - GenerateJsonFile(10000, _jsonFile); + GenerateJsonFile(1000, _jsonFile); using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString)) { connection.Open(); @@ -173,10 +173,10 @@ public void TestJsonStreaming() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestJsonStreamingAsync() { - GenerateJsonFile(10000, _jsonFile); + GenerateJsonFile(1000, _jsonFile); using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString)) { await connection.OpenAsync(); @@ -190,4 +190,3 @@ public async Task TestJsonStreamingAsync() } } } - diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs index ccf0c00919..55dffae12d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs @@ -22,7 +22,7 @@ public JsonTest(ITestOutputHelper output) { _output = output; } - + private static readonly string JsonDataString = "[{\"name\":\"Dave\",\"skills\":[\"Python\"]},{\"name\":\"Ron\",\"surname\":\"Peter\"}]"; private void ValidateRowsAffected(int rowsAffected) @@ -73,7 +73,7 @@ private void ValidateNullJson(SqlDataReader reader) } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonWrite() { string tableName = DataTestUtility.GenerateObjectName(); @@ -137,7 +137,7 @@ public void TestJsonWrite() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestJsonWriteAsync() { string tableName = DataTestUtility.GenerateObjectName(); @@ -201,7 +201,7 @@ public async Task TestJsonWriteAsync() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonRead() { string tableName = DataTestUtility.GenerateObjectName(); @@ -260,7 +260,7 @@ public void TestJsonRead() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestJsonReadAsync() { string tableName = DataTestUtility.GenerateObjectName(); @@ -319,7 +319,7 @@ public async Task TestJsonReadAsync() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestNullJson() { string tableName = DataTestUtility.GenerateObjectName(); @@ -350,7 +350,7 @@ public void TestNullJson() DataTestUtility.DropTable(connection, tableName); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonAPIs() { string tableName = DataTestUtility.GenerateObjectName(); @@ -398,7 +398,7 @@ public void TestJsonAPIs() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonWithMARS() { string table1Name = DataTestUtility.GenerateObjectName(); @@ -454,7 +454,7 @@ public void TestJsonWithMARS() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonSPParams() { string tableName = DataTestUtility.GenerateObjectName(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs index 3140d4c3ac..119190f8c5 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs @@ -20,7 +20,7 @@ public static class VectorFloat32TestData public static float[] testData = new float[] { 1.1f, 2.2f, 3.3f }; public static int vectorColumnLength = testData.Length; // Incorrect size for SqlParameter.Size - public static int IncorrectParamSize = 3234; + public static int IncorrectParamSize = 3234; public static IEnumerable GetVectorFloat32TestData() { // Pattern 1-4 with SqlVector(values: testData) @@ -43,11 +43,11 @@ public static IEnumerable GetVectorFloat32TestData() // Pattern 1-4 with SqlVector.Null yield return new object[] { 1, SqlVector.Null, Array.Empty(), vectorColumnLength }; - + // Following scenario is not supported in SqlClient. // This can only be fixed with a behavior change that SqlParameter.Value is internally set to DBNull.Value if it is set to null. //yield return new object[] { 2, SqlVector.Null, Array.Empty(), vectorColumnLength }; - + yield return new object[] { 3, SqlVector.Null, Array.Empty(), vectorColumnLength }; yield return new object[] { 4, SqlVector.Null, Array.Empty(), vectorColumnLength }; } @@ -128,7 +128,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader.GetSqlValue(0), expectedData, expectedLength); if (!reader.IsDBNull(0)) - { + { ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader.GetValue(0), expectedData, expectedLength); ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader[0], expectedData, expectedLength); ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader["VectorData"], expectedData, expectedLength); @@ -147,7 +147,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestSqlVectorFloat32ParameterInsertionAndReads( int pattern, @@ -213,7 +213,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( int pattern, @@ -247,7 +247,7 @@ public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( await ValidateInsertedDataAsync(conn, expectedValues, expectedLength); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestStoredProcParamsForVectorFloat32( int pattern, @@ -304,7 +304,7 @@ public void TestStoredProcParamsForVectorFloat32( Assert.Throws(() => command.ExecuteNonQuery()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestStoredProcParamsForVectorFloat32Async( int pattern, @@ -361,7 +361,7 @@ public async Task TestStoredProcParamsForVectorFloat32Async( await Assert.ThrowsAsync(async () => await command.ExecuteNonQueryAsync()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [InlineData(1)] [InlineData(2)] public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) @@ -374,8 +374,8 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) DataTable table = null; switch (bulkCopySourceMode) { - - case 1: + + case 1: // Use SqlServer table as source var insertCmd = new SqlCommand($"insert into {s_bulkCopySrcTableName} values (@VectorData)", sourceConnection); var vectorParam = new SqlParameter(s_vectorParamName, new SqlVector(VectorFloat32TestData.testData)); @@ -400,8 +400,8 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) throw new ArgumentOutOfRangeException(nameof(bulkCopySourceMode), $"Unsupported bulk copy source mode: {bulkCopySourceMode}"); } - - + + //Bulkcopy from sql server table to destination table using SqlCommand sourceDataCommand = new SqlCommand($"SELECT Id, VectorData FROM {s_bulkCopySrcTableName}", sourceConnection); using SqlDataReader reader = sourceDataCommand.ExecuteReader(); @@ -460,7 +460,7 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, ((SqlVector)verifyReader.GetSqlVector(0)).Length); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [InlineData(1)] [InlineData(2)] public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) @@ -560,7 +560,7 @@ public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, vector.Length); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestInsertVectorsFloat32WithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs index 84c16e1793..27c857f5c5 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs @@ -10,38 +10,83 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.VectorTest { public sealed class VectorAPIValidationTest { - // We need this testcase to validate ref assembly for vector APIs + // We need these testcases to validate ref assembly for vector APIs // Unit tests are covered under SqlVectorTest.cs [Fact] - public void VectorAPITest() + public void ValidateVectorSqlDbType() { // Validate that SqlVector is a valid type and has valid SqlDbType Assert.True(typeof(SqlVector).IsValueType, "SqlVector should be a value type."); Assert.Equal(36, (int)SqlDbTypeExtensions.Vector); + } + [Fact] + public void TestSqlVectorCreationAPIWithFloatArr() + { // Validate ctor1 with float[] : public SqlVector(System.ReadOnlyMemory memory) { } - var vector = new SqlVector(VectorFloat32TestData.testData); - Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + var testData = new float[] { 1.1f, 2.2f, 3.3f }; + var vector = new SqlVector(testData); + Assert.Equal(testData, vector.Memory.ToArray()); Assert.Equal(3, vector.Length); + } + [Fact] + public void TestSqlVectorCreationAPIWithROM() + { // Validate ctor2 with ReadOnlyMemory : public SqlVector(ReadOnlyMemory memory) { } - vector = new SqlVector(new ReadOnlyMemory(VectorFloat32TestData.testData)); - Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + var testData = new ReadOnlyMemory(new float[] { 1.1f, 2.2f, 3.3f }); + var vector = new SqlVector(testData); + Assert.Equal(testData.ToArray(), vector.Memory.ToArray()); Assert.Equal(3, vector.Length); + } + [Fact] + public void TestSqlVectorCreationAPICreateNull() + { + // Validate CreateNull method + var vector = SqlVector.CreateNull(5); + Assert.True(vector.IsNull); + Assert.Equal(5, vector.Length); + } + + [Fact] + public void TestIsNullProperty() + { //Validate IsNull property + var testData = new ReadOnlyMemory(new float[] { 1.1f, 2.2f, 3.3f }); + var vector = new SqlVector(testData); Assert.False(vector.IsNull, "IsNull should be false for non-null vector."); + vector = SqlVector.CreateNull(3); + Assert.True(vector.IsNull, "IsNull should be true for null vector."); + } + [Fact] + public void TestNullProperty() + { // Validate Null property returns null Assert.Null(SqlVector.Null); + } - //Validate length property + [Fact] + public void TestLengthProperty() + { + // Validate Length property is correctly populated for null and non-null vectors + var testData = new float[] { 1.1f, 2.2f, 3.3f }; + var vector = new SqlVector(testData); Assert.Equal(3, vector.Length); + vector = SqlVector.CreateNull(3); + Assert.Equal(3, vector.Length); + } - // Validate CreateNull method - vector = SqlVector.CreateNull(5); - Assert.True(vector.IsNull); - Assert.Equal(5, vector.Length); + [Fact] + public void TestMemoryProperty() + { + // Validate Memory property is correctly populated for non-null and null vectors + var testData = new float[] { 1.1f, 2.2f, 3.3f }; + var vector = new SqlVector(testData); + Assert.Equal(testData, vector.Memory.ToArray()); + vector = SqlVector.CreateNull(3); + Assert.True(vector.Memory.IsEmpty, "Null vector of given size point to empty ROM"); } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs index 5fb9cf7625..402a2777f8 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs @@ -81,7 +81,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestVectorDataInsertionAsVarchar() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -173,7 +173,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestVectorParameterInitializationAsync() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -245,7 +245,7 @@ public async Task TestVectorParameterInitializationAsync() await ValidateInsertedDataAsync(conn, null); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestVectorDataReadsAsVarchar() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -302,7 +302,7 @@ public void TestVectorDataReadsAsVarchar() Assert.Throws(() => reader.GetFieldValue(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestVectorDataReadsAsVarcharAsync() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -359,7 +359,7 @@ public async Task TestVectorDataReadsAsVarcharAsync() await Assert.ThrowsAsync(async () => await reader2.GetFieldValueAsync(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestStoredProcParamsForVectorAsVarchar() { // Test data @@ -405,7 +405,7 @@ public void TestStoredProcParamsForVectorAsVarchar() Assert.True(outputParam.Value == DBNull.Value); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestStoredProcParamsForVectorAsVarcharAsync() { // Test data @@ -456,7 +456,7 @@ public async Task TestStoredProcParamsForVectorAsVarcharAsync() Assert.True(outputParam.Value == DBNull.Value); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestSqlBulkCopyForVectorAsVarchar() { //Setup source with test data and create destination table for bulkcopy. @@ -521,7 +521,7 @@ public void TestSqlBulkCopyForVectorAsVarchar() Assert.True(verifyReader.IsDBNull(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestSqlBulkCopyForVectorAsVarcharAsync() { //Setup source with test data and create destination table for bulkcopy. @@ -586,7 +586,7 @@ public async Task TestSqlBulkCopyForVectorAsVarcharAsync() Assert.True(await verifyReader.IsDBNullAsync(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestInsertVectorsAsVarcharWithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs index 1b712ceaf5..27ceb12711 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs @@ -42,7 +42,7 @@ public class Config public string KerberosDomainUser = null; public bool IsManagedInstance = false; public string AliasName = null; - public bool IsJsonSupported = false; + public static Config Load(string configPath = @"config.json") { try diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json index a5f6cd996e..5ef2e9c99e 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json @@ -35,6 +35,5 @@ "ManagedIdentitySupported": true, "UserManagedIdentityClientId": "", "PowerShellPath": "", - "AliasName": "", - "IsJsonSupported": false + "AliasName": "" }