NancyFX + RavenDB를 사용 중입니다. 나는 현재 Ayende가 Denormalized Reference 기술을 사용하여 AggregateRoot에서 도메인 참조를 빌드하도록 구현하려고합니다. 이 링크를 읽으면 트릭이 부모 인스턴스를로드 한 다음 RavenDB의 'Include'문을 사용하여 참조 된 인스턴스를 미리 가져 오는 것임을 알 수 있습니다.RavenDB : UnitTests에서 RavenProfiler를 사용하려면 어떻게해야합니까?
이 모든 작업을 수행했는데 작동하는 것으로 보입니다. 단원 테스트를 통해 참조 된 인스턴스가 실제로 pre-fetched되었는지 여부를 확인하는 데 어려움을 겪고 있습니다.
이[Fact]
public void Should_preload_the_mentor_mentee_references_to_improve_performance()
{
//Given
var db = Fake.Db();
var mentor = Fake.Mentor(db);
var mentee = Fake.Mentee(db);
var relationship = Fake.Relationship(mentor, mentee, db);
//When
relationship = db
.Include("Mentor.Id")
.Include("Mentee.Id")
.Load<Relationship>(relationship.Id);
mentor = db.Load<User>(relationship.Mentor.Id);
mentee = db.Load<User>(relationship.Mentee.Id);
//Then
relationship.ShouldNotBe(null);
mentor.ShouldNotBe(null);
mentee.ShouldNotBe(null);
}
내 가짜 DB에서 내 인스턴스를로드 할 수 있습니다 검사 위의 단위 테스트는 (그 인 - 메모리, RavenDB의 예를 포함)하지만 그렇지 않은 : 여기 내 단위 테스트에서 미리보기가 설명하는 것입니다 미리 가져 왔는지 확인하십시오.
아마 RavenProfiler를 사용할 수 있다고 생각했습니다. 아마도 이것은 내가 주장 할 수있는 db 요청의 수를 계산할 것입니다 (예를 들어 요청> 1 일 경우 위의 단위 테스트가 실패합니다).
내가 나를 떨 만들어 내 단위 테스트 프로젝트 (아야)PM> install-package RavenDB.Client.MvcIntegration
나는 또한 경우 System.Web 참조를 추가했다,에 MVCIntegration 패키지를 설치했다이 일을합니다. 나는 이것이 효과가 있다고 생각하지 않는다.
public class InMemoryRavenSessionProvider : IRavenSessionProvider
{
private static IDocumentStore documentStore;
public static IDocumentStore DocumentStore { get { return (documentStore ?? (documentStore = CreateDocumentStore())); } }
private static IDocumentStore CreateDocumentStore()
{
var store = new EmbeddableDocumentStore { RunInMemory = true};
store.Initialize();
store.Conventions.IdentityPartsSeparator = "-";
RavenProfiler.InitializeFor(store); //<-- Here is the Profiler line
return store;
}
public IDocumentSession GetSession()
{
return DocumentStore.OpenSession();
}
}
마지막으로 내 단위 테스트의 끝에서 RavenProfiler에서 어떤 종류의 값을 검색하려고 :
나는 다음과 같이 내 가짜 DB 공급자에 적절한 초기화를 추가
var requests = RavenProfiler.CurrentRequestSessions();
이것은 작동하지 않았습니다. HttpContext가 null 이었기 때문에 RavenProfiler에서 실패했습니다. System.Web에 대한 예고가 있었음에 틀림 없습니다. 오 잘.
그래서 RavenDB 인스턴스에 대한 요청 수를 어떻게 계산합니까? MVC 나 System.Web을 필요로하지 않고도이 작업을 수행 할 수 있습니다. 그러면 쉽게 단위 테스트를 수행 할 수 있습니다.
감사
와우! 굉장 :) 정말 kewl 닌자 비밀 트릭이야! –
완벽. 그것은 치료를했습니다. 감사. – biofractal
최종 참고 사항 :이 기술을 사용하는 경우 db에 대한 각 호출이 요청으로 계산되므로 위의 예에서 실제 요청 수는 4가됩니다. 처음 세 요청은 다양한 가짜 개체를 저장하기위한 것이고 최종, 단일 요청은 세 인스턴스를 한 번에 모두 가져 오는 페치입니다. 좋은 소식은, RavenDB의 pre-fetching이 잘 작동한다는 것입니다 :-) – biofractal