Raven.Client.Exceptions.Database.DatabaseDoesNotExistException: 'Database '*****'不存在
Raven.Client.Exceptions.Database.DatabaseDoesNotExistException: 'Database '*****' does not exist
我正在使用 RavenTestDriver
进行 .net 核心单元测试。
这是我在单元测试解决方案中对 RavenTestDriver
的配置:
public class TestHostBuilder : RavenTestDriver, IAsyncLifetime
{
public async Task InitializeAsync()
{
ConfigureServer(new TestServerOptions
{
CommandLineArgs = new System.Collections.Generic.List<string> { "--RunInMemory=true", },
FrameworkVersion = null,
});
var hostBuilder = easy.api.Program.CreateHostBuilder(new string[0])
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder.UseTestServer();
})
.ConfigureServices(services =>
{
services.AddScoped<ICurrentUserService, InitRequest>();
services.AddRavenDbAsyncSession(GetDocumentStore());
services.AddScoped<IAsyncDocumentSession>((c) =>
{
return GetDocumentStore().OpenAsyncSession(new SessionOptions()
{
Database="test-server"
});
});
});
var host = hostBuilder.Start();
}
}
但是当我调用我的存储库来获取对象时,我得到了这个错误:
Database 'test-server' does not exist.'
at Raven.Client.Exceptions.Database.DatabaseDoesNotExistException.Throw(String databaseName) in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Exceptions\Database\DatabaseDoesNotExistException.cs:line 35
at Raven.Client.Http.RequestExecutor.<ExecuteAsync>d__114`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 883
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Raven.Client.Http.RequestExecutor.<ExecuteAsync>d__114`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 900
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.<UpdateTopologyAsync>d__101.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 455
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Raven.Client.Http.RequestExecutor.<FirstTopologyUpdate>d__109.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 678
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.<WaitForTopologyUpdate>d__107.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 613
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.<UnlikelyExecuteAsync>d__106`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 583
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Documents.Session.AsyncDocumentSession.<LoadAsync>d__51`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Documents\Session\AsyncDocumentSession.Load.cs:line 30
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at infrastructure.Persistence.RavenDb.RavenRepository`1.<GetByIdAsync>d__6.MoveNext() in D:\gitProjects\Orbis\infrastructure\Persistence\RavenDb\RavenRepository.cs:line 83
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at infrastructure.ApplicationCache.CacheableRepository`1.<GetAsync>d__8.MoveNext() in D:\gitProjects\Orbis\infrastructure\ApplicationCache\CacheableRepository.cs:line 48
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at easy.api.Application.Setting.Queries.GetClientAppSettingQueryHandler.<Handle>d__4.MoveNext() in D:\gitProjects\**\***\Application\Setting\Queries\GetClientAppSettingQuery.cs:line 35
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at api.common.Behaviors.UnhandledExceptionBehaviour`2.<Handle>d__2.MoveNext() in D:\gitProjects\**\api.common\Behaviors\UnhandledExceptionBehaviour.cs:line 22
调用前需要先创建数据库OpenAsyncSession
https://ravendb.net/docs/article-page/5.3/csharp/client-api/operations/server-wide/create-database#example
我正在使用 RavenTestDriver
进行 .net 核心单元测试。
这是我在单元测试解决方案中对 RavenTestDriver
的配置:
public class TestHostBuilder : RavenTestDriver, IAsyncLifetime
{
public async Task InitializeAsync()
{
ConfigureServer(new TestServerOptions
{
CommandLineArgs = new System.Collections.Generic.List<string> { "--RunInMemory=true", },
FrameworkVersion = null,
});
var hostBuilder = easy.api.Program.CreateHostBuilder(new string[0])
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder.UseTestServer();
})
.ConfigureServices(services =>
{
services.AddScoped<ICurrentUserService, InitRequest>();
services.AddRavenDbAsyncSession(GetDocumentStore());
services.AddScoped<IAsyncDocumentSession>((c) =>
{
return GetDocumentStore().OpenAsyncSession(new SessionOptions()
{
Database="test-server"
});
});
});
var host = hostBuilder.Start();
}
}
但是当我调用我的存储库来获取对象时,我得到了这个错误:
Database 'test-server' does not exist.'
at Raven.Client.Exceptions.Database.DatabaseDoesNotExistException.Throw(String databaseName) in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Exceptions\Database\DatabaseDoesNotExistException.cs:line 35
at Raven.Client.Http.RequestExecutor.<ExecuteAsync>d__114`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 883
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Raven.Client.Http.RequestExecutor.<ExecuteAsync>d__114`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 900
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.<UpdateTopologyAsync>d__101.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 455
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Raven.Client.Http.RequestExecutor.<FirstTopologyUpdate>d__109.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 678
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.<WaitForTopologyUpdate>d__107.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 613
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Http.RequestExecutor.<UnlikelyExecuteAsync>d__106`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Http\RequestExecutor.cs:line 583
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Raven.Client.Documents.Session.AsyncDocumentSession.<LoadAsync>d__51`1.MoveNext() in C:\Builds\RavenDB-Stable-5.3009\src\Raven.Client\Documents\Session\AsyncDocumentSession.Load.cs:line 30
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at infrastructure.Persistence.RavenDb.RavenRepository`1.<GetByIdAsync>d__6.MoveNext() in D:\gitProjects\Orbis\infrastructure\Persistence\RavenDb\RavenRepository.cs:line 83
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at infrastructure.ApplicationCache.CacheableRepository`1.<GetAsync>d__8.MoveNext() in D:\gitProjects\Orbis\infrastructure\ApplicationCache\CacheableRepository.cs:line 48
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at easy.api.Application.Setting.Queries.GetClientAppSettingQueryHandler.<Handle>d__4.MoveNext() in D:\gitProjects\**\***\Application\Setting\Queries\GetClientAppSettingQuery.cs:line 35
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at api.common.Behaviors.UnhandledExceptionBehaviour`2.<Handle>d__2.MoveNext() in D:\gitProjects\**\api.common\Behaviors\UnhandledExceptionBehaviour.cs:line 22
调用前需要先创建数据库OpenAsyncSession
https://ravendb.net/docs/article-page/5.3/csharp/client-api/operations/server-wide/create-database#example