2012-06-19 2 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 ..... 
} 

희망이 도움이됩니다.

관련 문제