Similar to the SqlServerData attribute available in the xUnit.net GitHub repository, you can create a custom attribute to load data from any source. A custom attribute class must implement DataAttribute, which is an abstract class that represents a data source to be used by a theory. The custom attribute class must override and implement the GetData method. This method returns IEnumerable<object[]>, which is used to wrap the content of the dataset to be returned.
Let's create a CsvData custom attribute that can be used to load data from a .csv file for use in data-driven unit tests. The class will have a constructor that takes two parameters. The first is a string argument containing the full path to the .csv file. The second ...