Skip to content

Commit

Permalink
XmlDataSource test
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 21, 2024
1 parent 8f73a4a commit 772c11d
Showing 1 changed file with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ public class DataSourceTests : AcceptanceTestBase
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework.Csv" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework.Xml" Version="$MSTestVersion$" />

<None Include="TestData.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Expand Down Expand Up @@ -63,7 +67,7 @@ public class MyTestClass

[DataTestMethod]
[DataSource("TestData")]
public void TestSum()
public void TestSumDataSource()
{
int expected = (int)TestContext.DataRow["expectedSum"];
int num1 = (int)TestContext.DataRow["num1"];
Expand All @@ -73,7 +77,17 @@ public void TestSum()

[TestMethod]
[CsvDataSource("TestData.csv")]
public void TestSum2(DataRow dataRow)
public void TestSumCsv(DataRow dataRow)
{
int expected = (int)dataRow["expectedSum"];
int num1 = (int)dataRow["num1"];
int num2 = (int)dataRow["num2"];
Assert.AreEqual(expected, num1 + num2);
}

[TestMethod]
[XmlDataSource("TestData.xml")]
public void TestSumXml(DataRow dataRow)
{
int expected = (int)dataRow["expectedSum"];
int num1 = (int)dataRow["num1"];
Expand All @@ -93,6 +107,31 @@ public void MyTest()
5,6,11
10,30,40
1,1,1

#file TestData.xml

<Root>
<MyTable>
<Num1>1</Num1>
<Num2>1</Num2>
<ExpectedSum>2</ExpectedSum>
</MyTable>
<MyTable>
<Num1>5</Num1>
<Num2>6</Num2>
<ExpectedSum>11</ExpectedSum>
</MyTable>
<MyTable>
<Num1>10</Num1>
<Num2>30</Num2>
<ExpectedSum>40</ExpectedSum>
</MyTable>
<MyTable>
<Num1>1</Num1>
<Num2>1</Num2>
<ExpectedSum>1</ExpectedSum>
</MyTable>
</Root>
""";

private readonly AcceptanceFixture _acceptanceFixture;
Expand Down Expand Up @@ -124,6 +163,6 @@ await DotnetCli.RunAsync(

TestHostResult result = await testHost.ExecuteAsync();
result.AssertExitCodeIs(ExitCodes.AtLeastOneTestFailed);
result.AssertOutputContainsSummary(failed: 2, passed: 7, skipped: 0);
result.AssertOutputContainsSummary(failed: 3, passed: 10, skipped: 0);
}
}

0 comments on commit 772c11d

Please sign in to comment.