public void Handle(MatchCommentaryEvent e, string aggregateId) { string id = ResultHeaderReadModel.IdFromBitsMatchId(e.BitsMatchId, e.RosterId); ResultHeaderReadModel results = DocumentSession.Load <ResultHeaderReadModel>(id); results.SetMatchCommentary(e.SummaryText, e.SummaryHtml, e.BodyText); }
public async Task MatchCommentaryBodyText(TestCase testCase) { // Act MatchResult matchResult = await Act(testCase); // Assert IDomainEvent[] changes = matchResult.GetUncommittedChanges(); MatchCommentaryEvent matchCommentaryEvent = (MatchCommentaryEvent)changes.Single(x => x is MatchCommentaryEvent); Assert.That(string.Join(" ", matchCommentaryEvent.BodyText), Is.EqualTo(testCase.ExpectedBodyText)); }
public void RegisterSeries( Action <TaskBase> publish, MatchSerie[] matchSeries, ResultSeriesReadModel.Serie[] opponentSeries, Player[] players, Dictionary <string, ResultForPlayerIndex.Result> resultsForPlayer) { if (matchSeries == null) { throw new ArgumentNullException(nameof(matchSeries)); } if (opponentSeries == null) { throw new ArgumentNullException(nameof(opponentSeries)); } if (players == null) { throw new ArgumentNullException(nameof(players)); } if (resultsForPlayer == null) { throw new ArgumentNullException(nameof(resultsForPlayer)); } if (rosterPlayers !.Count is not 8 and not 9 and not 10) { throw new MatchException("Roster must have 8, 9, or 10 players when registering results"); } foreach (MatchSerie matchSerie in matchSeries) { VerifyPlayers(matchSerie); ApplyChange(new SerieRegistered(matchSerie, BitsMatchId, RosterId !)); DoAwardMedals(registeredSeries); if (registeredSeries > 4) { throw new ArgumentException("Can only register up to 4 series"); } } MatchCommentaryEvent matchCommentaryEvent = CreateMatchCommentary( matchSeries, opponentSeries, players.ToDictionary(x => x.Id), resultsForPlayer); ApplyChange(matchCommentaryEvent); publish.Invoke(new MatchRegisteredTask(RosterId !, BitsMatchId, TeamScore, OpponentScore)); }
public bool Update( Action <TaskBase> publish, Roster roster, int teamScore, int opponentScore, MatchSerie[] matchSeries, ResultSeriesReadModel.Serie[] opponentSeries, Player[] players, Dictionary <string, ResultForPlayerIndex.Result> resultsForPlayer) { // check if anything has changed SortedDictionary <string, List <PinsAndScoreResult> > potentiallyNewPlayerPins = new(); foreach (MatchSerie matchSerie in matchSeries) { foreach (MatchTable matchTable in new[] { matchSerie.Table1, matchSerie.Table2, matchSerie.Table3, matchSerie.Table4 }) { foreach (MatchGame game in new[] { matchTable.Game1, matchTable.Game2 }) { if (potentiallyNewPlayerPins.TryGetValue(game.Player, out List <PinsAndScoreResult> list) == false) { list = new List <PinsAndScoreResult>(); potentiallyNewPlayerPins.Add(game.Player, list); } list.Add(new PinsAndScoreResult(game.Pins, matchTable.Score, matchSerie.SerieNumber)); } } } string oldResult = JsonConvert.SerializeObject( new SortedDictionary <string, List <PinsAndScoreResult> >(playerPins), Formatting.Indented); string newResult = JsonConvert.SerializeObject( potentiallyNewPlayerPins, Formatting.Indented); bool pinsOrPlayersDiffer = oldResult != newResult; bool scoresDiffer = (teamScore, opponentScore).CompareTo((TeamScore, OpponentScore)) != 0; MatchCommentaryEvent matchCommentaryEvent = CreateMatchCommentary( matchSeries, opponentSeries, players.ToDictionary(x => x.Id), resultsForPlayer); string newMatchCommentaryAsJson = JsonConvert.SerializeObject( new { matchCommentaryEvent.BodyText, matchCommentaryEvent.SummaryText }, Formatting.Indented); bool commentaryDiffers = matchCommentaryAsJson != newMatchCommentaryAsJson; if (pinsOrPlayersDiffer || scoresDiffer || commentaryDiffers) { MatchResultRegistered @event = new( roster.Id !, roster.Players, teamScore, opponentScore, roster.BitsMatchId, playerPins.Keys.AsEnumerable().ToArray()); ApplyChange(@event); RegisterSeries(publish, matchSeries, opponentSeries, players, resultsForPlayer); } return(roster.Date.AddDays(5) < SystemTime.UtcNow); }
private void Apply(MatchCommentaryEvent e) { matchCommentaryAsJson = JsonConvert.SerializeObject( new { e.BodyText, e.SummaryText }, Formatting.Indented); }
private void Apply(MatchCommentaryEvent _) { }