public void AggregateVersionIsSetToLatestEventId()
        {
            var testAggregateId = Guid.NewGuid();

            var firstEvent = new GameCreatedEvent()
            {
                AggregateId = testAggregateId, GameDate = DateTime.Now
            };
            var secondEvent = new PlayerAddedToGameEvent()
            {
                AggregateId = testAggregateId, PlayerName = "Dylan", Placing = 1, Winnings = 150
            };

            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);
        }
        public void ProcessDuplicateEvent()
        {
            var testEvent = new GameCreatedEvent();
            var mockIdempotencyChecker = new Mock <IIdempotencyChecker>();
            var mockQueryDataStore     = new Mock <IQueryDataStore>();

            mockIdempotencyChecker.Setup(x => x.CheckIdempotency(testEvent.EventId)).Returns(true);

            var sut = new EventHandlerFactory(mockQueryDataStore.Object, mockIdempotencyChecker.Object, null);

            sut.HandleEvent(testEvent);

            mockQueryDataStore.Verify(x => x.Insert(It.IsAny <GetGameCountByDateDto>()), Times.Never());
        }
Ejemplo n.º 3
0
        public async Task CreateGame(CreateGameCmd cmd)
        {
            var game   = new Game(cmd.Name);
            var player = CreatePlayerForCurrentUser();

            game.Join(player);
            await _repository.CreateGame(GameEntity.Create(game));

            var gameCreatedEvent = new GameCreatedEvent
            {
                GameId   = game.Id,
                GameName = game.Name,
                Players  = game.Players.Select(PlayerDto.Create)
            };
            await Clients.Group(LobbyGroup).GameCreated(gameCreatedEvent);
        }
        public void ProcessNewEvent()
        {
            var testEvent = new GameCreatedEvent();
            var mockIdempotencyChecker = new Mock <IIdempotencyChecker>();
            var mockQueryDataStore     = new Mock <IQueryDataStore>();
            var mockDatabaseLayer      = new Mock <IDatabaseLayer>();

            mockDatabaseLayer.Setup(x => x.ExecuteInTransaction(It.IsAny <Action>())).Callback <Action>(x => x());

            mockIdempotencyChecker.Setup(x => x.CheckIdempotency(testEvent.EventId)).Returns(false);

            var sut = new EventHandlerFactory(mockQueryDataStore.Object, mockIdempotencyChecker.Object, mockDatabaseLayer.Object);

            sut.HandleEvent(testEvent);

            mockQueryDataStore.Verify(x => x.Insert(It.IsAny <GetGameCountByDateDto>()));
        }
Ejemplo n.º 5
0
        public override async Task OnConnectedAsync()
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, LobbyGroup);

            var games = await _repository.GetStartedGamesByPlayer(GetUserId());

            foreach (var game in games)
            {
                await Clients.Caller.GameStarted(new GameStartedEvent { Game = GameSummaryDto.Create(game.ToModel()) });

                if (game.Status == GameStatus.ENDED)
                {
                    var endedEvent = new GameEndedEvent
                    {
                        GameId  = game.Id,
                        Results = game.Players.Select(p => new PlayerResultDto
                        {
                            Player = PlayerDto.Create(p),
                            Result = p.Result ?? 0
                        })
                    };
                    await Clients.Caller.GameEnded(endedEvent);
                }
            }

            var lobbyGames = await _repository.GetLobbyGames();

            foreach (var lobbyGame in lobbyGames)
            {
                var gameCreatedEvent = new GameCreatedEvent
                {
                    GameId   = lobbyGame.Id,
                    GameName = lobbyGame.Name,
                    Players  = lobbyGame.Players.Select(PlayerDto.Create),
                };
                await Clients.Caller.GameCreated(gameCreatedEvent);
            }
        }
Ejemplo n.º 6
0
 private void ApplyEvent(GameCreatedEvent e)
 {
     AggregateId = e.AggregateId;
 }
Ejemplo n.º 7
0
 private async Task HandleCreatedEventAsync(GameCreatedEvent createdEvent)
 => await _gameHub.Clients.All.SendAsync("GameCreatedAsync", _asDto.Game(createdEvent.Game));