feat(my-bets): personal bet journal with CLV tracking
Adds a manual bet-tracking journal that turns the analyzer into an actual bet tracker. Users record wagers; the journal auto-grades them when event results land and computes per-bet Closing-Line-Value against the latest pre-match snapshot — the strongest long-run indicator of betting skill. Domain: - PlacedBet entity (reuses Bet vocabulary for Scope/Type/Side/Value/Rate) with stake, placed-at, outcome, and notes. Derived GrossReturn / NetProfit. - BetOutcome enum (Pending / Won / Lost / Void). - BetOutcomeResolver: pure function grading any Match-scope bet against an EventResult. Handles 1X2, draws, handicap (incl. push), and totals. Period-scope bets stay manual since EventResult only carries full-time. Application: - IPlacedBetRepository abstraction. - ClosingLineValueCalculator: pure CLV math (implied-probability delta) + snapshot-matching predicate by Scope/Type/Side/Value. - BetJournalReport + BetJournalStats records. - Four use cases: Record / ResolvePending / BuildReport / Delete. - New ISnapshotRepository.GetLatestPreMatchAsync pushes the closing-line pick into a single SQLite query rather than materialising the 30-day window in memory per event. - ROI turnover excludes Void stakes — pushes are not real turnover and including them would dilute the user's edge. Infrastructure: - PlacedBetEntity / Configuration / Repository / Mapping helpers. - 20260516 migration adding the PlacedBets table with EventCode and Outcome indices. Intentionally NO foreign key to Events — the journal is user data and must survive snapshot-retention pruning. Covered by an explicit round-trip test. UI: - Pages/MyBets/Journal.razor: hero header, 4-card KPI strip (ROI / strike rate / avg CLV / net profit, tinted by tone), inline add-bet form with the same invariants as the Bet record, drill-down table with per-row outcome pills, CLV percentage-points column, P&L, notes underline, and inline-confirm delete. RU + EN i18n. - Nav entry under Analysis. Tests: +55 across Domain / Application / Infrastructure (resolver math including handicap push and total push boundaries, PlacedBet invariants and derived properties, CLV math + null-handling, four use cases under NSubstitute, EF round-trip including survives-event-deletion). All 379 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Application.Betting;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
|
||||
namespace Marathon.Application.Tests.Betting;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for <see cref="ClosingLineValueCalculator"/> covering the math
|
||||
/// itself and the snapshot-matching path used by the report use case.
|
||||
/// </summary>
|
||||
public sealed class ClosingLineValueCalculatorTests
|
||||
{
|
||||
private static readonly EventId EventId = new("11111111");
|
||||
|
||||
[Fact]
|
||||
public void Compute_Should_ReturnPositive_When_TakenRate_BeatsClose()
|
||||
{
|
||||
// Taken 2.20 (implied 0.4545); closed 2.00 (implied 0.5000) → CLV = +0.0455
|
||||
var clv = ClosingLineValueCalculator.Compute(takenRate: 2.20m, closingRate: 2.00m);
|
||||
|
||||
clv.Should().BeGreaterThan(0m);
|
||||
clv.Should().BeApproximately(0.04545m, 0.00001m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Compute_Should_ReturnNegative_When_TakenRate_WorseThanClose()
|
||||
{
|
||||
// Taken 1.80 (0.5556); closed 2.00 (0.5000) → CLV = -0.0556
|
||||
var clv = ClosingLineValueCalculator.Compute(takenRate: 1.80m, closingRate: 2.00m);
|
||||
|
||||
clv.Should().BeLessThan(0m);
|
||||
clv.Should().BeApproximately(-0.05556m, 0.00001m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Compute_Should_ReturnZero_When_RatesMatch()
|
||||
{
|
||||
ClosingLineValueCalculator.Compute(2.00m, 2.00m).Should().Be(0m);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(-1)]
|
||||
public void Compute_Should_Throw_When_AnyRateIsZeroOrNegative(decimal rate)
|
||||
{
|
||||
((Action)(() => ClosingLineValueCalculator.Compute(rate, 2m)))
|
||||
.Should().Throw<ArgumentOutOfRangeException>();
|
||||
((Action)(() => ClosingLineValueCalculator.Compute(2m, rate)))
|
||||
.Should().Throw<ArgumentOutOfRangeException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCompute_Should_ReturnNull_When_NoMatchingBetInSnapshot()
|
||||
{
|
||||
var taken = new Bet(MatchScope.Instance, BetType.Win, Side.Side1,
|
||||
value: null, new OddsRate(2.20m));
|
||||
|
||||
// Snapshot contains only Side2 — no match for Side1 Win.
|
||||
var snapshot = new OddsSnapshot(EventId, DateTimeOffset.UtcNow, OddsSource.PreMatch,
|
||||
new[] { new Bet(MatchScope.Instance, BetType.Win, Side.Side2, null, new OddsRate(1.70m)) });
|
||||
|
||||
var clv = ClosingLineValueCalculator.TryCompute(2.20m, taken, snapshot);
|
||||
|
||||
clv.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCompute_Should_ReturnNull_When_SnapshotIsNull()
|
||||
{
|
||||
var taken = new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m));
|
||||
ClosingLineValueCalculator.TryCompute(2m, taken, closingSnapshot: null).Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCompute_Should_MatchOnScopeTypeSideAndValue()
|
||||
{
|
||||
// Two handicap markets with different thresholds — pick the right one.
|
||||
var taken = new Bet(MatchScope.Instance, BetType.WinFora, Side.Side1,
|
||||
new OddsValue(-1.5m), new OddsRate(2.20m));
|
||||
|
||||
var snapshot = new OddsSnapshot(EventId, DateTimeOffset.UtcNow, OddsSource.PreMatch,
|
||||
new[]
|
||||
{
|
||||
new Bet(MatchScope.Instance, BetType.WinFora, Side.Side1,
|
||||
new OddsValue(-2.5m), new OddsRate(3.50m)), // wrong threshold
|
||||
new Bet(MatchScope.Instance, BetType.WinFora, Side.Side1,
|
||||
new OddsValue(-1.5m), new OddsRate(2.00m)), // match
|
||||
});
|
||||
|
||||
var clv = ClosingLineValueCalculator.TryCompute(2.20m, taken, snapshot);
|
||||
|
||||
clv.Should().BeApproximately(0.04545m, 0.00001m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Application.Abstractions;
|
||||
using Marathon.Application.UseCases;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
|
||||
namespace Marathon.Application.Tests.UseCases;
|
||||
|
||||
public sealed class BuildBetJournalReportUseCaseTests
|
||||
{
|
||||
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
||||
private static readonly DateTimeOffset Placed = new(2026, 5, 16, 12, 0, 0, MoscowOffset);
|
||||
private static readonly DateTimeOffset Kickoff = new(2026, 5, 16, 18, 0, 0, MoscowOffset);
|
||||
|
||||
private readonly IPlacedBetRepository _bets = Substitute.For<IPlacedBetRepository>();
|
||||
private readonly IEventRepository _events = Substitute.For<IEventRepository>();
|
||||
private readonly ISnapshotRepository _snapshots = Substitute.For<ISnapshotRepository>();
|
||||
|
||||
private BuildBetJournalReportUseCase CreateSut() =>
|
||||
new(_bets, _events, _snapshots, NullLogger<BuildBetJournalReportUseCase>.Instance);
|
||||
|
||||
private static PlacedBet MakeBet(
|
||||
EventId id,
|
||||
BetOutcome outcome,
|
||||
Side side = Side.Side1,
|
||||
decimal stake = 100m,
|
||||
decimal rate = 2.10m) =>
|
||||
new(
|
||||
Guid.NewGuid(), id,
|
||||
new Bet(MatchScope.Instance, BetType.Win, side, null, new OddsRate(rate)),
|
||||
stake, Placed, outcome, null);
|
||||
|
||||
private static Event MakeEvent(EventId id, DateTimeOffset scheduledAt) =>
|
||||
new(id, new SportCode(11), "BY", "L1", "Cat", scheduledAt, "Team A", "Team B");
|
||||
|
||||
private static OddsSnapshot MakeSnapshot(EventId id, DateTimeOffset at, decimal rateSide1) =>
|
||||
new(id, at, OddsSource.PreMatch,
|
||||
new[]
|
||||
{
|
||||
new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(rateSide1)),
|
||||
new Bet(MatchScope.Instance, BetType.Win, Side.Side2, null, new OddsRate(2.00m)),
|
||||
});
|
||||
|
||||
[Fact]
|
||||
public async Task Should_ReturnEmptyReport_When_NoBets()
|
||||
{
|
||||
_bets.ListAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Array.Empty<PlacedBet>().ToList().AsReadOnly());
|
||||
|
||||
var report = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
report.Bets.Should().BeEmpty();
|
||||
report.Stats.TotalBets.Should().Be(0);
|
||||
report.Stats.RoiPercent.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_AggregateStats_AcrossMixedOutcomes()
|
||||
{
|
||||
var id1 = new EventId("e-1");
|
||||
var id2 = new EventId("e-2");
|
||||
var id3 = new EventId("e-3");
|
||||
|
||||
_bets.ListAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[]
|
||||
{
|
||||
MakeBet(id1, BetOutcome.Won, stake: 100m, rate: 2.00m), // gross 200, +100
|
||||
MakeBet(id2, BetOutcome.Lost, stake: 100m, rate: 2.00m), // gross 0, -100
|
||||
MakeBet(id3, BetOutcome.Pending),
|
||||
}.ToList().AsReadOnly());
|
||||
|
||||
// Wire events so the report can compute CLV (we don't need actual CLV here — leave snapshots empty).
|
||||
foreach (var id in new[] { id1, id2, id3 })
|
||||
{
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(MakeEvent(id, Kickoff));
|
||||
_snapshots.GetLatestPreMatchAsync(id, Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>())
|
||||
.Returns((OddsSnapshot?)null);
|
||||
}
|
||||
|
||||
var report = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
report.Stats.TotalBets.Should().Be(3);
|
||||
report.Stats.PendingCount.Should().Be(1);
|
||||
report.Stats.WonCount.Should().Be(1);
|
||||
report.Stats.LostCount.Should().Be(1);
|
||||
report.Stats.TotalStaked.Should().Be(200m, "pending bets are excluded from totals");
|
||||
report.Stats.TotalReturned.Should().Be(200m);
|
||||
report.Stats.NetProfit.Should().Be(0m);
|
||||
report.Stats.RoiPercent.Should().Be(0m);
|
||||
report.Stats.StrikeRatePercent.Should().Be(50m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_ComputeClv_AgainstClosingSnapshot()
|
||||
{
|
||||
var id = new EventId("clv-event");
|
||||
var bet = MakeBet(id, BetOutcome.Won, rate: 2.20m, stake: 100m);
|
||||
|
||||
_bets.ListAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[] { bet }.ToList().AsReadOnly());
|
||||
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(MakeEvent(id, Kickoff));
|
||||
|
||||
// Closing snapshot returned by the dedicated repo method.
|
||||
_snapshots.GetLatestPreMatchAsync(id, Kickoff, Arg.Any<CancellationToken>())
|
||||
.Returns(MakeSnapshot(id, Kickoff.AddMinutes(-5), rateSide1: 2.00m));
|
||||
|
||||
var report = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
report.Bets.Should().HaveCount(1);
|
||||
report.Bets[0].ClvProbabilityDelta.Should().NotBeNull();
|
||||
// taken 2.20 vs closing 2.00 → +0.04545
|
||||
report.Bets[0].ClvProbabilityDelta!.Value.Should().BeApproximately(0.04545m, 0.00001m);
|
||||
report.Stats.AverageClvProbabilityDelta.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_LeaveClvNull_When_NoClosingSnapshotAvailable()
|
||||
{
|
||||
var id = new EventId("no-close");
|
||||
_bets.ListAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[] { MakeBet(id, BetOutcome.Won) }.ToList().AsReadOnly());
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(MakeEvent(id, Kickoff));
|
||||
_snapshots.GetLatestPreMatchAsync(id, Kickoff, Arg.Any<CancellationToken>())
|
||||
.Returns((OddsSnapshot?)null);
|
||||
|
||||
var report = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
report.Bets[0].ClvProbabilityDelta.Should().BeNull();
|
||||
report.Stats.AverageClvProbabilityDelta.Should().BeNull(
|
||||
"no rows had a computable CLV — average is undefined");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_ExcludeVoidStakes_FromRoiTurnover()
|
||||
{
|
||||
// 1 Won (+100), 1 Lost (-100), 1 Void (stake returned). Industry-standard
|
||||
// ROI excludes pushes from turnover, so total staked = 200, returned 200,
|
||||
// net 0, ROI 0%. If voids were included turnover would be 300 → ROI ≈ 0%
|
||||
// numerator but inflated denominator semantics.
|
||||
var ids = Enumerable.Range(1, 3)
|
||||
.Select(i => new EventId($"void-{i}")).ToArray();
|
||||
|
||||
_bets.ListAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[]
|
||||
{
|
||||
MakeBet(ids[0], BetOutcome.Won, stake: 100m, rate: 2.00m),
|
||||
MakeBet(ids[1], BetOutcome.Lost, stake: 100m, rate: 2.00m),
|
||||
MakeBet(ids[2], BetOutcome.Void, stake: 100m, rate: 2.00m),
|
||||
}.ToList().AsReadOnly());
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(MakeEvent(id, Kickoff));
|
||||
_snapshots.GetLatestPreMatchAsync(id, Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>())
|
||||
.Returns((OddsSnapshot?)null);
|
||||
}
|
||||
|
||||
var report = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
report.Stats.VoidCount.Should().Be(1);
|
||||
report.Stats.TotalStaked.Should().Be(200m,
|
||||
"void bets are pushes — the stake was returned and should not count as turnover");
|
||||
report.Stats.TotalReturned.Should().Be(200m);
|
||||
report.Stats.NetProfit.Should().Be(0m);
|
||||
report.Stats.RoiPercent.Should().Be(0m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_OrderBets_NewestPlacedFirst()
|
||||
{
|
||||
var ids = Enumerable.Range(0, 3).Select(i => new EventId($"ord-{i}")).ToArray();
|
||||
var older = new DateTimeOffset(2026, 5, 10, 12, 0, 0, MoscowOffset);
|
||||
var newer = new DateTimeOffset(2026, 5, 16, 12, 0, 0, MoscowOffset);
|
||||
|
||||
// Bet 0 is the middle one, bet 1 oldest, bet 2 newest.
|
||||
var b0 = new PlacedBet(Guid.NewGuid(), ids[0],
|
||||
new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m)),
|
||||
100m, older.AddDays(1), BetOutcome.Won, null);
|
||||
var b1 = new PlacedBet(Guid.NewGuid(), ids[1],
|
||||
new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m)),
|
||||
100m, older, BetOutcome.Lost, null);
|
||||
var b2 = new PlacedBet(Guid.NewGuid(), ids[2],
|
||||
new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m)),
|
||||
100m, newer, BetOutcome.Pending, null);
|
||||
|
||||
_bets.ListAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[] { b0, b1, b2 }.ToList().AsReadOnly());
|
||||
|
||||
foreach (var id in ids)
|
||||
{
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(MakeEvent(id, Kickoff));
|
||||
_snapshots.GetLatestPreMatchAsync(id, Arg.Any<DateTimeOffset>(), Arg.Any<CancellationToken>())
|
||||
.Returns((OddsSnapshot?)null);
|
||||
}
|
||||
|
||||
var report = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
report.Bets.Select(r => r.Bet.Id).Should().ContainInOrder(b2.Id, b0.Id, b1.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Application.Abstractions;
|
||||
using Marathon.Application.UseCases;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
|
||||
namespace Marathon.Application.Tests.UseCases;
|
||||
|
||||
public sealed class RecordPlacedBetUseCaseTests
|
||||
{
|
||||
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
||||
|
||||
private readonly IPlacedBetRepository _bets = Substitute.For<IPlacedBetRepository>();
|
||||
private readonly IEventRepository _events = Substitute.For<IEventRepository>();
|
||||
private readonly IResultRepository _results = Substitute.For<IResultRepository>();
|
||||
|
||||
private RecordPlacedBetUseCase CreateSut() =>
|
||||
new(_bets, _events, _results, NullLogger<RecordPlacedBetUseCase>.Instance);
|
||||
|
||||
private static PlacedBet MakePending(EventId id, Side side = Side.Side1) =>
|
||||
new(
|
||||
Id: Guid.NewGuid(),
|
||||
EventId: id,
|
||||
Selection: new Bet(MatchScope.Instance, BetType.Win, side, null, new OddsRate(2.10m)),
|
||||
Stake: 100m,
|
||||
PlacedAt: new DateTimeOffset(2026, 5, 16, 12, 0, 0, MoscowOffset),
|
||||
Outcome: BetOutcome.Pending,
|
||||
Notes: null);
|
||||
|
||||
[Fact]
|
||||
public async Task Should_Throw_When_EventDoesNotExist()
|
||||
{
|
||||
var id = new EventId("missing");
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns((Event?)null);
|
||||
|
||||
var act = async () => await CreateSut().ExecuteAsync(MakePending(id), CancellationToken.None);
|
||||
|
||||
await act.Should().ThrowAsync<InvalidOperationException>().WithMessage("*unknown event*");
|
||||
await _bets.DidNotReceive().AddAsync(Arg.Any<PlacedBet>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_PersistPending_When_NoResultYet()
|
||||
{
|
||||
var id = new EventId("event001");
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(TestFixtures.MakeEvent(id.Value));
|
||||
_results.GetAsync(id, Arg.Any<CancellationToken>()).Returns((EventResult?)null);
|
||||
|
||||
var bet = MakePending(id);
|
||||
|
||||
var stored = await CreateSut().ExecuteAsync(bet, CancellationToken.None);
|
||||
|
||||
stored.Outcome.Should().Be(BetOutcome.Pending, "no result yet — should remain pending");
|
||||
await _bets.Received(1).AddAsync(Arg.Any<PlacedBet>(), Arg.Any<CancellationToken>());
|
||||
await _bets.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_AutoGrade_When_ResultAlreadyAvailable()
|
||||
{
|
||||
var id = new EventId("event002");
|
||||
_events.GetAsync(id, Arg.Any<CancellationToken>()).Returns(TestFixtures.MakeEvent(id.Value));
|
||||
_results.GetAsync(id, Arg.Any<CancellationToken>())
|
||||
.Returns(new EventResult(id, 2, 1, Side.Side1, DateTimeOffset.UtcNow));
|
||||
|
||||
var bet = MakePending(id, side: Side.Side1);
|
||||
|
||||
var stored = await CreateSut().ExecuteAsync(bet, CancellationToken.None);
|
||||
|
||||
stored.Outcome.Should().Be(BetOutcome.Won, "Side1 was selected and Side1 won");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Application.Abstractions;
|
||||
using Marathon.Application.UseCases;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
|
||||
namespace Marathon.Application.Tests.UseCases;
|
||||
|
||||
public sealed class ResolvePendingBetsUseCaseTests
|
||||
{
|
||||
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
||||
private static readonly DateTimeOffset Placed =
|
||||
new(2026, 5, 16, 12, 0, 0, MoscowOffset);
|
||||
|
||||
private readonly IPlacedBetRepository _bets = Substitute.For<IPlacedBetRepository>();
|
||||
private readonly IResultRepository _results = Substitute.For<IResultRepository>();
|
||||
|
||||
private ResolvePendingBetsUseCase CreateSut() =>
|
||||
new(_bets, _results, NullLogger<ResolvePendingBetsUseCase>.Instance);
|
||||
|
||||
private static PlacedBet MakePending(EventId id, Side side = Side.Side1) =>
|
||||
new(
|
||||
Guid.NewGuid(), id,
|
||||
new Bet(MatchScope.Instance, BetType.Win, side, null, new OddsRate(2.10m)),
|
||||
100m, Placed, BetOutcome.Pending, null);
|
||||
|
||||
[Fact]
|
||||
public async Task Should_ReturnZero_When_NoPendingBets()
|
||||
{
|
||||
_bets.ListByOutcomeAsync(BetOutcome.Pending, Arg.Any<CancellationToken>())
|
||||
.Returns(Array.Empty<PlacedBet>().ToList().AsReadOnly());
|
||||
|
||||
var count = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
count.Should().Be(0);
|
||||
await _bets.DidNotReceive().UpdateAsync(Arg.Any<PlacedBet>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_GradeBetsWithResults_AndLeaveOthersAlone()
|
||||
{
|
||||
var idGraded = new EventId("event-1");
|
||||
var idUngraded = new EventId("event-2");
|
||||
|
||||
_bets.ListByOutcomeAsync(BetOutcome.Pending, Arg.Any<CancellationToken>())
|
||||
.Returns(new[]
|
||||
{
|
||||
MakePending(idGraded, side: Side.Side1),
|
||||
MakePending(idUngraded, side: Side.Side2),
|
||||
}.ToList().AsReadOnly());
|
||||
|
||||
_results.GetAsync(idGraded, Arg.Any<CancellationToken>())
|
||||
.Returns(new EventResult(idGraded, 2, 1, Side.Side1, DateTimeOffset.UtcNow));
|
||||
_results.GetAsync(idUngraded, Arg.Any<CancellationToken>())
|
||||
.Returns((EventResult?)null);
|
||||
|
||||
var count = await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
count.Should().Be(1, "only event-1 has a result");
|
||||
await _bets.Received(1).UpdateAsync(
|
||||
Arg.Is<PlacedBet>(b => b.EventId == idGraded && b.Outcome == BetOutcome.Won),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _bets.DidNotReceive().UpdateAsync(
|
||||
Arg.Is<PlacedBet>(b => b.EventId == idUngraded),
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_CacheResultLookups_PerEvent()
|
||||
{
|
||||
// Two pending bets on the same event — only one result fetch should fire.
|
||||
var id = new EventId("event-shared");
|
||||
|
||||
_bets.ListByOutcomeAsync(BetOutcome.Pending, Arg.Any<CancellationToken>())
|
||||
.Returns(new[]
|
||||
{
|
||||
MakePending(id, side: Side.Side1),
|
||||
MakePending(id, side: Side.Side2),
|
||||
}.ToList().AsReadOnly());
|
||||
|
||||
_results.GetAsync(id, Arg.Any<CancellationToken>())
|
||||
.Returns(new EventResult(id, 2, 1, Side.Side1, DateTimeOffset.UtcNow));
|
||||
|
||||
await CreateSut().ExecuteAsync(CancellationToken.None);
|
||||
|
||||
await _results.Received(1).GetAsync(id, Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Domain.Betting;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
|
||||
namespace Marathon.Domain.Tests.Betting;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for <see cref="BetOutcomeResolver"/> across every bet type +
|
||||
/// every important boundary (handicap push, total push, period-scope null).
|
||||
/// </summary>
|
||||
public sealed class BetOutcomeResolverTests
|
||||
{
|
||||
private static readonly EventId EventId = new("12345678");
|
||||
|
||||
// ── Win bets ─────────────────────────────────────────────────────────────
|
||||
|
||||
[Theory]
|
||||
[InlineData(Side.Side1, Side.Side1, BetOutcome.Won)]
|
||||
[InlineData(Side.Side1, Side.Side2, BetOutcome.Lost)]
|
||||
[InlineData(Side.Side1, Side.Draw, BetOutcome.Lost)]
|
||||
[InlineData(Side.Side2, Side.Side2, BetOutcome.Won)]
|
||||
[InlineData(Side.Side2, Side.Side1, BetOutcome.Lost)]
|
||||
public void Should_GradeWinBet(Side selectionSide, Side winner, BetOutcome expected)
|
||||
{
|
||||
var bet = MakeBet(BetType.Win, selectionSide);
|
||||
var result = MakeResult(winner);
|
||||
|
||||
BetOutcomeResolver.Resolve(bet, result).Should().Be(expected);
|
||||
}
|
||||
|
||||
// ── Draw bets ────────────────────────────────────────────────────────────
|
||||
|
||||
[Theory]
|
||||
[InlineData(Side.Draw, BetOutcome.Won)]
|
||||
[InlineData(Side.Side1, BetOutcome.Lost)]
|
||||
[InlineData(Side.Side2, BetOutcome.Lost)]
|
||||
public void Should_GradeDrawBet(Side winner, BetOutcome expected)
|
||||
{
|
||||
var bet = MakeBet(BetType.Draw, Side.Draw);
|
||||
var result = MakeResult(winner, 1, 1);
|
||||
|
||||
BetOutcomeResolver.Resolve(bet, result).Should().Be(expected);
|
||||
}
|
||||
|
||||
// ── Handicap (WinFora) ───────────────────────────────────────────────────
|
||||
|
||||
[Theory]
|
||||
// Side1 with +1.5 handicap; final 0-2 → adjusted 1.5 vs 2 → loss
|
||||
[InlineData(Side.Side1, 1.5, 0, 2, BetOutcome.Lost)]
|
||||
// Side1 with +1.5; final 1-2 → adjusted 2.5 vs 2 → win
|
||||
[InlineData(Side.Side1, 1.5, 1, 2, BetOutcome.Won)]
|
||||
// Side1 with -1.5; final 3-1 → adjusted 1.5 vs 1 → win
|
||||
[InlineData(Side.Side1, -1.5, 3, 1, BetOutcome.Won)]
|
||||
// Whole-number handicap that ties: Side1 +1, final 1-2 → 2 vs 2 → push (Void)
|
||||
[InlineData(Side.Side1, 1, 1, 2, BetOutcome.Void)]
|
||||
// Side2 with -1; final 0-2 → adjusted Side2 1 vs Side1 0 → win
|
||||
[InlineData(Side.Side2, -1, 0, 2, BetOutcome.Won)]
|
||||
public void Should_GradeHandicapBet(
|
||||
Side side, double handicap, int s1, int s2, BetOutcome expected)
|
||||
{
|
||||
var bet = new Bet(MatchScope.Instance, BetType.WinFora, side,
|
||||
new OddsValue((decimal)handicap), new OddsRate(1.85m));
|
||||
var result = new EventResult(EventId, s1, s2,
|
||||
DeriveWinner(s1, s2), DateTimeOffset.UtcNow);
|
||||
|
||||
BetOutcomeResolver.Resolve(bet, result).Should().Be(expected);
|
||||
}
|
||||
|
||||
// ── Totals ───────────────────────────────────────────────────────────────
|
||||
|
||||
[Theory]
|
||||
// Over 2.5; total 3 → win
|
||||
[InlineData(Side.More, 2.5, 1, 2, BetOutcome.Won)]
|
||||
// Over 2.5; total 2 → loss
|
||||
[InlineData(Side.More, 2.5, 0, 2, BetOutcome.Lost)]
|
||||
// Over 3.0; total 3 → push (Void)
|
||||
[InlineData(Side.More, 3.0, 1, 2, BetOutcome.Void)]
|
||||
// Under 2.5; total 2 → win
|
||||
[InlineData(Side.Less, 2.5, 1, 1, BetOutcome.Won)]
|
||||
// Under 2.5; total 3 → loss
|
||||
[InlineData(Side.Less, 2.5, 1, 2, BetOutcome.Lost)]
|
||||
public void Should_GradeTotalBet(
|
||||
Side side, double threshold, int s1, int s2, BetOutcome expected)
|
||||
{
|
||||
var bet = new Bet(MatchScope.Instance, BetType.Total, side,
|
||||
new OddsValue((decimal)threshold), new OddsRate(1.85m));
|
||||
var result = new EventResult(EventId, s1, s2,
|
||||
DeriveWinner(s1, s2), DateTimeOffset.UtcNow);
|
||||
|
||||
BetOutcomeResolver.Resolve(bet, result).Should().Be(expected);
|
||||
}
|
||||
|
||||
// ── Period-scope guard ───────────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnNull_When_BetScopeIsPeriod()
|
||||
{
|
||||
var bet = new Bet(new PeriodScope(1), BetType.Win, Side.Side1,
|
||||
value: null, new OddsRate(2.10m));
|
||||
var result = MakeResult(Side.Side1);
|
||||
|
||||
BetOutcomeResolver.Resolve(bet, result).Should().BeNull(
|
||||
"period scope cannot be graded from full-time score alone");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_When_BetOrResultIsNull()
|
||||
{
|
||||
((Action)(() => BetOutcomeResolver.Resolve(null!, MakeResult(Side.Side1))))
|
||||
.Should().Throw<ArgumentNullException>();
|
||||
((Action)(() => BetOutcomeResolver.Resolve(MakeBet(BetType.Win, Side.Side1), null!)))
|
||||
.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
private static Bet MakeBet(BetType type, Side side) =>
|
||||
new(MatchScope.Instance, type, side, value: null, new OddsRate(2.00m));
|
||||
|
||||
private static EventResult MakeResult(Side winner, int s1 = 1, int s2 = 0) =>
|
||||
new(EventId, s1, s2, winner, DateTimeOffset.UtcNow);
|
||||
|
||||
private static Side DeriveWinner(int s1, int s2) =>
|
||||
s1 == s2 ? Side.Draw : (s1 > s2 ? Side.Side1 : Side.Side2);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
|
||||
namespace Marathon.Domain.Tests.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Invariants and derived-property tests for <see cref="PlacedBet"/>.
|
||||
/// </summary>
|
||||
public sealed class PlacedBetTests
|
||||
{
|
||||
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
||||
private static readonly DateTimeOffset MoscowMoment =
|
||||
new(2026, 5, 16, 12, 0, 0, MoscowOffset);
|
||||
|
||||
private static PlacedBet Make(BetOutcome outcome, decimal rate = 2.10m, decimal stake = 100m) =>
|
||||
new(
|
||||
Id: Guid.NewGuid(),
|
||||
EventId: new EventId("12345678"),
|
||||
Selection: new Bet(MatchScope.Instance, BetType.Win, Side.Side1,
|
||||
value: null, new OddsRate(rate)),
|
||||
Stake: stake,
|
||||
PlacedAt: MoscowMoment,
|
||||
Outcome: outcome,
|
||||
Notes: null);
|
||||
|
||||
[Fact]
|
||||
public void Should_ComputeWonReturn_As_StakeTimesRate()
|
||||
{
|
||||
var bet = Make(BetOutcome.Won, rate: 2.10m, stake: 100m);
|
||||
|
||||
bet.GrossReturn.Should().Be(210m);
|
||||
bet.NetProfit.Should().Be(110m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ComputeLossReturn_As_Zero()
|
||||
{
|
||||
var bet = Make(BetOutcome.Lost, stake: 50m);
|
||||
|
||||
bet.GrossReturn.Should().Be(0m);
|
||||
bet.NetProfit.Should().Be(-50m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnStake_When_Outcome_IsVoid()
|
||||
{
|
||||
var bet = Make(BetOutcome.Void, stake: 75m);
|
||||
|
||||
bet.GrossReturn.Should().Be(75m);
|
||||
bet.NetProfit.Should().Be(0m);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_ReturnNullProfit_When_OutcomeIsPending()
|
||||
{
|
||||
var bet = Make(BetOutcome.Pending);
|
||||
|
||||
bet.GrossReturn.Should().BeNull();
|
||||
bet.NetProfit.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithOutcome_Should_ReturnNewInstance_With_GradedOutcome()
|
||||
{
|
||||
var pending = Make(BetOutcome.Pending);
|
||||
var graded = pending.WithOutcome(BetOutcome.Won);
|
||||
|
||||
graded.Should().NotBeSameAs(pending);
|
||||
graded.Outcome.Should().Be(BetOutcome.Won);
|
||||
graded.Id.Should().Be(pending.Id);
|
||||
graded.Stake.Should().Be(pending.Stake);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_When_StakeIsZeroOrNegative()
|
||||
{
|
||||
var act = () => new PlacedBet(
|
||||
Id: Guid.NewGuid(),
|
||||
EventId: new EventId("11111111"),
|
||||
Selection: new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m)),
|
||||
Stake: 0m,
|
||||
PlacedAt: MoscowMoment,
|
||||
Outcome: BetOutcome.Pending,
|
||||
Notes: null);
|
||||
|
||||
act.Should().Throw<ArgumentOutOfRangeException>().WithMessage("*Stake*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_When_PlacedAt_IsNotMoscowOffset()
|
||||
{
|
||||
var act = () => new PlacedBet(
|
||||
Id: Guid.NewGuid(),
|
||||
EventId: new EventId("11111111"),
|
||||
Selection: new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m)),
|
||||
Stake: 100m,
|
||||
PlacedAt: DateTimeOffset.UtcNow, // UTC offset, not Moscow
|
||||
Outcome: BetOutcome.Pending,
|
||||
Notes: null);
|
||||
|
||||
act.Should().Throw<ArgumentException>().WithMessage("*Moscow*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_NormaliseWhitespace_Notes_To_Null()
|
||||
{
|
||||
var bet = new PlacedBet(
|
||||
Id: Guid.NewGuid(),
|
||||
EventId: new EventId("11111111"),
|
||||
Selection: new Bet(MatchScope.Instance, BetType.Win, Side.Side1, null, new OddsRate(2m)),
|
||||
Stake: 100m,
|
||||
PlacedAt: MoscowMoment,
|
||||
Outcome: BetOutcome.Pending,
|
||||
Notes: " ");
|
||||
|
||||
bet.Notes.Should().BeNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
using FluentAssertions;
|
||||
using Marathon.Application.Storage;
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
using Marathon.Infrastructure.Persistence;
|
||||
using Marathon.Infrastructure.Persistence.Repositories;
|
||||
|
||||
namespace Marathon.Infrastructure.Tests.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Round-trip + query tests for <see cref="PlacedBetRepository"/>. Uses the
|
||||
/// in-memory SQLite fixture so the schema + indices declared in the migration
|
||||
/// are exercised on every test.
|
||||
/// </summary>
|
||||
public sealed class PlacedBetRoundTripTests : IDisposable
|
||||
{
|
||||
private static readonly TimeSpan MoscowOffset = TimeSpan.FromHours(3);
|
||||
private static readonly DateTimeOffset Placed =
|
||||
new(2026, 5, 16, 12, 0, 0, MoscowOffset);
|
||||
|
||||
private readonly InMemoryDbFixture _fixture;
|
||||
private readonly PlacedBetRepository _repo;
|
||||
|
||||
public PlacedBetRoundTripTests()
|
||||
{
|
||||
_fixture = new InMemoryDbFixture();
|
||||
_repo = new PlacedBetRepository(_fixture.DbContext);
|
||||
}
|
||||
|
||||
public void Dispose() => _fixture.Dispose();
|
||||
|
||||
private static PlacedBet MakeBet(
|
||||
Guid? id = null,
|
||||
string eventCode = "12345678",
|
||||
BetType type = BetType.Win,
|
||||
Side side = Side.Side1,
|
||||
decimal? value = null,
|
||||
decimal rate = 2.10m,
|
||||
decimal stake = 100m,
|
||||
DateTimeOffset? placedAt = null,
|
||||
BetOutcome outcome = BetOutcome.Pending,
|
||||
string? notes = null) =>
|
||||
new(
|
||||
Id: id ?? Guid.NewGuid(),
|
||||
EventId: new EventId(eventCode),
|
||||
Selection: new Bet(MatchScope.Instance, type, side,
|
||||
value is { } v ? new OddsValue(v) : null, new OddsRate(rate)),
|
||||
Stake: stake,
|
||||
PlacedAt: placedAt ?? Placed,
|
||||
Outcome: outcome,
|
||||
Notes: notes);
|
||||
|
||||
[Fact]
|
||||
public async Task PlacedBet_RoundTrip_PreservesAllFields()
|
||||
{
|
||||
var bet = MakeBet(
|
||||
type: BetType.WinFora,
|
||||
side: Side.Side2,
|
||||
value: -1.5m,
|
||||
rate: 2.30m,
|
||||
stake: 250m,
|
||||
notes: "test note");
|
||||
|
||||
await _repo.AddAsync(bet);
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var retrieved = await _repo.GetAsync(bet.Id);
|
||||
|
||||
retrieved.Should().NotBeNull();
|
||||
retrieved!.Id.Should().Be(bet.Id);
|
||||
retrieved.EventId.Value.Should().Be("12345678");
|
||||
retrieved.Selection.Type.Should().Be(BetType.WinFora);
|
||||
retrieved.Selection.Side.Should().Be(Side.Side2);
|
||||
retrieved.Selection.Value!.Value.Should().Be(-1.5m);
|
||||
retrieved.Selection.Rate.Value.Should().Be(2.30m);
|
||||
retrieved.Stake.Should().Be(250m);
|
||||
retrieved.PlacedAt.Should().Be(Placed);
|
||||
retrieved.PlacedAt.Offset.Should().Be(MoscowOffset);
|
||||
retrieved.Outcome.Should().Be(BetOutcome.Pending);
|
||||
retrieved.Notes.Should().Be("test note");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListByOutcomeAsync_ReturnsOnlyMatching()
|
||||
{
|
||||
await _repo.AddAsync(MakeBet(outcome: BetOutcome.Pending, eventCode: "1"));
|
||||
await _repo.AddAsync(MakeBet(outcome: BetOutcome.Won, eventCode: "2"));
|
||||
await _repo.AddAsync(MakeBet(outcome: BetOutcome.Pending, eventCode: "3"));
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var pending = await _repo.ListByOutcomeAsync(BetOutcome.Pending);
|
||||
|
||||
pending.Should().HaveCount(2);
|
||||
pending.Should().OnlyContain(b => b.Outcome == BetOutcome.Pending);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListByEventAsync_ReturnsEveryBet_OnTheEvent()
|
||||
{
|
||||
await _repo.AddAsync(MakeBet(eventCode: "evt-A", side: Side.Side1));
|
||||
await _repo.AddAsync(MakeBet(eventCode: "evt-A", side: Side.Side2));
|
||||
await _repo.AddAsync(MakeBet(eventCode: "evt-B"));
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var onA = await _repo.ListByEventAsync(new EventId("evt-A"));
|
||||
|
||||
onA.Should().HaveCount(2);
|
||||
onA.Should().OnlyContain(b => b.EventId.Value == "evt-A");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListByDateRangeAsync_FiltersByPlacedAt()
|
||||
{
|
||||
var older = new DateTimeOffset(2026, 5, 1, 12, 0, 0, MoscowOffset);
|
||||
var newer = new DateTimeOffset(2026, 5, 20, 12, 0, 0, MoscowOffset);
|
||||
|
||||
await _repo.AddAsync(MakeBet(placedAt: older, eventCode: "old"));
|
||||
await _repo.AddAsync(MakeBet(placedAt: newer, eventCode: "new"));
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var range = new DateRange(
|
||||
from: new DateTimeOffset(2026, 5, 10, 0, 0, 0, MoscowOffset),
|
||||
to: new DateTimeOffset(2026, 5, 31, 0, 0, 0, MoscowOffset));
|
||||
var inRange = await _repo.ListByDateRangeAsync(range);
|
||||
|
||||
inRange.Should().HaveCount(1);
|
||||
inRange[0].EventId.Value.Should().Be("new");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_PersistsOutcomeChange()
|
||||
{
|
||||
var bet = MakeBet(outcome: BetOutcome.Pending);
|
||||
await _repo.AddAsync(bet);
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var graded = bet.WithOutcome(BetOutcome.Won);
|
||||
await _repo.UpdateAsync(graded);
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var reloaded = await _repo.GetAsync(bet.Id);
|
||||
reloaded!.Outcome.Should().Be(BetOutcome.Won);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PlacedBet_Survives_Event_Deletion()
|
||||
{
|
||||
// Documents the explicit "no foreign key" design choice — the journal
|
||||
// is user data and must survive snapshot retention pruning the source
|
||||
// event row.
|
||||
var eventRepo = new EventRepository(_fixture.DbContext);
|
||||
var evt = new Event(
|
||||
Id: new EventId("evt-prune"),
|
||||
Sport: new SportCode(11),
|
||||
CountryCode: "England",
|
||||
LeagueId: "league",
|
||||
Category: string.Empty,
|
||||
ScheduledAt: new DateTimeOffset(2026, 5, 16, 20, 0, 0, MoscowOffset),
|
||||
Side1Name: "Home",
|
||||
Side2Name: "Away");
|
||||
await eventRepo.AddAsync(evt);
|
||||
await eventRepo.SaveChangesAsync();
|
||||
|
||||
var bet = MakeBet(eventCode: "evt-prune");
|
||||
await _repo.AddAsync(bet);
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
// Delete the event — the bet should remain untouched.
|
||||
await eventRepo.DeleteAsync(new EventId("evt-prune"));
|
||||
await eventRepo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
var stillThere = await _repo.GetAsync(bet.Id);
|
||||
|
||||
stillThere.Should().NotBeNull();
|
||||
stillThere!.EventId.Value.Should().Be("evt-prune");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_RemovesBet()
|
||||
{
|
||||
var bet = MakeBet();
|
||||
await _repo.AddAsync(bet);
|
||||
await _repo.SaveChangesAsync();
|
||||
_fixture.DbContext.ChangeTracker.Clear();
|
||||
|
||||
await _repo.DeleteAsync(bet.Id);
|
||||
await _repo.SaveChangesAsync();
|
||||
|
||||
(await _repo.GetAsync(bet.Id)).Should().BeNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user