Ejemplo n.º 1
0
    private async void GetLeaderboard()
    {
        if (m_context == null)
        {
            LogLine("A user is required to get leaderboards. Please sign in a user first.");
            LogLine("");
        }
        else
        {
            LogLine("Getting leaderboard...");
            LogLine("");

            try
            {
                LeaderboardResult result = await m_context.LeaderboardService.GetLeaderboardAsync(
                    m_context.AppConfig.ServiceConfigurationId, "LBEnemyDefeatsDescending");

                LogLeaderboardResult(result);

                // A single call to GetLeaderboardAsync only returns the top ten entries, so let's
                // request a couple more pages.
                const int maxResultsToLog = 3;
                int       resultsLogged   = 1;

                while (result.HasNext && resultsLogged < maxResultsToLog)
                {
                    result = await result.GetNextAsync(10);

                    LogLeaderboardResult(result);

                    resultsLogged++;
                }
            }
            catch (Exception ex)
            {
                LogLine("GetLeaderboard failed: " + ex.Message);
                LogLine("");
            }
        }
    }
        public async Task GetLeaderboard()
        {
            LeaderboardResult result = await context.LeaderboardService.GetLeaderboardAsync("Jumps", new LeaderboardQuery());

            MockXboxLiveData.MockRequestData mockRequestData = MockXboxLiveData.MockResponses["defaultLeaderboardData"];
            JObject responseJson = JObject.Parse(mockRequestData.Response.ResponseBodyString);

            Assert.AreEqual("GET", mockRequestData.Request.Method);
            Assert.AreEqual("https://leaderboards.xboxlive.com/scids/00000000-0000-0000-0000-0000694f5acb/leaderboards/stat(Jumps)", mockRequestData.Request.Url);
            Assert.IsTrue(result.HasNext);
            this.VerifyLeaderboardResult(result, responseJson);

            // Testing continuation token with GetNext.
            LeaderboardResult nextResult = await result.GetNextAsync(100);

            MockXboxLiveData.MockRequestData mockRequestDataWithContinuationToken = MockXboxLiveData.MockResponses["defaultLeaderboardDataWithContinuationToken"];
            JObject responseJsonWithContinuationToken = JObject.Parse(mockRequestDataWithContinuationToken.Response.ResponseBodyString);

            Assert.AreEqual("GET", mockRequestDataWithContinuationToken.Request.Method);
            Assert.AreEqual("https://leaderboards.xboxlive.com/scids/00000000-0000-0000-0000-0000694f5acb/leaderboards/stat(Jumps)?maxItems=100&continuationToken=6", mockRequestDataWithContinuationToken.Request.Url);
            Assert.IsFalse(nextResult.HasNext);
            this.VerifyLeaderboardResult(nextResult, responseJsonWithContinuationToken);
        }