Skip to content

Commit

Permalink
Adjust back again so that the exception is thrown by callers
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 17, 2024
1 parent 6ebcb5f commit 838302b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
25 changes: 19 additions & 6 deletions src/Adapter/MSTest.TestAdapter/Discovery/AssemblyEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,26 @@ private static bool ProcessTestDataSourceTests(UnitTestElement test, ReflectionT

if (!data.Any())
{
UnitTestElement discoveredTest = test.Clone();
// Make the test not data driven, because it had no data.
discoveredTest.TestMethod.DataType = DynamicDataType.None;
discoveredTest.DisplayName = dataSource.GetDisplayName(methodInfo, null) ?? discoveredTest.DisplayName;
if (MSTestSettings.CurrentSettings.ConsiderEmptyDataSourceAsInconclusive)
{
UnitTestElement discoveredTest = test.Clone();
// Make the test not data driven, because it had no data.
discoveredTest.TestMethod.DataType = DynamicDataType.None;
discoveredTest.DisplayName = dataSource.GetDisplayName(methodInfo, null) ?? discoveredTest.DisplayName;

tests.Add(discoveredTest);
continue;
tests.Add(discoveredTest);

continue;
}
else
{
throw new ArgumentException(
string.Format(
CultureInfo.InvariantCulture,
FrameworkMessages.DynamicDataIEnumerableEmpty,
"GetData",
dataSource.GetType().Name));
}
}

var testDisplayNameFirstSeen = new Dictionary<string, int>();
Expand Down
10 changes: 0 additions & 10 deletions src/Adapter/MSTest.TestAdapter/DynamicDataOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ public IEnumerable<object[]> GetData(Type? _dynamicDataDeclaringType, DynamicDat
_dynamicDataDeclaringType.FullName));
}

if (!MSTestSettings.CurrentSettings.ConsiderEmptyDataSourceAsInconclusive && !data.Any())
{
throw new ArgumentException(
string.Format(
CultureInfo.InvariantCulture,
FrameworkMessages.DynamicDataIEnumerableEmpty,
_dynamicDataSourceName,
_dynamicDataDeclaringType.FullName));
}

// Data is valid, return it.
return data;
}
Expand Down
17 changes: 12 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,19 @@ private bool ExecuteDataSourceBasedTests(List<TestResult> results)

if (!dataSource.Any())
{
var inconclusiveResult = new TestResult
if (MSTestSettings.CurrentSettings.ConsiderEmptyDataSourceAsInconclusive)
{
Outcome = UTF.UnitTestOutcome.Inconclusive,
};
results.Add(inconclusiveResult);
continue;
var inconclusiveResult = new TestResult
{
Outcome = UTF.UnitTestOutcome.Inconclusive,
};
results.Add(inconclusiveResult);
continue;
}
else
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DynamicDataIEnumerableEmpty, "GetData", testDataSource.GetType().Name));
}
}

foreach (object?[] data in dataSource)
Expand Down

0 comments on commit 838302b

Please sign in to comment.