Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 19, 2024
1 parent 04db4fd commit 3f45364
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
22 changes: 10 additions & 12 deletions src/Adapter/MSTest.TestAdapter/Discovery/AssemblyEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,21 +413,19 @@ private static bool ProcessTestDataSourceTests(UnitTestElement test, ReflectionT

if (!data.Any())
{
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;
}
else
if (!MSTestSettings.CurrentSettings.ConsiderEmptyDataSourceAsInconclusive)
{
throw dataSource.GetExceptionForEmptyDataSource(methodInfo);
}

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;
}

var testDisplayNameFirstSeen = new Dictionary<string, int>();
Expand Down
18 changes: 8 additions & 10 deletions src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,17 @@ private bool ExecuteDataSourceBasedTests(List<TestResult> results)

if (!dataSource.Any())
{
if (MSTestSettings.CurrentSettings.ConsiderEmptyDataSourceAsInconclusive)
{
var inconclusiveResult = new TestResult
{
Outcome = UTF.UnitTestOutcome.Inconclusive,
};
results.Add(inconclusiveResult);
continue;
}
else
if (!MSTestSettings.CurrentSettings.ConsiderEmptyDataSourceAsInconclusive)
{
throw testDataSource.GetExceptionForEmptyDataSource(_testMethodInfo.MethodInfo);
}

var inconclusiveResult = new TestResult
{
Outcome = UTF.UnitTestOutcome.Inconclusive,
};
results.Add(inconclusiveResult);
continue;
}

foreach (object?[] data in dataSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
internal static class EmptyDataSourceExceptionInfoExtensions
{
internal static ArgumentException GetExceptionForEmptyDataSource(this ITestDataSource dataSource, MethodInfo testMethodInfo)
=> dataSource is ITestDataSourceEmptyDataSourceExceptionInfo info ? info.GetExceptionForEmptyDataSource(testMethodInfo) : new ArgumentException(
string.Format(
CultureInfo.InvariantCulture,
FrameworkMessages.DynamicDataIEnumerableEmpty,
"GetData",
dataSource.GetType().Name));
=> dataSource is ITestDataSourceEmptyDataSourceExceptionInfo info
? info.GetExceptionForEmptyDataSource(testMethodInfo)
: new ArgumentException(
string.Format(
CultureInfo.InvariantCulture,
FrameworkMessages.DynamicDataIEnumerableEmpty,
"GetData",
dataSource.GetType().Name));

private static ArgumentException GetExceptionForEmptyDataSource(this ITestDataSourceEmptyDataSourceExceptionInfo info, MethodInfo testMethodInfo)
=> new(
Expand Down

0 comments on commit 3f45364

Please sign in to comment.