gpt4 book ai didi

ravendb - 在 Raven DB 中生成测试数据

转载 作者:行者123 更新时间:2023-12-03 01:53:35 25 4
gpt4 key购买 nike

我正在寻找一种在 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);
}
}

编辑: Raven-overflow真的很有帮助。感谢您指出正确的地方。

最佳答案

尝试查看RavenOverflow 。在那里,我有一个 FakeData具有虚假数据的项目(硬编码和随机生成)。然后可以在我的 Tests 中使用它项目或 Main Website :)

这是一些示例代码...

if (isDataToBeSeeded)
{
HelperUtilities.CreateSeedData(documentStore);
}

...

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 let's 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();
}
}

...

public static ICollection<Question> CreateFakeQuestions(IList<string> userIds, int numberOfFakeQuestions)
{
.... you get the idea .....
}

关于ravendb - 在 Raven DB 中生成测试数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11093561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com