tags:

views:

13

answers:

1

I am using NDBUbit to load data from XML file.Right now,I am manually giving GUID for each record(our primary key for all tables is unique-identifier) in the xml file.But,I wonder if there is a better way to do this?

A: 

For all test data in XML files for support of NDbUnit where your PK values are of type GUID, take note that all that's required is for the data type to be a GUID -- its doesn't actually have to be a 'random' GUID.

For such test data, so that you can properly reference other PKs in FKs (for example), I always recommend 'deterministic human-created GUIDs' be used in your test data. They both satisfy the req'ment that the value be a GUID and make working with them easier when you are crafting your test data.

As an example, see the following:

<?xml version="1.0" encoding="utf-8" ?> 
<UserDS xmlns="http://tempuri.org/UserDS.xsd"&gt;
    <Role>
        <ID>11111111-1111-1111-1111-111111111111</ID>
        <Name>Admin</Name>
        <Description>Serves as an administrator</Description>
    </Role>
    <Role>
        <ID>22222222-2222-2222-2222-222222222222</ID>
        <Name>User</Name>
        <Description>User with limited security</Description>
    </Role>
  <dbo.User>
    <ID>22222222-2222-2222-2222-222222222222</ID>
    <FirstName>John</FirstName>
    <LastName>Williams</LastName>
    <Age>30</Age>
    <SupervisorID>11111111-1111-1111-1111-111111111111</SupervisorID>
  </dbo.User>
  <dbo.User>
    <ID>11111111-1111-1111-1111-111111111111</ID>
    <FirstName>Hammad</FirstName>
        <LastName>Awan</LastName>
        <Age>29</Age>
    </dbo.User>
    <UserRole>
        <UserID>11111111-1111-1111-1111-111111111111</UserID>
        <RoleID>11111111-1111-1111-1111-111111111111</RoleID>
    </UserRole>
    <UserRole>
        <UserID>22222222-2222-2222-2222-222222222222</UserID>
        <RoleID>11111111-1111-1111-1111-111111111111</RoleID>
    </UserRole>
    <UserRole>
        <UserID>11111111-1111-1111-1111-111111111111</UserID>
        <RoleID>22222222-2222-2222-2222-222222222222</RoleID>
    </UserRole>
</UserDS>

In this case, to manage this test data all you need to 'know' about GUIDs is that they are 32chars long in the format 8chars-4chars-4chars-4chars-12chars. There's NOTHING that keeps all the characters from being the SAME if you are crafting your test data 'by hand' like this. This approach eliminates any need to generate "actual GUIDs" for your test data and permits you to easily refer to these by simple repeat-representations of GUIDs as shown in the sample above.

Note that in this kind of a scenario YOU are taking 100% of the responsibility for the 'uniqeness' of the GUIDs that you enter into your test data so this test data can only safely be used in isolation from other GUID-based data rows. This (generally) shouldn't be any issue as the whole point of NDbUnit is to load and manage data such as this in isolation.

If you don't want to edit your test data by hand in an XML file like this, we are close to an alpha-release of a tool called 'NDbUnit DataSet Editor' that provides a GUI for editing test data and also contains a 'Generate and insert GUID' toolbar button for just such situations. However, do note that the GUIDs generated in such a case will be 'real' GUIDs meaning that copy-and-paste would be the only reasonable way to reference one as a FK of another record elsewhere in the DataSet.

Hope this helps.

sbohlen
Yeh, thats what I have done "For such test data, so that you can properly reference other PKs in FKs (for example), I always recommend 'deterministic human-created GUIDs' be used in your test data. They both satisfy the req'ment that the value be a GUID and make working with them easier when you are crafting your test data."
jess
But,still seems a pain to me,to write these GUIDs by hand
jess