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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:38:15+00:00 2026-05-26T03:38:15+00:00

There is a collection of data in the database on which a integration test

  • 0

There is a collection of data in the database on which a integration test is run. For preventing NHibernate persisting objects modification in the database an EventListener that inherits from DefaultSaveOrUpdateEventListener was implemented.

Then there is a method:

public override void OnSaveOrUpdate(SaveOrUpdateEvent @event)
{
  @event.Session.CancelQuery();
  Trace.TraceWarning("NhibernateSaveUpdateCanceler: Persistence will be ignored.");
}

Unfortunately this does not work as expected. So intended behavior is to catch the moment when changes are written in the database and cancel it somehow though leaving objects as there are so modification on them can be validated.

Thanks.

EDIT

Cannot do this because there are multiple transaction in the tested method so there is contradiction in requirements by persisting changes so that there are available for all transaction from one side and that changes are not persistent in the database from the other.

  • 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-26T03:38:16+00:00Added an answer on May 26, 2026 at 3:38 am

    re-write your integration test with an Integration test fixture base. in the base class create:
    a fixture setup that initializes nhibernate and creates a session factory
    a fixture teardown that closes the session factory
    a test setup that creates a session and transaction
    a test teardown that rolls back the transaction and closes the session.

    like this

    [TestFixture]
    public abstract class TestFixtureBase
    {
        protected ISessionFactory SessionFactory { get; private set; }
        protected ISession Session { get; private set; }
        protected ITransaction Tx { get; private set; }
    
        [TestFixtureSetUp]
        public virtual void SetUp()
        {
            var nh = new NHInit();
    
            nh.Initialize();
    
            SessionFactory = nh.SessionFactory;
        }
    
        [TestFixtureTearDown]
        public virtual void TearDown()
        {
            SessionFactory.Close();
        }
    
    
        [SetUp]
        public void Test_Set_Up()
        {
            Session = SessionFactory.OpenSession();
            Tx = Session.BeginTransaction();
        }
    
        [TearDown]
        public void Test_tear_down()
        {
            Tx.Rollback();
            Tx.Dispose();
            Session.Close();
        }
    }
    

    then write your test.

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

Sidebar

Related Questions

In VB6, there used to be a Collection data type that would allow retrieval
In my application, I have three collection objects which store data. The data which
In the vein of programming questions : suppose there's a collection of objects that
Is there any tricky way to implement a set data structure (a collection of
Is there a collection (BCL or other) that has the following characteristics: Sends event
Folks, is there a collection of gotchas where Numpy differs from python, points that
Is there any open source collection framework, written in ActionScript that would emulate HashMap,
I have a bunch of data that I'm pulling into my application which frankly
In my DAL I have a data access object that retrievs database records to
i have 500 excel sheets which are used for data collection from various organisations

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.