public static List <string> GetOutputWindowsLines(this VisualStudioHost host) { if (host == null) { throw new ArgumentNullException(nameof(host)); } var lines = new List <string>(); try { CommonUtility.UIInvoke(() => { var outputPane = host.ObjectModel.Shell.ToolWindows.OutputWindow.GetOutputPane(_nugetOutputWindowGuid); lines.AddRange(outputPane.Text.Split('\n').Select(e => e.Trim()).Where(e => !string.IsNullOrEmpty(e))); }); } catch (ArgumentException) { // If no output has been printed into the nuget output window then the output pane will not be initialized // If no output has been printed we know there is no error in the output window. } return(lines); }
private void UseService <T>(FileInfo solutionFile, Action <T> action) where T : class { VisualStudioHost visualStudio = null; try { VisualStudioHostConfiguration configuration = CreateVisualStudioHostConfiguration(); configuration.AddCompositionAssembly(Assembly.GetExecutingAssembly().Location); visualStudio = LaunchVisualStudio(configuration); LoadSolution(visualStudio, solutionFile); WaitForAutoRestoreToComplete(visualStudio, solutionFile); using (Scope.Enter("Get service.")) { var service = visualStudio.Get <T>(); using (Scope.Enter("Verify service.")) { action(service); } } ShutDownVisualStudio(visualStudio); } catch (Exception ex) { HandleException(visualStudio, ex); } }
public void Dispose() { if (_visualStudioHost != null && _visualStudioHost.IsRunning) { try { if (_messageFilterSingleton != null) { _messageFilterSingleton.Dispose(); } _visualStudioHost.Stop(); } catch (COMException) { // VSO 178569: Access to DTE during shutdown may throw a variety of COM exceptions // if inaccessible. } catch (Exception) { //this.Logger.WriteException(EntryType.Warning, filterException, "Could not to tear down the message filter."); } _visualStudioHost = null; } }
public ApexTestContext(VisualStudioHost visualStudio, ProjectTemplate projectTemplate, ILogger logger, bool noAutoRestore = false, bool addNetStandardFeeds = false) { logger.LogInformation("Creating test context"); _pathContext = new SimpleTestPathContext(); if (noAutoRestore) { _pathContext.Settings.DisableAutoRestore(); } if (addNetStandardFeeds) { _pathContext.Settings.AddNetStandardFeeds(); } _visualStudio = visualStudio; _logger = logger; SolutionService = _visualStudio.Get <SolutionService>(); NuGetApexTestService = _visualStudio.Get <NuGetApexTestService>(); VisualStudioHostExtension.ClearWindows(_visualStudio); Project = CommonUtility.CreateAndInitProject(projectTemplate, _pathContext, SolutionService, logger); NuGetApexTestService.WaitForAutoRestore(); }
public void EnsureHost() { if (_visualStudioHost == null || !_visualStudioHost.IsRunning) { _messageFilterSingleton = new RetryMessageFilter(); _visualStudioHost = Operations.CreateAndStartHost <VisualStudioHost>(VisualStudioHostConfiguration); } }
public static void SelectProjectInSolutionExplorer(this VisualStudioHost host, string project) { CommonUtility.UIInvoke(() => { var item = host.ObjectModel.Shell.ToolWindows.SolutionExplorer.FindItemRecursive(project); item.Select(); }); }
private void ShutDownVisualStudio(VisualStudioHost visualStudio) { using (Scope.Enter("Close solution and shut down Visual Studio.")) { visualStudio.ObjectModel.Solution.Close(); visualStudio.Stop(); } }
private void BuildSolution(VisualStudioHost visualStudio) { using (Scope.Enter("Build solution.")) { // Rebuild to ensure a clean build. visualStudio.ObjectModel.Solution.BuildManager.Rebuild(); visualStudio.ObjectModel.Solution.BuildManager.Verify.Succeeded(); } }
private void LoadSolution(VisualStudioHost visualStudio, FileInfo solutionFile) { using (Scope.Enter("Load solution.")) { visualStudio.ObjectModel.Solution.WaitForFullyLoadedOnOpen = true; visualStudio.ObjectModel.Solution.Open(solutionFile.FullName); visualStudio.ObjectModel.Solution.Verify.HasProject(); } }
private VisualStudioHost LaunchVisualStudio(VisualStudioHostConfiguration configuration) { VisualStudioHost visualStudio = Operations.CreateHost <VisualStudioHost>(configuration); using (Scope.Enter("Launch Visual Studio.")) { visualStudio.Start(); } return(visualStudio); }
public static string AppendErrors(string s, VisualStudioHost visualStudio) { var errors = visualStudio.GetErrorsInOutputWindows(); if (errors.Any()) { s += Environment.NewLine + string.Join("\n\t error: ", errors); } return(s); }
/// <summary> /// Assert no errors in the error list /// </summary> internal static List <string> GetErrorListErrors(this VisualStudioHost host) { var errors = new List <string>(); CommonUtility.UIInvoke(() => { errors.AddRange(host.ObjectModel.Shell.ToolWindows.ErrorList.Messages.Select(e => e.Description)); }); return(errors); }
public static void ClearErrorWindow(this VisualStudioHost host) { try { CommonUtility.UIInvoke(() => host.ObjectModel.Shell.ToolWindows.ErrorList.HideAllItems()); } catch (ArgumentException) { // ignore errors } }
public static void AssertPackageReferenceDoesNotExist(VisualStudioHost visualStudio, ProjectTestExtension project, string packageName, ILogger logger) { logger.LogInformation($"Checking for PackageReference {packageName}"); var matches = GetPackageReferences(project) .Where(e => e.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)) .ToList(); logger.LogInformation($"Matches: {matches.Count}"); matches.Any().Should().BeFalse($"A PackageReference for {packageName} was found in {project.FullPath}"); }
public static void AssertPackageNotInPackagesConfig(VisualStudioHost visualStudio, ProjectTestExtension project, string packageName, ILogger logger) { logger.LogInformation($"Checking project for {packageName}"); var testService = visualStudio.Get <NuGetApexTestService>(); // Check using the IVs APIs var exists = testService.IsPackageInstalled(project.UniqueName, packageName); logger.LogInformation($"Exists: {exists}"); exists.Should().BeFalse(AppendErrors($"{packageName} should NOT be in {project.Name}", visualStudio)); }
public static void ClearOutputWindow(this VisualStudioHost host) { try { var outputPane = host.ObjectModel.Shell.ToolWindows.OutputWindow.GetOutputPane(_nugetOutputWindowGuid); outputPane.Clear(); } catch (ArgumentException) { //if outputPane doesn't exist, ignore it } }
public static void AssertPackageReferenceExists(VisualStudioHost visualStudio, ProjectTestExtension project, string packageName, string packageVersion, ILogger logger) { logger.LogInformation($"Checking for PackageReference {packageName} {packageVersion}"); var matches = GetPackageReferences(project) .Where(e => e.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase) && e.LibraryRange.VersionRange.MinVersion.Equals(NuGetVersion.Parse(packageVersion))) .ToList(); logger.LogInformation($"Matches: {matches.Count}"); matches.Any().Should().BeTrue($"A PackageReference with {packageName}/{packageVersion} was not found in {project.FullPath}"); }
public ApexTestContext(VisualStudioHost visualStudio, ProjectTemplate projectTemplate, bool noAutoRestore = false) { _pathContext = new SimpleTestPathContext(); if (noAutoRestore) { _pathContext.Settings.DisableAutoRestore(); } _visualStudio = visualStudio; SolutionService = _visualStudio.Get <SolutionService>(); Project = Utils.CreateAndInitProject(projectTemplate, _pathContext, SolutionService); }
public static bool HasNoErrorsInOutputWindows(this VisualStudioHost host) { try { var outputPane = host.ObjectModel.Shell.ToolWindows.OutputWindow.GetOutputPane(_nugetOutputWindowGuid); return(!outputPane.Text.ToLowerInvariant().Contains("failed")); } catch (ArgumentException) { // If no output has been printed into the nuget output window then the output pane will not be initialized // If no output has been printed we know there is no error in the output window. return(true); } }
protected override void DoHostTestInitialize() { base.DoHostTestInitialize(); VsHost = VisualStudio; Helpers = new HelperWrapper(VisualStudio); Solution.Open(SolutionPath); Solution.WaitForFullyLoaded(); // This will get modified after bug 627108 get fixed _webProject = Solution[ProjectName]; _libmanConfig = _webProject[LibManManifestFile]; _pathToLibmanFile = Path.Combine(SolutionRootPath, ProjectName, LibManManifestFile); _initialLibmanFileContent = File.ReadAllText(_pathToLibmanFile); }
private void HandleException(VisualStudioHost visualStudio, Exception ex) { using (Scope.Enter("Handle exception.")) { if (visualStudio != null && visualStudio.IsRunning) { visualStudio.CaptureHostProcessDumpIfRunning(MiniDumpType.WithFullMemory); visualStudio.HostProcess.Kill(); } Logger.WriteException(EntryType.Error, ex); Verify.Fail("Exception encountered during test execution"); Assert.Fail(ex.Message); } }
public static void AssertPackageNotInAssetsFile(VisualStudioHost visualStudio, ProjectTestExtension project, string packageName, string packageVersion, ILogger logger) { logger.LogInformation($"Checking assets file for {packageName}"); var testService = visualStudio.Get <NuGetApexTestService>(); testService.WaitForAutoRestore(); var assetsFilePath = GetAssetsFilePath(project.FullPath); // Project has an assets file, let's look there to assert var inAssetsFile = IsPackageInstalledInAssetsFile(assetsFilePath, packageName, packageVersion, false); logger.LogInformation($"Exists: {inAssetsFile}"); inAssetsFile.Should().BeFalse(AppendErrors($"{packageName}/{packageVersion} should not be installed in {project.Name}", visualStudio)); }
public ApexTestContext(VisualStudioHost visualStudio, ProjectTemplate projectTemplate, ILogger logger, bool noAutoRestore = false) { logger.LogInformation("Creating test context"); _pathContext = new SimpleTestPathContext(); if (noAutoRestore) { _pathContext.Settings.DisableAutoRestore(); } _visualStudio = visualStudio; _logger = logger; SolutionService = _visualStudio.Get <SolutionService>(); NuGetApexTestService = _visualStudio.Get <NuGetApexTestService>(); Project = Utils.CreateAndInitProject(projectTemplate, _pathContext, SolutionService, logger); NuGetApexTestService.WaitForAutoRestore(); }
private void WaitForAutoRestoreToComplete(VisualStudioHost visualStudio, FileInfo solutionFile) { using (Scope.Enter("Wait for auto restore completion.")) { var assetsFile = new FileInfo(Path.Combine(solutionFile.DirectoryName, solutionFile.Directory.Name, "obj", "project.assets.json")); var timeout = TimeSpan.FromMinutes(1); var interval = TimeSpan.FromSeconds(5); const string RestoreOutputCompletionMarker = "========== Finished =========="; visualStudio.ObjectModel.Solution.WaitForIntellisenseStage(TimeSpan.FromMinutes(5)); visualStudio.ObjectModel.Shell.ToolWindows.OutputWindow.ToolWindow.Show(); // Wait for the assets file to be created. Omni.Common.WaitFor.IsTrue( () => File.Exists(assetsFile.FullName), timeout, interval, $"An assets file was not created at '{assetsFile.FullName}'."); // Wait for the solution restore to complete. Omni.Common.WaitFor.IsTrue( () => { if (TryGetPackageManagerOutputWindowPane(visualStudio, out OutputWindowPaneTestExtension packageManagerOutputWindowPane)) { var output = packageManagerOutputWindowPane.Text; if (!string.IsNullOrEmpty(output)) { output = output.TrimEnd('\r', '\n'); return(output.Contains(RestoreOutputCompletionMarker)); } } return(false); }, timeout, interval, "Solution restore did not complete according to the Package Manager output window pane."); } }
private void OpenSolutionAndBuild(FileInfo solutionFile) { VisualStudioHost visualStudio = null; try { VisualStudioHostConfiguration configuration = CreateVisualStudioHostConfiguration(); visualStudio = LaunchVisualStudio(configuration); LoadSolution(visualStudio, solutionFile); WaitForAutoRestoreToComplete(visualStudio, solutionFile); BuildSolution(visualStudio); ShutDownVisualStudio(visualStudio); } catch (Exception ex) { HandleException(visualStudio, ex); } }
/// <summary> /// Assert no errors in the error list or output window /// </summary> internal static void AssertNoErrors(this VisualStudioHost host) { host.AssertNuGetOutputDoesNotHaveErrors(); host.GetErrorListErrors().Should().BeEmpty("Empty errors in error list"); }
/// <summary> /// Clear the error list and output window /// </summary> public static void ClearWindows(this VisualStudioHost host) { host.ClearOutputWindow(); host.ClearErrorWindow(); }
/// <summary> /// Assert no errors in nuget output window /// </summary> internal static void AssertNuGetOutputDoesNotHaveErrors(this VisualStudioHost host) { host.GetErrorsInOutputWindows().Should().BeEmpty(); }
public static bool HasNoErrorsInOutputWindows(this VisualStudioHost host) { return(host.GetErrorsInOutputWindows().Count == 0); }
public static List <string> GetErrorsInOutputWindows(this VisualStudioHost host) { return(host.GetOutputWindowsLines().Where(e => e.IndexOf("failed", StringComparison.OrdinalIgnoreCase) > -1).ToList()); }