Files
maraphon-app/tests/Marathon.Infrastructure.Tests/Scraping/MoscowDateParserTests.cs
alexei.dolgolyov e4d8476782 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.
2026-05-05 01:56:53 +03:00

92 lines
2.8 KiB
C#

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));
}
}