public void AggregateVersionIsSetToLatestEventId() { var testAggregateId = Guid.NewGuid(); var firstEvent = new GameCreatedEvent() { AggregateId = testAggregateId, GameDate = DateTime.Now }; var secondEvent = new PlayerAddedToGameEvent() { AggregateId = testAggregateId, PlayerId = Guid.NewGuid() }; using (var testEvents = CreateEventsTable()) { testEvents.Rows.Add(SerializeEvent(firstEvent), firstEvent.GetType().AssemblyQualifiedName); testEvents.Rows.Add(SerializeEvent(secondEvent), secondEvent.GetType().AssemblyQualifiedName); var mockDatabaseLayer = new Mock <IDatabaseLayer>(); mockDatabaseLayer.Setup(x => x.GetDataTable(It.IsAny <string>(), It.IsAny <object[]>())).Returns(testEvents); var sut = new EventRepository( mockDatabaseLayer.Object, null, null, null); var result = sut.GetAggregateById <Game>(testAggregateId); Assert.AreEqual(secondEvent.EventId, result.AggregateVersion); } }
private void ApplyEvent(PlayerAddedToGameEvent e) { _players.Add(new Player() { PlayerName = e.PlayerName, Placing = e.Placing, Winnings = e.Winnings, Payin = e.PayIn }); }
public void Handle(PlayerAddedToGameEvent e) { var game = QueryDataStore.GetData <GetGamesListDto>().First(x => x.GameId == e.AggregateId); if (e.Placing == 1) { game.Winner = e.PlayerName; game.Winnings = e.Winnings; } QueryDataStore.SaveChanges(); }
public void Handle(PlayerAddedToGameEvent e) { var game = QueryDataStore.GetData <GetGameResultsDto>().Single(x => x.GameId == e.AggregateId); game.Players.Add(new GetGameResultsDto.PlayerDto() { PlayerName = e.PlayerName, Placing = e.Placing, Winnings = e.Winnings, PayIn = e.PayIn }); QueryDataStore.SaveChanges(); }
public void PublishEventsWithAnOldVersionOfTheAggregateThrowsConcurrencyException() { Game testGame = (Game)Activator.CreateInstance(typeof(Game), true); testGame.AggregateId = Guid.NewGuid(); var originalVersion = Guid.NewGuid(); var testEvent = new PlayerAddedToGameEvent() { AggregateId = testGame.AggregateId, PlayerId = Guid.NewGuid() }; testGame.PendingEvents.Add(testEvent); var sut = new EventRepository(null, null, null, null); sut.PublishEvents(testGame, null, originalVersion); }