Ejemplo n.º 1
0
        private void SummarizeExpectedResults(ParseFileResult result, AppendedResults appendedResults)
        {
            if (result.Parsed)
            {
                if (!appendedResults.AppendedVisits.Any())
                {
                    throw new ExpectedException("File was parsed but no visits were appended.");
                }

                _log.Info($"Successfully parsed {appendedResults.AppendedVisits.Count} visits.");
            }
            else
            {
                var actualError   = result.ErrorMessage ?? string.Empty;
                var expectedError = Context.ExpectedError ?? string.Empty;

                if (!actualError.Equals(expectedError))
                {
                    throw new ExpectedException(
                              $"Expected an error message of '{expectedError}' but received '{actualError}' instead.");
                }

                _log.Info($"ParsedResult.Status == {Context.ExpectedStatus} with Error='{Context.ExpectedError}' as expected.");
            }
        }
 private void SummarizeResults(ParseFileResult result, AppendedResults appendedResults)
 {
     try
     {
         if (result.Status == Context.ExpectedStatus)
         {
             SummarizeExpectedResults(result, appendedResults);
         }
         else
         {
             SummarizeFailedResults(result, appendedResults);
         }
     }
     catch (ExpectedException e)
     {
         if (Context.DataPaths.Count > 1)
         {
             Log.Error(e.Message);
             ++FailedCount;
         }
         else
         {
             throw;
         }
     }
 }
Ejemplo n.º 3
0
 private void SummarizeResults(ParseFileResult result, AppendedResults appendedResults)
 {
     if (!result.Parsed)
     {
         if (result.Status == ParseFileStatus.CannotParse)
         {
             if (!string.IsNullOrEmpty(result.ErrorMessage))
             {
                 Log.Error($"Can't parse '{DataPath}'. {result.ErrorMessage}");
             }
             else
             {
                 Log.Warn($"File '{DataPath}' is not parsed by the plugin.");
             }
         }
         else
         {
             Log.Error($"Result: Parsed={result.Parsed} Status={result.Status} ErrorMessage={result.ErrorMessage}");
         }
     }
     else
     {
         if (!appendedResults.AppendedVisits.Any())
         {
             Log.Warn("File was parsed but no visits were appended.");
         }
         else
         {
             Log.Info($"Successfully parsed {appendedResults.AppendedVisits.Count} visits.");
         }
     }
 }
Ejemplo n.º 4
0
 private void SummarizeResults(ParseFileResult result, AppendedResults appendedResults)
 {
     if (result.Status == Context.ExpectedStatus)
     {
         SummarizeExpectedResults(result, appendedResults);
     }
     else
     {
         SummarizeFailedResults(result, appendedResults);
     }
 }
Ejemplo n.º 5
0
        private void SaveAppendedResults(AppendedResults appendedResults)
        {
            if (string.IsNullOrEmpty(Context.JsonPath))
            {
                return;
            }

            _log.Info($"Saving {appendedResults.AppendedVisits.Count} visits data to '{Context.JsonPath}'");

            File.WriteAllText(Context.JsonPath, appendedResults.ToJson().IndentJson());
        }
        private void SaveAppendedResults(string sourcePath, AppendedResults appendedResults)
        {
            if (string.IsNullOrEmpty(Context.JsonPath))
            {
                return;
            }

            var savePath = Directory.Exists(Context.JsonPath)
                ? Path.Combine(Context.JsonPath, $"{Path.GetFileName(sourcePath)}.json")
                : Context.JsonPath;

            Log.Info($"Saving {appendedResults.AppendedVisits.Count} visits data to '{savePath}'");

            File.WriteAllText(savePath, appendedResults.ToJson().IndentJson());
        }
Ejemplo n.º 7
0
        private void SummarizeFailedResults(ParseFileResult result, AppendedResults appendedResults)
        {
            if (result.Parsed)
            {
                throw new ExpectedException(
                          $"File was parsed successfully with {appendedResults.AppendedVisits.Count} visits appended.");
            }

            if (result.Status != ParseFileStatus.CannotParse)
            {
                throw new ExpectedException(
                          $"Result: Parsed={result.Parsed} Status={result.Status} ErrorMessage={result.ErrorMessage}");
            }

            if (!string.IsNullOrEmpty(result.ErrorMessage))
            {
                throw new ExpectedException($"Can't parse '{Context.DataPath}'. {result.ErrorMessage}");
            }

            throw new ExpectedException($"File '{Context.DataPath}' is not parsed by the plugin.");
        }
        private void SummarizeFailedResults(string path, ParseFileResultWithAttachments resultWithAttachments, AppendedResults appendedResults)
        {
            var result = resultWithAttachments.Result;

            var attachmentSummary = GetAttachmentSummary(resultWithAttachments.Attachments);

            if (result.Parsed)
            {
                throw new ExpectedException(
                          $"'{path}' was parsed successfully with {appendedResults.AppendedVisits.Count} visits{attachmentSummary} appended when {Context.ExpectedStatus} was expected.");
            }

            if (result.Status != ParseFileStatus.CannotParse)
            {
                throw new ExpectedException(
                          $"Result: '{path}' Parsed={result.Parsed} Status={result.Status} ErrorMessage={result.ErrorMessage}{attachmentSummary}");
            }

            var errorMessage = result.ErrorMessage;

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new ExpectedException($"Can't parse '{path}'. {errorMessage}{attachmentSummary}");
            }

            throw new ExpectedException($"File '{path}'{attachmentSummary} is not parsed by the plugin.");
        }
        private void SummarizeExpectedResults(string path, ParseFileResultWithAttachments resultWithAttachments, AppendedResults appendedResults)
        {
            var result = resultWithAttachments.Result;

            var attachmentSummary = GetAttachmentSummary(resultWithAttachments.Attachments);

            if (result.Parsed)
            {
                if (!appendedResults.AppendedVisits.Any())
                {
                    throw new ExpectedException($"'{path}' was parsed{attachmentSummary} but no visits were appended.");
                }

                Log.Info($"Successfully parsed {appendedResults.AppendedVisits.Count} visits{attachmentSummary} from '{path}'.");
            }
            else
            {
                var actualError   = result.ErrorMessage ?? string.Empty;
                var expectedError = Context.ExpectedError ?? string.Empty;

                if (!actualError.Equals(expectedError))
                {
                    throw new ExpectedException(
                              $"Expected an error message of '{expectedError}' but received '{actualError}' instead while parsing '{path}'{attachmentSummary}.");
                }

                Log.Info($"ParsedResult.Status == {Context.ExpectedStatus} with Error='{Context.ExpectedError}' as expected when parsing '{path}'{attachmentSummary}.");
            }
        }
 private void SummarizeResults(string path, ParseFileResultWithAttachments resultWithAttachments, AppendedResults appendedResults)
 {
     try
     {
         if (resultWithAttachments.Result?.Status == Context.ExpectedStatus)
         {
             SummarizeExpectedResults(path, resultWithAttachments, appendedResults);
         }
         else
         {
             SummarizeFailedResults(path, resultWithAttachments, appendedResults);
         }
     }
     catch (ExpectedException e)
     {
         if (Context.DataPaths.Count > 1)
         {
             Log.Error(e.Message);
             ++FailedCount;
         }
         else
         {
             throw;
         }
     }
 }
Ejemplo n.º 11
0
 private void SummarizeResults(string path, ParseFileResultWithAttachments resultWithAttachments, AppendedResults appendedResults)
 {
     try
     {
         // Use a string comparison of the enum status, since they are not the same enum (which allows different frameworks to be used)
         if ($"{resultWithAttachments.Result?.Status}" == $"{Context.ExpectedStatus}")
         {
             SummarizeExpectedResults(path, resultWithAttachments, appendedResults);
         }
         else
         {
             SummarizeFailedResults(path, resultWithAttachments, appendedResults);
         }
     }
     catch (ExpectedException e)
     {
         if (Context.DataPaths.Count > 1)
         {
             Log.Error(e.Message);
             ++FailedCount;
         }
         else
         {
             throw;
         }
     }
 }