Exemplo n.º 1
0
        private string GetPowershellScript(ISolutionProjectModel solutionProject, IServiceSettings settings)
        {
            StringBuilder builder = new StringBuilder();

            foreach (Project project in solutionProject.GetUnitTestProjects())
            {
                var unitTestInfos = project.GetTestMethods().ToArray();
                var command       = GetTestCommand(solutionProject, settings, unitTestInfos, true);
                builder.AppendLine($"\"{command.MsTestProcess.MsTestPath}\" {command}");
            }
            return(builder.ToString());
        }
Exemplo n.º 2
0
        private string GetBatchScript(ISolutionProjectModel solutionProject, IServiceSettings settings)
        {
            StringBuilder builder = new StringBuilder();

            foreach (Project project in solutionProject.GetUnitTestProjects())
            {
                var unitTestInfos = project.GetTestMethods().ToArray();
                //SetOrUpdateSettingsFile(projectViewModel, settings, unitTestInfos);
                var command = GetTestCommand(solutionProject, settings, unitTestInfos, true);
                builder.AppendLine($"Invoke-Expression \"{command.MsTestProcess.MsTestPath}\" {command}");
            }
            return(builder.ToString());
        }
Exemplo n.º 3
0
        public static bool NeedToBeCompiled(ISolutionProjectModel projectViewModel)
        {
            if (projectViewModel.IsDelphiProject)
            {
                return(false);
            }
            var shouldCompile = projectViewModel.GetSolutionProjects().Any(project => project.IsDirty && project.IsBuildEnabled);

            if (shouldCompile)
            {
                return(true);
            }
            shouldCompile = projectViewModel.GetUnitTestProjects().Select(project => project.GetOutputFile()).Any(info => !info.Exists);
            return(shouldCompile);
        }
Exemplo n.º 4
0
        public async Task RunAllTestsAsync(ISolutionProjectModel projectViewModel, IServiceSettings settings, CancellationToken cancellationToken = default(CancellationToken))
        {
            var unitTestServiceSettings = settings.GetSettingsFromProvider <UnitTestServiceSettings>(projectViewModel);
            await cancellationToken.WaitWhenPaused();

            try
            {
                if (!IsCancelled(projectViewModel, cancellationToken) && CanRunAnyTests(projectViewModel))
                {
                    if (NeedToBeCompiled(projectViewModel))
                    {
                        await serviceProvider.Get <LocalBuildService>().BuildSolutionsAsync(new[] { projectViewModel }, settings, cancellationToken);

                        var buildErrors = Output.FindErrorTasks(projectViewModel);
                        if (buildErrors.Any())
                        {
                            statusService.IncrementStep();
                            return;
                        }
                    }
                    await cancellationToken.WaitWhenPaused();

                    var externalActionService = serviceProvider.Get <ExternalActionService>();
                    await externalActionService.RunExternalPreActions(projectViewModel, this, cancellationToken : cancellationToken);

                    void OnError(MsTestCommand command, string s)
                    {
                        if (!cancellationToken.IsCancellationRequested)
                        {
                            OnTestError(projectViewModel, command, s, unitTestServiceSettings.CancelOnFailures);
                        }
                    }

                    void TestData(MsTestCommand command, string s)
                    {
                        if (!cancellationToken.IsCancellationRequested)
                        {
                            OnTestData(projectViewModel, command, s, unitTestServiceSettings.CancelOnFailures);
                        }
                    }

                    await cancellationToken.WaitWhenPaused();

                    int totalTestCount = 0;
                    using (new PauseCheckedActionScope(() => projectViewModel.CurrentOperation = GetOperationInfo(unitTestServiceSettings.TrackLiveOutput), () => projectViewModel.CurrentOperation = Operations.None, cancellationToken))
                    {
                        var  watch    = Stopwatch.StartNew();
                        bool executed = false;

                        //var unitTestInfos = projectViewModel.GetUnitTestProjects().SelectMany(project => project.GetTestMethods()).ToArray();
                        var result = new Dictionary <TestRun, IList <MsTestError> >();
                        foreach (Project project in projectViewModel.GetUnitTestProjects())
                        {
                            if (!cancellationToken.IsCancellationRequested)
                            {
                                var unitTestInfos = project.GetTestMethods().ToArray();
                                int progress      = 0;
                                int total         = unitTestInfos.Length;
                                totalTestCount = totalTestCount + total;
                                if (unitTestServiceSettings.TrackLiveOutput)
                                {
                                    projectViewModel.CurrentOperation.SetProgress(total, progress);
                                }

                                var command = GetTestCommand(projectViewModel, settings, unitTestInfos);
                                await command.ExecuteAsync((testCommand, s) =>
                                {
                                    if (unitTestServiceSettings.TrackLiveOutput && !string.IsNullOrEmpty(s) && s.Contains("[testname]"))
                                    {
                                        projectViewModel.CurrentOperation?.SetProgress(total, (++progress));
                                    }
                                    TestData(testCommand, s);
                                }, OnError, cancellationToken);

                                executed = true;
                                var results = OpenTestResultFileAndGetResults(project, command.ResultFile);
                                if (results.Key != null)
                                {
                                    result.Add(results.Key, results.Value);
                                }
                            }
                        }

                        watch.Stop();
                        List <MsTestError>   failedTests = result.SelectMany(pair => pair.Value).ToList();
                        BuildErrorsViewModel errorModel  = GetErrorsViewModel(projectViewModel);
                        int passed = totalTestCount - failedTests.Count;
                        if (errorModel != null && errorModel.Errors.Any())
                        {
                            projectViewModel.SetResult(new ValidationResult(false, errorModel));
                        }
                        else
                        {
                            projectViewModel.SetResult(ValidationResult.ValidResult);
                        }

                        await externalActionService.RunExternalPostActions(projectViewModel, this, passed == totalTestCount, cancellationToken : cancellationToken);

                        if (!cancellationToken.IsCancellationRequested)
                        {
                            Output.WriteLine(executed
                                                                ? string.Format("{2}/{3} Tests passed in testrun for {0} (completed in {1})", projectViewModel.SolutionFileName, watch.Elapsed, passed, totalTestCount)
                                                                : $"There are no Tests for {projectViewModel.SolutionFileName}");
                        }
                    }
                }
                else
                {
                    Output.WriteLine($"There are no Tests for {projectViewModel.SolutionFileName}");
                }
            }
            finally
            {
                statusService.IncrementStep();
            }
        }
Exemplo n.º 5
0
 public static bool CanRunAnyTests(ISolutionProjectModel projectViewModel)
 {
     return(!projectViewModel.IsDelphiProject && projectViewModel.GetUnitTestProjects().Any());
 }