Search code examples
unit-testingvs-unit-testing-frameworkndbunit

Read/Load multiple XML in a single test initialize with NDbUnit


I am trying to use the NDbUnit. I have created seperate XSD for each table instead of one large XSD for complete database.

My tests run fine when I use only single XSD and singe xml read. However for a perticular test, I need to have data in two or three different (but related) tables. If I try to read more than one xsd and xml, then it throws exception.

Here is my code

        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            IDbConnection connection = DbConnection.GetCurrentDbConnection();
            _mySqlDatabase = new NDbUnit.Core.SqlClient.SqlDbUnitTest(connection);
            _mySqlDatabase.ReadXmlSchema(@"Data\CompanyMaster.xsd");  
            _mySqlDatabase.ReadXml(@"Data\CompanyMaster.xml");
            _mySqlDatabase.ReadXmlSchema(@"Data\License.xsd");
            _mySqlDatabase.ReadXml(@"Data\License.xml");
            _mySqlDatabase.ReadXmlSchema(@"Data\LicenseDetails.xsd");
            _mySqlDatabase.ReadXml(@"Data\LicenseDetails.xml");
            _mySqlDatabase.ReadXmlSchema(@"RelatedLicense.xsd");
            _mySqlDatabase.ReadXml(@"Data\RelatedLicense.xml");    
        }

Here is the exception I get at the point where i try to read License.XSD as shown above

Class Initialization method ESMS.UnitTest.CompanyManagerTest.MyClassInitialize threw exception. System.ArgumentException: System.ArgumentException: Item has already been added. Key in dictionary: 'EnableTableAdapterManager' Key being added: 'EnableTableAdapterManager'.

I am not sure if this is the correct way of reading multiple XML,XSD with NDbUnit. I googled and Overflowed (i.e. searched stack overflow), but could not get any sensible direction. Could someone explain what is going wrong and how to correct?


Solution

  • Sbohlen showed me the way.

    It's true that as thing stands as of now, loading of multiple XSD's is not supported.

    However fortunately loading of multiple XMLs against single XSD is possible.

    So what I did was created a single XSD and pulled in all related tables onto it. Then used the AppendXml sytanx available along side of ReadXml. This way I could load the required test data into multiple tables and my tests started getting passed.

    This link would share more lights about the AppendXml http://code.google.com/p/ndbunit/issues/detail?id=27