Exemplo n.º 1
0
        private void UpdateTestPlanRunsIfNecessary()
        {
            if (Data.TestCaseRunsRetrievedCount != Data.AllTestCaseRunsCount)
            {
                return;
            }

            Log().InfoFormat("Finished getting test case runs for test plan run #{0}. The number of test case runs retrieved is {1}", Data.TestPlanRunId, Data.TestCaseRunsRetrievedCount);

            var testCasesFoundNames    = new List <string>();
            var testCasesNotFoundNames = new List <string>();
            var profile  = _profile.GetProfile <TestRunImportPluginProfile>();
            var resolver = _resolverFactory.GetResolver(profile, StorageRepository().Get <TestRunImportResultInfo>().ToArray(),
                                                        StorageRepository().Get <TestCaseTestPlanDTO>().ToArray());
            var result =
                resolver.ImportResultsForTestCaseRuns(
                    StorageRepository().Get <TestCaseRunDTO>(Data.TestPlanRunId.ToString()).ToArray(), testCasesFoundNames.Add,
                    testCasesNotFoundNames.Add);
            var affectedDtos = result.Where(r => r.Runned.HasValue && r.RunDate.HasValue).ToArray();

            Data.NumberOfTestCasesToUpdate = affectedDtos.Length;

            if (testCasesFoundNames.Count > 0)
            {
                Log().InfoFormat("Imported test cases: {0}", string.Join(" ,", testCasesFoundNames.ToArray()));
            }
            if (testCasesNotFoundNames.Count > 0)
            {
                Log().InfoFormat("Not imported test cases: {0}", string.Join(" ,", testCasesNotFoundNames.ToArray()));
            }

            Log().Info("Start updating test case runs with imported results");

            affectedDtos.ForEach(SendUpdateTestCaseRun);
        }
        public CheckMappingResult CheckMapping(TestRunImportPluginProfile settings,
                                               IEnumerable <TestCaseTestPlanDTO> testCaseTestPlans,
                                               PluginProfileErrorCollection errors)
        {
            try
            {
                var uri = settings.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson
                                                ? new Uri(string.Format("{0}/lastCompletedBuild/testReport/api/xml", settings.ResultsFilePath.TrimEnd(new[] { '/', '\\' })))
                                                : new Uri(settings.ResultsFilePath);
                var factoryResult = _streamFactory.OpenStream(uri, settings.PassiveMode);

                if (factoryResult != null)
                {
                    using (factoryResult.Stream)
                    {
                        using (var reader = new StreamReader(factoryResult.Stream))
                        {
                            try
                            {
                                var result = _resultsReaderFactory.GetResolver(settings, reader).GetTestRunImportResults();
                                if (result.Count > 0)
                                {
                                    var resolver = _resolverFactory.GetResolver(settings, result, testCaseTestPlans);
                                    return(resolver.ResolveTestCaseNames(errors));
                                }
                            }
                            catch (ApplicationException)
                            {
                                throw;
                            }
                            catch (XmlException ex)
                            {
                                throw new ApplicationException("Error parsing NUnit results XML file", ex);
                            }
                            catch (Exception ex)
                            {
                                throw new ApplicationException("Error importing NUnit results XML file", ex);
                            }
                        }
                    }
                }
            }
            catch (UriFormatException ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = "ResultsFilePath",
                    Message   = ex.Message
                });
            }
            catch (ApplicationException ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = "ResultsFilePath",
                    Message   = ex.Message
                });
            }
            catch (Exception ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = "ResultsFilePath",
                    Message   = string.Format("Could not read file \"{0}\": {1}", settings.ResultsFilePath, ex.Message)
                });
            }
            return(new CheckMappingResult {
                Errors = errors, NamesMappers = new List <NamesMapper>()
            });
        }