diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs index ea7bab78bf..cf04ff8636 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs @@ -58,7 +58,7 @@ private SqlVector(int length) /// public static SqlVector CreateNull(int length) => new(length); - /// + /// public SqlVector(ReadOnlyMemory memory) { (_elementType, _elementSize) = GetTypeFieldsOrThrow(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index b82b1fec0e..9cf3d3a6a0 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -92,12 +92,6 @@ public static class DataTestUtility //SQL Server EngineEdition private static string s_sqlServerEngineEdition; - // JSON Column type - public static readonly bool IsJsonSupported = false; - - // VECTOR column type - public static readonly bool IsVectorSupported = false; - // 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 @@ -179,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; @@ -456,6 +449,11 @@ public static bool IsNotAzureServer() return !AreConnStringsSetup() || !Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); } + public static bool IsAzureServer() + { + return AreConnStringsSetup() && Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); + } + public static bool IsNotNamedInstance() { return !AreConnStringsSetup() || !new SqlConnectionStringBuilder(TCPConnectionString).DataSource.Contains(@"\"); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj index 5464b5c504..ac6a4bb766 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj @@ -184,6 +184,9 @@ + + + @@ -212,6 +215,9 @@ + + + @@ -293,11 +299,6 @@ - - - - - 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..45a2c59a35 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs @@ -14,11 +14,11 @@ 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 +26,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 +87,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 +125,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 +159,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 +171,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 +265,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 +289,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..efcef3e674 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs @@ -22,8 +22,8 @@ public class JsonRecord 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) { @@ -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(); 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..9b3c37da4f 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs @@ -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 d2d8c52716..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,8 +147,8 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestSqlVectorFloat32ParameterInsertionAndReads( int pattern, object value, @@ -213,8 +213,8 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( int pattern, object value, @@ -247,8 +247,8 @@ public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( await ValidateInsertedDataAsync(conn, expectedValues, expectedLength); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestStoredProcParamsForVectorFloat32( int pattern, object value, @@ -304,8 +304,8 @@ public void TestStoredProcParamsForVectorFloat32( Assert.Throws(() => command.ExecuteNonQuery()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestStoredProcParamsForVectorFloat32Async( int pattern, object value, @@ -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 new file mode 100644 index 0000000000..a805cb4dc9 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs @@ -0,0 +1,92 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using Microsoft.Data.SqlTypes; +using Xunit; + +namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.VectorTest +{ + public sealed class VectorAPIValidationTest + { + // We need these testcases to validate ref assembly for vector APIs + // Unit tests are covered under SqlVectorTest.cs + [Fact] + 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 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) { } + 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); + } + + [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); + } + + [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"); + } + } +} 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..bf47188b34 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": "" }