Exemplo n.º 1
0
        public PlayersSyncResult(
            IEnumerable <PlayerRow> playerRows,
            IEnumerable <Player> players)
        {
            var playerRowsByID = playerRows.ToDictionary(r => r.ID);
            var playersByID    = players.ToDictionary(p => p.ID);

            DefunctPlayerRows = playerRowsByID.Values
                                .Where(r => !playersByID.ContainsKey(r.ID))
                                .ToArray();
            NewPlayerRows = PlayerRow.CreateRows(playersByID.Values
                                                 .Where(p => !playerRowsByID.ContainsKey(p.ID)))
                            .ToArray();

            var updatedPlayerRows = new List <PlayerRow>();

            foreach (var player in playersByID.Values)
            {
                if (playerRowsByID.TryGetValue(player.ID, out PlayerRow playerRow) &&
                    !player.Matches(playerRow))
                {
                    player.CopyTo(playerRow);
                    updatedPlayerRows.Add(playerRow);
                }
            }
            UpdatedPlayerRows = updatedPlayerRows;
        }
Exemplo n.º 2
0
        public void CreateRows()
        {
            var players = Enumerable.Range(0, 50)
                          .Select(i => new Player {
                ID = i.ToString(), Name = $"player {i}"
            });
            var playerRows = PlayerRow.CreateRows(players).ToArray();

            Assert.AreEqual(50, playerRows.Length);
            CollectionAssert.AreEqual(
                players.Select(f => f.ID).ToArray(),
                playerRows.Select(r => r.ID).ToArray());
            Assert.IsTrue(playerRows.All(r => r.PartitionKey == "0"));
            Assert.AreEqual(playerRows.Length, playerRows.Select(r => r.RowKey).Distinct().Count());
        }