예제 #1
0
 public void Dispose()
 {
     _shutdown = true;
     _uiEvent.Set();
     ThrowPendingException();
     AssertListener.ThrowUnhandled();
 }
예제 #2
0
파일: MockVs.cs 프로젝트: xyongy/PTVS
        public void Dispose()
        {
            // Dispose of packages while the UI thread is still running, it's
            // possible some packages may need to get back onto the UI thread
            // before their Dispose is complete.  TaskProvider does this - it wants
            // to wait for the task provider thread to exit, but the same thread
            // maybe attempting to get back onto the UI thread.  If we yank out
            // the UI thread first then it never makes it over and we just hang
            // and deadlock.
            foreach (var package in _loadedPackages)
            {
                package.Dispose();
            }

            _monSel.UnadviseSelectionEvents(_monSelCookie);
            Shell.SetProperty((int)__VSSPROPID6.VSSPROPID_ShutdownStarted, true);
            _serviceProvider.Dispose();
            Container.Dispose();
            _shutdown = true;
            _uiEvent.Set();
            if (!UIThread.Join(TimeSpan.FromSeconds(30)))
            {
                Console.WriteLine("Failed to wait for UI thread to terminate");
            }
            ThrowPendingException();
            AssertListener.ThrowUnhandled();
        }
예제 #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
                _isDisposed = true;
                try
                {
                    if (_onDispose != null)
                    {
                        foreach (var action in _onDispose)
                        {
                            try
                            {
                                action();
                            }
                            catch (Exception ex)
                            {
                                Debug.WriteLine("Exception calling action while disposing VisualStudioApp: {0}", ex);
                            }
                        }
                    }

                    if (_dte != null && _dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode)
                    {
                        try
                        {
                            _dte.Debugger.TerminateAll();
                            _dte.Debugger.Stop();
                        }
                        catch (COMException ex)
                        {
                            Debug.WriteLine("Exception disposing VisualStudioApp: {0}", ex);
                        }
                    }
                    DismissAllDialogs();
                    for (int i = 0; i < 100 && !_skipCloseAll; i++)
                    {
                        try
                        {
                            _dte.Solution.Close(false);
                            break;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());
                            _dte.Documents.CloseAll(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                            System.Threading.Thread.Sleep(200);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception disposing VisualStudioApp: {0}", ex);
                }

                AssertListener.ThrowUnhandled();
            }
        }
예제 #4
0
 public void WaitForAnalysis(CancellationToken?cancel = null)
 {
     if (_analyzer.Queue.Count == 0)
     {
         return;
     }
     _analyzer.AnalyzeQueuedEntries(cancel ?? CancellationTokens.After5s);
     AssertListener.ThrowUnhandled();
 }
예제 #5
0
 private void AfterTestRun()
 {
     try
     {
         _taskObserver.Value?.WaitForObservedTask();
         AssertListener.ThrowUnhandled();
     }
     finally
     {
         _taskObserver.Value = null;
     }
 }
예제 #6
0
 public void Dispose()
 {
     _shutdown = true;
     Shell.SetProperty((int)__VSSPROPID6.VSSPROPID_ShutdownStarted, true);
     _uiEvent.Set();
     if (!UIThread.Join(TimeSpan.FromSeconds(30)))
     {
         Console.WriteLine("Failed to wait for UI thread to terminate");
     }
     ThrowPendingException();
     _monSel.UnadviseSelectionEvents(_monSelCookie);
     AssertListener.ThrowUnhandled();
     Container.Dispose();
 }
예제 #7
0
        public SessionHolder <T> WaitForSession <T>() where T : IIntellisenseSession
        {
            var sessionStack = _app.ComponentModel.GetService <IIntellisenseSessionStackMapService>().GetStackForTextView(_window.TextView);

            for (int retries = 0; retries < 40; retries++)
            {
                var res = sessionStack.TopSession;
                if (res is T)
                {
                    return(new SessionHolder <T>((T)res, this));
                }
                Thread.Sleep(250);
                AssertListener.ThrowUnhandled();
            }

            Assert.Fail("Failed to find session " + typeof(T).FullName);
            throw new InvalidOperationException();
        }
예제 #8
0
        private IVsHostedPythonToolsTestResult InvokeTest(Type type, MethodInfo method, object[] arguments)
        {
            if (!_activeInstances.TryGetValue(type, out var instance))
            {
                instance = Activator.CreateInstance(type);
                _activeInstances[type] = instance;
            }

            var args      = new List <object>();
            var inputArgs = arguments.ToList();
            var sp        = ServiceProvider.GlobalProvider;
            var dte       = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE));

            try {
                try {
                    var shell = (IVsShell)ServiceProvider.GlobalProvider.GetService(typeof(SVsShell));
                    foreach (var guid in _dependentPackageGuids)
                    {
                        int installed;
                        var pkgGuid = guid;
                        ErrorHandler.ThrowOnFailure(
                            shell.IsPackageInstalled(ref pkgGuid, out installed)
                            );
                        if (installed == 0)
                        {
                            throw new NotSupportedException($"Package {pkgGuid} is not installed");
                        }
                        ErrorHandler.ThrowOnFailure(shell.LoadPackage(pkgGuid, out _));
                    }
                } catch (Exception ex) {
                    return(new HostedPythonToolsTestResult {
                        IsSuccess = false,
                        ExceptionType = ex.GetType().FullName,
                        ExceptionMessage = "Failed to load a dependent VS package." + Environment.NewLine + ex.Message,
                        ExceptionTraceback = new StringBuilder().AppendException(ex).ToString()
                    });
                }

                foreach (var a in method.GetParameters())
                {
                    if (a.ParameterType.IsAssignableFrom(typeof(IServiceProvider)))
                    {
                        args.Add(sp);
                    }
                    else if (a.ParameterType.IsAssignableFrom(typeof(EnvDTE.DTE)))
                    {
                        args.Add(dte);
                    }
                    else if (inputArgs.Count > 0 && a.ParameterType.IsInstanceOfType(inputArgs[0]))
                    {
                        args.Add(inputArgs[0]);
                        inputArgs.RemoveAt(0);
                    }
                    else
                    {
                        args.Add(ConstructParameter(a.ParameterType, sp, dte, inputArgs));
                    }
                }
            } catch (Exception ex) {
                ex = ExtractRealException(ex);

                return(new HostedPythonToolsTestResult {
                    IsSuccess = false,
                    ExceptionType = ex.GetType().FullName,
                    ExceptionMessage = "Failed to invoke test method with correct arguments." + Environment.NewLine + ex.Message,
                    ExceptionTraceback = new StringBuilder().AppendException(ex).ToString()
                });
            }

            AssertListener.Initialize();

            try {
                try {
                    if (typeof(Task).IsAssignableFrom(method.ReturnType))
                    {
                        ThreadHelper.JoinableTaskFactory.Run(() => (Task)method.Invoke(instance, args.ToArray()));
                    }
                    else
                    {
                        method.Invoke(instance, args.ToArray());
                    }

                    AssertListener.ThrowUnhandled();
                } finally {
                    foreach (var a in args)
                    {
                        if (a == sp || a == dte)
                        {
                            continue;
                        }
                        (a as IDisposable)?.Dispose();
                    }
                }
            } catch (Exception ex) {
                ex = ExtractRealException(ex);

                return(new HostedPythonToolsTestResult {
                    IsSuccess = false,
                    ExceptionType = ex.GetType().FullName,
                    ExceptionMessage = ex.Message,
                    ExceptionTraceback = new StringBuilder().AppendException(ex).ToString()
                });
            }

            return(new HostedPythonToolsTestResult {
                IsSuccess = true
            });
        }