0
votes

I have a project structure like this:
1. NHibernate Base classes to open session, data access function and CRUD methods. (Dll)
2. An exectue program (windows forms) which has domain classes and mappers in a separate namespace. (EXE)
3. NUnit test cases (Dll)
I have used the following code to create configuration:

public Configuration BuildConfig()
{
    var configuration = new Configuration();
    return Fluently.Configure(configuration)
        .Mappings(cfg => {
            cfg.FluentMappings.AddFromAssembly(Assembly.GetEntryAssembly());
        }).BuildConfiguration();
}

When I tried to create configuration from 2n program (Windows forms application) the configuration has successfully done.

Now I've referenced both the above assemblies in NUnit Test assembly and I have copied the same configuration settings (app.config) as the windows form. Fluent is not able to build the session factory and I'm getting the following exception:

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  Database was not configured through Database method.

Please help me to resolve this issue.

1

1 Answers

0
votes

I am relatively a newbie; but I think:

FluentMappings.AddFromAssembly(**Assembly.GetEntryAssembly()**); 

may work when executing the winforms.exe, but when testing will reflect into whatever is excuting your tests.

Maybe this should be:

FluentMappings.AddFromAssemblyOf< *mappings class* >()

Or, if you need to use reflection:

m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(*mappings class* )))