public void UserStatisticsApi() { int testStatExpected, testStatActual; var getRequest = new ClientModels.GetUserStatisticsRequest(); var getStatTask1 = PlayFabClientAPI.GetUserStatisticsAsync(getRequest); getStatTask1.Wait(); UUnitAssert.Null(getStatTask1.Result.Error, "UserStatistics should have been retrieved from Api call"); UUnitAssert.NotNull(getStatTask1.Result.Result, "UserStatistics should have been retrieved from Api call"); UUnitAssert.NotNull(getStatTask1.Result.Result.UserStatistics, "UserStatistics should have been retrieved from Api call"); if (!getStatTask1.Result.Result.UserStatistics.TryGetValue(TEST_STAT_NAME, out testStatExpected)) { testStatExpected = TEST_STAT_BASE; } testStatExpected = ((testStatExpected + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1) var updateRequest = new ClientModels.UpdateUserStatisticsRequest(); updateRequest.UserStatistics = new Dictionary <string, int>(); updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected; var updateTask = PlayFabClientAPI.UpdateUserStatisticsAsync(updateRequest); updateTask.Wait(); // The update doesn't return anything, so can't test anything other than failure // Test update result - no data returned, so error or no error, based on Title settings if (!TITLE_CAN_UPDATE_SETTINGS) { UUnitAssert.Null(updateTask.Result.Result, "UpdateStatistics should have failed"); UUnitAssert.NotNull(updateTask.Result.Error, "UpdateStatistics should have failed"); return; // The rest of this tests changing settings - Which we verified we cannot do } else // if (CAN_UPDATE_SETTINGS) { UUnitAssert.Null(updateTask.Result.Error, "UpdateStatistics call failed"); UUnitAssert.NotNull(updateTask.Result.Result, "UpdateStatistics call failed"); } getRequest = new ClientModels.GetUserStatisticsRequest(); var getStatTask2 = PlayFabClientAPI.GetUserStatisticsAsync(getRequest); getStatTask2.Wait(); UUnitAssert.Null(getStatTask2.Result.Error, "UserStatistics should have been retrieved from Api call"); UUnitAssert.NotNull(getStatTask2.Result.Result, "UserStatistics should have been retrieved from Api call"); UUnitAssert.NotNull(getStatTask2.Result.Result.UserStatistics, "UserStatistics should have been retrieved from Api call"); getStatTask2.Result.Result.UserStatistics.TryGetValue(TEST_STAT_NAME, out testStatActual); UUnitAssert.Equals(testStatExpected, testStatActual); }
public void UserStatisticsApi() { int testStatExpected, testStatActual; var getRequest = new ClientModels.GetUserStatisticsRequest(); PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.Equals("User Stats Received", lastReceivedMessage); testStatExpected = ((testStatReturn + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1) var updateRequest = new ClientModels.UpdateUserStatisticsRequest(); updateRequest.UserStatistics = new Dictionary <string, int>(); updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected; PlayFabClientAPI.UpdateUserStatistics(updateRequest, UpdateUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); // Test update result - no data returned, so error or no error, based on Title settings if (!TITLE_CAN_UPDATE_SETTINGS) { UUnitAssert.Equals("error message from PlayFab", lastReceivedMessage); return; // The rest of this tests changing settings - Which we verified we cannot do } else // if (CAN_UPDATE_SETTINGS) { UUnitAssert.Equals("User Stats Updated", lastReceivedMessage); } getRequest = new ClientModels.GetUserStatisticsRequest(); PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.Equals("User Stats Received", lastReceivedMessage); testStatActual = testStatReturn; UUnitAssert.Equals(testStatExpected, testStatActual); }
public void UserStatisticsApi() { int testStatExpected, testStatActual; var getRequest = new ClientModels.GetUserStatisticsRequest(); PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.Equals("User Stats Received", lastReceivedMessage); testStatExpected = ((testStatReturn + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1) var updateRequest = new ClientModels.UpdateUserStatisticsRequest(); updateRequest.UserStatistics = new Dictionary<string, int>(); updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected; PlayFabClientAPI.UpdateUserStatistics(updateRequest, UpdateUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); // Test update result - no data returned, so error or no error, based on Title settings if (!TITLE_CAN_UPDATE_SETTINGS) { UUnitAssert.Equals("error message from PlayFab", lastReceivedMessage); return; // The rest of this tests changing settings - Which we verified we cannot do } else // if (CAN_UPDATE_SETTINGS) { UUnitAssert.Equals("User Stats Updated", lastReceivedMessage); } getRequest = new ClientModels.GetUserStatisticsRequest(); PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.Equals("User Stats Received", lastReceivedMessage); testStatActual = testStatReturn; UUnitAssert.Equals(testStatExpected, testStatActual); }
public void UserStatisticsApi() { int testStatExpected, testStatActual; var getStatTask1 = Client.GetUserStatisticsAsync(); try { getStatTask1.Wait(); } catch (Exception ex) { UUnitAssert.True(false, ex.Message); } UUnitAssert.NotNull(getStatTask1.Result, "UserStatistics should have been retrieved from Api call"); if (!getStatTask1.Result.TryGetValue(TEST_STAT_NAME, out testStatExpected)) { testStatExpected = TEST_STAT_BASE; } testStatExpected = ((testStatExpected + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1) var updateRequest = new ClientModels.UpdateUserStatisticsRequest(); updateRequest.UserStatistics = new Dictionary <string, int>(); updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected; var updateTask = Client.UpdateUserStatisticsAsync(updateRequest); bool failed = false; string failedMessage = "UpdateStatistics should have failed"; try { updateTask.Wait(); // The update doesn't return anything, so can't test anything other than failure } catch (Exception ex) { failed = true; failedMessage = ex.Message; } // Test update result - no data returned, so error or no error, based on Title settings if (!TITLE_CAN_UPDATE_SETTINGS) { UUnitAssert.True(failed, failedMessage); } else { UUnitAssert.False(failed, failedMessage); } var getStatTask2 = Client.GetUserStatisticsAsync(); try { getStatTask2.Wait(); } catch (Exception ex) { UUnitAssert.True(false, ex.Message); } UUnitAssert.NotNull(getStatTask2.Result, "UserStatistics should have been retrieved from Api call"); getStatTask2.Result.TryGetValue(TEST_STAT_NAME, out testStatActual); UUnitAssert.Equals(testStatExpected, testStatActual); }