8
我在使用XML Datasource的MSTest時遇到了一些問題。假設我有一個看起來像這樣的XML文件:如何通過MSTest XML Datasource使用「deep」XML
<Users>
<User>
<Id>1</Id>
<Name>
<First>Mike</First>
<Last>Paterson</Last>
</Name>
</User>
<User>
<Id>2</Id>
<Name>
<First>John</First>
<Last>Doe</Last>
</Name>
</User>
</Users>
我的問題,但是,我不能得到阿霍德的名稱元素:
var name = row["Name"];
System.ArgumentException: Column 'Name' does not belong to table User.
我想這可能是更多的DataRow問題,但任何幫助真的不勝感激。
編輯:
即使我DataRow中複製到一個新的DataTable和編寫XML中的名稱元素不存在:
[DeploymentItem("XmlDatasourceTest\\Users.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\Users.xml", "User", DataAccessMethod.Sequential), TestMethod]
public void TestMethod1()
{
var row = TestContext.DataRow;
DataTable table = row.Table.Copy();
foreach (DataRow r in table.AsEnumerable().ToArray())
{
r.Delete();
}
table.ImportRow(row);
table.WriteXml(@"C:\test.xml");
}
第一行,這產生了:
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<User>
<Id>1</Id>
</User>
</DocumentElement>