Use xml file folder as data source for nhibernate

I am going to start writing NUnit tests for several classes in my project. A number of these classes use data collected through nhibernate from the sql server 2008 database.

The part of the program that I am going to test is very specific (and complex). Therefore, I created a folder from xml files. Combined xml files can lead to database structure. I mean, each XML file corresponds to a table in the database. Data in xml files is also database compatible.

Is there a way to use this folder of xml files as a data source for nhibernate? I mean: can I use nhibernate to collect my test data (which I specifically selected) instead of data from the database? That way, I could usefully test this component without corrupting the (test) database for future tests.

+4
source share
2 answers

"R" in ORM means "Relational". NHibernate is designed to interact with relational databases, not XML files.

Instead, you should mock the DAO / Repository layer to read from XML files without using NHibernate.

+2
source

I had a similar question and I found the answer (maybe) myself, since I have not tried it.

Here's a very promising chapter in a hibernation document: XML Mapping

This way you can store relational data in xml. There are also ways to provide referential integrity, although elements in the xsd schema.

But:

XML mapping is an experimental feature in Hibernate 3.0 and is currently under active development.

0
source

Source: https://habr.com/ru/post/1311613/


All Articles