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 8580577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:51:40+00:00 2026-06-11T20:51:40+00:00

I’ve been working on a project where we use a Fluent NHibernate ORM to

  • 0

I’ve been working on a project where we use a Fluent NHibernate ORM to access an SQL Server database and show and manipulate data.

In the initial development phase we’ve been writing unit tests against the actual database; which has been helpful in learning NHibernate, but this is not ideal as the database won’t always have what we need to test and the time to run tests starts to be too long.

So I’m hoping to try to use Mock Objects in the Unit Testing, I have little Mock experience, and right now I can’t always see how to change the functionality to allow me to do this.

Here’s a function I wrote yesterday (re-written to a more ‘abstract’ concept. But basically my code with different class names:

 public static IList<Order> GetAllOrders(long parentCompanyId)
    {
        using (var session = DbSetup.GetSession())
            {
                var idList =
                    (from p in session.Query<ParentCompanyList>() 
                     where p.ParentCompanyId == parentCompanyId 
                     select p.CompanyId)
                     .ToList<long>();

                IQuery q = session.CreateQuery("from Order as o where o.CompanyId in (:ids)");
                q.SetParameterList("ids", idList);

                var results = q.List<Order>();
                return results;
            }
    }

So I have an NHibernate.ISession which connects to the database, I’m running a query to find against a ParentCompanyList (Class fluently mapped to a database table) to fetch a list of CompanyIds for companies that are connected to the parent company, and then use this to fetch all olders from all companies associated with the parent company.

What I’m not sure of whether there is any good way to test this without going to the database.

Can I create mock objects that allow me to test this? How would I set that up?
Do I need to create a mock ISession which will return the appropriate List and IOrder results? At that point it seems I’m not actually testing anything of any value if I give back what I’m actually asking for…

Am I just misunderstanding something basic here?

  • 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-11T20:51:40+00:00Added an answer on June 11, 2026 at 8:51 pm

    When testing interaction with a database (queries, inserts ) it is best to use a database because the query translation, constraints and the like can only be tested that way. To improve performance and have test isolation an inmemory database is often used

    a blogpost from one of NHibernates contributers describing unit testing with NHibernate and sqlite

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
I want to construct a data frame in an Rcpp function, but when I
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.