开发者

Verifying NHibernate Mappings with NDBUnit

开发者 https://www.devze.com 2023-02-16 16:49 出处:网络
I\'m currently using NHibernate in a project and am using NDBUnit to populate a DB with data for my unit tests. What I\'d like to do is verify the XML used by NDBUnit against the class instances retur

I'm currently using NHibernate in a project and am using NDBUnit to populate a DB with data for my unit tests. What I'd like to do is verify the XML used by NDBUnit against the class instances returned back by NHibernate when I load the data.

Seems like I could use reflection on the classes to get all the properties, and then lookup those column values in the NDBUnit XML dataset. I'm just not sure if I'm reinventing the wheel or if there's a better alternative to verifying that all my NHibernate mappin开发者_Go百科gs are correct?


Check out PersistenceSpecification in Fluent NHibernate. There is nothing in that class that relies on Fluent NHibernate and I've used it before when testing plain old NHibernate hbm.xml files.

http://wiki.fluentnhibernate.org/Persistence_specification_testing

For example you can write tests like this:

[Test]
public void CanCorrectlyMapEmployee()
{
    new PersistenceSpecification<Employee>(session)
        .CheckProperty(c => c.Id, 1)
        .CheckProperty(c => c.FirstName, "John")
        .CheckProperty(c => c.LastName, "Doe")
        .VerifyTheMappings();
}

Highly recommended.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号