Files
chapter-organizer/Tests/Parsers/EventOccurrenceParserTestHelpers.cs
T
poprhythm 2d3b29176f Enhance event occurrence parsing with detailed issue reporting and location configuration
This commit introduces a new structure for handling parsing issues in the EventOccurrenceParser, allowing for detailed reporting of parsing problems such as unmatched lines, missing event definitions, and parsing failures for time, date, and location. A new ParsingIssue class has been added to encapsulate these details. Additionally, a LocationParsingConfiguration class has been implemented to support customizable location patterns, enhancing the flexibility of the parser. The EventOccurrenceParserService has been updated to utilize this configuration, and new tests have been added to ensure robust issue detection and reporting. Furthermore, the UI has been updated to display parsing issues, improving user feedback during the import process.
2026-01-06 23:08:42 -05:00

59 lines
1.4 KiB
C#

using Core.Entities;
using Core.Models;
using Tests.Builders;
namespace Tests.Parsers;
/// <summary>
/// Shared helper methods for EventOccurrenceParser tests.
/// </summary>
public static class EventOccurrenceParserTestHelpers
{
/// <summary>
/// Creates a temporary file with the specified content and returns the FileInfo.
/// </summary>
public static FileInfo CreateTempFile(string content)
{
var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".txt");
File.WriteAllText(tempPath, content);
return new FileInfo(tempPath);
}
/// <summary>
/// Creates a minimal EventDefinition for testing.
/// </summary>
public static EventDefinition CreateTestEvent(string name)
{
return EventDefinitionBuilder.Individual(name).Build();
}
/// <summary>
/// Creates a LocationParsingConfiguration for testing.
/// </summary>
public static LocationParsingConfiguration CreateLocationConfig(params string[] patterns)
{
return new LocationParsingConfiguration
{
LocationPatterns = patterns.ToList()
};
}
/// <summary>
/// Cleans up a temporary file.
/// </summary>
public static void CleanupTempFile(FileInfo file)
{
try
{
if (file.Exists)
File.Delete(file.FullName);
}
catch
{
// Ignore cleanup errors
}
}
}