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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:12:56+00:00 2026-05-20T05:12:56+00:00

I am using NUnit for test units. I have my interface on the domain

  • 0

I am using NUnit for test units. I have my interface on the domain so i am ready to make implementation of those interfaces in the persistence layer. My question is how do you actually make the unit tests for testing those repositories ? i believe this isnt a good idea to test directly from the database. Ive heard poeple that are using SQLite but it is okay to use mocks instead ? why are the poeple using SQLite for in-memory database when you can provide a mock with actuals entities ?

Any example would be welcome too.

Note: This is intended to be repositories coded in C# that gonna use NHibernate and Fluent NHibernate as mapping.

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-05-20T05:12:57+00:00Added an answer on May 20, 2026 at 5:12 am

    It of course depends, but in most cases I’d say it’s generally enough to just mock the repositories in your tests and using the in-memory SQLite database only to test your mappings (FluentNHibernate Persistence specification testing).

    For the NUnit mappings tests with SQLite I’m using the following base class:

    public abstract class MappingsTestBase
    {
        [SetUp]
        public void Setup()
        {
            _session = SessionFactory.OpenSession();
            BuildSchema(_session);
        }
    
        [TestFixtureTearDown]
        public void Terminate()
        {
            _session.Close();
            _session.Dispose();
    
            _session = null;
            _sessionFactory = null;
            _configuration = null;
        }
    
        #region NHibernate InMemory SQLite Session
    
        internal static ISession _session;
    
        private static ISessionFactory _sessionFactory;
        private static Configuration _configuration;
    
        private static ISessionFactory SessionFactory
        {
            get
            {
                if (_sessionFactory == null)
                {
                    FluentConfiguration configuration = Fluently.Configure()
                        .Database(SQLiteConfiguration.Standard.InMemory().ShowSql)
                        .Mappings(m => m.FluentMappings
                            .AddFromAssemblyOf<NHibernateSession>())
                        .ExposeConfiguration(c => _configuration = c);
    
                    _sessionFactory = configuration.BuildSessionFactory();
                }
    
                return _sessionFactory;
            }
        }
    
        private static void BuildSchema(ISession session)
        {
            SchemaExport export = new SchemaExport(_configuration);
            export.Execute(true, true, false, session.Connection, null);
        }
    
        #endregion
    }
    

    An example mappings test class deriving from the above base class could then look like the following:

    [TestFixture]
    public class MappingsTest : MappingsTestBase
    {
        [Test]
        public void Persistence_Employee_ShouldMapCorrectly()
        {
            Category employee = new PersistenceSpecification<Employee>(_session)
                .CheckProperty(e => e.Id, 1)
                .CheckProperty(e => e.FirstName, "John")
                .CheckProperty(e => e.LastName, "Doe")
                .VerifyTheMappings();
            ...
            Assert.Equals(employee.FirstName, "John");
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using C# 2.0 with Nunit Test. I have some object that needs
Having recently gotten into test driven development I am using the Nunit test runner
When using NUnit and the test project, we haven't been able to find a
Using NUnit 2.2 on .NET 3.5, the following test fails when using DateTime.Equals. Why?
I want to test ASP.NET application using NUnit, but it seems WebConfigurationManager.ConnectionStrings collection is
I am using NUnit (2.4.6) and my build/test night are done with Team City
I am currently using NUnit and testing a class library. Up until now, I
I want to start using Nunit (finally), I am using Visual Studio 2008. Is
I'm new to unit testing using nunit (and Java development in general). When creating
I am doing regression testing using NUnit, WatiN and VB.net. What i am doing

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.