11// Copyright (c) Microsoft. All rights reserved.
22
3- using System ;
4- using System . Collections . Generic ;
5- using System . Linq ;
6- using System . Threading . Tasks ;
73using Microsoft . Data . SqlClient ;
84using Microsoft . Extensions . Configuration ;
95using Microsoft . SemanticKernel . Connectors . SqlServer ;
106using Microsoft . SemanticKernel . Memory ;
7+ using SqlServerIntegrationTests ;
118using Xunit ;
129
1310namespace SemanticKernel . IntegrationTests . Connectors . SqlServer ;
1411
1512/// <summary>
1613/// Unit tests for <see cref="SqlServerMemoryStore"/> class.
1714/// </summary>
18- public class SqlServerMemoryStoreTests : IAsyncLifetime
15+ public class SqlServerMemoryStoreTests ( SqlServerContainerFixture fixture ) : IClassFixture < SqlServerContainerFixture > , IAsyncLifetime
1916{
20- private const string ? SkipReason = "Configure SQL Server or Azure SQL connection string and then set this to 'null'." ;
21- //private const string? SkipReason = null;
2217 private const string SchemaName = "sk_it" ;
2318 private const string DefaultCollectionName = "test" ;
2419 private const int TestEmbeddingDimensionsCount = 5 ;
@@ -27,16 +22,13 @@ public class SqlServerMemoryStoreTests : IAsyncLifetime
2722
2823 private SqlServerMemoryStore Store { get ; set ; } = null ! ;
2924
25+ private SqlServerContainerFixture Fixture { get ; } = fixture ;
26+
3027 public async Task InitializeAsync ( )
3128 {
32- var configuration = new ConfigurationBuilder ( )
33- . AddJsonFile ( path : "testsettings.json" , optional : false , reloadOnChange : true )
34- . AddJsonFile ( path : "testsettings.development.json" , optional : true , reloadOnChange : true )
35- . AddEnvironmentVariables ( )
36- . AddUserSecrets < SqlServerMemoryStore > ( )
37- . Build ( ) ;
29+ await this . Fixture . InitializeAsync ( ) ;
3830
39- var connectionString = configuration [ "SqlServer:ConnectionString" ] ;
31+ string connectionString = this . Fixture . GetConnectionString ( ) ;
4032
4133 if ( string . IsNullOrWhiteSpace ( connectionString ) )
4234 {
@@ -54,9 +46,11 @@ public async Task InitializeAsync()
5446 public async Task DisposeAsync ( )
5547 {
5648 await this . CleanupDatabaseAsync ( ) ;
49+
50+ await this . Fixture . DisposeAsync ( ) ;
5751 }
5852
59- [ Fact ( Skip = SkipReason ) ]
53+ [ Fact ]
6054 public async Task CreateCollectionAsync ( )
6155 {
6256 Assert . False ( await this . Store . DoesCollectionExistAsync ( DefaultCollectionName ) ) ;
@@ -65,15 +59,15 @@ public async Task CreateCollectionAsync()
6559 Assert . True ( await this . Store . DoesCollectionExistAsync ( DefaultCollectionName ) ) ;
6660 }
6761
68- [ Fact ( Skip = SkipReason ) ]
62+ [ Fact ]
6963 public async Task DropCollectionAsync ( )
7064 {
7165 await this . Store . CreateCollectionAsync ( DefaultCollectionName ) ;
7266 await this . Store . DeleteCollectionAsync ( DefaultCollectionName ) ;
7367 Assert . False ( await this . Store . DoesCollectionExistAsync ( DefaultCollectionName ) ) ;
7468 }
7569
76- [ Fact ( Skip = SkipReason ) ]
70+ [ Fact ]
7771 public async Task GetCollectionsAsync ( )
7872 {
7973 await this . Store . CreateCollectionAsync ( "collection1" ) ;
@@ -84,7 +78,7 @@ public async Task GetCollectionsAsync()
8478 Assert . Contains ( "collection2" , collections ) ;
8579 }
8680
87- [ Fact ( Skip = SkipReason ) ]
81+ [ Fact ]
8882 public async Task UpsertAsync ( )
8983 {
9084 await this . Store . CreateCollectionAsync ( DefaultCollectionName ) ;
@@ -104,7 +98,7 @@ public async Task UpsertAsync()
10498 Assert . Equal ( "Some id" , id ) ;
10599 }
106100
107- [ Theory ( Skip = SkipReason ) ]
101+ [ Theory ]
108102 [ InlineData ( true ) ]
109103 [ InlineData ( false ) ]
110104 public async Task GetAsync ( bool withEmbeddings )
@@ -128,7 +122,7 @@ public async Task GetAsync(bool withEmbeddings)
128122 record . Embedding . ToArray ( ) ) ;
129123 }
130124
131- [ Fact ( Skip = SkipReason ) ]
125+ [ Fact ]
132126 public async Task UpsertBatchAsync ( )
133127 {
134128 await this . Store . CreateCollectionAsync ( DefaultCollectionName ) ;
@@ -139,7 +133,7 @@ public async Task UpsertBatchAsync()
139133 id => Assert . Equal ( "Some other id" , id ) ) ;
140134 }
141135
142- [ Theory ( Skip = SkipReason ) ]
136+ [ Theory ]
143137 [ InlineData ( true ) ]
144138 [ InlineData ( false ) ]
145139 public async Task GetBatchAsync ( bool withEmbeddings )
@@ -180,7 +174,7 @@ public async Task GetBatchAsync(bool withEmbeddings)
180174 } ) ;
181175 }
182176
183- [ Fact ( Skip = SkipReason ) ]
177+ [ Fact ]
184178 public async Task RemoveAsync ( )
185179 {
186180 await this . Store . CreateCollectionAsync ( DefaultCollectionName ) ;
@@ -191,7 +185,7 @@ public async Task RemoveAsync()
191185 Assert . Null ( await this . Store . GetAsync ( DefaultCollectionName , "Some id" ) ) ;
192186 }
193187
194- [ Fact ( Skip = SkipReason ) ]
188+ [ Fact ]
195189 public async Task RemoveBatchAsync ( )
196190 {
197191 await this . Store . CreateCollectionAsync ( DefaultCollectionName ) ;
@@ -204,7 +198,7 @@ public async Task RemoveBatchAsync()
204198 Assert . Null ( await this . Store . GetAsync ( DefaultCollectionName , "Some other id" ) ) ;
205199 }
206200
207- [ Theory ( Skip = SkipReason ) ]
201+ [ Theory ]
208202 [ InlineData ( true ) ]
209203 [ InlineData ( false ) ]
210204 public async Task GetNearestMatchesAsync ( bool withEmbeddings )
@@ -248,7 +242,7 @@ public async Task GetNearestMatchesAsync(bool withEmbeddings)
248242 } ) ;
249243 }
250244
251- [ Fact ( Skip = SkipReason ) ]
245+ [ Fact ]
252246 public async Task GetNearestMatchesWithMinRelevanceScoreAsync ( )
253247 {
254248 await this . Store . CreateCollectionAsync ( DefaultCollectionName ) ;
@@ -265,7 +259,7 @@ public async Task GetNearestMatchesWithMinRelevanceScoreAsync()
265259 Assert . DoesNotContain ( firstId , results . Select ( r => r . Record . Metadata . Id ) ) ;
266260 }
267261
268- [ Theory ( Skip = SkipReason ) ]
262+ [ Theory ]
269263 [ InlineData ( true ) ]
270264 [ InlineData ( false ) ]
271265 public async Task GetNearestMatchAsync ( bool withEmbeddings )
0 commit comments