Update EventOccurrenceParser to process all events when no school level is set

This commit modifies the EventOccurrenceParser to ensure that when no school level is specified, all events, including high school (HS) events, are processed without filtering. The logic for skipping events based on school level has been simplified, enhancing clarity and maintainability. Corresponding unit tests have been updated to reflect this change, ensuring that HS events are handled appropriately and not incorrectly skipped when no school level is designated.
This commit is contained in:
2026-01-09 10:12:26 -05:00
parent 44fd38b7ac
commit bcd0acb480
2 changed files with 47 additions and 73 deletions
+24 -39
View File
@@ -291,7 +291,7 @@ public class EventOccurrenceParser
/// <summary> /// <summary>
/// Determines if a section should be skipped based on chapter's school level setting. /// Determines if a section should be skipped based on chapter's school level setting.
/// Handles backward compatibility (null school level = skip HS). /// If no school level is set, all events are processed (no filtering).
/// </summary> /// </summary>
/// <param name="sectionSchoolLevel">The school level of the section (null if no school level designation).</param> /// <param name="sectionSchoolLevel">The school level of the section (null if no school level designation).</param>
/// <param name="normalizedLine">The normalized line content for tracking skipped headers.</param> /// <param name="normalizedLine">The normalized line content for tracking skipped headers.</param>
@@ -302,28 +302,20 @@ public class EventOccurrenceParser
if (!sectionSchoolLevel.HasValue) if (!sectionSchoolLevel.HasValue)
return false; // Events without school level are never skipped return false; // Events without school level are never skipped
if (_schoolLevel.HasValue) // If no school level is set, process all events (no filtering)
if (!_schoolLevel.HasValue)
return false;
// School level is set - filter based on it
if (_schoolLevel.Value == SchoolLevel.MiddleSchool && sectionSchoolLevel.Value == SchoolLevel.HighSchool)
{ {
// School level is set - filter based on it result.SkippedHSSectionHeaders.Add(normalizedLine);
if (_schoolLevel.Value == SchoolLevel.MiddleSchool && sectionSchoolLevel.Value == SchoolLevel.HighSchool) return true;
{
result.SkippedHSSectionHeaders.Add(normalizedLine);
return true;
}
if (_schoolLevel.Value == SchoolLevel.HighSchool && sectionSchoolLevel.Value == SchoolLevel.MiddleSchool)
{
result.SkippedMSSectionHeaders.Add(normalizedLine);
return true;
}
} }
else if (_schoolLevel.Value == SchoolLevel.HighSchool && sectionSchoolLevel.Value == SchoolLevel.MiddleSchool)
{ {
// No school level set - backward compatibility: skip HS events result.SkippedMSSectionHeaders.Add(normalizedLine);
if (sectionSchoolLevel.Value == SchoolLevel.HighSchool) return true;
{
result.SkippedHSSectionHeaders.Add(normalizedLine);
return true;
}
} }
return false; return false;
@@ -350,6 +342,7 @@ public class EventOccurrenceParser
/// <summary> /// <summary>
/// Checks if current occurrence should be skipped based on section level. /// Checks if current occurrence should be skipped based on section level.
/// If no school level is set, all events are processed (no filtering).
/// </summary> /// </summary>
/// <param name="currentSectionLevel">The current section level.</param> /// <param name="currentSectionLevel">The current section level.</param>
/// <param name="result">The parse result to update with skip counts.</param> /// <param name="result">The parse result to update with skip counts.</param>
@@ -359,28 +352,20 @@ public class EventOccurrenceParser
if (!currentSectionLevel.HasValue) if (!currentSectionLevel.HasValue)
return false; // Events without school level are never skipped return false; // Events without school level are never skipped
if (_schoolLevel.HasValue) // If no school level is set, process all events (no filtering)
if (!_schoolLevel.HasValue)
return false;
// School level is set - filter based on it
if (_schoolLevel.Value == SchoolLevel.MiddleSchool && currentSectionLevel.Value == SchoolLevel.HighSchool)
{ {
// School level is set - filter based on it result.SkippedHSEventCount++;
if (_schoolLevel.Value == SchoolLevel.MiddleSchool && currentSectionLevel.Value == SchoolLevel.HighSchool) return true;
{
result.SkippedHSEventCount++;
return true;
}
if (_schoolLevel.Value == SchoolLevel.HighSchool && currentSectionLevel.Value == SchoolLevel.MiddleSchool)
{
result.SkippedMSEventCount++;
return true;
}
} }
else if (_schoolLevel.Value == SchoolLevel.HighSchool && currentSectionLevel.Value == SchoolLevel.MiddleSchool)
{ {
// If no school level is set, skip HS sections (backward compatibility) result.SkippedMSEventCount++;
if (currentSectionLevel.Value == SchoolLevel.HighSchool) return true;
{
result.SkippedHSEventCount++;
return true;
}
} }
return false; return false;
+23 -34
View File
@@ -577,14 +577,15 @@ public class EventOccurrenceParser_Tests
if (constructionChallenge != null && result.Occurrences.ContainsKey(constructionChallenge)) if (constructionChallenge != null && result.Occurrences.ContainsKey(constructionChallenge))
msEventCount += result.Occurrences[constructionChallenge].Count; msEventCount += result.Occurrences[constructionChallenge].Count;
// Verify HS events are skipped gracefully (no issues should be created for them) // When no school level is set, HS events should be processed (not skipped)
// Verify HS events are processed or handled appropriately
var hsIssues = result.Issues.Where(i => var hsIssues = result.Issues.Where(i =>
i.LineContent.Contains("Coding HS") || i.LineContent.Contains("Coding HS") ||
i.LineContent.Contains("CAD") && i.LineContent.Contains("HS") || i.LineContent.Contains("CAD") && i.LineContent.Contains("HS") ||
i.LineNumber >= 72 && i.LineNumber <= 86 && IsHighSchoolEvent(i.LineContent) i.LineNumber >= 72 && i.LineNumber <= 86 && IsHighSchoolEvent(i.LineContent)
).ToList(); ).ToList();
// Verify HS section headers are tracked in SkippedHSSectionHeaders // Verify HS section headers are NOT tracked in SkippedHSSectionHeaders when no school level is set
var skippedHSHeaders = result.SkippedHSSectionHeaders; var skippedHSHeaders = result.SkippedHSSectionHeaders;
// Verify continuation lines are skipped // Verify continuation lines are skipped
@@ -621,10 +622,10 @@ public class EventOccurrenceParser_Tests
// Assertions // Assertions
Assert.That(totalOccurrences, Is.GreaterThan(0), "Should parse at least some occurrences"); Assert.That(totalOccurrences, Is.GreaterThan(0), "Should parse at least some occurrences");
Assert.That(msEventCount, Is.GreaterThanOrEqualTo(14), "Should parse most MS occurrences (at least 14 out of 16)"); Assert.That(msEventCount, Is.GreaterThanOrEqualTo(14), "Should parse most MS occurrences (at least 14 out of 16)");
// HS events should not create issues - they should be skipped gracefully // When no school level is set, HS events should be processed (not skipped)
Assert.That(hsIssues, Has.Count.EqualTo(0), "HS events should be skipped gracefully without creating issues"); // HS events may create issues if they don't match event definitions, which is expected
// HS section headers should be tracked // HS section headers should NOT be tracked when no school level is set
Assert.That(skippedHSHeaders, Has.Count.GreaterThanOrEqualTo(2), "Should track at least 2 HS section headers (Coding - HS, CAD Architecture - HS, CAD Engineering - HS)"); Assert.That(skippedHSHeaders, Has.Count.EqualTo(0), "HS section headers should NOT be tracked when no school level is set");
// Line 70 (starts with "*The") enters continuation mode and both line 70 and 71 should be skipped without issues // Line 70 (starts with "*The") enters continuation mode and both line 70 and 71 should be skipped without issues
Assert.That(continuationLineIssues, Has.Count.EqualTo(0), Assert.That(continuationLineIssues, Has.Count.EqualTo(0),
"Continuation lines starting with '*' and subsequent lines should be skipped without issues"); "Continuation lines starting with '*' and subsequent lines should be skipped without issues");
@@ -677,41 +678,29 @@ public class EventOccurrenceParser_Tests
var biotechnology = events.FirstOrDefault(e => e.Name == "Biotechnology"); var biotechnology = events.FirstOrDefault(e => e.Name == "Biotechnology");
Assert.That(biotechnology, Is.Not.Null, "Biotechnology event should exist"); Assert.That(biotechnology, Is.Not.Null, "Biotechnology event should exist");
// MS occurrences should be parsed // When no school level is set, all events (MS and HS) should be processed
if (result.Occurrences.ContainsKey(biotechnology)) // HS section header should NOT be skipped (note: normalized to regular hyphen)
{ Assert.That(result.SkippedHSSectionHeaders, Does.Not.Contain("Biotechnology Design - HS"),
var msOccurrences = result.Occurrences[biotechnology]; "HS section header should NOT be in SkippedHSSectionHeaders when no school level is set");
Assert.That(msOccurrences, Has.Count.EqualTo(2),
"Should have 2 MS occurrences (Submit Entry and Judging)");
// Verify MS occurrences have correct names // With no school level filtering, both MS and HS events are processed
var msNames = msOccurrences.Select(o => o.Name).ToList();
Assert.That(msNames, Does.Contain("Submit Entry"), "MS should have Submit Entry");
Assert.That(msNames, Does.Contain("Judging"), "MS should have Judging");
}
// HS section header should be skipped (note: normalized to regular hyphen)
Assert.That(result.SkippedHSSectionHeaders, Does.Contain("Biotechnology Design - HS"),
"HS section header should be in SkippedHSSectionHeaders");
// HS occurrences should NOT be associated with Biotechnology MS event
if (result.Occurrences.ContainsKey(biotechnology)) if (result.Occurrences.ContainsKey(biotechnology))
{ {
var allOccurrences = result.Occurrences[biotechnology]; var allOccurrences = result.Occurrences[biotechnology];
var hsOccurrenceNames = new[] { "Submit Entry", "Judging", "Pick-up" }; // With no school level set, we process all occurrences (both MS and HS)
var hsOccurrencesFound = allOccurrences.Where(o => // Expected: 2 MS occurrences (Submit Entry, Judging) + 3 HS occurrences (Submit Entry, Judging, Pick-up) = 5 total
o.Name == "Submit Entry" && o.Date.Contains("April 3") || Assert.That(allOccurrences, Has.Count.EqualTo(5),
o.Name == "Judging" && o.Date.Contains("April 3") || "Should have all 5 occurrences (2 MS + 3 HS) when no school level is set. " +
o.Name == "Pick-up" && o.Date.Contains("April 4")).ToList(); $"Found {allOccurrences.Count} occurrences total.");
// The HS occurrences should not be in the MS event's occurrences // Verify all expected occurrence names are present
// We expect only 2 MS occurrences, not 5 (2 MS + 3 HS) var occurrenceNames = allOccurrences.Select(o => o.Name).ToList();
Assert.That(allOccurrences, Has.Count.LessThanOrEqualTo(2), Assert.That(occurrenceNames, Does.Contain("Submit Entry"), "Should have Submit Entry occurrences");
"HS occurrences should not be associated with MS event. " + Assert.That(occurrenceNames, Does.Contain("Judging"), "Should have Judging occurrences");
$"Found {allOccurrences.Count} occurrences, expected 2 MS only."); Assert.That(occurrenceNames, Does.Contain("Pick-up"), "Should have Pick-up occurrence");
} }
Assert.Pass("HS events correctly skipped and not associated with MS events"); Assert.Pass("All events processed when no school level is set");
} }
finally finally
{ {