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 CosmosMongoDB.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(CosmosMongoTestEnvironment.IsConnectionStringDefined);
|
||||
|
||||
public string Skip { get; set; } = "The Cosmos connection string hasn't been configured (CosmosMongo:ConnectionString).";
|
||||
|
||||
public string SkipReason
|
||||
=> this.Skip;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using VectorData.ConformanceTests.Support;
|
||||
|
||||
namespace CosmosMongoDB.ConformanceTests.Support;
|
||||
|
||||
public class CosmosMongoFixture : VectorStoreFixture
|
||||
{
|
||||
public override TestStore TestStore => CosmosMongoTestStore.Instance;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace CosmosMongoDB.ConformanceTests.Support;
|
||||
|
||||
#pragma warning disable CA1810 // Initialize all static fields when those fields are declared
|
||||
|
||||
public static class CosmosMongoTestEnvironment
|
||||
{
|
||||
public static readonly string? ConnectionString;
|
||||
|
||||
public static bool IsConnectionStringDefined => ConnectionString is not null;
|
||||
|
||||
static CosmosMongoTestEnvironment()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile(path: "testsettings.json", optional: true)
|
||||
.AddJsonFile(path: "testsettings.development.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddUserSecrets<CosmosConnectionStringRequiredAttribute>()
|
||||
.Build();
|
||||
|
||||
ConnectionString = configuration["CosmosMongo:ConnectionString"];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using Microsoft.SemanticKernel.Connectors.CosmosMongoDB;
|
||||
using MongoDB.Driver;
|
||||
using VectorData.ConformanceTests.Support;
|
||||
|
||||
namespace CosmosMongoDB.ConformanceTests.Support;
|
||||
|
||||
#pragma warning disable CA1001
|
||||
public sealed class CosmosMongoTestStore : TestStore
|
||||
#pragma warning restore CA1001
|
||||
{
|
||||
public static CosmosMongoTestStore Instance { get; } = new();
|
||||
|
||||
private MongoClient? _client;
|
||||
private IMongoDatabase? _database;
|
||||
|
||||
public MongoClient Client => this._client ?? throw new InvalidOperationException("Not initialized");
|
||||
public IMongoDatabase Database => this._database ?? throw new InvalidOperationException("Not initialized");
|
||||
|
||||
public override string DefaultIndexKind => Microsoft.Extensions.VectorData.IndexKind.IvfFlat;
|
||||
|
||||
public override string DefaultDistanceFunction => Microsoft.Extensions.VectorData.DistanceFunction.CosineDistance;
|
||||
|
||||
public CosmosMongoVectorStore GetVectorStore(CosmosMongoVectorStoreOptions options)
|
||||
=> new(this.Database, options);
|
||||
|
||||
private CosmosMongoTestStore()
|
||||
{
|
||||
}
|
||||
|
||||
protected override Task StartAsync()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(CosmosMongoTestEnvironment.ConnectionString))
|
||||
{
|
||||
throw new InvalidOperationException("Connection string is not configured, set the CosmosMongo:ConnectionString environment variable");
|
||||
}
|
||||
|
||||
this._client = new MongoClient(CosmosMongoTestEnvironment.ConnectionString);
|
||||
this._database = this._client.GetDatabase("VectorSearchTests");
|
||||
this.DefaultVectorStore = new CosmosMongoVectorStore(this._database);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user