private void OnTestError(ISolutionProjectModel projectViewModel, MsTestCommand command, string errors, bool cancelOnFailures) { lock (lockObj) { if (projectViewModel.CurrentOperation != null && !string.IsNullOrEmpty(errors)) { projectViewModel.CurrentOperation.ColorBrush = Brushes.DarkRed; } if (!string.IsNullOrEmpty(errors)) { foreach (MsTestError error in MsTestError.Parse(errors)) { UnitTestInfo testInfo = command.UnitTests.First(info => info.TestMethodName == error.TestName); string fileName = error.TestName; if (testInfo.ProjectFileItem != null && testInfo.ProjectFileItem.GetFile().Exists) { fileName = testInfo.ProjectFileItem.GetFile().FullName; } Output.WriteError($"{error.TestName}={error.ErrorMessage}", fileName, testInfo.Line, testInfo.Column, null, TaskCategory.User, testInfo.Project.FullPath, File.Exists(fileName)); } Output.WriteLine(errors); if (cancelOnFailures) { serviceProvider.Get <MainViewModel>().CompleteCancelCommand.Execute(null); } } } }
public async Task <bool> RunAsync(MsTestCommand command, Action <MsTestCommand, string> onDataReceived = null, Action <MsTestCommand, string> onError = null, CancellationToken cancellationToken = default(CancellationToken)) { //ProcessStartInfo startInfo = new ProcessStartInfo(MsTestPath) { Arguments = command.CommandString, Verb = "runas" }; //var process = Process.Start(startInfo); //process.WaitForExit(); //return Task.FromResult(true); Action <string> _onDataReceived = null; if (onDataReceived != null) { _onDataReceived = s => onDataReceived(command, s); } Action <string> _onError = null; if (onError != null) { _onError = s => onError(command, s); } var scriptExecutionSettings = GetScriptExecutionSettings(command.RequiresAdminPrivileges); Output.WriteLine(command.CommandString); var result = await ScriptHelper.ExecuteScriptAsync(MsTestPath, command.CommandString, scriptExecutionSettings, _onDataReceived, _onError, cancellationToken); return(result.ProcessResult); }
private void OnTestData(ISolutionProjectModel projectViewModel, MsTestCommand command, string data, bool cancelOnFailures) { if (data != null && (data.Contains("[Failed]") || data.Contains("[errormessage]"))) { if (projectViewModel.CurrentOperation != null) { projectViewModel.CurrentOperation.ColorBrush = Brushes.DarkRed; } if (cancelOnFailures) { serviceProvider.Get <MainViewModel>().CompleteCancelCommand.Execute(null); } } Output.WriteLine(data, projectViewModel.SolutionFileName, command.ResultFile); }
private MsTestCommand GetTestCommand(ISolutionProjectModel projectViewModel, IServiceSettings settings, UnitTestInfo[] unitTestInfos, bool isScriptExport = false) { var settingsSrv = serviceProvider.Get <SettingsService>(); var tsp = CheckoutAndBuild2Package.GetGlobalService <IDefaultTestSettingsProvider>(); var unitTestServiceSettings = settingsSrv.GetSettingsFromProvider <UnitTestServiceSettings>(projectViewModel); var testSettingsFile = projectViewModel.EnsureAbsolutePath(settingsSrv.Get(projectViewModel.TestSettingsFileKey(), tsp != null ? tsp.GetTestSettingsFile(projectViewModel, settings) : String.Empty)); var command = new MsTestCommand(unitTestInfos) { RequiresAdminPrivileges = unitTestServiceSettings.RequiresAdminPrivileges, SpecifyEachTest = unitTestServiceSettings.TrackLiveOutput && !isScriptExport }; if (!string.IsNullOrEmpty(testSettingsFile) && File.Exists(testSettingsFile)) { command.DefaultTestSettings = testSettingsFile; } return(command); }
public bool Run(MsTestCommand command, Action <MsTestCommand, string> onDataReceived = null, Action <MsTestCommand, string> onError = null) { Action <string> _onDataReceived = null; if (onDataReceived != null) { _onDataReceived = s => onDataReceived(command, s); } Action <string> _onError = null; if (onError != null) { _onError = s => onError(command, s); } Output.WriteLine(command.CommandString); var result = ScriptHelper.ExecuteScript(MsTestPath, command.CommandString, GetScriptExecutionSettings(command.RequiresAdminPrivileges), _onDataReceived, _onError); return(result.ProcessResult); }