I am having problems with MSTest using an XML data source. Suppose I have an XML file that looks like this:
<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>
My problem, however, is that I cannot get the Name element:
var name = row["Name"]; System.ArgumentException: Column 'Name' does not belong to table User.
I suppose this might be more of a DataRow issue, but any help would really be appreciated.
EDIT:
Even if I copy the DataRow to a new DataTable and write XML, the Name element is missing:
[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"); }
For the first line, this gives:
<?xml version="1.0" standalone="yes"?> <DocumentElement> <User> <Id>1</Id> </User> </DocumentElement>
mstest datarow xmldatasource
devlife
source share