in src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs [240:319]
private bool ExecuteDataSourceBasedTests(List<UTF.TestResult> results)
{
var isDataDriven = false;
UTF.DataSourceAttribute[] dataSourceAttribute = this.testMethodInfo.GetAttributes<UTF.DataSourceAttribute>(false);
if (dataSourceAttribute != null && dataSourceAttribute.Length == 1)
{
isDataDriven = true;
Stopwatch watch = new Stopwatch();
watch.Start();
try
{
IEnumerable<object> dataRows = PlatformServiceProvider.Instance.TestDataSource.GetData(this.testMethodInfo, this.testContext);
if (dataRows == null)
{
watch.Stop();
var inconclusiveResult = new UTF.TestResult();
inconclusiveResult.Outcome = UTF.UnitTestOutcome.Inconclusive;
inconclusiveResult.Duration = watch.Elapsed;
results.Add(inconclusiveResult);
}
else
{
try
{
int rowIndex = 0;
foreach (object dataRow in dataRows)
{
UTF.TestResult[] testResults = this.ExecuteTestWithDataRow(dataRow, rowIndex++);
results.AddRange(testResults);
}
}
finally
{
this.testContext.SetDataConnection(null);
this.testContext.SetDataRow(null);
}
}
}
catch (Exception ex)
{
watch.Stop();
var failedResult = new UTF.TestResult();
failedResult.Outcome = UTF.UnitTestOutcome.Error;
failedResult.TestFailureException = ex;
failedResult.Duration = watch.Elapsed;
results.Add(failedResult);
}
}
else
{
UTF.ITestDataSource[] testDataSources = this.testMethodInfo.GetAttributes<Attribute>(false)?.Where(a => a is UTF.ITestDataSource).OfType<UTF.ITestDataSource>().ToArray();
if (testDataSources != null && testDataSources.Length > 0)
{
isDataDriven = true;
foreach (var testDataSource in testDataSources)
{
foreach (var data in testDataSource.GetData(this.testMethodInfo.MethodInfo))
{
try
{
var testResults = this.ExecuteTestWithDataSource(testDataSource, data);
results.AddRange(testResults);
}
finally
{
this.testMethodInfo.SetArguments(null);
}
}
}
}
}
return isDataDriven;
}