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

  • Home
  • SEARCH
  • 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 538939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:05:03+00:00 2026-05-13T10:05:03+00:00

In a test method (for a Fluent NHibernate mapping, although that’s not really relevant)

  • 0

In a test method (for a Fluent NHibernate mapping, although that’s not really relevant) I have the following code wrapped in a bunch of usings and try/catch blocks:

new PersistenceSpecification<Entry>(session)
    .CheckProperty(e => e.Id, "1")
    .VerifyTheMappings();

I would like to refactor this so that I can pass it to a helper method (where I place the using and try/catch blocks).

My requirements for this to work as I want it to are

  1. session needs to be provided by one of the using statements
  2. Entry should be provided as a generic parameter, so I can test mappings of various objects
  3. It should be possible to replace .CheckProperty(e => e.Id, "1").VerifyTheMappings() with anything that’s called on a PersistenceSpecification<T> when defining the argument (in the test method).

Basically, I’d like to do something like this:

var testAction = new PersistenceSpecification<Entry>(session)
                      .CheckProperty(e => e.Id, "1")
                      .VerifyTheMappings();

HelpTestMethod(testAction)

but with the above requirements satisified.

  • 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-05-13T10:05:03+00:00Added an answer on May 13, 2026 at 10:05 am

    What about something like:

    Action<PersistenceSpecification<Entry>> testAction = pspec => pspec
                    .CheckProperty(e => e.Id, "1")
                    .VerifyTheMappings();
    
    HelpTestMethod<Entry>(testAction);
    
    public void HelpTestMethod<T>(Action<PersistenceSpecification<T>> testAction)
    {
        using(var session = new SessionFactory().CreateSession(...))
        {
            testAction(new PersistenceSpecification<T>( session ));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to test a method I have in my application, but I don't
What is the best way to unit test a method that doesn't return anything?
What is the best way to unit test a method that calls into multiple
I'm new to TDD and xUnit so I want to test my method that
I'm writing a unit test for a method that packs boolean values into a
It is my understanding that I can test that a method call will occur
I need to write a unit test for a method that will print a
How do I write a unit test for a method that use an external
Do you write one test per function/method, with multiple checks in the test, or
It is good practice to use the main method to test a java/.net class?

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.