I am trying to use a column value as the name of tests in order for all rows to display in the Test Explorer pane in Visual Studio on a per row basis.
The following is what would be my test that consumes the data from the CSV file. I tried using the "TestName" attribute and slicing ("{15:16}") the default name for the section of the string that I'd like to use as the test name. I am definitely now doing it correctly because it's just giving me the name of the method name.
The second method is my read operation. Additionally, I don't like having to assign my data to variables and then have to pass them. I am really looking for a more elegant way to solve reading and using CSV data for naming and testing so if anyone has any experience or thoughts I would love to hear them.
Please let me know if I've left any information out that would further clarify my goal.
class MegaTests
{
[TestCase(TestName = "{15:16}")]
[Test, TestCaseSource("GetTestData")]
public void MyExample_Test(string TestName, string json, string ExpectedResult, string Environment, string ChannelMessage, string ChannelSubject, string MessageCenterMessage, string MessageCenterSubject)
{
Console.WriteLine(TestName + " " + json + " " + ExpectedResult + " " + Environment + " " + ChannelMessage + " " + ChannelSubject + " " + MessageCenterMessage + " " + MessageCenterSubject);
}
private static IEnumerable<string[]> GetTestData()
{
//using (var csv = new CsvReader(new StreamReader(@"../../csv/data.csv"), true))
using (var csv = new CsvReader(new StreamReader(@"DataDriveFromCSV/csv/data.csv"), true))
{
while (csv.ReadNextRecord())
{
string TestName = csv[0];
string json = csv[1];
string ExpectedResult = csv[2];
string Environment = csv[3];
string ChannelMessage = csv[4];
string ChannelSubject = csv[5];
string MessageCenterMessage = csv[6];
string MessageCenterSubject = csv[7];
yield return new[] { TestName, json, ExpectedResult, Environment, ChannelMessage, ChannelSubject, MessageCenterMessage, MessageCenterSubject };
}
}
}