Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround the UWP release mode issue with DataRow data #3240

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/Adapter/MSTest.TestAdapter/Extensions/MethodInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,36 @@ internal static void InvokeAsSynchronousTask(this MethodInfo methodInfo, object?
{
int methodParametersLengthOrZero = methodParameters?.Length ?? 0;
int argumentsLengthOrZero = arguments?.Length ?? 0;
if (methodParametersLengthOrZero != argumentsLengthOrZero)

#if WINDOWS_UWP
// There is a bug with UWP in release mode where the arguments are wrapped in an object[], so we need to unwrap it.
// See https://github.com/microsoft/testfx/issues/3071
if (argumentsLengthOrZero == 1
&& argumentsLengthOrZero < methodParametersLengthOrZero
&& arguments![0] is object[] args)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could be even more restrictive and only unwrap if args.Length == methodParametersLengthOrZero, WDYT?

{
throw GetParameterCountMismatchException(methodInfo, arguments, methodParameters, methodParametersLengthOrZero, argumentsLengthOrZero, innerException: null);
arguments = args;
argumentsLengthOrZero = args.Length;
}
#endif

try
{
invokeResult = methodInfo.Invoke(classInstance, arguments);
}
catch (Exception ex) when (ex is TargetParameterCountException or ArgumentException)
{
throw GetParameterCountMismatchException(methodInfo, arguments, methodParameters, methodParametersLengthOrZero, argumentsLengthOrZero, ex);
throw new TestFailedException(
ObjectModel.UnitTestOutcome.Error,
string.Format(
CultureInfo.InvariantCulture,
Resource.CannotRunTestArgumentsMismatchError,
methodInfo.DeclaringType!.FullName,
methodInfo.Name,
methodParametersLengthOrZero,
string.Join(", ", methodParameters?.Select(p => p.ParameterType.Name) ?? Array.Empty<string>()),
argumentsLengthOrZero,
string.Join(", ", arguments?.Select(a => a?.GetType().Name ?? "null") ?? Array.Empty<string>())), ex);
}
}

Expand All @@ -189,17 +207,4 @@ internal static void InvokeAsSynchronousTask(this MethodInfo methodInfo, object?
}
#endif
}

private static TestFailedException GetParameterCountMismatchException(MethodInfo methodInfo, object?[]? arguments, ParameterInfo[]? methodParameters, int methodParametersLengthOrZero, int argumentsLengthOrZero, Exception? innerException) =>
new(
ObjectModel.UnitTestOutcome.Error,
string.Format(
CultureInfo.InvariantCulture,
Resource.CannotRunTestArgumentsMismatchError,
methodInfo.DeclaringType!.FullName,
methodInfo.Name,
methodParametersLengthOrZero,
string.Join(", ", methodParameters?.Select(p => p.ParameterType.Name) ?? Array.Empty<string>()),
argumentsLengthOrZero,
string.Join(", ", arguments?.Select(a => a?.GetType().Name ?? "null") ?? Array.Empty<string>())), innerException);
}