コード例 #1
0
        private TestSession NewSession(WorkingDirectory workingDirectory, ArchiveType archiveType, Uuid uuid)
        {
            Archive archive = new Archive(archiveType, uuid, workingDirectory);

            workingDirectory.CopyAddmlFileToAdministrativeMetadata();

            ConvertNoarkihToAddmlIfNoark4(archive);

            var testSession = new TestSession(archive);

            if (archiveType == ArchiveType.Noark5)
            {
                return(testSession);
            }

            ArchiveXmlFile addmlFile = archive.AddmlXmlUnit.File;

            try
            {
                AddmlInfo addml = AddmlUtil.ReadFromFile(addmlFile.FullName);

                var addmlDefinitionParser = new AddmlDefinitionParser(addml, workingDirectory, _statusEventHandler);

                testSession.AddmlDefinition = addmlDefinitionParser.GetAddmlDefinition();
            }
            catch (Exception exception)
            {
                var message = "Reading file " + addmlFile.Name + " failed: " + exception.Message;
                _log.Warning(exception, message);
                _statusEventHandler.RaiseEventOperationMessage(null, message, OperationMessageStatus.Error);
            }

            return(testSession);
        }
コード例 #2
0
        public void OnNavigatedTo(NavigationContext context)
        {
            try
            {
                _archiveType     = (ArchiveType)context.Parameters["archiveType"];
                _archiveFileName = (string)context.Parameters["archiveFileName"];

                _testSession = Directory.Exists(_archiveFileName)
                    ? _arkadeApi.CreateTestSession(ArchiveDirectory.Read(_archiveFileName, _archiveType))
                    : _arkadeApi.CreateTestSession(ArchiveFile.Read(_archiveFileName, _archiveType));

                if (!_testSession.IsTestableArchive())
                {
                    _statusEventHandler.RaiseEventOperationMessage(
                        Resources.GUI.TestrunnerArchiveTestability,
                        string.Format(Resources.GUI.TestrunnerArchiveNotTestable, ArkadeProcessingArea.LogsDirectory),
                        OperationMessageStatus.Warning
                        );
                }

                StartTestingCommand.RaiseCanExecuteChanged(); // testSession has been updated, reevaluate command
            }
            catch (Exception e)
            {
                string message = string.Format(Resources.GUI.ErrorReadingArchive, e.Message);
                Log.Error(e, message);
                _statusEventHandler.RaiseEventOperationMessage(null, message, OperationMessageStatus.Error);
            }
        }
コード例 #3
0
ファイル: Noark5TestEngine.cs プロジェクト: reftel/arkade5
        private List <IArkadeStructureTest> RunStructureTests(Archive archive)
        {
            List <IArkadeStructureTest> structureTests = _testProvider.GetStructureTests();

            foreach (var test in structureTests)
            {
                string testName = ArkadeTestInfoProvider.GetDisplayName(test);

                try
                {
                    _statusEventHandler.RaiseEventOperationMessage(testName, "", OperationMessageStatus.Started);
                    test.Test(archive);

                    var errorTestResults = test.GetTestRun().Results.Where(r => r.IsError());
                    if (errorTestResults.Any())
                    {
                        var message = new StringBuilder();

                        foreach (var result in errorTestResults)
                        {
                            message.AppendLine().AppendLine(result.Location + " - " + result.Message);
                        }

                        _statusEventHandler.RaiseEventOperationMessage(testName, message.ToString(),
                                                                       OperationMessageStatus.Error);
                    }
                    else
                    {
                        _statusEventHandler.RaiseEventOperationMessage(testName, "", OperationMessageStatus.Ok);
                    }
                }
                catch (Exception)
                {
                    _statusEventHandler.RaiseEventOperationMessage(testName, "", OperationMessageStatus.Error);
                    throw;
                }
            }
            return(structureTests);
        }
コード例 #4
0
        private List <AddmlFieldDefinition> ResolveFieldIndexesToDefinitions(List <FieldIndex> fieldIndexes, AddmlForeignKey foreignkey)
        {
            var definitions = new List <AddmlFieldDefinition>();

            foreach (var fieldIndex in fieldIndexes)
            {
                if (!_allFieldDefinitions.ContainsKey(fieldIndex))
                {
                    string errorMessage = "Missing ADDML definition object for field: " + fieldIndex;
                    Log.Debug(errorMessage + "\n" + foreignkey);
                    _statusEventHandler.RaiseEventOperationMessage(errorMessage, foreignkey.ToString(), OperationMessageStatus.Error);
                }
                else
                {
                    definitions.Add(_allFieldDefinitions[fieldIndex]);
                }
            }
            return(definitions);
        }
コード例 #5
0
ファイル: TestSessionFactory.cs プロジェクト: veridit/arkade5
 private void TarExtractionStartedEvent()
 {
     _statusEventHandler.RaiseEventOperationMessage(
         Resources.Messages.ReadingArchiveEvent,
         Resources.Messages.TarExtractionMessageStarted, OperationMessageStatus.Started);
 }
コード例 #6
0
        public TestSuite RunTestsOnArchive(TestSession testSession)
        {
            AddmlDefinition addmlDefinition = testSession.AddmlDefinition;

            _addmlProcessRunner.Init(addmlDefinition);

            List <FlatFile> flatFiles = addmlDefinition.GetFlatFiles();

            foreach (FlatFile file in flatFiles)
            {
                string testName = string.Format(Messages.RunningAddmlProcessesOnFile, file.GetName());

                var recordIdx = 1;

                _statusEventHandler.RaiseEventFileProcessingStarted(
                    new FileProcessingStatusEventArgs(testName, file.GetName())
                    );

                _addmlProcessRunner.RunProcesses(file);

                IRecordEnumerator recordEnumerator =
                    _flatFileReaderFactory.GetRecordEnumerator(testSession.Archive, file);

                int numberOfRecordsWithFieldDelimiterError = 0;

                while (recordEnumerator != null && recordEnumerator.MoveNext())
                {
                    try
                    {
                        _statusEventHandler.RaiseEventRecordProcessingStart();
                        Record record = recordEnumerator.Current;
                        _addmlProcessRunner.RunProcesses(file, record);

                        foreach (Field field in record.Fields)
                        {
                            _addmlProcessRunner.RunProcesses(file, field);
                        }
                    }
                    catch (ArkadeAddmlDelimiterException exception)
                    {
                        numberOfRecordsWithFieldDelimiterError++;

                        if (numberOfRecordsWithFieldDelimiterError <= MaxNumberOfSingleReportedFieldDelimiterErrors)
                        {
                            _testResultsFailedRecordsList.Add(new TestResult(ResultType.Error,
                                                                             new AddmlLocation(file.GetName(), exception.RecordName, ""),
                                                                             exception.Message + " Felttekst: " + exception.RecordData)
                                                              );

                            _statusEventHandler.RaiseEventOperationMessage(
                                $"{AddmlMessages.RecordLengthErrorTestName} i fil {file.GetName()}, post nummer {recordIdx}, feil nummer {numberOfRecordsWithFieldDelimiterError}",
                                exception.Message + " Felttekst: " + exception.RecordData, OperationMessageStatus.Error
                                );
                        }
                        else
                        {
                            _statusEventHandler.RaiseEventOperationMessage(
                                $"ADDML-poster med feil antall felt i filen {file.GetName()}",
                                $"Totalt antall: {numberOfRecordsWithFieldDelimiterError}",
                                OperationMessageStatus.Error
                                );
                        }
                    }
                    finally
                    {
                        _statusEventHandler.RaiseEventRecordProcessingStopped();
                    }

                    recordIdx++;
                }

                if (numberOfRecordsWithFieldDelimiterError > 0)
                {
                    _testResultsFailedRecordsList.Add(new TestResult(ResultType.ErrorGroup, new Location(file.GetName()),
                                                                     $"Filens totale antall poster med feil antall felt: {numberOfRecordsWithFieldDelimiterError}",
                                                                     numberOfRecordsWithFieldDelimiterError)
                                                      );
                }

                _addmlProcessRunner.EndOfFile(file);

                _statusEventHandler.RaiseEventFileProcessingFinished(
                    new FileProcessingStatusEventArgs(testName, file.GetName(), true)
                    );
            }

            TestSuite testSuite = _addmlProcessRunner.GetTestSuite();

            testSuite.AddTestRun(new AH_02_ControlExtraOrMissingFiles(addmlDefinition, testSession.Archive).GetTestRun());
            testSuite.AddTestRun(new AH_03_ControlRecordAndFieldDelimiters(_testResultsFailedRecordsList).GetTestRun());

            return(testSuite);
        }
コード例 #7
0
ファイル: TestRunnerViewModel.cs プロジェクト: halsov/arkade5
        private void RunTests()
        {
            try
            {
                NotifyStartRunningTests();

                if (Directory.Exists(_archiveFileName))
                {
                    _testSession = _arkadeApi.RunTests(ArchiveDirectory.Read(_archiveFileName, _archiveType));
                }
                else
                {
                    _testSession = _arkadeApi.RunTests(ArchiveFile.Read(_archiveFileName, _archiveType));
                }

                _testSession.TestSummary = new TestSummary(_numberOfProcessedFiles, _numberOfProcessedRecords, _numberOfTestsFinished);

                _testSession.AddLogEntry("Test run completed.");

                SaveHtmlReport();

                _testRunCompletedSuccessfully = true;
                _statusEventHandler.RaiseEventOperationMessage(Resources.UI.TestrunnerFinishedOperationMessage, null, OperationMessageStatus.Ok);
                NotifyFinishedRunningTests();
            }
            catch (ArkadeException e)
            {
                _testSession?.AddLogEntry("Test run failed: " + e.Message);
                _log.Error(e.Message, e);
                _statusEventHandler.RaiseEventOperationMessage(Resources.UI.TestrunnerFinishedWithError, e.Message, OperationMessageStatus.Error);
                NotifyFinishedRunningTests();
            }
            catch (Exception e)
            {
                _testSession?.AddLogEntry("Test run failed: " + e.Message);
                _log.Error(e.Message, e);

                var operationMessageBuilder = new StringBuilder();

                if (e.GetType() == typeof(FileNotFoundException))
                {
                    string nameOfMissingFile = new FileInfo(((FileNotFoundException)e).FileName).Name;
                    operationMessageBuilder.Append(string.Format(Resources.UI.FileNotFoundMessage, nameOfMissingFile));
                }
                else
                {
                    operationMessageBuilder.Append(e.Message);
                }

                string fileName = new DetailedExceptionMessage(e).WriteToFile();

                if (!string.IsNullOrEmpty(fileName))
                {
                    operationMessageBuilder.AppendLine("\n" + string.Format(Resources.UI.DetailedErrorMessageInfo, fileName));
                }

                string operationMessage = operationMessageBuilder.ToString();

                _statusEventHandler.RaiseEventOperationMessage(
                    Resources.UI.TestrunnerFinishedWithError, operationMessage, OperationMessageStatus.Error
                    );

                NotifyFinishedRunningTests();
            }
        }