From 926e01d26bc178923a7dc8bd4667520451eae470 Mon Sep 17 00:00:00 2001 From: Laurianti Date: Thu, 19 Nov 2026 23:41:44 +0100 Subject: [PATCH 1/2] SqlServer: make the Azure SQL tests conditional Skip the DiskANN test and the hybrid search tests outside Azure SQL. The hybrid search tests are compiled again. Fixes #20 --- .../SqlServer.ConformanceTests.csproj | 5 -- .../SqlServerHybridSearchTests.cs | 72 +++++++++++++++++++ .../SqlServerIndexKindTests.cs | 6 +- .../SqlServerTestSuiteImplementationTests.cs | 9 +-- .../Support/AzureSqlRequiredAttribute.cs | 16 ++++- 5 files changed, 87 insertions(+), 21 deletions(-) diff --git a/MEVD/test/SqlServer.ConformanceTests/SqlServer.ConformanceTests.csproj b/MEVD/test/SqlServer.ConformanceTests/SqlServer.ConformanceTests.csproj index 09fc18c..c529ebf 100644 --- a/MEVD/test/SqlServer.ConformanceTests/SqlServer.ConformanceTests.csproj +++ b/MEVD/test/SqlServer.ConformanceTests/SqlServer.ConformanceTests.csproj @@ -11,11 +11,6 @@ b7762d10-e29b-4bb1-8b74-b6d69a667dd4 - - - - - diff --git a/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs b/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs index 913a163..f9ddea9 100644 --- a/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs +++ b/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs @@ -8,6 +8,8 @@ namespace SqlServer.ConformanceTests; +// The HybridSearch tests require running against Azure SQL. +// The fixtures do not create their collections elsewhere, and each test is skipped. public class SqlServerHybridSearchTests( SqlServerHybridSearchTests.VectorAndStringFixture vectorAndStringFixture, SqlServerHybridSearchTests.MultiTextFixture multiTextFixture) @@ -15,13 +17,83 @@ public class SqlServerHybridSearchTests( IClassFixture, IClassFixture { + public override async Task HybridSearchAsync() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync(); + } + + public override async Task HybridSearchAsync_with_filter() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync_with_filter(); + } + + public override async Task HybridSearchAsync_with_top() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync_with_top(); + } + + public override async Task HybridSearchAsync_with_Skip() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync_with_Skip(); + } + + public override async Task HybridSearchAsync_with_multiple_keywords_ranks_matched_keywords_higher() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync_with_multiple_keywords_ranks_matched_keywords_higher(); + } + + public override async Task HybridSearchAsync_with_multiple_text_properties() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync_with_multiple_text_properties(); + } + + public override async Task HybridSearchAsync_without_explicitly_specified_property_fails() + { + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); + await base.HybridSearchAsync_without_explicitly_specified_property_fails(); + } + public new class VectorAndStringFixture : HybridSearchTests.VectorAndStringFixture { + private bool _initialized; + public override TestStore TestStore => SqlServerTestStore.Instance; + + public override async ValueTask InitializeAsync() + { + if (await AzureSqlHelper.GetIsAzureSqlAsync()) + { + await base.InitializeAsync(); + this._initialized = true; + } + } + + public override ValueTask DisposeAsync() + => this._initialized ? base.DisposeAsync() : default; } public new class MultiTextFixture : HybridSearchTests.MultiTextFixture { + private bool _initialized; + public override TestStore TestStore => SqlServerTestStore.Instance; + + public override async ValueTask InitializeAsync() + { + if (await AzureSqlHelper.GetIsAzureSqlAsync()) + { + await base.InitializeAsync(); + this._initialized = true; + } + } + + public override ValueTask DisposeAsync() + => this._initialized ? base.DisposeAsync() : default; } } diff --git a/MEVD/test/SqlServer.ConformanceTests/SqlServerIndexKindTests.cs b/MEVD/test/SqlServer.ConformanceTests/SqlServerIndexKindTests.cs index f15111d..66e4ac7 100644 --- a/MEVD/test/SqlServer.ConformanceTests/SqlServerIndexKindTests.cs +++ b/MEVD/test/SqlServer.ConformanceTests/SqlServerIndexKindTests.cs @@ -19,11 +19,7 @@ public class SqlServerIndexKindTests(SqlServerIndexKindTests.Fixture fixture) [Fact] public virtual async Task DiskAnn() { - // This test should be conditional (https://github.com/dotnet/extensions/issues/7605) - if (!await AzureSqlHelper.GetIsAzureSqlAsync()) - { - return; - } + await AzureSqlHelper.SkipUnlessAzureSqlAsync(); const string CollectionName = "IndexKindTests_DiskAnn"; diff --git a/MEVD/test/SqlServer.ConformanceTests/SqlServerTestSuiteImplementationTests.cs b/MEVD/test/SqlServer.ConformanceTests/SqlServerTestSuiteImplementationTests.cs index ff30635..fb2820f 100644 --- a/MEVD/test/SqlServer.ConformanceTests/SqlServerTestSuiteImplementationTests.cs +++ b/MEVD/test/SqlServer.ConformanceTests/SqlServerTestSuiteImplementationTests.cs @@ -5,11 +5,4 @@ namespace SqlServer.ConformanceTests; -public class SqlServerTestSuiteImplementationTests : TestSuiteImplementationTests -{ - protected override ICollection IgnoredTestBases { get; } = - [ - // Hybrid search not supported - typeof(HybridSearchTests<>) - ]; -} +public class SqlServerTestSuiteImplementationTests : TestSuiteImplementationTests; diff --git a/MEVD/test/SqlServer.ConformanceTests/Support/AzureSqlRequiredAttribute.cs b/MEVD/test/SqlServer.ConformanceTests/Support/AzureSqlRequiredAttribute.cs index 7d7b4bc..ad05848 100644 --- a/MEVD/test/SqlServer.ConformanceTests/Support/AzureSqlRequiredAttribute.cs +++ b/MEVD/test/SqlServer.ConformanceTests/Support/AzureSqlRequiredAttribute.cs @@ -13,13 +13,23 @@ internal static class AzureSqlHelper { private static bool? s_isAzureSql; + public static async Task SkipUnlessAzureSqlAsync() + => Assert.SkipUnless( + await GetIsAzureSqlAsync(), + "This test requires Azure SQL Database or SQL database in Microsoft Fabric."); + public static async Task GetIsAzureSqlAsync() { if (s_isAzureSql is null) { - var connectionString = SqlServerTestStore.Instance.ConnectionString; - - using SqlConnection connection = new(connectionString); + // Without a connection string the tests run against the SQL Server testcontainer. + if (!SqlServerTestEnvironment.IsConnectionStringDefined) + { + s_isAzureSql = false; + return false; + } + + using SqlConnection connection = new(SqlServerTestEnvironment.ConnectionString); await connection.OpenAsync(); using var command = connection.CreateCommand(); From f6e5ada0c71ba7c4c3f6a4c75ce3d2607fa17fbb Mon Sep 17 00:00:00 2001 From: Laurianti Date: Fri, 20 Nov 2026 15:32:26 +0100 Subject: [PATCH 2/2] SqlServer: skip the hybrid search tests in InitializeAsync --- .../SqlServerHybridSearchTests.cs | 46 ++----------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs b/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs index f9ddea9..757f3d4 100644 --- a/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs +++ b/MEVD/test/SqlServer.ConformanceTests/SqlServerHybridSearchTests.cs @@ -15,49 +15,13 @@ public class SqlServerHybridSearchTests( SqlServerHybridSearchTests.MultiTextFixture multiTextFixture) : HybridSearchTests(vectorAndStringFixture, multiTextFixture), IClassFixture, - IClassFixture + IClassFixture, + IAsyncLifetime { - public override async Task HybridSearchAsync() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync(); - } - - public override async Task HybridSearchAsync_with_filter() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync_with_filter(); - } + async ValueTask IAsyncLifetime.InitializeAsync() + => await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - public override async Task HybridSearchAsync_with_top() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync_with_top(); - } - - public override async Task HybridSearchAsync_with_Skip() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync_with_Skip(); - } - - public override async Task HybridSearchAsync_with_multiple_keywords_ranks_matched_keywords_higher() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync_with_multiple_keywords_ranks_matched_keywords_higher(); - } - - public override async Task HybridSearchAsync_with_multiple_text_properties() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync_with_multiple_text_properties(); - } - - public override async Task HybridSearchAsync_without_explicitly_specified_property_fails() - { - await AzureSqlHelper.SkipUnlessAzureSqlAsync(); - await base.HybridSearchAsync_without_explicitly_specified_property_fails(); - } + ValueTask IAsyncDisposable.DisposeAsync() => default; public new class VectorAndStringFixture : HybridSearchTests.VectorAndStringFixture {