Пример #1
0
        internal static async Task <ThreadRental> CreateAsync(SyncContextAdapter syncContextAdapter, ITestMethod testMethod)
        {
            var disposalTaskSource = new TaskCompletionSource <object?>();
            var syncContextSource  = new TaskCompletionSource <SynchronizationContext>();
            var thread             = new Thread(() =>
            {
                var uiSyncContext = syncContextAdapter.Create();
                if (syncContextAdapter.ShouldSetAsCurrent)
                {
                    SynchronizationContext.SetSynchronizationContext(uiSyncContext);
                }

                syncContextAdapter.InitializeThread();
                syncContextSource.SetResult(uiSyncContext);
                syncContextAdapter.PumpTill(uiSyncContext, disposalTaskSource.Task);
            });

            thread.Name = $"{testMethod.TestClass.Class.Name}.{testMethod.Method.Name}";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                thread.SetApartmentState(ApartmentState.STA);
            }

            thread.Start();

            var syncContext = await syncContextSource.Task.ConfigureAwait(false);

            var rental = new ThreadRental(
                syncContextAdapter,
                disposalTaskSource,
                syncContext);

            return(rental);
        }
Пример #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="UITestCaseRunner" /> class.
 /// </summary>
 /// <param name="testCase">The test case to be run.</param>
 /// <param name="displayName">The display name of the test case.</param>
 /// <param name="skipReason">The skip reason, if the test is to be skipped.</param>
 /// <param name="constructorArguments">The arguments to be passed to the test class constructor.</param>
 /// <param name="testMethodArguments">The arguments to be passed to the test method.</param>
 /// <param name="messageBus">The message bus to report run status to.</param>
 /// <param name="aggregator">The exception aggregator used to run code and collect exceptions.</param>
 /// <param name="cancellationTokenSource">The task cancellation token source, used to cancel the test run.</param>
 /// <param name="syncContextAdapter">The <see cref="SynchronizationContext" /> adapter to use.</param>
 internal UITestCaseRunner(
     IXunitTestCase testCase,
     string displayName,
     string skipReason,
     object[] constructorArguments,
     object[] testMethodArguments,
     IMessageBus messageBus,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource,
     SyncContextAdapter syncContextAdapter)
     : base(testCase, displayName, skipReason, constructorArguments, testMethodArguments, messageBus, aggregator, cancellationTokenSource) {
     this.syncContextAdapter = syncContextAdapter;
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UITestCaseRunner"/> class.
 /// </summary>
 /// <param name="testCase">The test case to be run.</param>
 /// <param name="displayName">The display name of the test case.</param>
 /// <param name="skipReason">The skip reason, if the test is to be skipped.</param>
 /// <param name="constructorArguments">The arguments to be passed to the test class constructor.</param>
 /// <param name="testMethodArguments">The arguments to be passed to the test method.</param>
 /// <param name="messageBus">The message bus to report run status to.</param>
 /// <param name="aggregator">The exception aggregator used to run code and collect exceptions.</param>
 /// <param name="cancellationTokenSource">The task cancellation token source, used to cancel the test run.</param>
 /// <param name="syncContextAdapter">The <see cref="SynchronizationContext"/> adapter to use.</param>
 internal UITestCaseRunner(
     IXunitTestCase testCase,
     string displayName,
     string skipReason,
     object[] constructorArguments,
     object[] testMethodArguments,
     IMessageBus messageBus,
     ExceptionAggregator aggregator,
     CancellationTokenSource cancellationTokenSource,
     SyncContextAdapter syncContextAdapter)
     : base(testCase, displayName, skipReason, constructorArguments, testMethodArguments, messageBus, aggregator, cancellationTokenSource)
 {
     this.syncContextAdapter = syncContextAdapter;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UITestInvoker"/> class.
 /// </summary>
 internal UITestInvoker(ITest test, IMessageBus messageBus, Type testClass, object[] constructorArguments, MethodInfo testMethod, object[] testMethodArguments, IReadOnlyList<BeforeAfterTestAttribute> beforeAfterAttributes, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource, SyncContextAdapter syncContextAdapter)
     : base(test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, beforeAfterAttributes, aggregator, cancellationTokenSource)
 {
     this.adapter = syncContextAdapter;
 }
Пример #5
0
 private ThreadRental(SyncContextAdapter syncContextAdapter, TaskCompletionSource <object?> disposalTaskSource, SynchronizationContext uiSyncContextSource)
 {
     this.SyncContextAdapter = syncContextAdapter;
     this.disposalTaskSource = disposalTaskSource;
     this.syncContext        = uiSyncContextSource;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UITestInvoker"/> class.
 /// </summary>
 internal UITestInvoker(ITest test, IMessageBus messageBus, Type testClass, object[] constructorArguments, MethodInfo testMethod, object[] testMethodArguments, IReadOnlyList <BeforeAfterTestAttribute> beforeAfterAttributes, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource, SyncContextAdapter syncContextAdapter)
     : base(test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, beforeAfterAttributes, aggregator, cancellationTokenSource)
 {
     this.adapter = syncContextAdapter;
 }