Ravendb 在Raven DB中生成测试数据
我正在寻找一种在Raven DB中生成测试数据的首选和可维护的方法。目前,我们的团队确实有办法通过.NET代码实现这一点。举例说明 然而,我正在寻找不同的选择。请分享Ravendb 在Raven DB中生成测试数据,ravendb,seed,test-data,Ravendb,Seed,Test Data,我正在寻找一种在Raven DB中生成测试数据的首选和可维护的方法。目前,我们的团队确实有办法通过.NET代码实现这一点。举例说明 然而,我正在寻找不同的选择。请分享 public void Execute() { using (var documentStore = new DocumentStore { ConnectionStringName = "RavenDb" }) { documentS
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);
}
}
编辑:非常有用。谢谢你指出正确的地方 尝试签出。在那里,我有一个项目,有虚假的数据(硬编码和随机生成)。然后可以在我的项目或中使用:)
下面是一些示例代码
if (isDataToBeSeeded)
{
HelperUtilities.CreateSeedData(documentStore);
}
公共静态void CreateSedData(IDocumentStore documentStore)
{
条件.Requires(documentStore).IsNotNull();
使用(IDocumentSession documentSession=documentStore.OpenSession())
{
//首先,检查以确保我们没有任何数据。
var user=documentSession.Load(1);
如果(用户!=null)
{
//哦!我们有一个用户,所以假设我们确实有一些种子数据。
返回;
}
//我们没有用户,因此假设我们根本没有数据。
//所以,让我们假装一下:)
//用户。
ICollection users=FakeUsers.CreateFakeUsers(50);
StoreFakeEntities(用户、文档会话);
//问题。
ICollection questions=FakeQuestions.CreateFakeQuestions(users.Select(x=>x.Id).ToList());
StoreFakenties(问题、文件会议);
documentSession.SaveChanges();
//确保我们的所有索引都没有过时。
documentStore.waitForStaleIndexeTomplete();
}
}
公共静态ICollection CreateFakeQuestions(IList用户ID,int numberOfFakeQuestions)
{
……你明白了。。。。。
}
希望这有帮助
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();
}
}
public static ICollection<Question> CreateFakeQuestions(IList<string> userIds, int numberOfFakeQuestions)
{
.... u get the idea .....
}