// Copyright (c) Microsoft. All rights reserved.
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.InMemory;
using Xunit;
namespace SemanticKernel.Connectors.InMemory.UnitTests;
///
/// Contains tests for the class.
///
public class InMemoryServiceCollectionExtensionsTests
{
private readonly IServiceCollection _serviceCollection;
public InMemoryServiceCollectionExtensionsTests()
{
this._serviceCollection = new ServiceCollection();
}
[Fact]
public void AddVectorStoreRegistersClass()
{
// Act.
this._serviceCollection.AddInMemoryVectorStore();
// Assert.
var serviceProvider = this._serviceCollection.BuildServiceProvider();
var vectorStore = serviceProvider.GetRequiredService();
Assert.NotNull(vectorStore);
Assert.IsType(vectorStore);
}
[Fact]
public void AddVectorStoreRecordCollectionRegistersClass()
{
// Act.
this._serviceCollection.AddInMemoryVectorStoreRecordCollection("testcollection");
// Assert.
this.AssertVectorStoreRecordCollectionCreated();
}
private void AssertVectorStoreRecordCollectionCreated()
{
var serviceProvider = this._serviceCollection.BuildServiceProvider();
var collection = serviceProvider.GetRequiredService>();
Assert.NotNull(collection);
Assert.IsType>(collection);
var vectorizedSearch = serviceProvider.GetRequiredService>();
Assert.NotNull(vectorizedSearch);
Assert.IsType>(vectorizedSearch);
}
#pragma warning disable CA1812 // Avoid uninstantiated internal classes
private sealed class TestRecord
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
{
[VectorStoreKey]
public string Id { get; set; } = string.Empty;
[VectorStoreVector(4)]
public ReadOnlyMemory Vector { get; set; }
}
}