如何在我的单元测试项目中使用没有 .NET 5 的 RavenDB.RavenTestDriver 5+?

How to use RavenDB.RavenTestDriver 5+ without .NET 5 in my unit tests project?

当 运行 RavenDB 测试驱动程序 5.0+ 时出现异常,需要 ASP.NET Core 5.0.0。

Sstem.InvalidOperationException: Unable to start the RavenDB Server
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '5.0.0' was not found.
  - The following frameworks were found:
      2.1.23 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      3.1.9 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

如何在不将我的项目迁移到 .NET 5.0 的情况下使用它?

是的,可以在没有 ASP.NET/.NET 5 的情况下使用 RavenDB 5。

您需要在配置时明确指定版本,或者直接设置为空:

var ravenServerOptions = new TestServerOptions()
{
    FrameworkVersion = null
};

ConfigureServer(ravenServerOptions);

例如使用 NUnit:

[TestFixture]
public class FooTest : RavenTestDriver
{
    private IDocumentStore store;

    [OneTimeSetUp]
    public void OneTimeSetUp()
    {
        var ravenServerOptions = new TestServerOptions()
        {
            FrameworkVersion = null
        };

        ConfigureServer(ravenServerOptions);

        store = GetDocumentStore();
    }

    [OneTimeTearDown]
    public void OneTimeTearDown()
    {
        store.Dispose();
    }

    [Test]
    public void Test()
    {

    }
}