diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestMethodInfo.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestMethodInfo.cs
index 29cc5f7563..9ea784dbc4 100644
--- a/src/Adapter/MSTest.TestAdapter/Execution/TestMethodInfo.cs
+++ b/src/Adapter/MSTest.TestAdapter/Execution/TestMethodInfo.cs
@@ -6,6 +6,7 @@
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions;
+using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -37,22 +38,30 @@ public class TestMethodInfo : ITestMethod
internal TestMethodInfo(
MethodInfo testMethod,
TestClassInfo parent,
- TestMethodOptions testMethodOptions)
+ ITestContext testContext)
{
DebugEx.Assert(testMethod != null, "TestMethod should not be null");
DebugEx.Assert(parent != null, "Parent should not be null");
TestMethod = testMethod;
Parent = parent;
- TestMethodOptions = testMethodOptions;
+ TestContext = testContext;
ExpectedException = ResolveExpectedException();
RetryAttribute = GetRetryAttribute();
+ TimeoutInfo = GetTestTimeout();
+ Executor = GetTestMethodAttribute();
}
+ internal TimeoutInfo TimeoutInfo { get; /*For testing only*/set; }
+
+ internal TestMethodAttribute Executor { get; /*For testing only*/set; }
+
+ internal ITestContext TestContext { get; }
+
///
/// Gets a value indicating whether timeout is set.
///
- public bool IsTimeoutSet => TestMethodOptions.TimeoutInfo.Timeout != TimeoutWhenNotSet;
+ public bool IsTimeoutSet => TimeoutInfo.Timeout != TimeoutWhenNotSet;
///
/// Gets the reason why the test is not runnable.
@@ -104,11 +113,6 @@ internal TestMethodInfo(
///
internal TestClassInfo Parent { get; }
- ///
- /// Gets the options for the test method in this environment.
- ///
- internal TestMethodOptions TestMethodOptions { get; }
-
internal ExpectedExceptionBaseAttribute? ExpectedException { get; set; /*set for testing only*/ }
internal RetryBaseAttribute? RetryAttribute { get; }
@@ -146,7 +150,7 @@ public virtual TestResult Invoke(object?[]? arguments)
// check if arguments are set for data driven tests
arguments ??= Arguments;
- using LogMessageListener listener = new(TestMethodOptions.CaptureDebugTraces);
+ using LogMessageListener listener = new(MSTestSettings.CurrentSettings.CaptureDebugTraces);
watch.Start();
try
{
@@ -163,8 +167,8 @@ public virtual TestResult Invoke(object?[]? arguments)
result.DebugTrace = listener.GetAndClearDebugTrace();
result.LogOutput = listener.GetAndClearStandardOutput();
result.LogError = listener.GetAndClearStandardError();
- result.TestContextMessages = TestMethodOptions.TestContext?.GetAndClearDiagnosticMessages();
- result.ResultFiles = TestMethodOptions.TestContext?.GetResultFiles();
+ result.TestContextMessages = TestContext?.GetAndClearDiagnosticMessages();
+ result.ResultFiles = TestContext?.GetResultFiles();
}
}
@@ -248,6 +252,43 @@ public virtual TestResult Invoke(object?[]? arguments)
return newParameters;
}
+ ///
+ /// Gets the test timeout for the test method.
+ ///
+ /// The timeout value if defined in milliseconds. 0 if not defined.
+ private TimeoutInfo GetTestTimeout()
+ {
+ DebugEx.Assert(TestMethod != null, "TestMethod should be non-null");
+ TimeoutAttribute? timeoutAttribute = ReflectHelper.Instance.GetFirstNonDerivedAttributeOrDefault(TestMethod, inherit: false);
+ if (timeoutAttribute is null)
+ {
+ return TimeoutInfo.FromTestTimeoutSettings();
+ }
+
+ if (!timeoutAttribute.HasCorrectTimeout)
+ {
+ string message = string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorInvalidTimeout, TestMethod.DeclaringType!.FullName, TestMethod.Name);
+ throw new TypeInspectionException(message);
+ }
+
+ return TimeoutInfo.FromTimeoutAttribute(timeoutAttribute);
+ }
+
+ ///
+ /// Provides the Test Method Extension Attribute of the TestClass.
+ ///
+ /// Test Method Attribute.
+ private TestMethodAttribute GetTestMethodAttribute()
+ {
+ // Get the derived TestMethod attribute from reflection.
+ // It should be non-null as it was already validated by IsValidTestMethod.
+ TestMethodAttribute testMethodAttribute = ReflectHelper.Instance.GetFirstDerivedAttributeOrDefault(TestMethod, inherit: false)!;
+
+ // Get the derived TestMethod attribute from Extended TestClass Attribute
+ // If the extended TestClass Attribute doesn't have extended TestMethod attribute then base class returns back the original testMethod Attribute
+ return Parent.ClassAttribute.GetTestMethodAttribute(testMethodAttribute) ?? testMethodAttribute;
+ }
+
///
/// Resolves the expected exception attribute. The function will try to
/// get all the expected exception attributes defined for a testMethod.
@@ -385,7 +426,7 @@ private TestResult ExecuteInternal(object?[]? arguments, CancellationTokenSource
// Expected Exception was thrown, so Pass the test
result.Outcome = UTF.UnitTestOutcome.Passed;
}
- else if (realException.IsOperationCanceledExceptionFromToken(TestMethodOptions.TestContext!.Context.CancellationTokenSource.Token))
+ else if (realException.IsOperationCanceledExceptionFromToken(TestContext!.Context.CancellationTokenSource.Token))
{
result.Outcome = UTF.UnitTestOutcome.Timeout;
result.TestFailureException = new TestFailedException(
@@ -395,7 +436,7 @@ private TestResult ExecuteInternal(object?[]? arguments, CancellationTokenSource
CultureInfo.InvariantCulture,
Resource.Execution_Test_Timeout,
TestMethodName,
- TestMethodOptions.TimeoutInfo.Timeout)
+ TimeoutInfo.Timeout)
: string.Format(
CultureInfo.InvariantCulture,
Resource.Execution_Test_Cancelled,
@@ -434,7 +475,7 @@ private TestResult ExecuteInternal(object?[]? arguments, CancellationTokenSource
}
// Update TestContext with outcome and exception so it can be used in the cleanup logic.
- if (TestMethodOptions.TestContext is { } testContext)
+ if (TestContext is { } testContext)
{
testContext.SetOutcome(result.Outcome);
// Uwnrap the exception if it's a TestFailedException
@@ -612,12 +653,12 @@ private void RunTestCleanupMethod(TestResult result, CancellationTokenSource? ti
try
{
// Reset the cancellation token source to avoid cancellation of cleanup methods because of the init or test method cancellation.
- TestMethodOptions.TestContext!.Context.CancellationTokenSource = new CancellationTokenSource();
+ TestContext!.Context.CancellationTokenSource = new CancellationTokenSource();
// If we are running with a method timeout, we need to cancel the cleanup when the overall timeout expires. If it already expired, nothing to do.
if (timeoutTokenSource is { IsCancellationRequested: false })
{
- timeoutTokenSource?.Token.Register(TestMethodOptions.TestContext.Context.CancellationTokenSource.Cancel);
+ timeoutTokenSource?.Token.Register(TestContext.Context.CancellationTokenSource.Cancel);
}
// Test cleanups are called in the order of discovery
@@ -820,7 +861,7 @@ private bool RunTestInitializeMethod(object classInstance, TestResult result, Ca
return FixtureMethodRunner.RunWithTimeoutAndCancellation(
() => methodInfo.InvokeAsSynchronousTask(classInstance, null),
- TestMethodOptions.TestContext!.Context.CancellationTokenSource,
+ TestContext!.Context.CancellationTokenSource,
timeout,
methodInfo,
new InstanceExecutionContextScope(classInstance, Parent.ClassType),
@@ -828,7 +869,7 @@ private bool RunTestInitializeMethod(object classInstance, TestResult result, Ca
Resource.TestInitializeTimedOut,
timeoutTokenSource is null
? null
- : (timeoutTokenSource, TestMethodOptions.TimeoutInfo.Timeout));
+ : (timeoutTokenSource, TimeoutInfo.Timeout));
}
private TestFailedException? InvokeCleanupMethod(MethodInfo methodInfo, object classInstance, int remainingCleanupCount, CancellationTokenSource? timeoutTokenSource)
@@ -841,7 +882,7 @@ timeoutTokenSource is null
return FixtureMethodRunner.RunWithTimeoutAndCancellation(
() => methodInfo.InvokeAsSynchronousTask(classInstance, null),
- TestMethodOptions.TestContext!.Context.CancellationTokenSource,
+ TestContext!.Context.CancellationTokenSource,
timeout,
methodInfo,
new InstanceExecutionContextScope(classInstance, Parent.ClassType, remainingCleanupCount),
@@ -849,7 +890,7 @@ timeoutTokenSource is null
Resource.TestCleanupTimedOut,
timeoutTokenSource is null
? null
- : (timeoutTokenSource, TestMethodOptions.TimeoutInfo.Timeout));
+ : (timeoutTokenSource, TimeoutInfo.Timeout));
}
///
@@ -874,7 +915,7 @@ private bool SetTestContext(object classInstance, TestResult result)
{
if (Parent.TestContextProperty != null && Parent.TestContextProperty.CanWrite)
{
- Parent.TestContextProperty.SetValue(classInstance, TestMethodOptions.TestContext);
+ Parent.TestContextProperty.SetValue(classInstance, TestContext);
}
return true;
@@ -912,7 +953,7 @@ private bool SetTestContext(object classInstance, TestResult result)
object? classInstance = null;
try
{
- classInstance = Parent.Constructor.Invoke(Parent.IsParameterlessConstructor ? null : [TestMethodOptions.TestContext]);
+ classInstance = Parent.Constructor.Invoke(Parent.IsParameterlessConstructor ? null : [TestContext]);
}
catch (Exception ex)
{
@@ -935,10 +976,10 @@ private bool SetTestContext(object classInstance, TestResult result)
// It also seems that in rare cases the ex can be null.
Exception realException = ex.GetRealException();
- if (realException.IsOperationCanceledExceptionFromToken(TestMethodOptions.TestContext!.Context.CancellationTokenSource.Token))
+ if (realException.IsOperationCanceledExceptionFromToken(TestContext!.Context.CancellationTokenSource.Token))
{
result.Outcome = UTF.UnitTestOutcome.Timeout;
- result.TestFailureException = new TestFailedException(UTFUnitTestOutcome.Timeout, string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TestMethodOptions.TimeoutInfo.Timeout));
+ result.TestFailureException = new TestFailedException(UTFUnitTestOutcome.Timeout, string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TimeoutInfo.Timeout));
}
else
{
@@ -969,13 +1010,13 @@ private TestResult ExecuteInternalWithTimeout(object?[]? arguments)
{
DebugEx.Assert(IsTimeoutSet, "Timeout should be set");
- if (TestMethodOptions.TimeoutInfo.CooperativeCancellation)
+ if (TimeoutInfo.CooperativeCancellation)
{
CancellationTokenSource? timeoutTokenSource = null;
try
{
- timeoutTokenSource = new(TestMethodOptions.TimeoutInfo.Timeout);
- timeoutTokenSource.Token.Register(TestMethodOptions.TestContext!.Context.CancellationTokenSource.Cancel);
+ timeoutTokenSource = new(TimeoutInfo.Timeout);
+ timeoutTokenSource.Token.Register(TestContext!.Context.CancellationTokenSource.Cancel);
if (timeoutTokenSource.Token.IsCancellationRequested)
{
return new()
@@ -983,7 +1024,7 @@ private TestResult ExecuteInternalWithTimeout(object?[]? arguments)
Outcome = UTF.UnitTestOutcome.Timeout,
TestFailureException = new TestFailedException(
UTFUnitTestOutcome.Timeout,
- string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TestMethodOptions.TimeoutInfo.Timeout)),
+ string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TimeoutInfo.Timeout)),
};
}
@@ -1001,7 +1042,7 @@ private TestResult ExecuteInternalWithTimeout(object?[]? arguments)
TestFailureException = new TestFailedException(
UTFUnitTestOutcome.Timeout,
timeoutTokenSource.Token.IsCancellationRequested
- ? string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TestMethodOptions.TimeoutInfo.Timeout)
+ ? string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TimeoutInfo.Timeout)
: string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Cancelled, TestMethodName)),
};
}
@@ -1016,7 +1057,7 @@ private TestResult ExecuteInternalWithTimeout(object?[]? arguments)
TestResult? result = null;
Exception? failure = null;
- if (PlatformServiceProvider.Instance.ThreadOperations.Execute(ExecuteAsyncAction, TestMethodOptions.TimeoutInfo.Timeout, TestMethodOptions.TestContext!.Context.CancellationTokenSource.Token))
+ if (PlatformServiceProvider.Instance.ThreadOperations.Execute(ExecuteAsyncAction, TimeoutInfo.Timeout, TestContext!.Context.CancellationTokenSource.Token))
{
if (failure != null)
{
@@ -1032,15 +1073,15 @@ private TestResult ExecuteInternalWithTimeout(object?[]? arguments)
}
// Timed out or canceled
- string errorMessage = string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TestMethodOptions.TimeoutInfo.Timeout);
- if (TestMethodOptions.TestContext.Context.CancellationTokenSource.IsCancellationRequested)
+ string errorMessage = string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Timeout, TestMethodName, TimeoutInfo.Timeout);
+ if (TestContext.Context.CancellationTokenSource.IsCancellationRequested)
{
errorMessage = string.Format(CultureInfo.CurrentCulture, Resource.Execution_Test_Cancelled, TestMethodName);
}
else
{
// Cancel the token source as test has timed out
- TestMethodOptions.TestContext.Context.CancellationTokenSource.Cancel();
+ TestContext.Context.CancellationTokenSource.Cancel();
}
TestResult timeoutResult = new() { Outcome = UTF.UnitTestOutcome.Timeout, TestFailureException = new TestFailedException(UTFUnitTestOutcome.Timeout, errorMessage) };
diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
index 3bb822823c..962eb3ab59 100644
--- a/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
+++ b/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
@@ -64,7 +64,7 @@ public TestMethodRunner(TestMethodInfo testMethodInfo, TestMethod testMethod, IT
internal TestResult[] Execute(string initializationLogs, string initializationErrorLogs, string initializationTrace, string initializationTestContextMessages)
{
bool isSTATestClass = AttributeComparer.IsDerived(_testMethodInfo.Parent.ClassAttribute);
- bool isSTATestMethod = AttributeComparer.IsDerived(_testMethodInfo.TestMethodOptions.Executor);
+ bool isSTATestMethod = AttributeComparer.IsDerived(_testMethodInfo.Executor);
bool isSTARequested = isSTATestClass || isSTATestMethod;
bool isWindowsOS = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (isSTARequested && isWindowsOS && Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
@@ -161,7 +161,7 @@ internal TestResult[] RunTestMethod()
DebugEx.Assert(_testMethodInfo.TestMethod != null, "Test method should not be null.");
List results = [];
- if (_testMethodInfo.TestMethodOptions.Executor == null)
+ if (_testMethodInfo.Executor == null)
{
throw ApplicationStateGuard.Unreachable();
}
@@ -457,7 +457,7 @@ private TestResult[] ExecuteTest(TestMethodInfo testMethodInfo)
{
try
{
- return _testMethodInfo.TestMethodOptions.Executor.Execute(testMethodInfo);
+ return _testMethodInfo.Executor.Execute(testMethodInfo);
}
catch (Exception ex)
{
@@ -469,7 +469,7 @@ private TestResult[] ExecuteTest(TestMethodInfo testMethodInfo)
string.Format(
CultureInfo.CurrentCulture,
Resource.UTA_ExecuteThrewException,
- _testMethodInfo.TestMethodOptions.Executor.GetType().FullName,
+ _testMethodInfo.Executor.GetType().FullName,
ex.ToString()),
ex),
},
diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs b/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs
index 0ebacf9a1d..47a3ce2ef2 100644
--- a/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs
+++ b/src/Adapter/MSTest.TestAdapter/Execution/TypeCache.cs
@@ -80,7 +80,7 @@ public IEnumerable AssemblyInfoListWithExecutableCleanupMethod
/// Get the test method info corresponding to the parameter test Element.
///
/// The .
- public TestMethodInfo? GetTestMethodInfo(TestMethod testMethod, ITestContext testContext, bool captureDebugTraces)
+ public TestMethodInfo? GetTestMethodInfo(TestMethod testMethod, ITestContext testContext)
{
Guard.NotNull(testMethod);
Guard.NotNull(testContext);
@@ -96,7 +96,7 @@ public IEnumerable AssemblyInfoListWithExecutableCleanupMethod
}
// Get the testMethod
- return ResolveTestMethodInfo(testMethod, testClassInfo, testContext, captureDebugTraces);
+ return ResolveTestMethodInfo(testMethod, testClassInfo, testContext);
}
///
@@ -678,16 +678,14 @@ private void UpdateInfoIfTestInitializeOrCleanupMethod(
///
/// The TestMethodInfo for the given test method. Null if the test method could not be found.
///
- private TestMethodInfo ResolveTestMethodInfo(TestMethod testMethod, TestClassInfo testClassInfo, ITestContext testContext, bool captureDebugTraces)
+ private TestMethodInfo ResolveTestMethodInfo(TestMethod testMethod, TestClassInfo testClassInfo, ITestContext testContext)
{
DebugEx.Assert(testMethod != null, "testMethod is Null");
DebugEx.Assert(testClassInfo != null, "testClassInfo is Null");
MethodInfo methodInfo = GetMethodInfoForTestMethod(testMethod, testClassInfo);
- TimeoutInfo timeout = GetTestTimeout(methodInfo, testMethod);
- var testMethodOptions = new TestMethodOptions(timeout, testContext, captureDebugTraces, GetTestMethodAttribute(methodInfo, testClassInfo));
- var testMethodInfo = new TestMethodInfo(methodInfo, testClassInfo, testMethodOptions);
+ var testMethodInfo = new TestMethodInfo(methodInfo, testClassInfo, testContext);
SetCustomProperties(testMethodInfo, testContext);
@@ -700,25 +698,6 @@ private DiscoveryTestMethodInfo ResolveTestMethodInfoForDiscovery(TestMethod tes
return new DiscoveryTestMethodInfo(methodInfo, testClassInfo);
}
- ///
- /// Provides the Test Method Extension Attribute of the TestClass.
- ///
- /// The method info.
- /// The test class info.
- /// Test Method Attribute.
- private TestMethodAttribute GetTestMethodAttribute(MethodInfo methodInfo, TestClassInfo testClassInfo)
- {
- // Get the derived TestMethod attribute from reflection.
- // It should be non-null as it was already validated by IsValidTestMethod.
- TestMethodAttribute testMethodAttribute = _reflectionHelper.GetFirstDerivedAttributeOrDefault(methodInfo, inherit: false)!;
-
- // Get the derived TestMethod attribute from Extended TestClass Attribute
- // If the extended TestClass Attribute doesn't have extended TestMethod attribute then base class returns back the original testMethod Attribute
- testMethodAttribute = testClassInfo.ClassAttribute.GetTestMethodAttribute(testMethodAttribute) ?? testMethodAttribute;
-
- return testMethodAttribute;
- }
-
///
/// Resolves a method by using the method name.
///
@@ -796,31 +775,6 @@ private MethodInfo GetMethodInfoForTestMethod(TestMethod testMethod, TestClassIn
return methods.FirstOrDefault(method => method.DeclaringType!.FullName == testMethod.DeclaringClassFullName);
}
- ///
- /// Gets the test timeout for the parameter test method.
- ///
- /// The method Info.
- /// The test Method.
- /// The timeout value if defined in milliseconds. 0 if not defined.
- private TimeoutInfo GetTestTimeout(MethodInfo methodInfo, TestMethod testMethod)
- {
- DebugEx.Assert(methodInfo != null, "TestMethod should be non-null");
- TimeoutAttribute? timeoutAttribute = _reflectionHelper.GetFirstNonDerivedAttributeOrDefault(methodInfo, inherit: false);
-
- if (timeoutAttribute != null)
- {
- if (!timeoutAttribute.HasCorrectTimeout)
- {
- string message = string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorInvalidTimeout, testMethod.FullClassName, testMethod.Name);
- throw new TypeInspectionException(message);
- }
-
- return TimeoutInfo.FromTimeoutAttribute(timeoutAttribute);
- }
-
- return TimeoutInfo.FromTestTimeoutSettings();
- }
-
///
/// Set custom properties.
///
diff --git a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs
index be00ad50a9..b06727fd44 100644
--- a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs
+++ b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs
@@ -153,8 +153,7 @@ internal async Task RunSingleTestAsync(TestMethod testMethod, IDic
// Get the testMethod
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- testContextForTestExecution,
- MSTestSettings.CurrentSettings.CaptureDebugTraces);
+ testContextForTestExecution);
TestResult[] result;
if (!IsTestMethodRunnable(testMethod, testMethodInfo, out TestResult[]? notRunnableResult))
diff --git a/src/Adapter/MSTest.TestAdapter/ObjectModel/TestMethodOptions.cs b/src/Adapter/MSTest.TestAdapter/ObjectModel/TestMethodOptions.cs
deleted file mode 100644
index 8b1804ce83..0000000000
--- a/src/Adapter/MSTest.TestAdapter/ObjectModel/TestMethodOptions.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
-using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
-
-///
-/// A facade service for options passed to a test method.
-///
-internal sealed record TestMethodOptions(TimeoutInfo TimeoutInfo, ITestContext? TestContext, bool CaptureDebugTraces, TestMethodAttribute Executor);
diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/ClassCleanupManagerTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/ClassCleanupManagerTests.cs
index 183c8d57de..357fd2ad77 100644
--- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/ClassCleanupManagerTests.cs
+++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/ClassCleanupManagerTests.cs
@@ -17,11 +17,11 @@ public class ClassCleanupManagerTests : TestContainer
public void AssemblyCleanupRunsAfterAllTestsFinishEvenIfWeScheduleTheSameTestMultipleTime()
{
ReflectHelper reflectHelper = Mock.Of();
- MethodInfo methodInfo = typeof(ClassCleanupManagerTests).GetMethod(nameof(FakeTestMethod), BindingFlags.Instance | BindingFlags.NonPublic)!;
- MethodInfo classCleanupMethodInfo = typeof(ClassCleanupManagerTests).GetMethod(nameof(FakeClassCleanupMethod), BindingFlags.Instance | BindingFlags.NonPublic)!;
+ MethodInfo methodInfo = typeof(FakeTestClass).GetMethod(nameof(FakeTestClass.FakeTestMethod), BindingFlags.Instance | BindingFlags.NonPublic)!;
+ MethodInfo classCleanupMethodInfo = typeof(FakeTestClass).GetMethod(nameof(FakeTestClass.FakeClassCleanupMethod), BindingFlags.Instance | BindingFlags.NonPublic)!;
// Full class name must agree between unitTestElement.TestMethod.FullClassName and testMethod.FullClassName;
string fullClassName = methodInfo.DeclaringType!.FullName!;
- TestMethod testMethod = new(nameof(FakeTestMethod), fullClassName, typeof(ClassCleanupManagerTests).Assembly.FullName!, isAsync: false);
+ TestMethod testMethod = new(nameof(FakeTestClass.FakeTestMethod), fullClassName, typeof(FakeTestClass).Assembly.FullName!, isAsync: false);
// Setting 2 of the same test to run, we should run assembly cleanup after both these tests
// finish, not after the first one finishes.
@@ -33,7 +33,7 @@ public void AssemblyCleanupRunsAfterAllTestsFinishEvenIfWeScheduleTheSameTestMul
var classCleanupManager = new ClassCleanupManager(testsToRun, ClassCleanupBehavior.EndOfClass, ClassCleanupBehavior.EndOfClass, reflectHelper);
- TestClassInfo testClassInfo = new(typeof(ClassCleanupManagerTests), null!, true, null!, null!)
+ TestClassInfo testClassInfo = new(typeof(FakeTestClass), null!, true, new TestClassAttribute(), null!)
{
// This needs to be set, to allow running class cleanup.
ClassCleanupMethod = classCleanupMethodInfo,
@@ -51,11 +51,17 @@ public void AssemblyCleanupRunsAfterAllTestsFinishEvenIfWeScheduleTheSameTestMul
Assert.IsTrue(classCleanupManager.ShouldRunEndOfAssemblyCleanup);
}
- private void FakeTestMethod()
+ [TestClass]
+ private class FakeTestClass
{
- }
+ [TestMethod]
+ internal void FakeTestMethod()
+ {
+ }
- private void FakeClassCleanupMethod()
- {
+ [ClassCleanup]
+ internal void FakeClassCleanupMethod()
+ {
+ }
}
}
diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodInfoTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodInfoTests.cs
index a34b3ae398..42e058a3e4 100644
--- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodInfoTests.cs
+++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodInfoTests.cs
@@ -41,8 +41,6 @@ public class TestMethodInfoTests : TestContainer
private readonly UTF.ExpectedExceptionAttribute _expectedException;
- private readonly TestMethodOptions _testMethodOptions;
-
public TestMethodInfoTests()
{
_constructorInfo = typeof(DummyTestClass).GetConstructor([])!;
@@ -55,12 +53,15 @@ public TestMethodInfoTests()
_testContextImplementation = new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary());
_testClassInfo = new TestClassInfo(typeof(DummyTestClass), _constructorInfo, true, _classAttribute, _testAssemblyInfo);
_expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException));
- _testMethodOptions = new TestMethodOptions(TimeoutInfo.FromTimeout(3600 * 1000), _testContextImplementation, false, _testMethodAttribute);
_testMethodInfo = new TestMethodInfo(
_methodInfo,
parent: _testClassInfo,
- testMethodOptions: _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
// Reset test hooks
DummyTestClass.TestConstructorMethodBody = () => { };
@@ -89,7 +90,11 @@ public void TestMethodInfoInvokeShouldWaitForAsyncTestMethodsToComplete()
DummyTestClass.DummyAsyncTestMethodBody = () => Task.Run(() => methodCalled = true);
MethodInfo asyncMethodInfo = typeof(DummyTestClass).GetMethod("DummyAsyncTestMethod")!;
- var method = new TestMethodInfo(asyncMethodInfo, _testClassInfo, _testMethodOptions);
+ var method = new TestMethodInfo(asyncMethodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -105,7 +110,11 @@ public void TestMethodInfoInvokeAsyncShouldHandleThrowAssertInconclusive()
var method = new TestMethodInfo(
asyncMethodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -120,7 +129,11 @@ public void TestMethodInfoInvokeAsyncShouldHandleAssertInconclusive()
var method = new TestMethodInfo(
asyncMethodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -135,7 +148,11 @@ public void TestMethodInfoInvokeShouldHandleThrowAssertInconclusive()
var method = new TestMethodInfo(
dummyMethodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -150,7 +167,11 @@ public void TestMethodInfoInvokeShouldHandleAssertInconclusive()
var method = new TestMethodInfo(
dummyMethodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -164,7 +185,11 @@ public void TestMethodInfoInvokeShouldReportTestContextMessages()
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -178,7 +203,11 @@ public void TestMethodInfoInvokeShouldClearTestContextMessagesAfterReporting()
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -207,7 +236,11 @@ public void Invoke_WhenTestMethodThrowsMissingMethodException_TestOutcomeIsFaile
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -259,7 +292,11 @@ public void TestMethodInfoInvokeShouldSetErrorMessageIfTestClassConstructorThrow
{
ConstructorInfo ctorInfo = typeof(DummyTestClassWithParameterizedCtor).GetConstructors().Single();
var testClass = new TestClassInfo(typeof(DummyTestClassWithParameterizedCtor), ctorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(_methodInfo, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(_methodInfo, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
string errorMessage = string.Format(
@@ -289,7 +326,11 @@ public void TestMethodInfoInvokeShouldSetStackTraceInformationIfTestClassConstru
{
ConstructorInfo ctorInfo = typeof(DummyTestClassWithParameterizedCtor).GetConstructors().Single();
var testClass = new TestClassInfo(typeof(DummyTestClassWithParameterizedCtor), ctorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(_methodInfo, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(_methodInfo, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
var exception = method.Invoke(null).TestFailureException as TestFailedException;
@@ -308,7 +349,11 @@ public void TestMethodInfoInvokeShouldSetResultFilesIfTestContextHasAttachments(
testContext.SetupGet(tc => tc.Context).Returns(mockInnerContext.Object);
mockInnerContext.SetupGet(tc => tc.CancellationTokenSource).Returns(new CancellationTokenSource());
- var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions with { TestContext = testContext.Object });
+ var method = new TestMethodInfo(_methodInfo, _testClassInfo, testContext.Object)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
Verify(result.ResultFiles!.Contains("C:\\temp.txt"));
@@ -318,7 +363,11 @@ public void TestMethodInfoInvoke_WhenCtorHasOneParameterOfTypeTestContext_SetsIt
{
ConstructorInfo ctorInfo = typeof(DummyTestClass).GetConstructor([typeof(UTFExtension.TestContext)])!;
var testClassInfo = new TestClassInfo(typeof(DummyTestClass), ctorInfo, false, _classAttribute, _testAssemblyInfo);
- var testMethodInfo = new TestMethodInfo(_methodInfo, testClassInfo, _testMethodOptions);
+ var testMethodInfo = new TestMethodInfo(_methodInfo, testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -332,7 +381,11 @@ public void TestMethodInfoInvoke_WhenCtorHasOneParameterOfTypeTestContext_SetsIt
public void TestMethodInfoInvokeShouldNotThrowIfTestContextIsNotPresent()
{
var testClass = new TestClassInfo(typeof(DummyTestClass), _constructorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(_methodInfo, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(_methodInfo, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result;
void RunMethod() => result = method.Invoke(null);
@@ -344,7 +397,11 @@ public void TestMethodInfoInvokeShouldNotThrowIfTestContextIsNotPresent()
public void TestMethodInfoInvokeShouldNotThrowIfTestContextDoesNotHaveASetter()
{
var testClass = new TestClassInfo(typeof(DummyTestClass), _constructorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(_methodInfo, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(_methodInfo, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result;
void RunMethod() => result = method.Invoke(null);
@@ -404,7 +461,11 @@ public void TestMethodInfoInvoke_WhenCtorHasOneParameterOfTypeTestContextAndTest
{
ConstructorInfo ctorInfo = typeof(DummyTestClass).GetConstructor([typeof(UTFExtension.TestContext)])!;
var testClassInfo = new TestClassInfo(typeof(DummyTestClass), ctorInfo, false, _classAttribute, _testAssemblyInfo);
- var testMethodInfo = new TestMethodInfo(_methodInfo, testClassInfo, _testMethodOptions);
+ var testMethodInfo = new TestMethodInfo(_methodInfo, testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTFExtension.TestContext? testContext = null;
DummyTestClass.TestContextSetterBody = context => testContext = context as UTFExtension.TestContext;
@@ -494,7 +555,12 @@ public void TestMethodInfoInvokeWhenTestThrowsReturnsExpectedResult()
_testClassInfo.TestInitializeMethod!.Name,
"System.ArgumentException: Some exception message ---> System.InvalidOperationException: Inner exception message");
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
// Act.
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -519,7 +585,12 @@ public void TestInitialize_WhenTestReturnsTaskFromException_DisplayProperExcepti
// Arrange.
DummyTestClass.TestInitializeMethodBodyAsync = async classInstance => await Task.FromException(new Exception("Outer", new InvalidOperationException("Inner")));
_testClassInfo.TestInitializeMethod = typeof(DummyTestClass).GetMethod("DummyTestInitializeMethodAsync")!;
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
// Act.
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -555,7 +626,12 @@ public void TestMethodInfoInvokeWhenTestThrowsAssertFailReturnsExpectedResult()
_testClassInfo.TestInitializeMethod!.Name,
"Assert.Fail failed. dummyFailMessage");
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
// Act.
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -586,7 +662,12 @@ public void TestMethodInfoInvokeWhenTestThrowsAssertInconclusiveReturnsExpectedR
_testClassInfo.TestInitializeMethod!.Name,
"Assert.Inconclusive failed. dummyFailMessage");
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
// Act.
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -614,7 +695,11 @@ public void TestCleanup_WhenTestReturnsTaskFromException_DisplayProperException(
// Arrange.
DummyTestClass.TestCleanupMethodBodyAsync = async classInstance => await Task.FromException(new Exception("Outer", new InvalidOperationException("Inner")));
_testClassInfo.TestCleanupMethod = typeof(DummyTestClass).GetMethod("DummyTestCleanupMethodAsync")!;
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions);
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
// Act.
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -876,7 +961,11 @@ public void TestMethodInfoInvokeShouldCallDisposeForDisposableTestClass()
DummyTestClassWithDisposable.DisposeMethodBody = () => disposeCalled = true;
ConstructorInfo ctorInfo = typeof(DummyTestClassWithDisposable).GetConstructor([])!;
var testClass = new TestClassInfo(typeof(DummyTestClassWithDisposable), ctorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(typeof(DummyTestClassWithDisposable).GetMethod("DummyTestMethod")!, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(typeof(DummyTestClassWithDisposable).GetMethod("DummyTestMethod")!, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
method.Invoke(null);
@@ -891,7 +980,11 @@ public void TestMethodInfoInvoke_WhenTestClassIsAsyncDisposable_ShouldDisposeAsy
DummyTestClassWithAsyncDisposable.DisposeAsyncMethodBody = () => asyncDisposeCalled = true;
ConstructorInfo ctorInfo = typeof(DummyTestClassWithAsyncDisposable).GetConstructor([])!;
var testClass = new TestClassInfo(typeof(DummyTestClassWithAsyncDisposable), ctorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(typeof(DummyTestClassWithAsyncDisposable).GetMethod("DummyTestMethod")!, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(typeof(DummyTestClassWithAsyncDisposable).GetMethod("DummyTestMethod")!, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
// Act
method.Invoke(null);
@@ -912,7 +1005,11 @@ public void TestMethodInfoInvoke_WhenTestClassIsDisposableAndAsyncDisposable_Sho
ConstructorInfo ctorInfo = typeof(DummyTestClassWithAsyncDisposableAndDisposable).GetConstructor([])!;
var testClass = new TestClassInfo(typeof(DummyTestClassWithAsyncDisposableAndDisposable), ctorInfo, true, _classAttribute, _testAssemblyInfo);
- var method = new TestMethodInfo(typeof(DummyTestClassWithAsyncDisposableAndDisposable).GetMethod("DummyTestMethod")!, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(typeof(DummyTestClassWithAsyncDisposableAndDisposable).GetMethod("DummyTestMethod")!, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
// Act
method.Invoke(null);
@@ -933,7 +1030,11 @@ public void TestMethodInfoInvokeShouldCallDisposeForDisposableTestClassIfTestCle
{
TestCleanupMethod = typeof(DummyTestClassWithDisposable).GetMethod("DummyTestCleanupMethod")!,
};
- var method = new TestMethodInfo(typeof(DummyTestClassWithDisposable).GetMethod("DummyTestMethod")!, testClass, _testMethodOptions);
+ var method = new TestMethodInfo(typeof(DummyTestClassWithDisposable).GetMethod("DummyTestMethod")!, testClass, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
method.Invoke(null);
@@ -996,7 +1097,12 @@ public void TestMethodInfoInvokeShouldNotCallTestCleanupIfClassSetContextThrows(
public void TestMethodInfoInvokeShouldSetResultAsPassedIfExpectedExceptionIsThrown()
{
DummyTestClass.TestMethodBody = o => throw new DivideByZeroException();
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -1006,7 +1112,12 @@ public void TestMethodInfoInvokeShouldSetResultAsPassedIfExpectedExceptionIsThro
public void TestMethodInfoInvokeShouldSetResultAsFailedIfExceptionDifferentFromExpectedExceptionIsThrown()
{
DummyTestClass.TestMethodBody = o => throw new IndexOutOfRangeException();
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -1019,7 +1130,12 @@ public void TestMethodInfoInvokeShouldSetResultAsFailedIfExceptionDifferentFromE
public void TestMethodInfoInvokeShouldSetResultAsFailedWhenExceptionIsExpectedButIsNotThrown()
{
DummyTestClass.TestMethodBody = o => { return; };
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
UTF.TestResult result = testMethodInfo.Invoke(null);
Verify(result.Outcome == UTF.UnitTestOutcome.Failed);
string message = "Test method did not throw expected exception System.DivideByZeroException.";
@@ -1029,7 +1145,12 @@ public void TestMethodInfoInvokeShouldSetResultAsFailedWhenExceptionIsExpectedBu
public void TestMethodInfoInvokeShouldSetResultAsInconclusiveWhenExceptionIsAssertInconclusiveException()
{
DummyTestClass.TestMethodBody = o => throw new UTF.AssertInconclusiveException();
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
UTF.TestResult result = testMethodInfo.Invoke(null);
Verify(result.Outcome == UTF.UnitTestOutcome.Inconclusive);
string message = "Exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException' was thrown.";
@@ -1048,7 +1169,12 @@ public void TestMethodInfoInvokeShouldSetTestOutcomeBeforeTestCleanup()
}
};
_testClassInfo.TestCleanupMethod = typeof(DummyTestClass).GetMethod("DummyTestCleanupMethod")!;
- var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions) { ExpectedException = _expectedException };
+ var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ ExpectedException = _expectedException,
+ };
UTF.TestResult result = testMethodInfo.Invoke(null);
@@ -1061,8 +1187,10 @@ public void HandleMethodExceptionShouldInvokeVerifyOfCustomExpectedException()
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = customExpectedException,
};
@@ -1078,8 +1206,10 @@ public void HandleMethodExceptionShouldSetOutcomeAsFailedIfVerifyOfExpectedExcep
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = customExpectedException,
};
@@ -1095,8 +1225,10 @@ public void HandleMethodExceptionShouldSetOutcomeAsInconclusiveIfVerifyOfExpecte
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = customExpectedException,
};
@@ -1113,8 +1245,10 @@ public void HandleMethodExceptionShouldInvokeVerifyOfDerivedCustomExpectedExcept
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = derivedCustomExpectedException,
};
@@ -1133,8 +1267,10 @@ public void VerifyShouldNotThrowIfThrownExceptionCanBeAssignedToExpectedExceptio
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = expectedException,
};
@@ -1152,8 +1288,10 @@ public void VerifyShouldThrowExceptionIfThrownExceptionCannotBeAssignedToExpecte
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = expectedException,
};
@@ -1174,8 +1312,10 @@ public void VerifyShouldRethrowExceptionIfThrownExceptionIsAssertFailedException
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = expectedException,
};
@@ -1195,8 +1335,10 @@ public void VerifyShouldRethrowExceptionIfThrownExceptionIsAssertInconclusiveExc
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = expectedException,
};
@@ -1213,8 +1355,10 @@ public void VerifyShouldThrowIfThrownExceptionIsNotSameAsExpectedException()
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = expectedException,
};
@@ -1232,8 +1376,10 @@ public void VerifyShouldRethrowIfThrownExceptionIsAssertExceptionWhichIsNotSameA
var method = new TestMethodInfo(
_methodInfo,
_testClassInfo,
- _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(0) })
+ _testContextImplementation)
{
+ TimeoutInfo = TimeoutInfo.FromTimeout(0),
+ Executor = _testMethodAttribute,
ExpectedException = expectedException,
};
@@ -1254,7 +1400,11 @@ public void ResolveExpectedExceptionShouldThrowWhenAttributeIsDefinedTwice_Diffe
new UTF.TestClassAttribute(),
new TestAssemblyInfo(typeof(DummyTestClassForExpectedException).Assembly));
- TypeInspectionException ex = UTF.Assert.ThrowsException(() => new TestMethodInfo(testMethodInfo, classInfo, _testMethodOptions));
+ TypeInspectionException ex = UTF.Assert.ThrowsException(() => new TestMethodInfo(testMethodInfo, classInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ });
UTF.Assert.AreEqual("The test method 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests+DummyTestClassForExpectedException.DummyTestMethod1' has multiple attributes derived from 'ExpectedExceptionBaseAttribute' defined on it. Only one such attribute is allowed.", ex.Message);
}
@@ -1268,7 +1418,11 @@ public void ResolveExpectedExceptionShouldThrowWhenAttributeIsDefinedTwice_SameC
new UTF.TestClassAttribute(),
new TestAssemblyInfo(typeof(DummyTestClassForExpectedException).Assembly));
- TypeInspectionException ex = UTF.Assert.ThrowsException(() => new TestMethodInfo(testMethodInfo, classInfo, _testMethodOptions));
+ TypeInspectionException ex = UTF.Assert.ThrowsException(() => new TestMethodInfo(testMethodInfo, classInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ });
UTF.Assert.AreEqual("The test method 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestMethodInfoTests+DummyTestClassForExpectedException.DummyTestMethod1' has multiple attributes derived from 'ExpectedExceptionBaseAttribute' defined on it. Only one such attribute is allowed.", ex.Message);
}
@@ -1283,7 +1437,11 @@ public void ResolveExpectedExceptionHelperShouldReturnExpectedExceptionAttribute
new UTF.TestClassAttribute(),
new TestAssemblyInfo(typeof(DummyTestClassForExpectedException).Assembly));
- var testMethodInfo = new TestMethodInfo(methodInfo, classInfo, _testMethodOptions);
+ var testMethodInfo = new TestMethodInfo(methodInfo, classInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
Verify(testMethodInfo.ExpectedException is not null);
Verify(((UTF.ExpectedExceptionAttribute)testMethodInfo.ExpectedException).ExceptionType == typeof(DivideByZeroException));
@@ -1300,7 +1458,11 @@ public void ResolveExpectedExceptionHelperShouldReturnNullIfExpectedExceptionAtt
new UTF.TestClassAttribute(),
new TestAssemblyInfo(typeof(DummyTestClassForExpectedException).Assembly));
- var testMethodInfo = new TestMethodInfo(methodInfo, classInfo, _testMethodOptions);
+ var testMethodInfo = new TestMethodInfo(methodInfo, classInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
Verify(testMethodInfo.ExpectedException is null);
}
@@ -1351,7 +1513,11 @@ public void TestMethodInfoInvokeShouldReturnTestFailureOnTimeout()
testablePlatformServiceProvider.MockThreadOperations.Setup(
to => to.Execute(It.IsAny(), It.IsAny(), It.IsAny())).Returns(false);
- var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(1) });
+ var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(1),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
@@ -1363,7 +1529,11 @@ public void TestMethodInfoInvokeShouldReturnTestFailureOnTimeout()
public void TestMethodInfoInvokeShouldReturnTestPassedOnCompletionWithinTimeout()
{
DummyTestClass.TestMethodBody = o => { /* do nothing */ };
- var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions);
+ var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
Verify(result.Outcome == UTF.UnitTestOutcome.Passed);
}
@@ -1379,7 +1549,11 @@ public void TestMethodInfoInvokeShouldCancelTokenSourceOnTimeout()
testablePlatformServiceProvider.MockThreadOperations.Setup(
to => to.Execute(It.IsAny(), It.IsAny(), It.IsAny())).Returns(false);
- var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(1) });
+ var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(1),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
Verify(result.Outcome == UTF.UnitTestOutcome.Timeout);
@@ -1409,7 +1583,11 @@ public void TestMethodInfoInvokeShouldFailOnTokenSourceCancellation()
});
_testContextImplementation.CancellationTokenSource.CancelAfter(100);
- var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions with { TimeoutInfo = TimeoutInfo.FromTimeout(100000) });
+ var method = new TestMethodInfo(_methodInfo, _testClassInfo, _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(100000),
+ Executor = _testMethodAttribute,
+ };
UTF.TestResult result = method.Invoke(null);
Verify(result.Outcome == UTF.UnitTestOutcome.Timeout);
@@ -1427,7 +1605,11 @@ public void ResolveArgumentsShouldReturnProvidedArgumentsWhenTooFewParameters()
var method = new TestMethodInfo(
simpleArgumentsMethod,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
object[] arguments = ["RequiredStr1"];
object[] expectedArguments = ["RequiredStr1"];
@@ -1444,7 +1626,11 @@ public void ResolveArgumentsShouldReturnProvidedArgumentsWhenTooManyParameters()
var method = new TestMethodInfo(
simpleArgumentsMethod,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
object?[] arguments = ["RequiredStr1", "RequiredStr2", "ExtraStr3"];
object?[] expectedArguments = ["RequiredStr1", "RequiredStr2", "ExtraStr3"];
@@ -1461,7 +1647,11 @@ public void ResolveArgumentsShouldReturnAdditionalOptionalParametersWithNoneProv
var method = new TestMethodInfo(
optionalArgumentsMethod,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
object?[] arguments = ["RequiredStr1"];
object?[] expectedArguments = ["RequiredStr1", null, null];
@@ -1478,7 +1668,11 @@ public void ResolveArgumentsShouldReturnAdditionalOptionalParametersWithSomeProv
var method = new TestMethodInfo(
optionalArgumentsMethod,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
object?[] arguments = ["RequiredStr1", "OptionalStr1"];
object?[] expectedArguments = ["RequiredStr1", "OptionalStr1", null];
@@ -1495,7 +1689,11 @@ public void ResolveArgumentsShouldReturnEmptyParamsWithNoneProvided()
var method = new TestMethodInfo(
paramsArgumentMethod,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
object[] arguments = [1];
object[] expectedArguments = [1, Array.Empty()];
@@ -1514,7 +1712,11 @@ public void ResolveArgumentsShouldReturnPopulatedParamsWithAllProvided()
var method = new TestMethodInfo(
paramsArgumentMethod,
_testClassInfo,
- _testMethodOptions);
+ _testContextImplementation)
+ {
+ TimeoutInfo = TimeoutInfo.FromTimeout(3600 * 1000),
+ Executor = _testMethodAttribute,
+ };
object[] arguments = [1, "str1", "str2", "str3"];
object[] expectedArguments = [1, new string[] { "str1", "str2", "str3" }];
diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodRunnerTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodRunnerTests.cs
index 4ebf9748e4..0ac437c610 100644
--- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodRunnerTests.cs
+++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestMethodRunnerTests.cs
@@ -6,6 +6,7 @@
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
+using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.TestableImplementations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -42,7 +43,7 @@ public TestMethodRunnerTests()
_testContextImplementation = new TestContextImplementation(_testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary());
_testClassInfo = GetTestClassInfo();
- _testMethodOptions = new TestMethodOptions(TimeoutInfo.FromTimeout(200), _testContextImplementation, false, _testMethodAttribute);
+ _testMethodOptions = new TestMethodOptions(TimeoutInfo.FromTimeout(200), _testContextImplementation, _testMethodAttribute);
// Reset test hooks
DummyTestClass.TestConstructorMethodBody = () => { };
@@ -159,7 +160,7 @@ public void RunTestMethodForMultipleResultsReturnMultipleResults()
new TestResult { Outcome = UTF.UnitTestOutcome.Failed },
]);
- var localTestMethodOptions = new TestMethodOptions(TimeoutInfo.FromTimeout(200), _testContextImplementation, false, testMethodAttributeMock.Object);
+ var localTestMethodOptions = new TestMethodOptions(TimeoutInfo.FromTimeout(200), _testContextImplementation, testMethodAttributeMock.Object);
var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, localTestMethodOptions, null!);
var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
@@ -213,19 +214,18 @@ public void RunTestMethodShouldGiveTestResultAsFailedWhenTestMethodFails()
public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataSourceAttribute()
{
- var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => new TestResult() { Outcome = UTF.UnitTestOutcome.Passed });
- var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
-
DataSourceAttribute dataSourceAttribute = new("DummyConnectionString", "DummyTableName");
var attributes = new Attribute[] { dataSourceAttribute };
- TestDataSource testDataSource = new();
-
// Setup mocks
_testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(_methodInfo, It.IsAny())).Returns(attributes);
+
+ var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => new TestResult() { Outcome = UTF.UnitTestOutcome.Passed });
_testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.GetData(testMethodInfo, _testContextImplementation)).Returns([1, 2, 3]);
+ var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
+
TestResult[] results = testMethodRunner.RunTestMethod();
// check for outcome
@@ -261,15 +261,15 @@ public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataRowA
public void RunTestMethodShouldSetDataRowIndexForDataDrivenTestsWhenDataIsProvidedUsingDataSourceAttribute()
{
- var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => new UTF.TestResult());
- var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
+ MethodInfo methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals(nameof(DummyTestClass.DummyDataSourceTestMethod), StringComparison.Ordinal));
+ object[] attributes = methodInfo.GetCustomAttributes(inherit: false);
- DataSourceAttribute dataSourceAttribute = new("DummyConnectionString", "DummyTableName");
+ // Setup mocks
+ _testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(methodInfo, It.IsAny())).Returns(attributes);
- var attributes = new Attribute[] { dataSourceAttribute };
+ var testMethodInfo = new TestableTestMethodInfo(methodInfo, _testClassInfo, _testMethodOptions, () => new UTF.TestResult());
+ var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
- // Setup mocks
- _testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(_methodInfo, It.IsAny())).Returns(attributes);
_testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.GetData(testMethodInfo, _testContextImplementation)).Returns([1, 2, 3]);
TestResult[] results = testMethodRunner.RunTestMethod();
@@ -282,9 +282,6 @@ public void RunTestMethodShouldSetDataRowIndexForDataDrivenTestsWhenDataIsProvid
public void RunTestMethodShouldRunOnlyDataSourceTestsWhenBothDataSourceAndDataRowAreProvided()
{
- var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => new UTF.TestResult());
- var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
-
DataSourceAttribute dataSourceAttribute = new("DummyConnectionString", "DummyTableName");
int dummyIntData = 2;
string dummyStringData = "DummyString";
@@ -296,6 +293,10 @@ public void RunTestMethodShouldRunOnlyDataSourceTestsWhenBothDataSourceAndDataRo
// Setup mocks
_testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(_methodInfo, It.IsAny())).Returns(attributes);
+
+ var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => new UTF.TestResult());
+ var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
+
_testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.GetData(testMethodInfo, _testContextImplementation)).Returns([1, 2, 3]);
TestResult[] results = testMethodRunner.RunTestMethod();
@@ -309,8 +310,6 @@ public void RunTestMethodShouldRunOnlyDataSourceTestsWhenBothDataSourceAndDataRo
public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvidedForDataDrivenTests()
{
TestResult testResult = new();
- var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
- var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
int dummyIntData = 2;
string dummyStringData = "DummyString";
@@ -324,6 +323,9 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvided
// Setup mocks
_testablePlatformServiceProvider.MockReflectionOperations.Setup(ro => ro.GetCustomAttributes(_methodInfo, It.IsAny())).Returns(attributes);
+ var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
+ var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
+
TestResult[] results = testMethodRunner.RunTestMethod();
Verify(results.Length == 1);
@@ -333,8 +335,6 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvided
public void RunTestMethodShouldFillInDisplayNameWithDataRowArgumentsIfNoDisplayNameIsProvidedForDataDrivenTests()
{
TestResult testResult = new();
- var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
- var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
int dummyIntData = 2;
string dummyStringData = "DummyString";
@@ -347,6 +347,9 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowArgumentsIfNoDisplayN
// Setup mocks
_testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(_methodInfo, It.IsAny())).Returns(attributes);
+ var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
+ var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
+
TestResult[] results = testMethodRunner.RunTestMethod();
Verify(results.Length == 1);
@@ -360,9 +363,6 @@ public void RunTestMethodShouldSetResultFilesIfPresentForDataDrivenTests()
ResultFiles = new List() { "C:\\temp.txt" },
};
- var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
- var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
-
int dummyIntData1 = 1;
int dummyIntData2 = 2;
DataRowAttribute dataRowAttribute1 = new(dummyIntData1);
@@ -373,6 +373,9 @@ public void RunTestMethodShouldSetResultFilesIfPresentForDataDrivenTests()
// Setup mocks
_testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(_methodInfo, It.IsAny())).Returns(attributes);
+ var testMethodInfo = new TestableTestMethodInfo(_methodInfo, _testClassInfo, _testMethodOptions, () => testResult);
+ var testMethodRunner = new TestMethodRunner(testMethodInfo, _testMethod, _testContextImplementation);
+
TestResult[] results = testMethodRunner.RunTestMethod();
Verify(results[0].ResultFiles!.Contains("C:\\temp.txt"));
Verify(results[1].ResultFiles!.Contains("C:\\temp.txt"));
@@ -437,12 +440,33 @@ private static void InitMethodThrowingException(TestContext tc)
=> throw new ArgumentException();
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
- public class TestableTestMethodInfo : TestMethodInfo
+ private sealed class TestMethodOptions
+ {
+ public TimeoutInfo TimeoutInfo { get; }
+
+ public ITestContext TestContext { get; }
+
+ public TestMethodAttribute TestMethodAttribute { get; }
+
+ public TestMethodOptions(TimeoutInfo timeoutInfo, ITestContext testContextImplementation, TestMethodAttribute testMethodAttribute)
+ {
+ TimeoutInfo = timeoutInfo;
+ TestContext = testContextImplementation;
+ TestMethodAttribute = testMethodAttribute;
+ }
+ }
+
+ private class TestableTestMethodInfo : TestMethodInfo
{
private readonly Func _invokeTest;
internal TestableTestMethodInfo(MethodInfo testMethod, TestClassInfo parent, TestMethodOptions testMethodOptions, Func invoke)
- : base(testMethod, parent, testMethodOptions) => _invokeTest = invoke;
+ : base(testMethod, parent, testMethodOptions.TestContext)
+ {
+ TimeoutInfo = testMethodOptions.TimeoutInfo;
+ Executor = testMethodOptions.TestMethodAttribute;
+ _invokeTest = invoke;
+ }
public override TestResult Invoke(object?[]? arguments) =>
// Ignore args for now
@@ -493,6 +517,9 @@ public TestContext TestContext
public void DummyTestMethod() => TestMethodBody(this);
+ [DataSource("DummyConnectionString", "DummyTableName")]
+ public void DummyDataSourceTestMethod() => TestMethodBody(this);
+
public Task DummyAsyncTestMethod() =>
// We use this method to validate async TestInitialize, TestCleanup, TestMethod
DummyAsyncTestMethodBody();
diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestPropertyAttributeTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestPropertyAttributeTests.cs
index 0c8c44aa3e..cb1fa3b141 100644
--- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestPropertyAttributeTests.cs
+++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestPropertyAttributeTests.cs
@@ -50,8 +50,7 @@ public void GetTestMethodInfoShouldAddPropertiesFromContainingClassCorrectly()
_ = _typeCache.GetTestMethodInfo(
testMethod,
- testContext,
- false);
+ testContext);
Assert.IsTrue(testContext.TryGetPropertyValue("TestMethodKeyFromBase", out object? value1));
Assert.AreEqual("TestMethodValueFromBase", value1);
@@ -81,8 +80,7 @@ public void GetTestMethodInfoShouldAddPropertiesFromContainingClassAndBaseClasse
_ = _typeCache.GetTestMethodInfo(
testMethod,
- testContext,
- false);
+ testContext);
Assert.IsTrue(testContext.TryGetPropertyValue("DerivedMethod1Key", out object? value1));
Assert.AreEqual("DerivedMethod1Value", value1);
@@ -127,8 +125,7 @@ public void GetTestMethodInfoShouldAddPropertiesFromContainingClassAndBaseClasse
_ = _typeCache.GetTestMethodInfo(
testMethod,
- testContext,
- false);
+ testContext);
Assert.IsTrue(testContext.TryGetPropertyValue("DerivedMethod2Key", out object? value1));
Assert.AreEqual("DerivedMethod2Value", value1);
diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TypeCacheTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TypeCacheTests.cs
index d8fb1597b7..b64f05e4cb 100644
--- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TypeCacheTests.cs
+++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TypeCacheTests.cs
@@ -58,13 +58,13 @@ public void GetTestMethodInfoShouldThrowIfTestMethodIsNull()
var testMethod = new TestMethod("M", "C", "A", isAsync: false);
var context = new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary());
- VerifyThrows(() => _typeCache.GetTestMethodInfo(null!, context, false));
+ VerifyThrows(() => _typeCache.GetTestMethodInfo(null!, context));
}
public void GetTestMethodInfoShouldThrowIfTestContextIsNull()
{
var testMethod = new TestMethod("M", "C", "A", isAsync: false);
- VerifyThrows(() => _typeCache.GetTestMethodInfo(testMethod, null!, false));
+ VerifyThrows(() => _typeCache.GetTestMethodInfo(testMethod, null!));
}
public void GetTestMethodInfoShouldReturnNullIfClassInfoForTheMethodIsNull()
@@ -74,8 +74,7 @@ public void GetTestMethodInfoShouldReturnNullIfClassInfoForTheMethodIsNull()
Verify(
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false) is null);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary())) is null);
}
public void GetTestMethodInfoShouldReturnNullIfLoadingTypeThrowsTypeLoadException()
@@ -85,8 +84,7 @@ public void GetTestMethodInfoShouldReturnNullIfLoadingTypeThrowsTypeLoadExceptio
Verify(
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false) is null);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary())) is null);
}
public void GetTestMethodInfoShouldThrowIfLoadingTypeThrowsException()
@@ -99,8 +97,7 @@ public void GetTestMethodInfoShouldThrowIfLoadingTypeThrowsException()
void Action() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TypeInspectionException exception = VerifyThrows(Action);
@@ -115,8 +112,7 @@ public void GetTestMethodInfoShouldThrowIfTypeDoesNotHaveADefaultConstructor()
void Action() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TypeInspectionException exception = VerifyThrows(Action);
Verify(exception.Message.StartsWith("Cannot find a valid constructor for test class 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TypeCacheTests+DummyTestClassWithNoDefaultConstructor'. Valid constructors are 'public' and either parameterless or with one parameter of type 'TestContext'.", StringComparison.Ordinal));
@@ -130,8 +126,7 @@ public void GetTestMethodInfoShouldThrowIfTestContextHasATypeMismatch()
void Action() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TypeInspectionException exception = VerifyThrows(Action);
Verify(exception.Message.StartsWith($"The {className}.TestContext has incorrect type.", StringComparison.Ordinal));
@@ -145,8 +140,7 @@ public void GetTestMethodInfoShouldThrowIfTestContextHasMultipleAmbiguousTestCon
void Action() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TypeInspectionException exception = VerifyThrows(Action);
Verify(exception.Message.StartsWith(string.Format(CultureInfo.InvariantCulture, "Unable to find property {0}.TestContext. Error:{1}.", className, "Ambiguous match found."), StringComparison.Ordinal));
@@ -163,8 +157,7 @@ public void GetTestMethodInfoShouldSetTestContextIfPresent()
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(testMethodInfo is not null);
Verify(testMethodInfo.Parent.TestContextProperty is not null);
@@ -181,8 +174,7 @@ public void GetTestMethodInfoShouldSetTestContextToNullIfNotPresent()
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(testMethodInfo is not null);
Verify(testMethodInfo.Parent.TestContextProperty is null);
@@ -201,8 +193,7 @@ public void GetTestMethodInfoShouldAddAssemblyInfoToTheCache()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.AssemblyInfoCache.Count == 1);
}
@@ -221,8 +212,7 @@ public void GetTestMethodInfoShouldNotThrowIfWeFailToDiscoverTypeFromAnAssembly(
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.AssemblyInfoCache.Count == 1);
}
@@ -240,8 +230,7 @@ public void GetTestMethodInfoShouldCacheAssemblyInitializeAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.AssemblyInfoCache.Count == 1);
Verify(type.GetMethod("AssemblyInit")! == _typeCache.AssemblyInfoCache.First().AssemblyInitializeMethod);
@@ -260,8 +249,7 @@ public void GetTestMethodInfoShouldCacheAssemblyCleanupAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.AssemblyInfoCache.Count == 1);
Verify(type.GetMethod("AssemblyCleanup")! == _typeCache.AssemblyInfoCache.First().AssemblyCleanupMethod);
@@ -282,8 +270,7 @@ public void GetTestMethodInfoShouldCacheAssemblyInitAndCleanupAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.AssemblyInfoCache.Count == 1);
Verify(type.GetMethod("AssemblyCleanup")! == _typeCache.AssemblyInfoCache.First().AssemblyCleanupMethod);
@@ -304,8 +291,7 @@ public void GetTestMethodInfoShouldThrowIfAssemblyInitHasIncorrectSignature()
void A() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Exception exception = VerifyThrows(A);
@@ -334,8 +320,7 @@ public void GetTestMethodInfoShouldThrowIfAssemblyCleanupHasIncorrectSignature()
void A() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Exception exception = VerifyThrows(A);
@@ -361,13 +346,11 @@ public void GetTestMethodInfoShouldCacheAssemblyInfoInstanceAndReuseTheCache()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
_mockReflectHelper.Verify(rh => rh.IsDerivedAttributeDefined(type, false), Times.Once);
Verify(_typeCache.AssemblyInfoCache.Count == 1);
@@ -388,8 +371,7 @@ public void GetTestMethodInfoShouldAddClassInfoToTheCache()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(_typeCache.ClassInfoCache.First().TestInitializeMethod is null);
@@ -409,8 +391,7 @@ public void GetTestMethodInfoShouldCacheClassInitializeAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(_typeCache.ClassInfoCache.First().BaseClassInitMethods.Count == 0);
@@ -438,8 +419,7 @@ public void GetTestMethodInfoShouldCacheBaseClassInitializeAttributes()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(_typeCache.ClassInfoCache.First().BaseClassCleanupMethods.Count == 0, "No base class cleanup");
@@ -459,8 +439,7 @@ public void GetTestMethodInfoShouldCacheClassCleanupAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(type.GetMethod("AssemblyCleanup")! == _typeCache.ClassInfoCache.First().ClassCleanupMethod);
@@ -483,8 +462,7 @@ public void GetTestMethodInfoShouldCacheBaseClassCleanupAttributes()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(_typeCache.ClassInfoCache.First().BaseClassInitMethods.Count == 0, "No base class init");
@@ -505,8 +483,7 @@ public void GetTestMethodInfoShouldCacheClassInitAndCleanupAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(type.GetMethod("AssemblyInit")! == _typeCache.ClassInfoCache.First().ClassInitializeMethod);
@@ -543,8 +520,7 @@ public void GetTestMethodInfoShouldCacheBaseClassInitAndCleanupAttributes()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(type.GetMethod("AssemblyInit")! == _typeCache.ClassInfoCache.First().ClassInitializeMethod);
@@ -600,8 +576,7 @@ public void GetTestMethodInfoShouldCacheParentAndGrandparentClassInitAndCleanupA
var testMethod = new TestMethod("TestMethod", type.FullName!, "A", isAsync: false);
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TestClassInfo? classInfo = _typeCache.ClassInfoCache.FirstOrDefault();
Verify(_typeCache.ClassInfoCache.Count == 1);
@@ -631,8 +606,7 @@ public void GetTestMethodInfoShouldThrowIfClassInitHasIncorrectSignature()
void A() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Exception exception = VerifyThrows(A);
@@ -661,8 +635,7 @@ public void GetTestMethodInfoShouldThrowIfClassCleanupHasIncorrectSignature()
void A() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Exception exception = VerifyThrows(A);
@@ -690,8 +663,7 @@ public void GetTestMethodInfoShouldCacheTestInitializeAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(type.GetMethod("TestInit")! == _typeCache.ClassInfoCache.First().TestInitializeMethod);
@@ -710,8 +682,7 @@ public void GetTestMethodInfoShouldCacheTestCleanupAttribute()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(type.GetMethod("TestCleanup")! == _typeCache.ClassInfoCache.First().TestCleanupMethod);
@@ -731,8 +702,7 @@ public void GetTestMethodInfoShouldThrowIfTestInitOrCleanupHasIncorrectSignature
void A() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TypeInspectionException exception = VerifyThrows(A);
@@ -761,8 +731,7 @@ public void GetTestMethodInfoShouldCacheTestInitializeAttributeDefinedInBaseClas
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(baseType.GetMethod("TestInit")! == _typeCache.ClassInfoCache.First().BaseTestInitializeMethodsQueue.Peek());
@@ -782,8 +751,7 @@ public void GetTestMethodInfoShouldCacheTestCleanupAttributeDefinedInBaseClass()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(_typeCache.ClassInfoCache.Count == 1);
Verify(baseType.GetMethod("TestCleanup")! == _typeCache.ClassInfoCache.First().BaseTestCleanupMethodsQueue.Peek());
@@ -800,13 +768,11 @@ public void GetTestMethodInfoShouldCacheClassInfoInstanceAndReuseFromCache()
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
_testablePlatformServiceProvider.MockFileOperations.Verify(fo => fo.LoadAssembly(It.IsAny(), It.IsAny()), Times.Once);
Verify(_typeCache.ClassInfoCache.Count == 1);
@@ -825,8 +791,7 @@ public void GetTestMethodInfoShouldThrowIfTestMethodHasIncorrectSignatureOrCanno
void A() =>
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Exception exception = VerifyThrows(A);
@@ -848,13 +813,12 @@ public void GetTestMethodInfoShouldReturnTestMethodInfo()
_mockReflectHelper.Setup(rh => rh.GetFirstDerivedAttributeOrDefault(It.IsAny(), false)).CallBase();
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(methodInfo == testMethodInfo!.TestMethod);
- Verify(testMethodInfo.TestMethodOptions.TimeoutInfo.Timeout == 0);
+ Verify(testMethodInfo.TimeoutInfo.Timeout == 0);
Verify(_typeCache.ClassInfoCache.First() == testMethodInfo.Parent);
- Verify(testMethodInfo.TestMethodOptions.Executor is not null);
+ Verify(testMethodInfo.Executor is not null);
}
public void GetTestMethodInfoShouldReturnTestMethodInfoWithTimeout()
@@ -868,13 +832,12 @@ public void GetTestMethodInfoShouldReturnTestMethodInfoWithTimeout()
_mockReflectHelper.Setup(rh => rh.GetFirstDerivedAttributeOrDefault(It.IsAny(), false)).CallBase();
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(methodInfo == testMethodInfo!.TestMethod);
- Verify(testMethodInfo.TestMethodOptions.TimeoutInfo.Timeout == 10);
+ Verify(testMethodInfo.TimeoutInfo.Timeout == 10);
Verify(_typeCache.ClassInfoCache.First() == testMethodInfo.Parent);
- Verify(testMethodInfo.TestMethodOptions.Executor is not null);
+ Verify(testMethodInfo.Executor is not null);
}
public void GetTestMethodInfoShouldThrowWhenTimeoutIsNegative()
@@ -888,8 +851,7 @@ public void GetTestMethodInfoShouldThrowWhenTimeoutIsNegative()
void A() => _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Exception exception = VerifyThrows(A);
@@ -914,8 +876,7 @@ public void GetTestMethodInfoShouldThrowWhenTimeoutIsZero()
void A() => _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
TypeInspectionException exception = VerifyThrows(A);
@@ -948,10 +909,9 @@ public void GetTestMethodInfoWhenTimeoutAttributeNotSetShouldReturnTestMethodInf
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
- Verify(testMethodInfo!.TestMethodOptions.TimeoutInfo.Timeout == 4000);
+ Verify(testMethodInfo!.TimeoutInfo.Timeout == 4000);
}
public void GetTestMethodInfoWhenTimeoutAttributeSetShouldReturnTimeoutBasedOnAttributeEvenIfGlobalTimeoutSet()
@@ -976,10 +936,9 @@ public void GetTestMethodInfoWhenTimeoutAttributeSetShouldReturnTimeoutBasedOnAt
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
- Verify(testMethodInfo!.TestMethodOptions.TimeoutInfo.Timeout == 10);
+ Verify(testMethodInfo!.TimeoutInfo.Timeout == 10);
}
public void GetTestMethodInfoForInvalidGlobalTimeoutShouldReturnTestMethodInfoWithTimeoutZero()
@@ -1001,10 +960,9 @@ public void GetTestMethodInfoForInvalidGlobalTimeoutShouldReturnTestMethodInfoWi
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
- Verify(testMethodInfo!.TestMethodOptions.TimeoutInfo.Timeout == 0);
+ Verify(testMethodInfo!.TimeoutInfo.Timeout == 0);
}
public void GetTestMethodInfoShouldReturnTestMethodInfoForMethodsAdornedWithADerivedTestMethodAttribute()
@@ -1016,14 +974,13 @@ public void GetTestMethodInfoShouldReturnTestMethodInfoForMethodsAdornedWithADer
_mockReflectHelper.Setup(rh => rh.GetFirstDerivedAttributeOrDefault(It.IsAny(), false)).CallBase();
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(methodInfo == testMethodInfo!.TestMethod);
- Verify(testMethodInfo.TestMethodOptions.TimeoutInfo.Timeout == 0);
+ Verify(testMethodInfo.TimeoutInfo.Timeout == 0);
Verify(_typeCache.ClassInfoCache.First() == testMethodInfo.Parent);
- Verify(testMethodInfo.TestMethodOptions.Executor is not null);
- Verify(testMethodInfo.TestMethodOptions.Executor is DerivedTestMethodAttribute);
+ Verify(testMethodInfo.Executor is not null);
+ Verify(testMethodInfo.Executor is DerivedTestMethodAttribute);
}
public void GetTestMethodInfoShouldSetTestContextWithCustomProperty()
@@ -1039,7 +996,7 @@ public void GetTestMethodInfoShouldSetTestContextWithCustomProperty()
new ThreadSafeStringWriter(null!, "test"),
new Dictionary());
- typeCache.GetTestMethodInfo(testMethod, testContext, false);
+ typeCache.GetTestMethodInfo(testMethod, testContext);
KeyValuePair customProperty = ((IDictionary)testContext.Properties).FirstOrDefault(p => p.Key.Equals("WhoAmI", StringComparison.Ordinal));
Verify((object)customProperty is not null);
@@ -1059,7 +1016,7 @@ public void GetTestMethodInfoShouldReportWarningIfCustomPropertyHasSameNameAsPre
new ThreadSafeStringWriter(null!, "test"),
new Dictionary());
- TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext, false);
+ TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext);
Verify(testMethodInfo is not null);
string expectedMessage = string.Format(
@@ -1084,7 +1041,7 @@ public void GetTestMethodInfoShouldReportWarningIfCustomPropertyNameIsEmpty()
new ThreadSafeStringWriter(null!, "test"),
new Dictionary());
- TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext, false);
+ TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext);
Verify(testMethodInfo is not null);
string expectedMessage = string.Format(
@@ -1108,7 +1065,7 @@ public void GetTestMethodInfoShouldReportWarningIfCustomPropertyNameIsNull()
new ThreadSafeStringWriter(null!, "test"),
new Dictionary());
- TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext, false);
+ TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext);
Verify(testMethodInfo is not null);
string expectedMessage = string.Format(
@@ -1132,7 +1089,7 @@ public void GetTestMethodInfoShouldNotAddDuplicateTestPropertiesToTestContext()
new ThreadSafeStringWriter(null!, "test"),
new Dictionary());
- TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext, false);
+ TestMethodInfo? testMethodInfo = typeCache.GetTestMethodInfo(testMethod, testContext);
Verify(testMethodInfo is not null);
@@ -1150,13 +1107,12 @@ public void GetTestMethodInfoShouldReturnTestMethodInfoForDerivedTestClasses()
_mockReflectHelper.Setup(rh => rh.GetFirstDerivedAttributeOrDefault(It.IsAny(), false)).CallBase();
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(methodInfo == testMethodInfo!.TestMethod);
- Verify(testMethodInfo.TestMethodOptions.TimeoutInfo.Timeout == 0);
+ Verify(testMethodInfo.TimeoutInfo.Timeout == 0);
Verify(_typeCache.ClassInfoCache.First() == testMethodInfo.Parent);
- Verify(testMethodInfo.TestMethodOptions.Executor is not null);
+ Verify(testMethodInfo.Executor is not null);
}
public void GetTestMethodInfoShouldReturnTestMethodInfoForDerivedClassMethodOverloadByDefault()
@@ -1168,13 +1124,12 @@ public void GetTestMethodInfoShouldReturnTestMethodInfoForDerivedClassMethodOver
_mockReflectHelper.Setup(rh => rh.GetFirstDerivedAttributeOrDefault(It.IsAny(), false)).CallBase();
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
Verify(methodInfo == testMethodInfo!.TestMethod);
- Verify(testMethodInfo.TestMethodOptions.TimeoutInfo.Timeout == 0);
+ Verify(testMethodInfo.TimeoutInfo.Timeout == 0);
Verify(_typeCache.ClassInfoCache.First() == testMethodInfo.Parent);
- Verify(testMethodInfo.TestMethodOptions.Executor is not null);
+ Verify(testMethodInfo.Executor is not null);
}
public void GetTestMethodInfoShouldReturnTestMethodInfoForDeclaringTypeMethodOverload()
@@ -1190,15 +1145,14 @@ public void GetTestMethodInfoShouldReturnTestMethodInfoForDeclaringTypeMethodOve
_mockReflectHelper.Setup(rh => rh.GetFirstDerivedAttributeOrDefault(It.IsAny(), false)).CallBase();
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
// The two MethodInfo instances will have different ReflectedType properties,
// so cannot be compared directly. Use MethodHandle to verify it's the same.
Verify(methodInfo.MethodHandle == testMethodInfo!.TestMethod.MethodHandle);
- Verify(testMethodInfo.TestMethodOptions.TimeoutInfo.Timeout == 0);
+ Verify(testMethodInfo.TimeoutInfo.Timeout == 0);
Verify(_typeCache.ClassInfoCache.First() == testMethodInfo.Parent);
- Verify(testMethodInfo.TestMethodOptions.Executor is not null);
+ Verify(testMethodInfo.Executor is not null);
}
#endregion
@@ -1228,8 +1182,7 @@ public void ClassInfoListWithExecutableCleanupMethodsShouldReturnEmptyListWhenCl
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
IEnumerable cleanupMethods = _typeCache.ClassInfoListWithExecutableCleanupMethods;
@@ -1250,8 +1203,7 @@ public void ClassInfoListWithExecutableCleanupMethodsShouldReturnClassInfosWithE
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
IEnumerable cleanupMethods = _typeCache.ClassInfoListWithExecutableCleanupMethods;
@@ -1284,8 +1236,7 @@ public void AssemblyInfoListWithExecutableCleanupMethodsShouldReturnEmptyListWhe
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
IEnumerable cleanupMethods = _typeCache.AssemblyInfoListWithExecutableCleanupMethods;
@@ -1306,8 +1257,7 @@ public void AssemblyInfoListWithExecutableCleanupMethodsShouldReturnAssemblyInfo
_typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
IEnumerable cleanupMethods = _typeCache.AssemblyInfoListWithExecutableCleanupMethods;
@@ -1332,8 +1282,7 @@ public void ResolveExpectedExceptionHelperShouldThrowIfMultipleExpectedException
{
TestMethodInfo? testMethodInfo = _typeCache.GetTestMethodInfo(
testMethod,
- new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()),
- false);
+ new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null!, "test"), new Dictionary()));
}
catch (Exception ex)
{