chore: import upstream snapshot with attribution
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using VectorData.ConformanceTests.Xunit;
|
||||
|
||||
namespace CosmosNoSql.ConformanceTests.Support;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the sqlite_vec extension is properly installed, and skips the test(s) otherwise.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
|
||||
public sealed class CosmosConnectionStringRequiredAttribute : Attribute, ITestCondition
|
||||
{
|
||||
public ValueTask<bool> IsMetAsync() => new(CosmosNoSqlTestEnvironment.IsConnectionStringDefined);
|
||||
|
||||
public string Skip { get; set; } = "The Cosmos connection string hasn't been configured (CosmosNoSql:ConnectionString).";
|
||||
|
||||
public string SkipReason
|
||||
=> this.Skip;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using VectorData.ConformanceTests.Support;
|
||||
|
||||
namespace CosmosNoSql.ConformanceTests.Support;
|
||||
|
||||
public class CosmosNoSqlFixture : VectorStoreFixture
|
||||
{
|
||||
public override TestStore TestStore => CosmosNoSqlTestStore.Instance;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace CosmosNoSql.ConformanceTests.Support;
|
||||
|
||||
#pragma warning disable CA1810 // Initialize all static fields when those fields are declared
|
||||
|
||||
internal static class CosmosNoSqlTestEnvironment
|
||||
{
|
||||
public static readonly string? ConnectionString;
|
||||
|
||||
public static bool IsConnectionStringDefined => ConnectionString is not null;
|
||||
|
||||
static CosmosNoSqlTestEnvironment()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile(path: "testsettings.json", optional: true)
|
||||
.AddJsonFile(path: "testsettings.development.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddUserSecrets<CosmosConnectionStringRequiredAttribute>()
|
||||
.Build();
|
||||
|
||||
ConnectionString = configuration["CosmosNoSql:ConnectionString"];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
#if NET472
|
||||
using System.Net.Http;
|
||||
#endif
|
||||
using System.Text.Json;
|
||||
using Microsoft.Azure.Cosmos;
|
||||
using Microsoft.SemanticKernel.Connectors.CosmosNoSql;
|
||||
using VectorData.ConformanceTests.Support;
|
||||
|
||||
namespace CosmosNoSql.ConformanceTests.Support;
|
||||
|
||||
#pragma warning disable CA1001 // Type owns disposable fields (_connection) but is not disposable
|
||||
#pragma warning disable CA2000 // Dispose objects before losing scope
|
||||
|
||||
internal sealed class CosmosNoSqlTestStore : TestStore
|
||||
{
|
||||
public static CosmosNoSqlTestStore Instance { get; } = new();
|
||||
|
||||
private CosmosClient? _client;
|
||||
private Database? _database;
|
||||
|
||||
public override string DefaultIndexKind => Microsoft.Extensions.VectorData.IndexKind.Flat;
|
||||
|
||||
public CosmosClient Client
|
||||
=> this._client ?? throw new InvalidOperationException("Call InitializeAsync() first");
|
||||
|
||||
public Database Database
|
||||
=> this._database ?? throw new InvalidOperationException("Call InitializeAsync() first");
|
||||
|
||||
public CosmosNoSqlVectorStore GetVectorStore(CosmosNoSqlVectorStoreOptions options)
|
||||
=> new(this.Database, options);
|
||||
|
||||
private CosmosNoSqlTestStore()
|
||||
{
|
||||
}
|
||||
|
||||
#pragma warning disable CA5400 // HttpClient may be created without enabling CheckCertificateRevocationList
|
||||
protected override async Task StartAsync()
|
||||
{
|
||||
var connectionString = CosmosNoSqlTestEnvironment.ConnectionString;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
{
|
||||
throw new InvalidOperationException("Connection string is not configured, set the CosmosNoSql:ConnectionString environment variable");
|
||||
}
|
||||
|
||||
var options = new CosmosClientOptions
|
||||
{
|
||||
UseSystemTextJsonSerializerWithOptions = JsonSerializerOptions.Default,
|
||||
ConnectionMode = ConnectionMode.Gateway,
|
||||
HttpClientFactory = () => new HttpClient(new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator })
|
||||
};
|
||||
|
||||
this._client = new CosmosClient(connectionString, options);
|
||||
this._database = this._client.GetDatabase("VectorDataIntegrationTests");
|
||||
await this._client.CreateDatabaseIfNotExistsAsync("VectorDataIntegrationTests");
|
||||
this.DefaultVectorStore = new CosmosNoSqlVectorStore(this._database);
|
||||
}
|
||||
#pragma warning restore CA5400
|
||||
|
||||
protected override Task StopAsync()
|
||||
{
|
||||
this._client?.Dispose();
|
||||
return base.StopAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user