WIP(initial-implementation): parallel batch P2/P3/P5 — code complete, unreviewed

Snapshot of the parallel batch (Phases 2 + 3 + 5) at session pause. Solution does
NOT build cleanly yet — known cross-phase compile issues remain to be resolved
before review. See plans/initial-implementation/PLAN.md "Resume Notes" section
for the exact tomorrow-morning action list.

Phase 2 (Storage):
- Repository interfaces in Marathon.Application/Abstractions
- DateRange, ExportKind, StorageOptions in Marathon.Application/Storage
- EF Core 8 + SQLite (WAL) persistence: 7 entities + configurations + 4 repos
- Hand-written InitialCreate migration (dotnet ef blocked by parallel work)
- ClosedXML ExcelExporter with exact customer-spec wide columns
- PersistenceModule.AddMarathonPersistence DI extension
- Round-trip + export tests (cannot run yet — see cross-phase issues)

Phase 3 (Scraping):
- IOddsScraper, IBetPlacer in Marathon.Application/Abstractions
- ScrapingOptions in Marathon.Infrastructure/Configuration
- MarathonbetScraper with 4 parsers (Upcoming, Live, EventOdds, Results)
- Helpers: ServerTimeProvider, PeriodScopeMapper, OutcomeCodeMapper, MoscowDateParser
- UserAgentRotatorHandler + Polly v8 resilience pipeline
- ScrapingModule.AddMarathonScraping DI extension
- GlobalUsings.cs aliases for EventId / Configuration disambiguation
- Parser tests with trimmed HTML fixtures
- ScrapeResultsAsync interim no-op (Phase 8 will replace via watch-list polling)

Phase 5 (UI shell — killed mid-final-verify, assumed ~95%):
- Marathon.UI populated: MainLayout, App.razor, Pages (Home, Settings),
  Components, Theme (MarathonTheme.cs + Tokens.cs + app.css), Resources
  (SharedResource.{cs,ru.resx,en.resx}), Services (ISettingsWriter), wwwroot
- WPF host: App.xaml(.cs), MainWindow.xaml(.cs), Marathon.Hosts.WpfBlazor.csproj
  with Microsoft.AspNetCore.Components.WebView.Wpf + MudBlazor + Serilog
- appsettings.json + appsettings.Development.json with all sections wired
- bUnit tests: MainLayoutTests, LocaleSwitcherTests, ThemeToggleTests,
  JsonSettingsWriterTests + Support helpers

Cross-phase issues to resolve at next session:
1. Phase 2 repository classes are 'internal' — Phase 3's tests can't reference
   them. Fix: add InternalsVisibleTo to Marathon.Infrastructure.csproj.
2. Phase 5: LocalizationOptions namespace ambiguity (AspNetCore vs Extensions).
3. Phase 5: WpfBlazor Serilog API mismatch.

Reviewer has NOT run on this batch. Move to Phase 4 only after build is green
and a combined parallel-batch reviewer passes.
This commit is contained in:
2026-05-05 01:56:53 +03:00
parent 144c936e90
commit e4d8476782
129 changed files with 8524 additions and 121 deletions
@@ -0,0 +1,195 @@
using FluentAssertions;
using Marathon.Domain.Enums;
using Marathon.Infrastructure.Scraping.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
namespace Marathon.Infrastructure.Tests.Scraping;
public sealed class EventOddsParserTests
{
private static string FixturePath(string filename) => Path.Combine(
AppContext.BaseDirectory,
"Fixtures", "marathonbet", filename);
private readonly EventOddsParser _sut;
public EventOddsParserTests()
{
var serverTime = new ServerTimeProvider(NullLogger<ServerTimeProvider>.Instance);
var periodMapper = new PeriodScopeMapper(basketballQuarterMode: false);
_sut = new EventOddsParser(
serverTime,
periodMapper,
NullLogger<EventOddsParser>.Instance);
}
// ── Football fixture ───────────────────────────────────────────────────
[Fact]
public async Task ParseAsync_FootballFixture_ReturnsNonNullSnapshot()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
snapshot.Should().NotBeNull();
}
[Fact]
public async Task ParseAsync_FootballFixture_SnapshotEventIdMatches()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
snapshot!.EventId.Value.Should().Be("26456117");
}
[Fact]
public async Task ParseAsync_FootballFixture_MatchWin1Extracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var win1 = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Win && b.Side == Side.Side1);
win1.Should().NotBeNull("Match Win-1 bet must be present");
win1!.Rate.Value.Should().Be(1.65m);
}
[Fact]
public async Task ParseAsync_FootballFixture_MatchDrawExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var draw = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Draw);
draw.Should().NotBeNull("Match Draw bet must be present");
draw!.Rate.Value.Should().Be(4.1m);
}
[Fact]
public async Task ParseAsync_FootballFixture_MatchWin2Extracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var win2 = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Win && b.Side == Side.Side2);
win2.Should().NotBeNull("Match Win-2 bet must be present");
win2!.Rate.Value.Should().Be(5.7m);
}
[Fact]
public async Task ParseAsync_FootballFixture_HandicapBetsExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var fora1 = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.WinFora && b.Side == Side.Side1);
var fora2 = snapshot.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.WinFora && b.Side == Side.Side2);
fora1.Should().NotBeNull("Handicap Side1 must be present");
fora2.Should().NotBeNull("Handicap Side2 must be present");
fora1!.Value!.Value.Should().Be(-1.0m);
fora1.Rate.Value.Should().Be(2.04m);
fora2!.Value!.Value.Should().Be(1.0m);
fora2.Rate.Value.Should().Be(1.82m);
}
[Fact]
public async Task ParseAsync_FootballFixture_TotalBetsExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var totalLess = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Total && b.Side == Side.Less);
var totalMore = snapshot.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Total && b.Side == Side.More);
totalLess.Should().NotBeNull("Total Less must be present");
totalMore.Should().NotBeNull("Total More must be present");
totalLess!.Value!.Value.Should().Be(2.5m);
totalMore!.Value!.Value.Should().Be(2.5m);
}
[Fact]
public async Task ParseAsync_FootballFixture_Period1WinExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var p1Win1 = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is PeriodScope { Number: 1 } && b.Type == BetType.Win && b.Side == Side.Side1);
var p1Draw = snapshot.Bets.FirstOrDefault(b =>
b.Scope is PeriodScope { Number: 1 } && b.Type == BetType.Draw);
var p1Win2 = snapshot.Bets.FirstOrDefault(b =>
b.Scope is PeriodScope { Number: 1 } && b.Type == BetType.Win && b.Side == Side.Side2);
p1Win1.Should().NotBeNull("Period-1 Win-1 must be present for football");
p1Draw.Should().NotBeNull("Period-1 Draw must be present for football");
p1Win2.Should().NotBeNull("Period-1 Win-2 must be present for football");
}
[Fact]
public async Task ParseAsync_FootballFixture_SourceIsStamped()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.Live);
snapshot!.Source.Should().Be(OddsSource.Live);
}
// ── Basketball fixture ─────────────────────────────────────────────────
[Fact]
public async Task ParseAsync_BasketballFixture_MatchWin1WithNoDrawExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-basketball-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
snapshot.Should().NotBeNull();
var win1 = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Win && b.Side == Side.Side1);
var draw = snapshot.Bets.FirstOrDefault(b =>
b.Scope is MatchScope && b.Type == BetType.Draw);
win1.Should().NotBeNull("Basketball Match Win-1 must be present");
draw.Should().BeNull("Basketball (OT market) has no Draw outcome");
}
[Fact]
public async Task ParseAsync_BasketballFixture_Period1WinsExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath("event-basketball-sample.html"));
var snapshot = await _sut.ParseAsync(html, OddsSource.PreMatch);
var p1Win1 = snapshot!.Bets.FirstOrDefault(b =>
b.Scope is PeriodScope { Number: 1 } && b.Type == BetType.Win && b.Side == Side.Side1);
var p1Win2 = snapshot.Bets.FirstOrDefault(b =>
b.Scope is PeriodScope { Number: 1 } && b.Type == BetType.Win && b.Side == Side.Side2);
p1Win1.Should().NotBeNull("Basketball Period-1 Win-1 must be present");
p1Win2.Should().NotBeNull("Basketball Period-1 Win-2 must be present");
}
}
@@ -0,0 +1,91 @@
using FluentAssertions;
using Marathon.Infrastructure.Scraping.Parsers;
namespace Marathon.Infrastructure.Tests.Scraping;
public sealed class MoscowDateParserTests
{
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
// Server time anchor: 2026-05-05 00:42:28 Moscow
private static readonly DateTimeOffset Anchor =
new(2026, 5, 5, 0, 42, 28, MoscowOffset);
[Fact]
public void TryParse_TimeOnlyFormat_UsesAnchorDateWithParsedTime()
{
// "03:00" → today's date from anchor + 03:00
var result = MoscowDateParser.TryParse("03:00", Anchor);
result.Should().NotBeNull();
result!.Value.Year.Should().Be(2026);
result.Value.Month.Should().Be(5);
result.Value.Day.Should().Be(5);
result.Value.Hour.Should().Be(3);
result.Value.Minute.Should().Be(0);
result.Value.Offset.Should().Be(MoscowOffset);
}
[Fact]
public void TryParse_FullDateFormat_ParsesCorrectly()
{
var result = MoscowDateParser.TryParse("06 мая 22:00", Anchor);
result.Should().NotBeNull();
result!.Value.Year.Should().Be(2026);
result.Value.Month.Should().Be(5);
result.Value.Day.Should().Be(6);
result.Value.Hour.Should().Be(22);
result.Value.Minute.Should().Be(0);
result.Value.Offset.Should().Be(MoscowOffset);
}
[Fact]
public void TryParse_FullDateWithLeadingSpaces_ParsesCorrectly()
{
var result = MoscowDateParser.TryParse(" 07 мая 02:30 ", Anchor);
result.Should().NotBeNull();
result!.Value.Day.Should().Be(7);
result.Value.Hour.Should().Be(2);
result.Value.Minute.Should().Be(30);
}
[Fact]
public void TryParse_NullInput_ReturnsNull()
{
MoscowDateParser.TryParse(null, Anchor).Should().BeNull();
}
[Fact]
public void TryParse_EmptyInput_ReturnsNull()
{
MoscowDateParser.TryParse(string.Empty, Anchor).Should().BeNull();
}
[Fact]
public void TryParse_UnrecognizedFormat_ReturnsNull()
{
MoscowDateParser.TryParse("tomorrow at noon", Anchor).Should().BeNull();
}
[Fact]
public void TryParse_YearRollover_AddsOneYear()
{
// Anchor is Dec 31, event is Jan 1 next year
var decAnchor = new DateTimeOffset(2026, 12, 31, 10, 0, 0, MoscowOffset);
var result = MoscowDateParser.TryParse("01 января 12:00", decAnchor);
result.Should().NotBeNull();
result!.Value.Year.Should().Be(2027);
result.Value.Month.Should().Be(1);
result.Value.Day.Should().Be(1);
}
[Fact]
public void TryParse_ResultAlwaysHasMoscowOffset()
{
var result = MoscowDateParser.TryParse("15:30", Anchor);
result!.Value.Offset.Should().Be(TimeSpan.FromHours(3));
}
}
@@ -0,0 +1,76 @@
using FluentAssertions;
using Marathon.Domain.Enums;
using Marathon.Infrastructure.Scraping.Parsers;
namespace Marathon.Infrastructure.Tests.Scraping;
public sealed class OutcomeCodeMapperTests
{
[Theory]
[InlineData("1", Side.Side1)]
[InlineData("draw", Side.Draw)]
[InlineData("3", Side.Side2)]
public void TryMap_MatchResultVocabulary_ReturnsExpectedSide(string code, Side expected)
{
OutcomeCodeMapper.TryMap(code).Should().Be(expected);
}
[Theory]
[InlineData("RN_H", Side.Side1)]
[InlineData("RN_D", Side.Draw)]
[InlineData("RN_A", Side.Side2)]
public void TryMap_PeriodResultVocabulary_ReturnsExpectedSide(string code, Side expected)
{
OutcomeCodeMapper.TryMap(code).Should().Be(expected);
}
[Theory]
[InlineData("HB_H", Side.Side1)]
[InlineData("HB_A", Side.Side2)]
public void TryMap_HandicapVocabulary_ReturnsExpectedSide(string code, Side expected)
{
OutcomeCodeMapper.TryMap(code).Should().Be(expected);
}
[Theory]
[InlineData("Under_213.5", Side.Less)]
[InlineData("Under_3.5", Side.Less)]
[InlineData("Over_213.5", Side.More)]
[InlineData("Over_3.5", Side.More)]
public void TryMap_TotalVocabulary_ReturnsExpectedSide(string code, Side expected)
{
OutcomeCodeMapper.TryMap(code).Should().Be(expected);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData("unknown_code")]
[InlineData("HD")]
[InlineData("yes")]
public void TryMap_UnknownOrEmptyCodes_ReturnsNull(string code)
{
OutcomeCodeMapper.TryMap(code).Should().BeNull();
}
[Theory]
[InlineData("Under_213.5", 213.5)]
[InlineData("Under_3.5", 3.5)]
[InlineData("Over_213.5", 213.5)]
[InlineData("Over_3.5", 3.5)]
[InlineData("Over_1", 1.0)]
public void TryParseTotalThreshold_ValidCodes_ReturnsThreshold(string code, decimal expected)
{
OutcomeCodeMapper.TryParseTotalThreshold(code).Should().Be(expected);
}
[Theory]
[InlineData("1")]
[InlineData("RN_H")]
[InlineData("HB_H")]
[InlineData("")]
public void TryParseTotalThreshold_NonTotalCodes_ReturnsNull(string code)
{
OutcomeCodeMapper.TryParseTotalThreshold(code).Should().BeNull();
}
}
@@ -0,0 +1,74 @@
using FluentAssertions;
using Marathon.Domain.Enums;
using Marathon.Infrastructure.Scraping.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
namespace Marathon.Infrastructure.Tests.Scraping;
public sealed class ResultsParserTests
{
private static string FixturePath(string filename) => Path.Combine(
AppContext.BaseDirectory,
"Fixtures", "marathonbet", filename);
private readonly ResultsParser _sut = new(NullLogger<ResultsParser>.Instance);
[Fact]
public async Task ParseAsync_CompletedEvent_ReturnsEventResult()
{
var html = await File.ReadAllTextAsync(FixturePath("event-completed-sample.html"));
var result = await _sut.ParseAsync(html);
result.Should().NotBeNull("matchIsComplete=true should yield an EventResult");
}
[Fact]
public async Task ParseAsync_CompletedEvent_EventIdMatches()
{
var html = await File.ReadAllTextAsync(FixturePath("event-completed-sample.html"));
var result = await _sut.ParseAsync(html);
result!.EventId.Value.Should().Be("26456100");
}
[Fact]
public async Task ParseAsync_CompletedEvent_ScoreParsedCorrectly()
{
var html = await File.ReadAllTextAsync(FixturePath("event-completed-sample.html"));
var result = await _sut.ParseAsync(html);
result!.Side1Score.Should().Be(3);
result.Side2Score.Should().Be(1);
}
[Fact]
public async Task ParseAsync_CompletedEvent_WinnerIsSide1()
{
var html = await File.ReadAllTextAsync(FixturePath("event-completed-sample.html"));
var result = await _sut.ParseAsync(html);
result!.WinnerSide.Should().Be(Side.Side1);
}
[Fact]
public async Task ParseAsync_IncompleteEvent_ReturnsNull()
{
var html = await File.ReadAllTextAsync(FixturePath("event-football-sample.html"));
var result = await _sut.ParseAsync(html);
result.Should().BeNull("matchIsComplete=false should return null");
}
[Fact]
public async Task ParseAsync_EmptyHtml_ReturnsNull()
{
var result = await _sut.ParseAsync("<html><body></body></html>");
result.Should().BeNull();
}
}
@@ -0,0 +1,49 @@
using FluentAssertions;
using Marathon.Infrastructure.Scraping.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
namespace Marathon.Infrastructure.Tests.Scraping;
public sealed class ServerTimeProviderTests
{
private readonly ServerTimeProvider _sut = new(NullLogger<ServerTimeProvider>.Instance);
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
[Fact]
public void ExtractServerTime_ValidInitData_ReturnsMoscowTime()
{
const string html = @"<html><head><script>
initData = {""serverTime"":""2026,05,05,00,42,28""};
</script></head><body></body></html>";
var result = _sut.ExtractServerTime(html);
result.Should().NotBeNull();
result!.Value.Year.Should().Be(2026);
result.Value.Month.Should().Be(5);
result.Value.Day.Should().Be(5);
result.Value.Hour.Should().Be(0);
result.Value.Minute.Should().Be(42);
result.Value.Second.Should().Be(28);
result.Value.Offset.Should().Be(MoscowOffset);
}
[Fact]
public void ExtractServerTime_MissingInitData_ReturnsNull()
{
const string html = "<html><body>No initData here.</body></html>";
_sut.ExtractServerTime(html).Should().BeNull();
}
[Fact]
public void ExtractServerTime_ExtraWhitespaceAroundKey_ParsesCorrectly()
{
const string html = @"<script>serverTime : ""2026,01,15,08,30,00""</script>";
var result = _sut.ExtractServerTime(html);
result.Should().NotBeNull();
result!.Value.Month.Should().Be(1);
result.Value.Day.Should().Be(15);
}
}
@@ -0,0 +1,102 @@
using FluentAssertions;
using Marathon.Infrastructure.Scraping.Parsers;
using Microsoft.Extensions.Logging.Abstractions;
namespace Marathon.Infrastructure.Tests.Scraping;
public sealed class UpcomingEventsParserTests
{
private static readonly string FixturePath = Path.Combine(
AppContext.BaseDirectory,
"Fixtures", "marathonbet", "listing-sample.html");
private readonly UpcomingEventsParser _sut;
public UpcomingEventsParserTests()
{
var serverTimeProvider = new ServerTimeProvider(
NullLogger<ServerTimeProvider>.Instance);
_sut = new UpcomingEventsParser(
serverTimeProvider,
NullLogger<UpcomingEventsParser>.Instance);
}
[Fact]
public async Task ParseAsync_SampleListing_ReturnsThreeEvents()
{
var html = await File.ReadAllTextAsync(FixturePath);
var events = await _sut.ParseAsync(html);
events.Should().HaveCount(3);
}
[Fact]
public async Task ParseAsync_SampleListing_FootballEventHasCorrectSport()
{
var html = await File.ReadAllTextAsync(FixturePath);
var events = await _sut.ParseAsync(html);
var football = events.Single(e => e.Id.Value == "26456117");
football.Sport.Value.Should().Be(11); // Football canonical ID
}
[Fact]
public async Task ParseAsync_SampleListing_BasketballEventHasCorrectSport()
{
var html = await File.ReadAllTextAsync(FixturePath);
var events = await _sut.ParseAsync(html);
var basketball = events.Single(e => e.Id.Value == "26769028");
basketball.Sport.Value.Should().Be(6); // Basketball canonical ID
}
[Fact]
public async Task ParseAsync_SampleListing_EventNamesAreSplit()
{
var html = await File.ReadAllTextAsync(FixturePath);
var events = await _sut.ParseAsync(html);
var football = events.Single(e => e.Id.Value == "26456117");
football.Side1Name.Should().Be("Арсенал");
football.Side2Name.Should().Be("Атлетико Мадрид");
}
[Fact]
public async Task ParseAsync_SampleListing_ScheduledAtIsMoscowOffset()
{
var html = await File.ReadAllTextAsync(FixturePath);
var events = await _sut.ParseAsync(html);
foreach (var evt in events)
{
evt.ScheduledAt.Offset.Should().Be(TimeSpan.FromHours(3),
"all events must be in Moscow time (UTC+3)");
}
}
[Fact]
public async Task ParseAsync_SampleListing_FootballEventLeagueExtracted()
{
var html = await File.ReadAllTextAsync(FixturePath);
var events = await _sut.ParseAsync(html);
var football = events.Single(e => e.Id.Value == "26456117");
football.LeagueId.Should().Contain("UEFA");
}
[Fact]
public async Task ParseAsync_EmptyHtml_ReturnsEmptyList()
{
const string html = "<html><head><script>initData={\"serverTime\":\"2026,05,05,10,00,00\"}</script></head><body></body></html>";
var events = await _sut.ParseAsync(html);
events.Should().BeEmpty();
}
}