Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7840411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:46:26+00:00 2026-06-02T15:46:26+00:00

I am using NancyFX + RavenDB. I am currently trying to implement the Ayende

  • 0

I am using NancyFX + RavenDB. I am currently trying to implement the Ayende recommended Denormalized Reference technique to build Domain references out from an AggregateRoot. If you read that link you can see that the trick is to load the parent instance and then pre-fetch the referenced instances using RavenDB’s ‘Include’ statement.

I have done all this and it appears to work but I am struggling to determine, via a unit-test, whether the referenced instances really are pre-fetched. Here is a snippet from my unit-test to illustrate:

[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);
}

The unit test above checks that I can load my instances from my fake db (its an in-memory, embedded instance of RavenDB) but it does not check whether they are pre-fetched.

I thought that perhaps I could use the RavenProfiler. Maybe this would count the number of db requests which I could then assert against (the unit-test above would fail if requests > 1 for example).

To make this work I had to install the MVCIntegration package to my unit-test project (ouch)

PM> install-package RavenDB.Client.MvcIntegration

I also had to add a reference to System.Web, which made me shiver. I don’t think this is going to work.

I then added the appropriate initialisation to my Fake db provider, like this:

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

Finally I tried to retrieve a value of some sort from the RavenProfiler at the end of my unit-test:

var requests = RavenProfiler.CurrentRequestSessions();

This did not work! It failed inside the RavenProfiler because the HttpContext was null – which was what my premonition about the System.Web must have been about. Oh well.

So, how do I count the number of requests made to my RavenDB instance? And can this be done without requiring MVC or System.Web so it can easily be bolted into unit-tests?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:46:27+00:00Added an answer on June 2, 2026 at 3:46 pm

    You can use the following code for this:

    session.Advanced.NumberOfRequests
    

    The RavenDB profiler won’t run against an embedded document store.

    Also you can take a look at the unit tests in the Raven source, they test this scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using the arcsynthesis opengl tutorial and I'm trying to build the unofficial sdk that
Using Google Maps InfoBox - http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html Currently the map will scroll - pan control
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable
Using jQuery, one can easily find out whether a particular element is visible using
I am brand new to NancyFX and currently enthralled by its low-ceremony approach to
Using jQuery UI Resizable I'm trying to prevent resizing based on various rules. The
Using Javascript I'm trying to loop through a 3 level nested array with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.