using Core.Entities; using Core.Parsers.EventOccurrence; using FuzzySharp; using NUnit.Framework; namespace Tests.Parsers.EventOccurrence; [TestFixture] public class SectionHeaderMatcher_Tests { [Test] public void IsGeneralSchedule_GeneralScheduleLine_ReturnsTrue() { // Act & Assert Assert.That(SectionHeaderMatcher.IsGeneralSchedule("General Schedule"), Is.True); Assert.That(SectionHeaderMatcher.IsGeneralSchedule("General Schedule - MS"), Is.True); } [Test] public void IsGeneralSchedule_RegularEvent_ReturnsFalse() { // Act & Assert Assert.That(SectionHeaderMatcher.IsGeneralSchedule("Test Event - MS"), Is.False); } [Test] public void HasSchoolLevel_ContainsMS_ReturnsTrue() { // Act & Assert Assert.That(SectionHeaderMatcher.HasSchoolLevel("Test Event - MS"), Is.True); Assert.That(SectionHeaderMatcher.HasSchoolLevel("Test Event MS"), Is.True); } [Test] public void HasSchoolLevel_ContainsHS_ReturnsTrue() { // Act & Assert Assert.That(SectionHeaderMatcher.HasSchoolLevel("Test Event - HS"), Is.True); Assert.That(SectionHeaderMatcher.HasSchoolLevel("Test Event HS"), Is.True); } [Test] public void HasSchoolLevel_NoSchoolLevel_ReturnsFalse() { // Act & Assert Assert.That(SectionHeaderMatcher.HasSchoolLevel("Test Event"), Is.False); } [Test] public void MatchEventDefinition_ExactMatch_ReturnsEvent() { // Arrange var events = new List { new() { Name = "Test Event" }, new() { Name = "Another Event" } }; // Act var result = SectionHeaderMatcher.MatchEventDefinition("Test Event", events); // Assert Assert.That(result, Is.Not.Null); Assert.That(result!.Name, Is.EqualTo("Test Event")); } [Test] public void MatchEventDefinition_CloseMatch_ReturnsEvent() { // Arrange var events = new List { new() { Name = "Test Event" }, new() { Name = "Another Event" } }; // Act var result = SectionHeaderMatcher.MatchEventDefinition("Test Evnt", events); // Typo but close // Assert Assert.That(result, Is.Not.Null); Assert.That(result!.Name, Is.EqualTo("Test Event")); } [Test] public void MatchEventDefinition_NoMatch_ReturnsNull() { // Arrange var events = new List { new() { Name = "Test Event" } }; // Act var result = SectionHeaderMatcher.MatchEventDefinition("Completely Different Event", events); // Assert Assert.That(result, Is.Null); } [Test] public void MatchEventDefinition_EmptyEvents_ReturnsNull() { // Arrange var events = new List(); // Act var result = SectionHeaderMatcher.MatchEventDefinition("Test Event", events); // Assert Assert.That(result, Is.Null); } [Test] public void MatchEventDefinition_MultipleMatches_ReturnsBestMatch() { // Arrange var events = new List { new() { Name = "Test Event" }, new() { Name = "Test Event Advanced" }, new() { Name = "Another Event" } }; // Act var result = SectionHeaderMatcher.MatchEventDefinition("Test Event", events); // Assert Assert.That(result, Is.Not.Null); Assert.That(result!.Name, Is.EqualTo("Test Event")); // Exact match should win } [Test] public void GetBestMatchRatio_ValidEvents_ReturnsRatio() { // Arrange var events = new List { new() { Name = "Test Event" } }; // Act var ratio = SectionHeaderMatcher.GetBestMatchRatio("Test Event", events); // Assert Assert.That(ratio, Is.GreaterThan(50)); // Should be high for exact match } [Test] public void GetBestMatchRatio_EmptyEvents_ReturnsZero() { // Arrange var events = new List(); // Act var ratio = SectionHeaderMatcher.GetBestMatchRatio("Test Event", events); // Assert Assert.That(ratio, Is.EqualTo(0)); } }