XMLデータソースを使用したMSTestで問題が発生しています。次のような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>
ただし、私の問題は、Name要素を取得できないことです。
var name = row["Name"];
System.ArgumentException: Column 'Name' does not belong to table User.
これはDataRowの質問の方が多いと思いますが、何か助けていただければ幸いです。
編集:
DataRowを新しいDataTableにコピーして、XMLを記述しても、Name要素は存在しません。
[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>