I'm going to start writing NUnit tests for a few classes in my project. A certain number of these classes use data gathered through nhibernate from a sql server 2008 database.
The part of the program I'm about to test is very specific (and complicated). Therefore I have made a folder of xml files. Combined, the xml fil开发者_运维技巧es could result in the database structure. I mean each xml file corresponds to a table in the database. The data in the xml files is also consistent with the database.
Is there a way to use this folder of xml files as data source for nhibernate? I mean: can I use nhibernate to gather my test data (wich I have specifically chosen) instead of data from the database? In this way, I could usefully test this component without corrrupting the (test) database for future tests.
The "R" in ORM stands for "Relational". NHibernate is designed to communicate with relational databases, not with XML files.
Instead, you should mock your DAO/Repository layer to read from XML files without using NHibernate.
I had a similar question here and found the answer (possibly) myself, since I have not tried it out.
Here is a very promising looking chapter of the hibernate docu: XML Mapping
So it IS possible to store relational data in xml. There are alsow ways to ensure referential integrity though elements in the xsd schema.
But:
XML Mapping is an experimental feature in Hibernate 3.0 and is currently under active development.
精彩评论