Skip to content

Commit

Permalink
Add TODO for moving away from OleDb and add test for the new attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 21, 2024
1 parent 70af843 commit d7cf953
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public CsvDataSourceAttribute(string fileName)

IEnumerable<object?[]> ITestDataSource.GetData(MethodInfo methodInfo)
{
// We specifically use OleDb to read a CSV file...
// TODO: Avoid using OleDb and instead parse Csv directly. Maybe use https://www.nuget.org/packages/CsvHelper? Write our own?
// When that happens, the OleDb dependency in the csproj should be
// removed, and relevant tests for CsvDataSource should run on Linux.

// We better work with a full path, if nothing else, errors become easier to report
string fullPath = Path.GetFullPath(FileName);
if (!File.Exists(fullPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DataSourceTests : AcceptanceTestBase
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$MicrosoftNETTestSdkVersion$" />
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework" Version="$MSTestVersion$" />
<PackageReference Include="MSTest.TestFramework.Csv" Version="$MSTestVersion$" />

<None Include="TestData.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down Expand Up @@ -52,6 +53,7 @@ public class DataSourceTests : AcceptanceTestBase


#file MyTestClass.cs
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
Expand All @@ -69,6 +71,16 @@ public void TestSum()
Assert.AreEqual(expected, num1 + num2);
}

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

[TestMethod]
public void MyTest()
{
Expand Down Expand Up @@ -112,6 +124,6 @@ await DotnetCli.RunAsync(

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

0 comments on commit d7cf953

Please sign in to comment.