示例#1
0
        public async Task ResetPlayerDataSuccessTimeOut()
        {
            this.SetUpMockAuth();

            var    mockHttp          = new MockHttpMessageHandler();
            Guid   jobId             = Guid.NewGuid();
            var    submitJobUri      = new Uri(new Uri(ClientSettings.Singleton.OmegaResetToolEndpoint), "/submitJob");
            string submitJobResponse = $"\"{jobId}\"";
            string submitJobContent  = $"{{\"userId\":\"{DefaultXuid}\",\"Scid\":\"{DefaultScid}\"}}";

            mockHttp.Expect(submitJobUri.ToString())
            .WithContent(submitJobContent)
            .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox))
            .Respond("application/json", submitJobResponse);

            var    queryJobUri      = new Uri(new Uri(ClientSettings.Singleton.OmegaResetToolEndpoint), "/jobs/" + jobId);
            string queryJobResponse = $"{{\'jobId\':'{jobId}','overallStatus':'InProgress'}}";

            var mockRequest = mockHttp.When(queryJobUri.ToString())
                              .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox))
                              .Respond("application/json", queryJobResponse);

            TestHook.MockHttpHandler = mockHttp;

            var resetResult = await PlayerReset.ResetPlayerDataAsync(DefaultScid, DefaultSandbox, DefaultXuid);

            Assert.AreEqual(ResetOverallResult.Timeout, resetResult.OverallResult);
            Assert.AreEqual(0, resetResult.ProviderStatus.Count);

            mockHttp.VerifyNoOutstandingExpectation();
            Assert.AreEqual(PlayerReset.MaxPollingAttempts, mockHttp.GetMatchCount(mockRequest));
        }
示例#2
0
        public async Task ResetPlayerDataSuccess()
        {
            this.SetUpMockAuth();

            var    mockHttp          = new MockHttpMessageHandler();
            Guid   jobId             = Guid.NewGuid();
            var    submitJobUri      = new Uri(new Uri(ClientSettings.Singleton.OmegaResetToolEndpoint), "/submitJob");
            string submitJobResponse = $"\"{jobId}\"";
            string submitJobContent  = $"{{\"userId\":\"{DefaultXuid}\",\"Scid\":\"{DefaultScid}\"}}";

            mockHttp.Expect(submitJobUri.ToString())
            .WithContent(submitJobContent)
            .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox))
            .Respond("application/json", submitJobResponse);

            var    queryJobUri      = new Uri(new Uri(ClientSettings.Singleton.OmegaResetToolEndpoint), "/jobs/" + jobId);
            string queryJobResponse = $"{{\'jobId\':'{jobId}','overallStatus':'CompletedSuccess'," +
                                      $"'providerStatus':[" +
                                      $"{{'provider':'StatsDelete','status':'CompletedSuccess'}}," +
                                      $"{{'provider':'TitleHistoryDelete','status':'CompletedSuccess'}}," +
                                      $"{{'provider':'AchievementsDelete','status':'CompletedSuccess'}}," +
                                      $"{{'provider':'GoalEngineDelete','status':'CompletedSuccess'}}," +
                                      $"{{'provider':'Leaderboards','status':'CompletedSuccess'}}" +
                                      $"]}}";

            mockHttp.Expect(queryJobUri.ToString())
            .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox))
            .Respond("application/json", queryJobResponse);

            TestHook.MockHttpHandler = mockHttp;

            var resetResult = await PlayerReset.ResetPlayerDataAsync(DefaultScid, DefaultSandbox, DefaultXuid);

            Assert.AreEqual(ResetOverallResult.Succeeded, resetResult.OverallResult);
            Assert.AreEqual(5, resetResult.ProviderStatus.Count);

            Assert.IsNull(resetResult.ProviderStatus[0].ErrorMessage);
            Assert.AreEqual("StatsDelete", resetResult.ProviderStatus[0].Provider);
            Assert.AreEqual(ResetProviderStatus.CompletedSuccess, resetResult.ProviderStatus[0].Status);

            Assert.IsNull(resetResult.ProviderStatus[1].ErrorMessage);
            Assert.AreEqual("TitleHistoryDelete", resetResult.ProviderStatus[1].Provider);
            Assert.AreEqual(ResetProviderStatus.CompletedSuccess, resetResult.ProviderStatus[1].Status);

            Assert.IsNull(resetResult.ProviderStatus[2].ErrorMessage);
            Assert.AreEqual("AchievementsDelete", resetResult.ProviderStatus[2].Provider);
            Assert.AreEqual(ResetProviderStatus.CompletedSuccess, resetResult.ProviderStatus[2].Status);

            Assert.IsNull(resetResult.ProviderStatus[3].ErrorMessage);
            Assert.AreEqual("GoalEngineDelete", resetResult.ProviderStatus[3].Provider);
            Assert.AreEqual(ResetProviderStatus.CompletedSuccess, resetResult.ProviderStatus[3].Status);

            Assert.IsNull(resetResult.ProviderStatus[4].ErrorMessage);
            Assert.AreEqual("Leaderboards", resetResult.ProviderStatus[4].Provider);
            Assert.AreEqual(ResetProviderStatus.CompletedSuccess, resetResult.ProviderStatus[4].Status);

            mockHttp.VerifyNoOutstandingExpectation();
        }
示例#3
0
        public async Task ResetPlayerDataSubmitJobError()
        {
            this.SetUpMockAuth();

            var    mockHttp         = new MockHttpMessageHandler();
            Guid   jobId            = Guid.NewGuid();
            var    submitJobUri     = new Uri(new Uri(ClientSettings.Singleton.OmegaResetToolEndpoint), "/submitJob");
            string submitJobContent = $"{{\"userId\":\"{DefaultXuid}\",\"Scid\":\"{DefaultScid}\"}}";

            mockHttp.Expect(submitJobUri.ToString())
            .WithContent(submitJobContent)
            .WithHeaders("Authorization", this.ExpectedToken(DefaultScid, DefaultSandbox))
            .Respond(HttpStatusCode.BadRequest);

            TestHook.MockHttpHandler = mockHttp;

            var resetResult = await PlayerReset.ResetPlayerDataAsync(DefaultScid, DefaultSandbox, DefaultXuid);

            Assert.AreEqual(ResetOverallResult.CompletedError, resetResult.OverallResult);
            Assert.AreEqual(0, resetResult.ProviderStatus.Count);

            mockHttp.VerifyNoOutstandingExpectation();
        }
        private static async Task <int> OnReset(ResetOptions options)
        {
            if (options == null)
            {
                Console.WriteLine("Unknown parameter error");
                return(-1);
            }

            DevAccount account = ToolAuthentication.LoadLastSignedInUser();

            if (account == null)
            {
                Console.Error.WriteLine("Didn't found dev sign in info, please use \"XblDevAccount.exe signin\" to initiate.");
                return(-1);
            }

            Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}");
            Console.WriteLine($"Resetting player {options.XboxUserId} data for scid {options.ServiceConfigurationId}, sandbox {options.Sandbox}");

            try
            {
                UserResetResult result = await PlayerReset.ResetPlayerDataAsync(
                    options.ServiceConfigurationId,
                    options.Sandbox, options.XboxUserId);

                switch (result.OverallResult)
                {
                case ResetOverallResult.Succeeded:
                    Console.WriteLine("Resetting has completed successfully.");
                    return(0);

                case ResetOverallResult.CompletedError:
                    Console.WriteLine("Resetting has completed with some error:");
                    if (!string.IsNullOrEmpty(result.HttpErrorMessage))
                    {
                        Console.WriteLine($"\t{result.HttpErrorMessage}");
                    }

                    PrintProviderDetails(result.ProviderStatus);
                    return(-1);

                case ResetOverallResult.Timeout:
                    Console.WriteLine("Resetting has timed out:");
                    PrintProviderDetails(result.ProviderStatus);
                    return(-1);

                default:
                    Console.WriteLine("has completed with unknown error");
                    return(-1);
                }
            }
            catch (HttpRequestException ex)
            {
                Console.WriteLine("Error: player data reset failed");

                if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized)))
                {
                    Console.WriteLine(
                        $"Unable to authorize the account with XboxLive service with scid : {options.ServiceConfigurationId} and sandbox : {options.Sandbox}, please contact your administrator.");
                }
                else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden)))
                {
                    Console.WriteLine(
                        "Your account doesn't have access to perform the operation, please contact your administrator.");
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }

                return(-1);
            }
        }
示例#5
0
        private static async Task <int> OnReset(ResetOptions options)
        {
            string xuid = string.Empty;

            if (options == null)
            {
                Console.WriteLine("Unknown parameter error");
                return(-1);
            }

            if (!string.IsNullOrEmpty(options.TestAccount))
            {
                TestAccount testAccount = await ToolAuthentication.SignInTestAccountAsync(options.TestAccount, options.Sandbox);

                if (testAccount == null)
                {
                    Console.Error.WriteLine($"Failed to log in to test account {options.TestAccount}.");
                    return(-1);
                }

                xuid = testAccount.Xuid;

                Console.WriteLine($"Using Test account {options.TestAccount} ({testAccount.Gamertag}) with xuid {xuid}");
            }
            else if (!string.IsNullOrEmpty(options.XboxUserId))
            {
                DevAccount account = ToolAuthentication.LoadLastSignedInUser();
                if (account == null)
                {
                    Console.Error.WriteLine("Resetting by XUID requires a signed in Partner Center account. Please use \"XblDevAccount.exe signin\" to log in.");
                    return(-1);
                }

                xuid = options.XboxUserId;

                Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}");
            }

            Console.WriteLine($"Resetting data for player with XUID {xuid} for SCID {options.ServiceConfigurationId} in sandbox {options.Sandbox}");

            try
            {
                UserResetResult result = await PlayerReset.ResetPlayerDataAsync(
                    options.ServiceConfigurationId,
                    options.Sandbox, xuid);

                switch (result.OverallResult)
                {
                case ResetOverallResult.Succeeded:
                    Console.WriteLine("Player data has been reset successfully.");
                    return(0);

                case ResetOverallResult.CompletedError:
                    Console.WriteLine("An error occurred while resetting player data:");
                    if (!string.IsNullOrEmpty(result.HttpErrorMessage))
                    {
                        Console.WriteLine($"\t{result.HttpErrorMessage}");
                    }

                    PrintProviderDetails(result.ProviderStatus);
                    return(-1);

                case ResetOverallResult.Timeout:
                    Console.WriteLine("Player data reset has timed out:");
                    PrintProviderDetails(result.ProviderStatus);
                    return(-1);

                default:
                    Console.WriteLine("An unknown error occurred while resetting player data.");
                    return(-1);
                }
            }
            catch (HttpRequestException ex)
            {
                Console.WriteLine("Error: player data reset failed");

                if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized)))
                {
                    Console.WriteLine(
                        $"Unable to authorize the account with Xbox Live and scid : {options.ServiceConfigurationId} and sandbox : {options.Sandbox}, please contact your administrator.");
                }
                else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden)))
                {
                    Console.WriteLine(
                        "Your account doesn't have access to perform the operation, please contact your administrator.");
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }

                return(-1);
            }
        }