在Raven DB中生成测试数据

EL *_*bov 4 test-data seed ravendb

我正在寻找Raven DB中测试数据生成的首选和可维护方式.目前,我们的团队确实有办法通过.NET代码实现这一目标.提供了示例.

但是,我正在寻找不同的选择.请分享.

public void Execute()
        {
            using (var documentStore = new DocumentStore { ConnectionStringName = "RavenDb" })
            {
                documentStore.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites;

                // Override the default key prefix generation strategy of Pascal case to lower case.
                documentStore.Conventions.FindTypeTagName = type => DocumentConvention.DefaultTypeTagName(type).ToLower();

                documentStore.Initialize();

                InitializeData(documentStore);
            }
        }
Run Code Online (Sandbox Code Playgroud)

编辑: Raven-overflow真的很有帮助.谢谢你指出了正确的地方.

Pur*_*ome 7

尝试查看RavenOverflow.在那里,我有一个假数据的FakeData项目(硬编码和随机生成).然后可以在我的测试项目或主网站中使用它 :)

这是一些示例代码......

if (isDataToBeSeeded)
{
    HelperUtilities.CreateSeedData(documentStore);
}
Run Code Online (Sandbox Code Playgroud)

....

public static void CreateSeedData(IDocumentStore documentStore)
{
    Condition.Requires(documentStore).IsNotNull();

    using (IDocumentSession documentSession = documentStore.OpenSession())
    {
        // First, check to make sure we don't have any data.
        var user = documentSession.Load<User>(1);
        if (user != null)
        {
            // ooOooo! we have a user, so it's assumed we actually have some seeded data.
            return;
        }

        // We have no users, so it's assumed we therefore have no data at all.
        // So lets fake some up :)

        // Users.
        ICollection<User> users = FakeUsers.CreateFakeUsers(50);
        StoreFakeEntities(users, documentSession);

        // Questions.
        ICollection<Question> questions = FakeQuestions.CreateFakeQuestions(users.Select(x => x.Id).ToList());
        StoreFakeEntities(questions, documentSession);

        documentSession.SaveChanges();

        // Make sure all our indexes are not stale.
        documentStore.WaitForStaleIndexesToComplete();
    }
}
Run Code Online (Sandbox Code Playgroud)

....

public static ICollection<Question> CreateFakeQuestions(IList<string> userIds, int numberOfFakeQuestions)
{
.... u get the idea .....
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.