Esempio n. 1
0
        public void Handle(GameUncompletedEvent e)
        {
            var dto = QueryDataStore.GetData <GameLookupDto>().Single(x => x.GameId == e.GameId);

            dto.Completed = false;
            QueryDataStore.Update(dto);
        }
        public async Task QueryFileNameNoFiltered()
        {
            var id        = Guid.NewGuid();
            var version   = Guid.NewGuid().ToString();
            var etag      = Guid.NewGuid().ToString();
            var createdOn = DateTime.UtcNow;

            var random = new Random();
            var count  = random.Next(1, 25);
            var items  = new List <IDictionary <string, object> >(count);

            for (var i = 0; i < count; i++)
            {
                var filtered = new Dictionary <string, object>();
                filtered.Add(TableStorage.PartitionKey, id);
                filtered.Add(TableStorage.RowKey, version);
                filtered.Add(TableStorage.Timestamp, createdOn);
                filtered.Add(TableStorage.ETag, etag);
                filtered.Add("FileName", Guid.NewGuid().ToString());
                items.Add(filtered);
            }

            var table = Substitute.For <ITableStorage>();

            table.Query(Arg.Any <TableQuery>()).Returns(Task.FromResult <IEnumerable <IDictionary <string, object> > >(items));

            var store = new QueryDataStore(table);
            var r     = await store.Query(id, version, null);

            Assert.IsNotNull(r);
            Assert.AreEqual(count, r.Count());

            table.Received().Query(Arg.Any <TableQuery>());
        }
Esempio n. 3
0
        public void Handle(GameDateChangedEvent e)
        {
            var dto = QueryDataStore.GetData <GameLookupDto>().Single(x => x.GameId == e.GameId);

            dto.GameDate = e.GameDate;
            QueryDataStore.Update(dto);
        }
        public void Handle(GameCompletedEvent e)
        {
            foreach (var p in e.Placings)
            {
                var player = QueryDataStore.GetData <PlayerLookupDto>().Single(x => x.PlayerId == p.Key);
                var dto    = QueryDataStore.GetData <GetGamePlayersDto>().Single(x => x.GameId == e.GameId && x.PlayerId == player.PlayerId);

                dto.Placing = p.Value;

                if (dto.Placing == 1)
                {
                    dto.Winnings = e.First;
                }

                if (dto.Placing == 2)
                {
                    dto.Winnings = e.Second;
                }

                if (dto.Placing == 3)
                {
                    dto.Winnings = e.Third;
                }

                QueryDataStore.Update(dto);
            }
        }
Esempio n. 5
0
 public void Handle(GameCreatedEvent e)
 {
     QueryDataStore.Insert(new GetGameResultsDto()
     {
         GameId   = e.AggregateId,
         GameDate = e.GameDate
     });
 }
 public void Handle(PlayerCreatedEvent e)
 {
     QueryDataStore.Insert(new GetPlayerCountByNameDto()
     {
         PlayerId   = e.PlayerId,
         PlayerName = e.PlayerName,
     });
 }
        public void Handle(RebuyRemovedEvent e)
        {
            var dto = QueryDataStore.GetData <GetGamePlayersDto>().Single(p => p.GameId == e.GameId && p.PlayerId == e.PlayerId);

            dto.PayIn -= 10;

            QueryDataStore.Update(dto);
        }
Esempio n. 8
0
 public void Handle(PlayerCreatedEvent e)
 {
     QueryDataStore.Insert(new PlayerLookupDto()
     {
         PlayerId   = e.PlayerId,
         PlayerName = e.PlayerName,
     });
 }
        public void Handle(GameUncompletedEvent e)
        {
            var dto = QueryDataStore.GetData <GetGamesListDto>().Single();

            dto.Completed = false;

            QueryDataStore.Update(dto);
        }
Esempio n. 10
0
 public void Handle(PlayerAddedToGameEvent e)
 {
     QueryDataStore.Insert(new GamePlayersLookupDto()
     {
         GameId   = e.GameId,
         PlayerId = e.PlayerId,
     });
 }
Esempio n. 11
0
 public void Handle(GameCreatedEvent e)
 {
     QueryDataStore.Insert(new GetGamesListDto()
     {
         GameId   = e.GameId,
         GameDate = e.GameDate,
     });
 }
Esempio n. 12
0
 public void Handle(GameCreatedEvent e)
 {
     QueryDataStore.Insert(new GameLookupDto()
     {
         GameId    = e.GameId,
         GameDate  = e.GameDate,
         Completed = false,
     });
 }
 public void Handle(GameCompletedEvent e)
 {
     foreach (var player in e.Placings)
     {
         var dto = QueryDataStore.GetData <GetPlayersDto>().Single(p => p.PlayerId == player.Key);
         dto.GamesPlayed++;
         QueryDataStore.Update(dto);
     }
 }
Esempio n. 14
0
        public void Handle(PlayerAddedToGameEvent e)
        {
            var dto = new GetGamesWithPlayerDto();

            dto.GameId     = e.AggregateId;
            dto.PlayerName = e.PlayerName;

            QueryDataStore.Insert <GetGamesWithPlayerDto>(dto);
        }
        public void Handle(GameDeletedEvent e)
        {
            var games = QueryDataStore.GetData <GetPlayerGamesDto>().Where(x => x.GameId == e.AggregateId).ToList();

            foreach (var g in games)
            {
                QueryDataStore.Delete <GetPlayerGamesDto>(g);
            }
        }
        public void Handle(RebuyAddedEvent e)
        {
            var dto = QueryDataStore.GetData <GetGamePlayersDto>().Single(p => p.GameId == e.GameId && p.PlayerId == e.PlayerId);

            dto.PayIn += e.RebuyAmount;
            dto.Rebuys++;

            QueryDataStore.Update(dto);
        }
        public void Handle(GameCreatedEvent e)
        {
            var dto = new LookupGameDatesDto();

            dto.GameId   = e.AggregateId;
            dto.GameDate = e.GameDate;

            QueryDataStore.Insert <LookupGameDatesDto>(dto);
        }
Esempio n. 18
0
        public void Handle(GameDeletedEvent e)
        {
            var dtos = QueryDataStore.GetData <GetGamesWithPlayerDto>().Where(x => x.GameId == e.AggregateId).ToList();

            foreach (var d in dtos)
            {
                QueryDataStore.Delete <GetGamesWithPlayerDto>(d);
            }
        }
 public void Handle(PlayerCreatedEvent e)
 {
     QueryDataStore.Insert(new GetPlayersDto()
     {
         PlayerId    = e.PlayerId,
         PlayerName  = e.PlayerName,
         GamesPlayed = 0,
     });
 }
        public void Handle(GameDateChangedEvent e)
        {
            var dto = QueryDataStore.GetData <GetGameCountByDateDto>().Single(x => x.GameId == e.GameId);

            dto.GameYear  = e.GameDate.Year;
            dto.GameMonth = e.GameDate.Month;
            dto.GameDay   = e.GameDate.Day;

            QueryDataStore.Update <GetGameCountByDateDto>(dto);
        }
 public void Handle(GameCreatedEvent e)
 {
     QueryDataStore.Insert(new GetGameCountByDateDto()
     {
         GameId    = e.GameId,
         GameYear  = e.GameDate.Year,
         GameMonth = e.GameDate.Month,
         GameDay   = e.GameDate.Day,
     });
 }
Esempio n. 22
0
 public void Handle(GameCreatedEvent e)
 {
     QueryDataStore.Insert(new GetGamesListDto()
     {
         GameId   = e.AggregateId,
         GameDate = e.GameDate,
         Winnings = 0,
         Winner   = string.Empty
     });
 }
Esempio n. 23
0
        public void Handle(GameUncompletedEvent e)
        {
            // How does this Single even work, shouldn't we need to filter by GameId
            // should probably write a test for this first
            var dto = QueryDataStore.GetData <GetGamesListDto>().Single();

            dto.Completed = false;

            QueryDataStore.Update(dto);
        }
Esempio n. 24
0
        public void Handle(PlayerRenamedEvent e)
        {
            var dto = QueryDataStore.GetData <GetGameResultsDto>().Single(x => x.GameId == e.AggregateId);

            var renamedPlayer = dto.Players.First(p => p.PlayerName == e.OldPlayerName);

            renamedPlayer.PlayerName = e.NewPlayerName;

            QueryDataStore.SaveChanges();
        }
        public void Handle(GameUncompletedEvent e)
        {
            var gamePlayersDto = QueryDataStore.GetData <GamePlayersLookupDto>().Where(x => x.GameId == e.GameId).ToList();

            foreach (var player in gamePlayersDto)
            {
                var dto = QueryDataStore.GetData <GetPlayersDto>().Single(x => x.PlayerId == player.PlayerId);
                dto.GamesPlayed--;
                QueryDataStore.Update(dto);
            }
        }
        public void Handle(PlayerAddedToGameEvent e)
        {
            var dto = new LookupGamePlayersDto();

            dto.GameId     = e.AggregateId;
            dto.Winnings   = e.Winnings;
            dto.PayIn      = e.PayIn;
            dto.PlayerName = e.PlayerName;

            QueryDataStore.Insert <LookupGamePlayersDto>(dto);
        }
        public void Handle(PlayerAddedToGameEvent e)
        {
            var player = QueryDataStore.GetData <PlayerLookupDto>().Single(p => p.PlayerId == e.PlayerId);

            QueryDataStore.Insert(new GetGamePlayersDto()
            {
                GameId     = e.GameId,
                PlayerId   = e.PlayerId,
                PlayerName = player.PlayerName,
            });
        }
        public void Handle(PlayerRenamedEvent e)
        {
            var players = QueryDataStore.GetData <GetPlayerGamesDto>().Where(x => x.PlayerName == e.OldPlayerName).ToList();

            foreach (var p in players)
            {
                p.PlayerName = e.NewPlayerName;
            }

            QueryDataStore.SaveChanges();
        }
Esempio n. 29
0
        public void Handle(PlayerRenamedEvent e)
        {
            var games = QueryDataStore.GetData <GetGamesListDto>().Where(x => x.Winner == e.OldPlayerName);

            foreach (var g in games)
            {
                g.Winner = e.NewPlayerName;
            }

            QueryDataStore.SaveChanges();
        }
Esempio n. 30
0
        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 async Task Query()
        {
            var id = Guid.NewGuid();
            var version = Guid.NewGuid().ToString();
            var fileName = Guid.NewGuid().ToString();
            var etag = Guid.NewGuid().ToString();
            var createdOn = DateTime.UtcNow;

            var items = new List<IDictionary<string, object>>();
            var dic = new Dictionary<string, object>();
            dic.Add(TableStorage.PartitionKey, id);
            dic.Add(TableStorage.RowKey, version);
            dic.Add(TableStorage.Timestamp, createdOn);
            dic.Add(TableStorage.ETag, etag);
            dic.Add("FileName", fileName);

            items.Add(dic);

            var table = Substitute.For<ITableStorage>();
            table.Query(Arg.Any<TableQuery>()).Returns(Task.FromResult<IEnumerable<IDictionary<string, object>>>(items));

            var store = new QueryDataStore(table);
            var r = await store.Query(id, version, fileName);

            Assert.IsNotNull(r);
            Assert.AreEqual(1, r.Count());
            var d = r.First();
            Assert.IsFalse(d.ContainsKey(TableStorage.PartitionKey));
            Assert.IsFalse(d.ContainsKey(TableStorage.RowKey));
            Assert.IsFalse(d.ContainsKey(TableStorage.Timestamp));
            Assert.IsFalse(d.ContainsKey(TableStorage.ETag));
            Assert.AreEqual(id, d["Identifier"]);
            Assert.AreEqual(version, d["Version"]);
            Assert.AreEqual(createdOn, d["CreatedOn"]);

            table.Received().Query(Arg.Any<TableQuery>());
        }
        public async Task QueryFileNameNoFiltered()
        {
            var id = Guid.NewGuid();
            var version = Guid.NewGuid().ToString();
            var etag = Guid.NewGuid().ToString();
            var createdOn = DateTime.UtcNow;

            var random = new Random();
            var count = random.Next(1, 25);
            var items = new List<IDictionary<string, object>>(count);
            for (var i = 0; i < count; i++)
            {
                var filtered = new Dictionary<string, object>();
                filtered.Add(TableStorage.PartitionKey, id);
                filtered.Add(TableStorage.RowKey, version);
                filtered.Add(TableStorage.Timestamp, createdOn);
                filtered.Add(TableStorage.ETag, etag);
                filtered.Add("FileName", Guid.NewGuid().ToString());
                items.Add(filtered);
            }

            var table = Substitute.For<ITableStorage>();
            table.Query(Arg.Any<TableQuery>()).Returns(Task.FromResult<IEnumerable<IDictionary<string, object>>>(items));

            var store = new QueryDataStore(table);
            var r = await store.Query(id, version, null);

            Assert.IsNotNull(r);
            Assert.AreEqual(count, r.Count());

            table.Received().Query(Arg.Any<TableQuery>());
        }
        public async Task QueryNoRowReturnsNull()
        {
            var id = Guid.NewGuid();
            var fileName = Guid.NewGuid().ToString();

            var table = Substitute.For<ITableStorage>();
            table.Query(Arg.Any<TableQuery>()).Returns(Task.FromResult<IEnumerable<IDictionary<string, object>>>(null));

            var store = new QueryDataStore(table);
            var r = await store.Query(id, null, fileName);

            Assert.IsNull(r);

            table.Received().Query(Arg.Any<TableQuery>());
        }