semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

Add connector unit test base

Open JohnMasen opened this issue 2 years ago • 0 comments

Motivation and Context

  1. Why is this change required? The unit test project for memory connectors lack of a unified test collection. This makes unit tests for memory connectors hard to create.
  2. What problem does it solve? Provides a unified test class base. User can easily create memory connector unit tests for their own connector.
  3. What scenario does it contribute to? Memory connector unit test.
  4. If it fixes an open issue, please link to the issue here. N/A

Description

This PR addes a base class for memory connector unit tests.

There're 2 ways to use this class;

Simple implementation:

public class MyTestClass : MemoryStorageTestBase
{
    protected override Task<IMemoryStore> CreateStoreAsync()
    {
        return Task.FromResult(new MyMemoryStore());
    }
}

Or you can add your own cleanup code like this:

public class MyTestClass : MemoryStorageTestBase
{
    protected override Task<IMemoryStore> CreateStoreAsync()
    {
        //your init code
        myMemoryStore=...
        //return the result
        return Task.FromResult<IMemoryStore>(myMemoryStore);
    }
    protected override Task CloseStoreAsync(IMemoryStore memoryStore)
    {
        //your clean up code here
        memoryStore.Dispose();
    }
}

Contribution Checklist

  • [x] The code builds clean without any errors or warnings
  • [x] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
  • [x] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with dotnet format
  • [x] All unit tests pass, and I have added new tests where possible
  • [x] I didn't break anyone :smile:

JohnMasen avatar May 26 '23 17:05 JohnMasen