2012-06-19 82 views
4

我正在尋找Raven DB中測試數據生成的首選和可維護方式。目前,我們的團隊確實有辦法通過.NET代碼來完成它。提供示例。在Raven DB中生成測試數據

但是,我正在尋找不同的選項。請分享。

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是真的很有幫助。感謝您指出正確的地方。

回答

7

試試看看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 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 ..... 
} 

希望這會有所幫助。