예제 #1
0
        public async Task LoadAndSave_NotDuplicatingWhenGoingUp()
        {
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);

            var ranks1 = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, GateWay.Europe, GameMode.GM_1v1, 0)
            };
            var ranks2 = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 8, 1456, GateWay.Europe, GameMode.GM_1v1, 0)
            };
            await rankRepository.InsertRanks(ranks1);

            await rankRepository.InsertRanks(ranks2);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 0);
            await playerRepository.UpsertPlayerOverview(player);

            var playerLoaded = await rankRepository.LoadPlayersOfLeague(1, 0, GateWay.Europe, GameMode.GM_1v1);

            Assert.AreEqual(1, playerLoaded.Count);
            Assert.AreEqual(8, playerLoaded[0].RankNumber);
        }
예제 #2
0
        public async Task LoadAndSave()
        {
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);

            var ranks = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, GateWay.America, GameMode.GM_1v1, 0)
            };
            await rankRepository.InsertRanks(ranks);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 0);

            player.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player);

            await playerRepository.UpsertPlayerOverview(player);

            await playerRepository.UpsertPlayerOverview(player);

            var playerLoaded = await rankRepository.LoadPlayersOfLeague(1, 0, GateWay.America, GameMode.GM_1v1);

            Assert.AreEqual(1, playerLoaded.Count);
            Assert.AreEqual("0_peter#123@10_GM_1v1", playerLoaded[0].Players.First().Id);
            Assert.AreEqual(1, playerLoaded[0].Players.First().Wins);
            Assert.AreEqual(12, playerLoaded[0].RankNumber);
            Assert.AreEqual(1456, playerLoaded[0].RankingPoints);
            Assert.AreEqual(0, playerLoaded[0].Players.First().Losses);
        }
예제 #3
0
        public async Task LoadPlayersOfLeague_RaceBasedMMR()
        {
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);

            var ranks = new List <Rank>
            {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, Race.HU, GateWay.Europe, GameMode.GM_1v1, 2),
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 8, 1456, Race.NE, GateWay.Europe, GameMode.GM_1v1, 2)
            };
            await rankRepository.InsertRanks(ranks);

            var player1 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 2, Race.HU);
            await playerRepository.UpsertPlayerOverview(player1);

            var player2 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 2, Race.NE);
            await playerRepository.UpsertPlayerOverview(player2);

            var playerLoaded = await rankRepository.LoadPlayersOfLeague(1, 2, GateWay.Europe, GameMode.GM_1v1);

            Assert.AreEqual(2, playerLoaded.Count);
        }
예제 #4
0
        public async Task SearchRanks_WithRaceSpecificRank_DifferentSeasons()
        {
            // Arrange
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);

            var ranks = new List <Rank>
            {
                //old one
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 2, 1000, null, GateWay.America, GameMode.GM_1v1, 1),

                //mmr based
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 2, 1000, Race.HU, GateWay.America, GameMode.GM_1v1, 2),
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 3, 2000, Race.NE, GateWay.America, GameMode.GM_1v1, 2)
            };
            await rankRepository.InsertRanks(ranks);

            var player1 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 1, null);

            player1.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player1);

            var player2 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 2, Race.HU);

            player2.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player2);

            var player3 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 2, Race.NE);

            player3.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player3);

            // Act
            var playerLoaded = await rankRepository.SearchPlayerOfLeague("ete", 1, GateWay.America, GameMode.GM_1v1);

            // Assert
            Assert.AreEqual(1, playerLoaded.Count);

            // Act
            var playerLoaded2 = await rankRepository.SearchPlayerOfLeague("ete", 2, GateWay.America, GameMode.GM_1v1);

            // Assert
            Assert.AreEqual(2, playerLoaded2.Count);
        }
예제 #5
0
        public async Task LoadAndSearch_NulLString()
        {
            var playerRepository = new PlayerRepository(MongoClient);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 0);
            await playerRepository.UpsertPlayerOverview(player);

            Assert.IsEmpty(await playerRepository.LoadOverviewLike(null, GateWay.Europe));
        }
예제 #6
0
        public async Task ReturnRanks_WhenPlayersHavePersonalSettingsConfigured_MustHaveCorrectPersonalSettings()
        {
            // Arrange
            var rankRepository             = new RankRepository(MongoClient, personalSettingsProvider);
            var playerRepository           = new PlayerRepository(MongoClient);
            var personalSettingsRepository = new PersonalSettingsRepository(MongoClient);
            var clanRepository             = new ClanRepository(MongoClient);
            var queryHandler = new RankQueryHandler(rankRepository, playerRepository, clanRepository);

            var ranks = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, null, GateWay.America, GameMode.GM_1v1, 1)
            };
            await rankRepository.InsertRanks(ranks);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 1, null);

            player.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player);

            var playerStats = new PlayerOverallStats()
            {
                BattleTag = "peter#123",
            };
            await playerRepository.UpsertPlayer(playerStats);

            var settings = new PersonalSetting("peter#123")
            {
                ProfilePicture = new ProfilePicture()
                {
                    Race = AvatarCategory.HU, PictureId = 5
                },
                Country = "BG"
            };
            await personalSettingsRepository.Save(settings);

            // Act
            var playerLoaded = await queryHandler.LoadPlayersOfLeague(1, 1, GateWay.America, GameMode.GM_1v1);

            // Assert
            Assert.AreEqual(1, playerLoaded.Count);

            var playerRank = playerLoaded[0];

            Assert.AreEqual("1_peter#123@10_GM_1v1", playerRank.Players.First().Id);
            Assert.AreEqual(playerRank.PlayersInfo[0].SelectedRace, AvatarCategory.HU);
            Assert.AreEqual(playerRank.PlayersInfo[0].PictureId, 5);
            Assert.AreEqual(playerRank.PlayersInfo[0].Country, "BG");
        }
예제 #7
0
        public async Task LoadAndSearch()
        {
            var playerRepository = new PlayerRepository(MongoClient);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 0);
            await playerRepository.UpsertPlayerOverview(player);

            var playerLoaded = (await playerRepository.LoadOverviewLike("PeT", GateWay.Europe)).Single();

            Assert.AreEqual(player.Id, playerLoaded.Id);
            Assert.AreEqual(GateWay.Europe, playerLoaded.GateWay);
        }
예제 #8
0
        public void UpdateOverview_2v2AT()
        {
            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123"), PlayerId.Create("wolf#123")
            }, GateWay.Europe, GameMode.GM_2v2_AT, 0);

            player.RecordWin(true, 1230);

            Assert.AreEqual(1, player.Games);
            Assert.AreEqual(1, player.Wins);

            Assert.AreEqual(GameMode.GM_2v2_AT, player.GameMode);
            Assert.AreEqual(1, player.Games);
            Assert.AreEqual(1, player.Wins);
            Assert.AreEqual(0, player.Losses);
        }
예제 #9
0
        public void UpdateOverview()
        {
            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 0);

            player.RecordWin(true, 1230);
            player.RecordWin(false, 1240);
            player.RecordWin(false, 1250);

            Assert.AreEqual(3, player.Games);
            Assert.AreEqual(1, player.Wins);
            Assert.AreEqual(2, player.Losses);
            Assert.AreEqual("peter#123", player.PlayerIds[0].BattleTag);
            Assert.AreEqual("peter", player.PlayerIds[0].Name);
            Assert.AreEqual("0_peter#123@20_GM_1v1", player.Id);
            Assert.AreEqual(1250, player.MMR);
        }
예제 #10
0
        public async Task ReturnRanks_WithRaceSpecificRank()
        {
            // Arrange
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);
            var queryHandler     = new RankQueryHandler(rankRepository, playerRepository, new ClanRepository(MongoClient));

            var ranks = new List <Rank>
            {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 2, 1000, Race.HU, GateWay.America, GameMode.GM_1v1, 2),
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 3, 2000, Race.NE, GateWay.America, GameMode.GM_1v1, 2)
            };
            await rankRepository.InsertRanks(ranks);

            var player1 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 2, Race.HU);

            player1.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player1);

            var player2 = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 2, Race.NE);

            player2.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player2);

            // Act
            var playerLoaded = await queryHandler.LoadPlayersOfLeague(1, 2, GateWay.America, GameMode.GM_1v1);

            // Assert
            Assert.AreEqual(2, playerLoaded.Count);

            Assert.AreEqual("peter#123", playerLoaded[0].Player.PlayerIds.Single().BattleTag);
            Assert.AreEqual("peter#123", playerLoaded[1].Player.PlayerIds.Single().BattleTag);
        }
예제 #11
0
        public async Task LoadAndSave_NotFound()
        {
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);

            var ranks = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, GateWay.Europe, GameMode.GM_1v1, 0)
            };
            await rankRepository.InsertRanks(ranks);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.Europe, GameMode.GM_1v1, 0);
            await playerRepository.UpsertPlayerOverview(player);

            var playerLoaded = await rankRepository.LoadPlayersOfLeague(1, 0, GateWay.America, GameMode.GM_1v1);

            Assert.IsEmpty(playerLoaded);
        }
예제 #12
0
        public async Task ReturnRanks_ClanGetsResolved()
        {
            // Arrange
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);
            var clanRepository   = new ClanRepository(MongoClient);
            var queryHandler     = new RankQueryHandler(rankRepository, playerRepository, clanRepository);

            var ranks = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, GateWay.America, GameMode.GM_1v1, 1)
            };
            await rankRepository.InsertRanks(ranks);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 1);

            player.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player);

            var playerStats = new PlayerOverallStats()
            {
                BattleTag = "peter#123",
            };
            await playerRepository.UpsertPlayer(playerStats);

            await clanRepository.UpsertMemberShip(new ClanMembership { BattleTag = "peter#123", ClanId = "W3C" });

            // Act
            var playerLoaded = await queryHandler.LoadPlayersOfLeague(1, 1, GateWay.America, GameMode.GM_1v1);

            // Assert
            Assert.AreEqual(1, playerLoaded.Count);

            var playerRank = playerLoaded[0];

            Assert.AreEqual("W3C", playerRank.PlayersInfo.Single().ClanId);
        }
예제 #13
0
        public async Task LoadClan_PopulateRanks()
        {
            var clan = await CreateFoundedClanForTest();

            await _rankRepository.UpsertSeason(new Season(0));

            await _rankRepository.UpsertSeason(new Season(1));

            await _rankRepository.InsertRanks(new List <Rank>
            {
                new Rank(new List <string> {
                    clan.Members[0]
                }, 1, 5, 1500, null, GateWay.Europe, GameMode.GM_1v1, 1)
            });

            await _rankRepository.InsertLeagues(new List <LeagueConstellation>
            {
                new LeagueConstellation(1, GateWay.Europe, GameMode.GM_1v1, new List <League>
                {
                    new League(1, 2, "Wood", 5)
                })
            });

            var playerRepository = new PlayerRepository(MongoClient);
            await playerRepository.UpsertPlayerOverview(PlayerOverview.Create(new List <PlayerId>
            {
                PlayerId.Create(clan.Members[0])
            },
                                                                              GateWay.Europe,
                                                                              GameMode.GM_1v1,
                                                                              1,
                                                                              null));

            var clanLoaded = await _handler.LoadClan(clan.ClanId);

            Assert.AreEqual(1, clanLoaded.Ranks.First().League);
            Assert.AreEqual(2, clanLoaded.Ranks.First().LeagueOrder);
            Assert.AreEqual("Wood", clanLoaded.Ranks.First().LeagueName);
            Assert.AreEqual(5, clanLoaded.Ranks.First().LeagueDivision);
        }
예제 #14
0
        public async Task ReturnRanks_WhenPlayersDoNotHavePersonalSettingsConfigured_MustHaveNotThrowError()
        {
            // Arrange
            var rankRepository   = new RankRepository(MongoClient);
            var playerRepository = new PlayerRepository(MongoClient);
            var clanRepository   = new ClanRepository(MongoClient);
            var queryHandler     = new RankQueryHandler(rankRepository, playerRepository, clanRepository);

            var ranks = new List <Rank> {
                new Rank(new List <string> {
                    "peter#123"
                }, 1, 12, 1456, GateWay.America, GameMode.GM_1v1, 1)
            };
            await rankRepository.InsertRanks(ranks);

            var player = PlayerOverview.Create(new List <PlayerId> {
                PlayerId.Create("peter#123")
            }, GateWay.America, GameMode.GM_1v1, 1);

            player.RecordWin(true, 1234);
            await playerRepository.UpsertPlayerOverview(player);

            var playerStats = new PlayerOverallStats()
            {
                BattleTag = "peter#123",
            };
            await playerRepository.UpsertPlayer(playerStats);

            // Act
            var playerLoaded = await queryHandler.LoadPlayersOfLeague(1, 1, GateWay.America, GameMode.GM_1v1);

            // Assert
            Assert.AreEqual(1, playerLoaded.Count);

            var playerRank = playerLoaded[0];

            Assert.AreEqual("1_peter#123@10_GM_1v1", playerRank.Players.First().Id);
        }