相关疑难解决方法(0)

RavenDb:强制索引等到单元测试时不会陈旧

使用RavenDb进行单元测试时,通常会检索或以其他方式处理新添加的数据.这可能导致"陈旧索引"例外,例如

Bulk operation cancelled because the index is stale and allowStale is false
Run Code Online (Sandbox Code Playgroud)

根据一些答案

强制数据库(IDocumentStore实例)在处理查询或批处理操作之前等待其索引未过时的方法是DefaultQueryingConsistency = ConsistencyOptions.QueryYourWritesIDocumentStore初始化期间使用,如下所示:

public class InMemoryRavenSessionProvider : IRavenSessionProvider
{
    private static IDocumentStore documentStore;

    public static IDocumentStore DocumentStore
    {
        get { return (documentStore ?? (documentStore = CreateDocumentStore())); }
    }

    private static IDocumentStore CreateDocumentStore()
    {
        var store = new EmbeddableDocumentStore
        {
            RunInMemory = true,
            Conventions = new DocumentConvention
            {
                DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites,
                IdentityPartsSeparator = "-"
            }
        }; …
Run Code Online (Sandbox Code Playgroud)

unit-testing ravendb

24
推荐指数
2
解决办法
4419
查看次数

标签 统计

ravendb ×1

unit-testing ×1