What I did is not testing the database, but just checking the generated mapping. So, for example, I have an agreement that says that all foreign keys are written as ID, and I test it as (I use xunit, not mstest, but hopefully you can get the concept ...):
[Fact] public void AddDefaultConventions_ShouldNameMappingToForeinKeyCorrectly() { var configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008) .Mappings(m => { m.FluentMappings.Conventions.Add(new CustomForeignKeyConvention()); m.FluentMappings.Add<TestClassMap>(); m.FluentMappings.Add<TestClass2Map>(); }) .BuildConfiguration(); var typeMapping = configuration.GetClassMapping(typeof(TestClass2)); var property = typeMapping.GetProperty("Parent"); Assert.Equal("ParentID", property.ColumnIterator.First().Text); } private class TestClass { public virtual int ID { get; set; } } private class TestClass2 { public virtual int ID { get; set; } public virtual TestClass Parent { get; set; } } private class TestClassMap : ClassMap<TestClass> { public TestClassMap() { Id(x => x.ID); } } private class TestClass2Map : ClassMap<TestClass2> { public TestClass2Map() { Id(x => x.ID); References(x => x.Parent); } }
Btw. it would not be too difficult to test against the database, just try to select something from TestClass2 and make sure that the exception is not thrown ... but I think the way I showed is simpler, and I believe that when FluentNhibernate can generate the right one NHibernate mapping, NHibernate can generate the right queries for me.
source share