Skip to content

Instantly share code, notes, and snippets.

@PeterHevesi
Last active July 3, 2024 10:34
Show Gist options
  • Save PeterHevesi/b2d9c2f46e2c92191fe2806638a8bc9c to your computer and use it in GitHub Desktop.
Save PeterHevesi/b2d9c2f46e2c92191fe2806638a8bc9c to your computer and use it in GitHub Desktop.
using System.Collections;
namespace TestOfCategories;
public class MyTestCase(string name, int someNumber, string someString)
{
public int SomeNumber { get; } = someNumber;
public string SomeString { get; } = someString;
public string DataName { get; } = name;
}
public class MyTestCaseData : TestCaseData
{
public MyTestCaseData(MyTestCase testCase) : base(testCase)
{
SetName($"{testCase.DataName} {testCase.SomeNumber} {testCase.SomeString} ");
SetCategory(testCase.DataName);
}
}
public class SimpleTestData_FirstDataSource
{
public static IEnumerable GetTestCases
{
get
{
yield return new MyTestCaseData(new MyTestCase("SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 1", 1, "FIREFOX"));
yield return new MyTestCaseData(new MyTestCase("SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 2", 2, "FIREFOX"));
yield return new MyTestCaseData(new MyTestCase("SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 3", 3, "FIREFOX"));
//THIS IS THE ONLY SOLUTION => TO PUT CATEGORY AGAIN IN THE NAME:
//yield return new MyTestCaseData(new MyTestCase("FIREFOX - SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 1", 1, "FIREFOX"));
//yield return new MyTestCaseData(new MyTestCase("FIREFOX - SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 2", 2, "FIREFOX"));
//yield return new MyTestCaseData(new MyTestCase("FIREFOX - SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 3", 3, "FIREFOX"));
}
}
}
public class SimpleTestData_SecondDataSource
{
public static IEnumerable GetTestCases
{
get
{
yield return new MyTestCaseData(new MyTestCase("SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 1", 1, "CHROME"));
yield return new MyTestCaseData(new MyTestCase("SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 2", 2, "CHROME"));
yield return new MyTestCaseData(new MyTestCase("SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 3", 3, "CHROME"));
//THIS IS THE ONLY SOLUTION => TO PUT CATEGORY AGAIN IN THE NAME:
//yield return new MyTestCaseData(new MyTestCase("CHROME - SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 1", 1, "CHROME"));
//yield return new MyTestCaseData(new MyTestCase("CHROME - SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 2", 2, "CHROME"));
//yield return new MyTestCaseData(new MyTestCase("CHROME - SAME NAME OF DATA CASE AS IN OTHER SOURCE - DONT CHANGE THIS - 3", 3, "CHROME"));
}
}
}
public class Tests
{
[Test]
[TestCaseSource(typeof(SimpleTestData_FirstDataSource), Category ="FIREFOX")]
[TestCaseSource(typeof(SimpleTestData_SecondDataSource), Category ="CHROME")]
public void SimpleTest(MyTestCase data)
{
Console.WriteLine(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment