在使用 NDbUnit 初始化的单个测试中读取/加载多个 XML
我正在尝试使用 NDbUnit。我为每个表创建了单独的 XSD,而不是为整个数据库创建一个大型 XSD。
当我仅使用单个 XSD 和单个 xml 读取时,我的测试运行良好。然而,对于特定的测试,我需要在两个或三个不同(但相关)的表中包含数据。如果我尝试读取多个 xsd 和 xml,则会抛出异常。
这是我的代码
[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");
}
这是我在尝试读取 License.XSD 时遇到的异常,如上所示
类初始化方法 ESMS.UnitTest.CompanyManagerTest.MyClassInitialize 抛出异常。 系统参数异常: System.ArgumentException:项目有 已经添加了。字典中的关键字: 'EnableTableAdapterManager' 键为 添加:“EnableTableAdapterManager”。
我不确定这是否是使用 NDbUnit 读取多个 XML、XSD 的正确方法。我用谷歌搜索并溢出(即搜索堆栈溢出),但无法获得任何明智的方向。有人可以解释一下出了什么问题以及如何纠正吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是 NDbUnit 的用途。不支持将多个 XSD 或 XML 文件读取到单个测试范围中。 NDbUnit 使用单个 XSD 中的信息来分析表之间的关系(FK 等),以便能够在 CRUD 操作期间正确操作表,因此要求单个 XSD 描述表的整个范围您希望 NDbUnit 在测试运行期间进行操作。
可能可以加载多个 XML 文件(包含测试数据),但这不是经过测试/支持的场景。我有兴趣了解您所拥有的哪种使用场景会阻止仅使用一个包含所需测试数据的 XML 文件。
但肯定是一次只能加载一个 XSD 文件(包含一个或多个表的架构及其关系等)。
希望这能澄清一点。
This isn't how NDbUnit is intended to be used. There is no support for reading multiple XSD or XML files into a single test-scope. NDbUnit uses the information in the single XSD to analyze relationships (FKs, etc.) between your tables in order to be able to properly manipulate the tables during its CRUD operations and so the requirement is that the single XSD describe the entire scope of the tables that you want NDbUnit to manipulate during a test-run.
It might be possible to load multiple XML files (containing your test data) but this is not a tested/supported scenario. I'd be interested in understanding what usage scenario you have that would preclude having just one XML file with your needed test data.
But its definitely the case that only a single XSD file (containing the schema of one or more tables and their relationships, etc.) can be loaded at a time.
Hope this clears this up a bit.
斯博伦给我指明了道路。
确实,就目前情况而言,不支持加载多个 XSD。
然而幸运的是,可以针对单个 XSD 加载多个 XML。
因此,我所做的就是创建一个 XSD 并将所有相关表拉入其中。然后使用 ReadXml 旁边可用的
AppendXml
sytanx。这样我就可以将所需的测试数据加载到多个表中,并且我的测试开始通过。此链接将分享有关
AppendXml
http 的更多信息://code.google.com/p/ndbunit/issues/detail?id=27Sbohlen 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