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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:00:33+00:00 2026-06-15T00:00:33+00:00

Given that most real world applications have fairly complicated relationships between entities, is there

  • 0

Given that most real world applications have fairly complicated relationships between entities, is there much value in testing individual class mappings? It seems that to be truly valuable, NHibernate tests should revolve around retrieving, persisting and deleting entire object graphs, starting at the aggregate root level (i.e. Customer–>Order–>OrderDetails). But if I go down that road, it seems I would have to test CRUD operations at every conceivable level in the object tree to validate that the “whole” works as expected; leading to an explosion of tests:

  • Delete a Customer
  • Delete an Order
  • Delete an OrderItem
  • Insert a Customer
  • Insert an Order
  • Insert an OrderItem

So, unless I’m missing something, which I very likely am, my choices are:

  1. Write one fixture suite per class/mapping
    • Pros: Simpler to write CRUD operations
    • Cons: Diminished test value, as they provide no assurance that entire aggregate roots
      are being persisted correctly
  2. Write one fixture suite per object graph
    • Cons: Tests harder to write/explosion of test scenarios
    • Pros: Higher value as tests since they test persistence from the application’s perspective (i.e. testing mutations against the unified/integrated object graph)

If at all relevant, I’m using the NHibernate.Mapping.ByCode ConventionModelMapper to generate mappings using conventions.

  • 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-15T00:00:35+00:00Added an answer on June 15, 2026 at 12:00 am

    Yes, when testing that my mappings are working as expected, I test at the class level and test each of that individual classes relationships.

    For instance, if I have a Customer object which has a list of Order objects, I would write integration tests for my Customer object to ensure that I can do all of the CRUD operations on that object. I would then write tests for all of the relationships that the Customer object has such as having a list of Orders, Addresses, etc. Those tests would cover things such as cascading inserts/updates/deletes and the ability to eagerly fetch those child collections in a query.

    So although I’m testing at at the class level, because I’m testing all of the relationships for each class, I am technically testing the entire object graph as long as I continue this testing behavior in each of my tests for each of my mapped classes.

    Update ( Adding brief example ):

    public class Customer
    {
        public int CustomerId { get; set; }
        public string CompanyName { get; set; }
        public IList<Address> Addresses { get; set; }
        public IList<Order> Orders { get; set; }
    }
    
    public class Address
    {
        public int AddressId { get; set; }
    }
    
    public class Order
    {
        public int OrderId { get; set; }
        public string Status { get; set; }
        public IList<OrderDetail> OrderDetails { get; set; }
    }
    
    public class OrderDetail
    {
        public int OrderDetailId { get; set; }
        public string City { get; set; }
    }
    
    [TestFixture]
    public class CustomerMappingTests
    {
        private ISession session;
    
        [SetUp]
        public void SetUp()
        {
            session = UnitOfWork.Current.GetSession();
        }
    
        [TearDown]
        public void TearDown()
        {
            session.Dispose();
        }
    
        [Test]
        public void CanGetCustomer()
        {
            // Arrange
            const int customerId = 1;
    
            // Act
            var customer = session.Query<Customer>()
                .Where( x => x.CustomerId == customerId )
                .FirstOrDefault();
    
            // Assert
            Assert.NotNull( customer );
            Assert.That( customer.CustomerId == customerId );
        }
    
        [Test]
        public void CanGetCustomerAddresses()
        {
            // Arrange
            const int customerId = 1;
    
            // Act
            var customer = session.Query<Customer>()
                .Where( x => x.CustomerId == customerId )
                .Fetch( x => x.Addresses )
                .FirstOrDefault();
    
            // Assert
            Assert.NotNull( customer.Addresses.Count > 0 );
        }
    
        [Test]
        public void CanGetCustomerOrders()
        {
            // Arrange
            const int customerId = 1;
    
            // Act
            var customer = session.Query<Customer>()
                .Where( x => x.CustomerId == customerId )
                .Fetch( x => x.Orders )
                .FirstOrDefault();
    
            // Assert
            Assert.NotNull( customer.Orders.Count > 0 );
        }
    
        [Test]
        public void CanSaveCustomer()
        {
            // Arrange
            const string companyName = "SnapShot Corporation";
            var customer = new Customer { CompanyName = companyName };
    
            // Act
            session.Save( customer );
    
            session.Flush(); // Update the database right away
            session.Clear(); // Clear cache
    
            var customer2 = session.Query<Customer>()
                .Where( x => x.CompanyName == companyName )
                .FirstOrDefault();
    
            // Assert
            Assert.NotNull( customer2 );
            Assert.That( customer2.CompanyName == companyName );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was given an unusual request recently that I'm having the most difficult time
Given that the web application doesn't have su privileges, I'd like to execute a
Given that I have a Foo model w/ the standard Rails timestamp columns what
Given that I have this resultset structure (superfluous fields have been stripped) Id |
What's the most efficient algorithm anyone can think of that, given a natural number
When using NSURLRequest on the iPhone, what are the real world performance differences between
I'm working with kinect and ofxopeni. I have a point cloud in real world
There have been many threads started over the confusion in the way that Math.Round
Given that an input String may be specified as follows: read(xpath(‘...’)) or xpath(‘...’) or
Given that sorl isn't an app directory wide and the template tag definition lives

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.