S#harp Architecture – Testing multiple database mappings in MappingIntegrationTests

Standard
I’m using s#harp for a project that needs to map multiple db’s. Whilst this process of setting this up is well documented on the wiki (http://wiki.sharparchitecture.net/FAQ.ashx) the process of getting mutli db mappings to pass the MappingIntegrationTests isn’t.
For what it’s worth I’ve hacked together a means to test that each Fluent mapping is tested to see if it matches one of the db’s. It aint pretty but it does smoke out dodgy mappings.
——————————————————-
//Add a list that holds the session keys
private List<string> sessionKeys;
[SetUp]
public virtual void SetUp()
{
    string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
    configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
    new AutoPersistenceModelGenerator().Generate(),
    "../../../../app/Humanities.IBusiness.Web/NHibernate.config");
/* ADD EXTRA DB'S TO SESSION CONFIG  */
    var configuration2 = NHibernateSession.AddConfiguration(DataGlobals.ROLES_DB_FACTORY_KEY,
    mappingAssemblies,
    new AutoPersistenceModelGenerator().Generate(),
        "../../../../app/Humanities.IBusiness.Web/NHibernateForRolesDb.config",null,null, null);
/* ADD EACH SESSION KEY TO LIST */
    sessionKeys = new List<string>();
    sessionKeys.Add(DataGlobals.DEFAULT_DB_KEY);
    sessionKeys.Add(DataGlobals.ROLES_DB_FACTORY_KEY);
}

[Test]

public void CanConfirmDatabaseMatchesMappings()
{
//GET ALL META DATA FROM SESSION (NOTE DOESN@T MATTER WHICH SESSION FACTORY IS USED!
    var allClassMetadata = NHibernateSession.GetDefaultSessionFactory().GetAllClassMetadata();
    if (NHibernateSession.IsConfiguredForMultipleDatabases())
    {
    //INTEROGATE EACH CLASS
        foreach (var entry in allClassMetadata)
        {
            bool found = false;
            //ENSURE EACH CLASS MAPS TO A DB
            foreach (string key in sessionKeys)
           {
                ISession session = NHibernateSession.CurrentFor(key);
                try
                {
                    session.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
                    .SetMaxResults(0).List();
                    found = true;
                }
                catch (Exception ex) { }
            }
        if (found == false)
            throw new MappingException("Mapping not found for " + entry.Key.ToString());
    }
}

else //Do what you'd normally do or do the above...

A record of my asp.net MVC stack

Standard

For my next project I’ll be using asp.mvc2. To this end I’ve been trying to make sense of the tools and libraries that I’ll need to accomplish this. I’m eager to avoid a complete stack like http://sharparchitecture.net/ until I’ve completely got my head around each component. I usually find it better for understanding to build from the ground up rather than to try and decompile the steps that others have taken in adopting a particular stack.

So far I’ve got the following:

Moq

Nunit

Castle Windsor

Inversion of Control and Dependency Injection with Castle Windsor Container – Part I

Inversion of Control and Dependency Injection with Castle Windsor Container – Part II

Inversion of Control and Dependency Injection with Castle Windsor Container – Part III

Inversion of Control and Dependency Injection with Castle Windsor Container – Part IV

Inversion of Control Containers and the Dependency Injection pattern – Martin Fowler

Fluent NHibernate

http://blogs.hibernatingrhinos.com/nhibernate/Default.aspx

http://dotnetslackers.com/articles/ado_net/Your-very-first-NHibernate-application-Part-1.aspx

ASP.MVC2

This list will likely increase and or change as I hone in the components that I really see advantage in.