public void CloudScript() { var getUrlTask = PlayFabClientAPI.GetCloudScriptUrlAsync(new GetCloudScriptUrlRequest()); WaitForResultSuccess(getUrlTask, "Failed to get LogicServerURL"); var request = new RunCloudScriptRequest(); request.ActionId = "helloWorld"; var cloudTask = PlayFabClientAPI.RunCloudScriptAsync(request); WaitForResultSuccess(cloudTask, "Failed to Execute CloudScript"); UUnitAssert.False(string.IsNullOrEmpty(cloudTask.Result.Result.ResultsEncoded), "Failed to Execute CloudScript"); // Get the helloWorld return message JObject jobj = cloudTask.Result.Result.Results as JObject; UUnitAssert.NotNull(jobj); JToken jtok; jobj.TryGetValue("messageValue", out jtok); UUnitAssert.NotNull(jtok); JValue jval = jtok as JValue; UUnitAssert.NotNull(jval); string actualMessage = jval.Value as string; UUnitAssert.StringEquals("Hello " + playFabId + "!", actualMessage); }
public void CloudScript() { var cloudTask = Client.ExecuteCloudScriptAsync("helloWorld"); try { cloudTask.Wait(); } catch (Exception ex) { UUnitAssert.True(false, ex.Message); } UUnitAssert.NotNull(cloudTask.Result, "Failed to Execute CloudScript"); UUnitAssert.NotNull(cloudTask.Result.FunctionResult, "Failed to Execute CloudScript"); // Get the helloWorld return message var jobj = (JObject)cloudTask.Result.FunctionResult; UUnitAssert.NotNull(jobj); JToken jtok; jobj.TryGetValue("messageValue", out jtok); UUnitAssert.NotNull(jtok); var jval = jtok as JValue; UUnitAssert.NotNull(jval); var actualMessage = jval.Value as string; UUnitAssert.StringEquals("Hello " + _playFabId + "!", actualMessage); }
public void LoginOrRegister() { if (!PlayFabClientAPI.IsClientLoggedIn()) // If we haven't already logged in... { var loginRequest = new LoginWithEmailAddressRequest(); loginRequest.Email = USER_EMAIL; loginRequest.Password = USER_PASSWORD; loginRequest.TitleId = PlayFabSettings.TitleId; PlayFabClientAPI.LoginWithEmailAddress(loginRequest, LoginCallback, SharedErrorCallback); WaitForApiCalls(); // We don't do any test here, because the user may not exist, and thus login might fail, but the test should not } if (PlayFabClientAPI.IsClientLoggedIn()) { return; // Success, already logged in } // If the setup failed to log in a user, we need to create one. var registerRequest = new RegisterPlayFabUserRequest(); registerRequest.TitleId = PlayFabSettings.TitleId; registerRequest.Username = USER_NAME; registerRequest.Email = USER_EMAIL; registerRequest.Password = USER_PASSWORD; PlayFabClientAPI.RegisterPlayFabUser(registerRequest, RegisterCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("User Registration Successful", lastReceivedMessage); // If we get here, we definitely registered a new user, and we definitely want to verify success UUnitAssert.True(PlayFabClientAPI.IsClientLoggedIn(), "User login failed"); }
public void UserCharacter() { var request = new ServerModels.ListUsersCharactersRequest(); request.PlayFabId = playFabId; // Received from client upon login PlayFabServerAPI.GetAllUsersCharacters(request, GetCharsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Get Chars Successful", lastReceivedMessage); // The target character may not exist, but we don't fail, since we can create it below if (targetCharacter == null) { // Create the targetCharacter since it doesn't exist var grantRequest = new ServerModels.GrantCharacterToUserRequest(); grantRequest.PlayFabId = playFabId; grantRequest.CharacterName = CHAR_NAME; grantRequest.CharacterType = CHAR_TEST_TYPE; PlayFabServerAPI.GrantCharacterToUser(grantRequest, GrantCharCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Grant Char Successful", lastReceivedMessage); // Attempt to get characters again PlayFabServerAPI.GetAllUsersCharacters(request, GetCharsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Get Chars Successful", lastReceivedMessage); } // Save the requested character UUnitAssert.NotNull(targetCharacter, "The test character did not exist, and was not successfully created"); }
public void AccountInfo() { GetAccountInfoRequest request = new GetAccountInfoRequest(); request.PlayFabId = playFabId; PlayFabClientAPI.GetAccountInfo(request, AcctInfoCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Enums tested", lastReceivedMessage); }
public void CloudScriptError() { var request = new ExecuteCloudScriptRequest { FunctionName = "throwError" }; var cloudTask = PlayFabClientAPI.ExecuteCloudScriptAsync(request); WaitForResultSuccess(cloudTask, "Failed to Execute CloudScript"); // Get the JavascriptException result UUnitAssert.IsNull(cloudTask.Result.Result.FunctionResult); UUnitAssert.NotNull(cloudTask.Result.Result.Error); UUnitAssert.StringEquals(cloudTask.Result.Result.Error.Error, "JavascriptException"); }
private void WriteEvent() { var request = new WriteClientPlayerEventRequest(); request.EventName = "ForumPostEvent"; request.Timestamp = DateTime.UtcNow; request.Body = new Dictionary <string, object>(); request.Body["Subject"] = "My First Post"; request.Body["Body"] = "My awesome post."; PlayFabClientAPI.WritePlayerEvent(request, WriteEventCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("WriteEvent posted successfully.", lastReceivedMessage); }
public void LoginWithAdvertisingId() { PlayFabSettings.AdvertisingIdType = PlayFabSettings.AD_TYPE_ANDROID_ID; PlayFabSettings.AdvertisingIdValue = "PlayFabTestId"; var loginRequest = new LoginWithEmailAddressRequest(); loginRequest.Email = USER_EMAIL; loginRequest.Password = USER_PASSWORD; loginRequest.TitleId = PlayFabSettings.TitleId; PlayFabClientAPI.LoginWithEmailAddress(loginRequest, LoginCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals(PlayFabSettings.AD_TYPE_ANDROID_ID + "_Successful", PlayFabSettings.AdvertisingIdType); }
public void LoginWithAdvertisingId() { PlayFabSettings.AdvertisingIdType = PlayFabSettings.AD_TYPE_ANDROID_ID; PlayFabSettings.AdvertisingIdValue = "PlayFabTestId"; var loginRequest = new LoginWithEmailAddressRequest(); loginRequest.Email = USER_EMAIL; loginRequest.Password = USER_PASSWORD; loginRequest.TitleId = PlayFabSettings.TitleId; var loginTask = PlayFabClientAPI.LoginWithEmailAddressAsync(loginRequest); WaitForResultSuccess(loginTask, "Login with advertId failed"); UUnitAssert.StringEquals(PlayFabSettings.AD_TYPE_ANDROID_ID + "_Successful", PlayFabSettings.AdvertisingIdType); }
private void CloudScript() { if (string.IsNullOrEmpty(PlayFabSettings.LogicServerUrl)) { PlayFabClientAPI.GetCloudScriptUrl(new GetCloudScriptUrlRequest(), CloudScriptUrlCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.True(lastReceivedMessage.StartsWith("CloudScript setup complete: ")); } var request = new RunCloudScriptRequest(); request.ActionId = "helloWorld"; PlayFabClientAPI.RunCloudScript(request, CloudScriptHwCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Hello " + playFabId + "!", lastReceivedMessage); }
public void CloudScriptError() { var cloudTask = Client.ExecuteCloudScriptAsync("throwError"); try { cloudTask.Wait(); } catch (Exception ex) { UUnitAssert.True(false, ex.Message); } // Get the JavascriptException result UUnitAssert.IsNull(cloudTask.Result.FunctionResult); UUnitAssert.NotNull(cloudTask.Result.Error); UUnitAssert.StringEquals(cloudTask.Result.Error.Error, "JavascriptException"); }
private void WritePlayerEvent() { var request = new WritePlayerClientEventRequest(); request.Event = new PlayStreamPlayerEventData(); request.Event.EventName = "forum_post_event"; request.Event.EventNamespace = "com.mygame.forums"; request.Event.EntityType = "player"; request.Event.Timestamp = DateTime.UtcNow; request.Event.CustomTags = new Dictionary <string, string>(); request.Event.CustomTags["Region"] = "US-East"; request.Event.CustomTags["Subject"] = "My First Post"; request.Event.CustomTags["Body"] = "My is my awesome post."; PlayFabClientAPI.WritePlayerEvent(request, WriteEventCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("WriteEvent posted successfully.", lastReceivedMessage); }
public void LoginWithAdvertisingId() { PlayFabSettings.AdvertisingIdType = PlayFabSettings.AD_TYPE_ANDROID_ID; PlayFabSettings.AdvertisingIdValue = "PlayFabTestId"; var loginRequest = new LoginWithCustomIDRequest { TitleId = PlayFabSettings.TitleId, CustomId = PlayFabSettings.BuildIdentifier, CreateAccount = true }; var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(loginRequest); WaitForResultSuccess(loginTask, "Login with advertId failed"); loginTask.Wait(); // We don't care about success or fail here UUnitAssert.StringEquals(PlayFabSettings.AD_TYPE_ANDROID_ID + "_Successful", PlayFabSettings.AdvertisingIdType); }
public void LoginWithAdvertisingId() { Client.Settings.AdvertisingIdType = PlayFabDefaultSettings.AD_TYPE_ANDROID_ID; Client.Settings.AdvertisingIdValue = "PlayFabTestId"; var loginTask = Client.LoginWithCustomIDAsync(Client.Settings.TitleId, PlayFabVersion.BuildIdentifier, true); try { loginTask.Wait(); } catch (Exception ex) { UUnitAssert.True(false, ex.Message); } _playFabId = loginTask.Result.PlayFabId; // Needed for subsequent tests UUnitAssert.True(Client.IsClientLoggedIn(), "User login failed"); UUnitAssert.StringEquals(PlayFabDefaultSettings.AD_TYPE_ANDROID_ID + "_Successful", Client.Settings.AdvertisingIdType); }
public void LoginWithAdvertisingId() { PlayFabSettings.AdvertisingIdType = PlayFabSettings.AD_TYPE_ANDROID_ID; PlayFabSettings.AdvertisingIdValue = "PlayFabTestId"; var loginRequest = new LoginWithCustomIDRequest { TitleId = PlayFabSettings.TitleId, CustomId = PlayFabSettings.BuildIdentifier, CreateAccount = true }; var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(loginRequest); WaitForResultSuccess(loginTask, "Login with advertId failed"); _playFabId = loginTask.Result.Result.PlayFabId; // Needed for subsequent tests UUnitAssert.True(PlayFabClientAPI.IsClientLoggedIn(), "User login failed"); UUnitAssert.StringEquals(PlayFabSettings.AD_TYPE_ANDROID_ID + "_Successful", PlayFabSettings.AdvertisingIdType); }
public void LeaderBoard() { var clientRequest = new ClientModels.GetLeaderboardRequest(); clientRequest.MaxResultsCount = 3; clientRequest.StatisticName = TEST_STAT_NAME; PlayFabClientAPI.GetLeaderboard(clientRequest, GetClientLbCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Get Client Leaderboard Successful", lastReceivedMessage); // Testing anything more would be testing actual functionality of the Leaderboard, which is outside the scope of this test. var serverRequest = new ServerModels.GetLeaderboardRequest(); serverRequest.MaxResultsCount = 3; serverRequest.StatisticName = TEST_STAT_NAME; PlayFabServerAPI.GetLeaderboard(serverRequest, GetServerLbCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("Get Server Leaderboard Successful", lastReceivedMessage); }
public void UserDataApi() { int testCounterValueExpected, testCounterValueActual; var getRequest = new GetUserDataRequest(); PlayFabClientAPI.GetUserData(getRequest, GetUserDataCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.Equals("User Data Received", lastReceivedMessage); int.TryParse(testCounterReturn.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 UpdateUserDataRequest(); updateRequest.Data = new Dictionary <string, string>(); updateRequest.Data[TEST_DATA_KEY] = testCounterValueExpected.ToString(); PlayFabClientAPI.UpdateUserData(updateRequest, UpdateUserDataCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("User Data Updated", lastReceivedMessage); getRequest = new GetUserDataRequest(); PlayFabClientAPI.GetUserData(getRequest, GetUserDataCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("User Data Received", lastReceivedMessage); int.TryParse(testCounterReturn.Value, out testCounterValueActual); UUnitAssert.IntEquals(testCounterValueExpected, testCounterValueActual); DateTime timeUpdated = testCounterReturn.LastUpdated; DateTime minTest = DateTime.UtcNow - TimeSpan.FromMinutes(5); DateTime maxTest = DateTime.UtcNow + TimeSpan.FromMinutes(5); UUnitAssert.True(minTest <= timeUpdated && timeUpdated <= maxTest); // UnityEngine.Debug.Log((DateTime.UtcNow - timeUpdated).TotalSeconds); UUnitAssert.True(Math.Abs((DateTime.UtcNow - timeUpdated).TotalMinutes) < 5); // Make sure that this timestamp is recent - This must also account for the difference between local machine time and server time }
public void UserStatisticsApi() { int testStatExpected, testStatActual; var getRequest = new ClientModels.GetUserStatisticsRequest(); PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("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.StringEquals("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.StringEquals("User Stats Updated", lastReceivedMessage); } getRequest = new ClientModels.GetUserStatisticsRequest(); PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.StringEquals("User Stats Received", lastReceivedMessage); testStatActual = testStatReturn; UUnitAssert.IntEquals(testStatExpected, testStatActual); }
public void CloudScript() { var request = new ExecuteCloudScriptRequest(); request.FunctionName = "helloWorld"; var cloudTask = PlayFabClientAPI.ExecuteCloudScriptAsync(request); WaitForResultSuccess(cloudTask, "Failed to Execute CloudScript"); // Get the helloWorld return message JObject jobj = cloudTask.Result.Result.FunctionResult as JObject; UUnitAssert.NotNull(jobj); JToken jtok; jobj.TryGetValue("messageValue", out jtok); UUnitAssert.NotNull(jtok); JValue jval = jtok as JValue; UUnitAssert.NotNull(jval); string actualMessage = jval.Value as string; UUnitAssert.StringEquals("Hello " + playFabId + "!", actualMessage); }