public void UserDataApi() { string TEST_KEY = "testCounter"; ClientModels.UserDataRecord testCounter; int testCounterValueExpected, testCounterValueActual; var getRequest = new ClientModels.GetUserDataRequest(); var getDataTask1 = PlayFabClientAPI.GetUserDataAsync(getRequest); getDataTask1.Wait(); UUnitAssert.Null(getDataTask1.Result.Error, "UserData should have been retrieved from Api call"); UUnitAssert.NotNull(getDataTask1.Result.Result, "UserData should have been retrieved from Api call"); UUnitAssert.NotNull(getDataTask1.Result.Result.Data, "UserData should have been retrieved from Api call"); if (!getDataTask1.Result.Result.Data.TryGetValue(TEST_KEY, out testCounter)) { testCounter = new ClientModels.UserDataRecord(); testCounter.Value = "0"; } int.TryParse(testCounter.Value, out testCounterValueExpected); testCounterValueExpected = (testCounterValueExpected + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds var updateRequest = new ClientModels.UpdateUserDataRequest(); updateRequest.Data = new Dictionary<string, string>(); updateRequest.Data[TEST_KEY] = testCounterValueExpected.ToString(); var updateTask = PlayFabClientAPI.UpdateUserDataAsync(updateRequest); updateTask.Wait(); // The update doesn't return anything interesting except versionID. It's better to just re-call GetUserData again below to verify the update UUnitAssert.Null(updateTask.Result.Error, "UpdateUserData call failed"); UUnitAssert.NotNull(updateTask.Result.Result, "UpdateUserData call failed"); getRequest = new ClientModels.GetUserDataRequest(); var getDataTask2 = PlayFabClientAPI.GetUserDataAsync(getRequest); getDataTask2.Wait(); UUnitAssert.Null(getDataTask2.Result.Error, "UserData should have been retrieved from Api call"); UUnitAssert.NotNull(getDataTask2.Result.Result, "UserData should have been retrieved from Api call"); UUnitAssert.NotNull(getDataTask2.Result.Result.Data, "UserData should have been retrieved from Api call"); getDataTask2.Result.Result.Data.TryGetValue(TEST_KEY, out testCounter); UUnitAssert.NotNull(testCounter, "The updated UserData was not found in the Api results"); int.TryParse(testCounter.Value, out testCounterValueActual); UUnitAssert.Equals(testCounterValueExpected, testCounterValueActual); var timeUpdated = testCounter.LastUpdated; var testMin = DateTime.UtcNow - TimeSpan.FromMinutes(5); var testMax = testMin + TimeSpan.FromMinutes(10); UUnitAssert.True(testMin <= timeUpdated && timeUpdated <= testMax); }
private void GetUserDataCallback(GetUserDataResult result) { lastReceivedMessage = "User Data Received"; if (!result.Data.TryGetValue(TEST_DATA_KEY, out testCounterReturn)) { testCounterReturn = new UserDataRecord(); testCounterReturn.Value = "0"; } }