using FluentAssertions; using Marathon.Infrastructure.Scraping.Parsers; using Microsoft.Extensions.Logging.Abstractions; namespace Marathon.Infrastructure.Tests.Scraping; /// /// Regression test for the live-listing parser. The fixture /// diag-live-sample.html is a real /su/live capture from /// 2026-05-09 with 16 in-progress matches. Pre-fix the parser returned /// 0 because: /// /// Live rows omit data-event-path — the pre-match-only /// attribute the parser made mandatory. /// The closest data-sport-treeId ancestor on the live /// page is a category-tree wrapper (e.g. 26418=Football), not /// the canonical breadcrumb sport ID (11=Football) the rest of /// the app uses. /// /// public sealed class LiveEventsParserTests { private static readonly string FixturePath = Path.Combine( AppContext.BaseDirectory, "Fixtures", "marathonbet", "diag-live-sample.html"); private readonly LiveEventsParser _sut; public LiveEventsParserTests() { var serverTimeProvider = new ServerTimeProvider( NullLogger.Instance); _sut = new LiveEventsParser( serverTimeProvider, NullLogger.Instance); } [Fact] public async Task ParseAsync_LiveSample_ReturnsAllSixteenLiveEvents() { var html = await File.ReadAllTextAsync(FixturePath); var events = await _sut.ParseAsync(html); events.Should().HaveCount(16); } [Fact] public async Task ParseAsync_LiveSample_SynthesizesLiveTreeIdEventPaths() { var html = await File.ReadAllTextAsync(FixturePath); var events = await _sut.ParseAsync(html); events.Should().OnlyContain(e => e.EventPath != null && e.EventPath.StartsWith("live/")); } [Fact] public async Task ParseAsync_LiveSample_MapsKnownSportNamesToCanonicalIds() { // The live page wraps rows in containers whose data-sport-treeId is a // category ID (e.g. 26418 for Football-live). The parser resolves // these to canonical breadcrumb IDs via the sport-category-label text // for the known sports (Football=11, Basketball=6, Tennis=22723, // Hockey=43658). Other sports (cybersport, table tennis, …) keep // their category-tree ID and the UI renders them as "Sport ". var html = await File.ReadAllTextAsync(FixturePath); var events = await _sut.ParseAsync(html); // The fixture has Эльче-Алавес under Футбол → must be sport=11 var football = events.SingleOrDefault(e => e.Id.Value == "26340575"); football.Should().NotBeNull(); football!.Sport.Value.Should().Be(11); } }