Click to See Complete Forum and Search --> : TDD, Linq to Data objects and importing from XML


Efitap
February 18th, 2009, 02:51 AM
This is more a strategy question than anything else.

I am working on a database driven application where all my entities are represented (and extended) as class objects using linq to data objects.

The quest is, because I am a test driven person, I hope that there is a good method for importing test-data into the test database using XML. I have done this on a specific imlpementation so far, but a more general solution would be preferered, i.e:

if I have the table PERSON in the database:

PERSON
ID (not null, index, PK)
NAME( nvarChar50, nullable)
AGE( int, nullable)


Then, with linq to data objects, I simply drag this table onto my dbml to create

partial public class person: INotifyPropertyChanged, INotifyPropertyChanging
{
...
}

On the most important tables, I've extended the classes generated by adding a few functions of my own (as well as enums where appropriate)

Big question is:

I would like to have an XML for prepping a test scenario, i.e. if I'm testing a function that does something with PERSON objects that are over the age of 50, then I'd like the xml to look something like:


<testplan>
<tabledata>
<PERSON name="Efitap" age="44" />
<PERSON name="Metusalem" age="123" />
</tabledata>
</testplan>


In my tests, I can then load all the test data that I need into my test database, perform my tests, then roll back the TransactionScope in which I run all my tests in (for lack of a better term, I call this "functional unit testing" )

The project that I am on has hundreds of tables, making writing code to import and export data from all the tables more or less impossible / too expensive.

For all automation needs, such as creating a purchase order with random products, I already have functions that respond to the xml, i.e:


...
<scenario id="1" code="3.1.2" description="Order is regognized as large by selecting the largest product in stock">
<pickingorder text="Order 1: Speditor A" customerId="7777">
<pickinstruction quantity="1" autoProduct="true" autoSelection="largestVolume" />
<pickinstruction quantity="1" autoProduct="true" autoSelection="smallestVolume" />
</pickingorder>
</scenario>
...


Does anyone have a good strategy example of how I can do this?