コード例 #1
0
        /// <inheritdoc/>
        public void Run(Action action, PlatformApartmentState apartmentState, bool waitForCompletion)
        {
            if (action == null)
            {
                return;
            }

            Exception exThrown = null;
            var       thread   = new System.Threading.Thread(() =>
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    exThrown = e;
                }
            });

            ApartmentState state = Enum.TryParse(apartmentState.ToString(), out state) ? state : ApartmentState.MTA;

            thread.SetApartmentState(state);
            thread.IsBackground = true;
            thread.Start();
            if (waitForCompletion)
            {
                thread.Join();
                if (exThrown != null)
                {
                    throw exThrown;
                }
            }
        }
コード例 #2
0
ファイル: BaseRunTestsTests.cs プロジェクト: navin22/nvstest
        private void SetupForExecutionThreadApartmentStateTests(PlatformApartmentState apartmentState)
        {
            this.mockThread = new Mock <IThread>();

            this.runTestsInstance = new TestableBaseRunTests(
                $@"<RunSettings>
                  <RunConfiguration>
                     <ExecutionThreadApartmentState>{apartmentState}</ExecutionThreadApartmentState>
                   </RunConfiguration>
                </RunSettings>",
                testExecutionContext,
                null,
                this.mockTestRunEventsHandler.Object,
                this.mockTestPlatformEventSource.Object,
                null,
                this.mockThread.Object,
                this.mockRequestData.Object);
            TestPluginCacheTests.SetupMockExtensions(new string[] { typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location }, () => { });
            var assemblyLocation        = typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location;
            var executorUriExtensionMap = new List <Tuple <Uri, string> >
            {
                new Tuple <Uri, string>(new Uri(BaseRunTestsExecutorUri), assemblyLocation)
            };

            this.runTestsInstance.GetExecutorUriExtensionMapCallback = (fh, rc) => { return(executorUriExtensionMap); };
        }
コード例 #3
0
ファイル: PlatformThread.cs プロジェクト: zcsizmadia/vstest
        /// <inheritdoc/>
        public void Run(Action action, PlatformApartmentState apartmentState, bool waitForCompletion)
        {
            if (apartmentState == PlatformApartmentState.STA)
            {
                throw new ThreadApartmentStateNotSupportedException();
            }

            if (action == null)
            {
                return;
            }

            Task task = Task.Run(action);

            if (waitForCompletion)
            {
                task.Wait();
            }
        }
コード例 #4
0
        /// <inheritdoc/>
        public void Run(Action action, PlatformApartmentState apartmentState, bool waitForCompletion)
        {
            if (apartmentState == PlatformApartmentState.STA)
            {
                throw new ThreadApartmentStateNotSupportedException();
            }

            if (action == null)
            {
                return;
            }

            Exception exThrown = null;
            var       thread   = new Thread(() =>
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    exThrown = e;
                }
            });

            // ApartmentState is not supported in netcoreapp1.0.
            thread.IsBackground = true;
            thread.Start();
            if (waitForCompletion)
            {
                thread.Join();
                if (exThrown != null)
                {
                    // Preserve the stacktrace when re-throwing the exception.
                    ExceptionDispatchInfo.Capture(exThrown).Throw();
                }
            }
        }
コード例 #5
0
ファイル: PlatformThread.cs プロジェクト: pavelhorak/vstest
        /// <inheritdoc/>
        public void Run(Action action, PlatformApartmentState apartmentState, bool waitForCompletion)
        {
            if (apartmentState == PlatformApartmentState.STA)
            {
                throw new ThreadApartmentStateNotSupportedException();
            }

            if (action == null)
            {
                return;
            }

            Exception exThrown = null;
            var       thread   = new Thread(() =>
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    exThrown = e;
                }
            });

            // ApartmentState is not supported in netcoreapp1.0.
            thread.IsBackground = true;
            thread.Start();
            if (waitForCompletion)
            {
                thread.Join();
                if (exThrown != null)
                {
                    throw exThrown;
                }
            }
        }
コード例 #6
0
ファイル: PlatformThread.cs プロジェクト: pavelhorak/vstest
 /// <inheritdoc />
 public void Run(Action action, PlatformApartmentState platformApartmentState, bool waitForCompletion)
 {
     throw new NotImplementedException();
 }