public void PfPush_JavaSerialization(UUnitTestContext testContext) { var javaPkg = new AndroidJavaObject("com.playfab.unityplugin.GCM.PlayFabNotificationPackage"); var expectedPkgs = new[] { new PlayFabNotificationPackage("test message0", "test title", 10), new PlayFabNotificationPackage("test message1", "test title", 11), new PlayFabNotificationPackage("test message2", "test title", 12), }; expectedPkgs[0].SetScheduleTime(DateTime.Now + TimeSpan.FromSeconds(10), ScheduleTypes.ScheduledLocal); expectedPkgs[1].SetScheduleTime(DateTime.UtcNow + TimeSpan.FromSeconds(10), ScheduleTypes.ScheduledUtc); expectedPkgs[2].SetScheduleTime(null, ScheduleTypes.None); for (var i = 0; i < expectedPkgs.Length; i++) { var expectedPkg = expectedPkgs[i]; expectedPkg.ToJava(ref javaPkg); var javaScheduleType = javaPkg.Get <string>("ScheduleType"); testContext.StringEquals(expectedPkg.ScheduleType.ToString(), javaScheduleType, "ScheduleType not assigned " + i + ", " + expectedPkg.ScheduleType + ", " + javaScheduleType); var actualPkg = PlayFabNotificationPackage.FromJava(javaPkg); testContext.StringEquals(expectedPkg.Message, actualPkg.Message, "Message mismatch " + i + ", " + expectedPkg.Message + ", " + actualPkg.Message); testContext.StringEquals(expectedPkg.Title, actualPkg.Title, "Title mismatch " + i + ", " + expectedPkg.Title + ", " + actualPkg.Title); testContext.IntEquals(expectedPkg.Id, actualPkg.Id, "Id mismatch " + i + ", " + expectedPkg.Id + ", " + actualPkg.Id); testContext.ObjEquals(expectedPkg.ScheduleType, actualPkg.ScheduleType, "ScheduleType mismatch " + i + ", " + expectedPkg.ScheduleType + ", " + actualPkg.ScheduleType); testContext.DateTimeEquals(expectedPkg.ScheduleDate, actualPkg.ScheduleDate, TimeSpan.FromSeconds(1), javaPkg.Get <string>("ScheduleDate")); } testContext.EndTest(UUnitFinishState.PASSED, null); }
//[UUnitTest] public void ArrayOfObjects(UUnitTestContext testContext) { var actualJson = "[{\"a\":\"aValue\"}, {\"b\":\"bValue\"}]"; var actualObjectList = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <List <object> >(actualJson); var actualObjectArray = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <object[]>(actualJson); testContext.IntEquals(actualObjectList.Count, 2); testContext.IntEquals(actualObjectArray.Length, 2); testContext.StringEquals(((JsonObject)actualObjectList[0])["a"] as string, "aValue"); testContext.StringEquals(((JsonObject)actualObjectList[1])["b"] as string, "bValue"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void ArrayOfObjects(UUnitTestContext testContext) { string actualJson = "[{\"a\":\"aValue\"}, {\"b\":\"bValue\"}]"; var actualObjectList = JsonWrapper.DeserializeObject <List <object> >(actualJson); var actualObjectArray = JsonWrapper.DeserializeObject <object[]>(actualJson); testContext.IntEquals(actualObjectList.Count, 2); testContext.IntEquals(actualObjectArray.Length, 2); testContext.StringEquals(((JsonObject)actualObjectList[0])["a"] as string, "aValue"); testContext.StringEquals(((JsonObject)actualObjectList[1])["b"] as string, "bValue"); testContext.EndTest(UUnitFinishState.PASSED, null); }
private void LoginWithAdvertisingIdContinued(PlayFabResult <LoginResult> loginResult, UUnitTestContext testContext, string failMessage) { PlayFabId = loginResult.Result.PlayFabId; // Needed for subsequent tests testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "User login failed"); testContext.StringEquals(PlayFabSettings.AD_TYPE_ANDROID_ID + "_Successful", PlayFabSettings.AdvertisingIdType); }
private void CloudScriptErrorContinued(PlayFabResult <ClientModels.ExecuteCloudScriptResult> cloudResult, UUnitTestContext testContext, string failMessage) { // Get the JavascriptException result testContext.IsNull(cloudResult.Result.FunctionResult); testContext.NotNull(cloudResult.Result.Error); testContext.StringEquals(cloudResult.Result.Error.Error, "JavascriptException"); }
public void TestSimpleJsonSerializeStringWithEscapes(UUnitTestContext testContext) { const string escapedStringRaw = @"Get skull0\u001bp"; //const string escapedString = "Get skull0\u001bp"; const string unescapedString = "Get skull0p"; const string escapedJsonString = "{\"StringValue\":\"" + escapedStringRaw + "\"}"; var playFabSerializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); var sv = playFabSerializer.DeserializeObject <StringValueClass>(escapedJsonString); testContext.StringEquals(unescapedString, sv.StringValue); string actualJsonString = playFabSerializer.SerializeObject(sv); testContext.StringEquals(escapedJsonString, actualJsonString); testContext.EndTest(UUnitFinishState.PASSED, null); }
private void CloudScriptContinued(PlayFabResult <ExecuteCloudScriptResult> cloudResult, UUnitTestContext testContext, string failMessage) { // Get the helloWorld return message testContext.NotNull(cloudResult.Result.FunctionResult); var jobj = (JsonObject)cloudResult.Result.FunctionResult; var messageValue = jobj["messageValue"] as string; testContext.StringEquals("Hello " + PlayFabId + "!", messageValue); }
public void TestDeserializeToObject(UUnitTestContext testContext) { var testInt = PlayFabSimpleJson.DeserializeObject <object>("1"); var testString = PlayFabSimpleJson.DeserializeObject <object>("\"a string\""); testContext.IntEquals((int)(ulong)testInt, 1); testContext.StringEquals((string)testString, "a string"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void TimeSpanJson(UUnitTestContext testContext) { var span = TimeSpan.FromSeconds(5); var actualJson = JsonWrapper.SerializeObject(span); var expectedJson = "5"; testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
//[UUnitTest] public void TimeSpanJson(UUnitTestContext testContext) { var span = TimeSpan.FromSeconds(5); var actualJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(span); var expectedJson = "5"; testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void TimeSpanJson(UUnitTestContext testContext) { TimeSpan span = TimeSpan.FromSeconds(5); string actualJson = JsonWrapper.SerializeObject(span, PlayFabUtil.ApiSerializerStrategy); string expectedJson = "5"; testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void PfPush_JsonSerialization(UUnitTestContext testContext) { var tempJavaPkgObj = new AndroidJavaObject("com.playfab.unityplugin.GCM.PlayFabNotificationPackage"); var javaPkgClass = new AndroidJavaClass("com.playfab.unityplugin.GCM.PlayFabNotificationPackage"); var expectedPkgs = new[] { new PlayFabNotificationPackage("test message0", "test title1", 10), new PlayFabNotificationPackage("test message1", "test title2", 11), new PlayFabNotificationPackage("test message2", "test title3", 12), }; expectedPkgs[0].SetScheduleTime(DateTime.Now + TimeSpan.FromSeconds(10), ScheduleTypes.ScheduledLocal); expectedPkgs[1].SetScheduleTime(DateTime.UtcNow + TimeSpan.FromSeconds(10), ScheduleTypes.ScheduledUtc); expectedPkgs[2].SetScheduleTime(null, ScheduleTypes.None); for (var i = 0; i < expectedPkgs.Length; i++) { var expectedPkg = expectedPkgs[i]; expectedPkg.ToJava(ref tempJavaPkgObj); var firstJson = tempJavaPkgObj.Call <string>("toJson"); var javaPkgObj = javaPkgClass.CallStatic <AndroidJavaObject>("fromJson", firstJson); var secondJson = javaPkgObj.Call <string>("toJson"); testContext.StringEquals(firstJson, secondJson); PlayFabNotificationPackage actualPkg = null;; try { actualPkg = JsonWrapper.DeserializeObject <PlayFabNotificationPackage>(secondJson); } catch (Exception) { testContext.Fail("JSON PARSE FAILURE:\n1stJson: " + firstJson + "\n2ndJson:" + secondJson); } testContext.NotNull(actualPkg); testContext.StringEquals(expectedPkg.Message, actualPkg.Message, "Message mismatch " + i + ", " + expectedPkg.Message + ", " + actualPkg.Message + "\nExJson: " + secondJson + "\nAcJson:" + secondJson); testContext.StringEquals(expectedPkg.Title, actualPkg.Title, "Title mismatch " + i + ", " + expectedPkg.Title + ", " + actualPkg.Title + ", " + secondJson + ", " + secondJson); testContext.IntEquals(expectedPkg.Id, actualPkg.Id, "Id mismatch " + i + ", " + expectedPkg.Id + ", " + actualPkg.Id + ", " + secondJson + ", " + secondJson); testContext.ObjEquals(expectedPkg.ScheduleType, actualPkg.ScheduleType, "ScheduleType mismatch " + i + ", " + expectedPkg.ScheduleType + ", " + actualPkg.ScheduleType + ", " + secondJson + ", " + secondJson); testContext.DateTimeEquals(expectedPkg.ScheduleDate, actualPkg.ScheduleDate, TimeSpan.FromSeconds(1), "ScheduleDate mismatch " + i + ", " + expectedPkg.ScheduleDate + ", " + actualPkg.ScheduleDate + ", " + secondJson + ", " + secondJson); } testContext.EndTest(UUnitFinishState.PASSED, null); }
//[UUnitTest] public void TestDeserializeToObject(UUnitTestContext testContext) { var serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); var testInt = serializer.DeserializeObject <object>("1"); var testString = serializer.DeserializeObject <object>("\"a string\""); testContext.IntEquals((int)(ulong)testInt, 1); testContext.StringEquals((string)testString, "a string"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void JsonPropertyTest(UUnitTestContext testContext) { var expectedObject = new JsonPropertyAttrTestClass { InvalidField = "asdf", InvalidProperty = "fdsa" }; string json = JsonWrapper.SerializeObject(expectedObject); // Verify that the field names have been transformed by the JsonProperty attribute testContext.False(json.ToLower().Contains("invalid"), json); testContext.False(json.ToLower().Contains("hidenull"), json); testContext.True(json.ToLower().Contains("shownull"), json); // Verify that the fields are re-serialized into the proper locations by the JsonProperty attribute var actualObject = JsonWrapper.DeserializeObject <JsonPropertyAttrTestClass>(json); testContext.StringEquals(expectedObject.InvalidField, actualObject.InvalidField, actualObject.InvalidField); testContext.StringEquals(expectedObject.InvalidProperty, actualObject.InvalidProperty, actualObject.InvalidProperty); testContext.EndTest(UUnitFinishState.PASSED, null); }
void TestFileContent(UUnitTestContext testContext, byte[] result) { var json = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); testContext.NotNull(result, "Raw file result was null"); testContext.True(result.Length > 0, "Raw file result was zero length"); testContext.StringEquals(json.SerializeObject(_testPayload), json.SerializeObject(result), json.SerializeObject(result)); DeleteFiles(testContext, new List <string> { TEST_FILE_NAME }, true, UUnitFinishState.PASSED, "File " + TEST_FILE_NAME + " was succesfully created and uploaded to server with PUT"); }
private void GetObjects2Continued(PlayFabResult <GetObjectsResponse> result, UUnitTestContext testContext, string failMessage) { testContext.IntEquals(result.Result.Objects.Count, 1); testContext.StringEquals(result.Result.Objects[TEST_DATA_KEY].ObjectName, TEST_DATA_KEY); if (!int.TryParse(result.Result.Objects[TEST_DATA_KEY].EscapedDataObject, out int actualValue)) { actualValue = -1000; } testContext.IntEquals(_testInteger, actualValue, "Failed: " + _testInteger + "!=" + actualValue + ", Returned json: " + result.Result.Objects[TEST_DATA_KEY].EscapedDataObject); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void MultipleInstanceWithDifferentSettings(UUnitTestContext testContext) { PlayFabApiSettings settings1 = new PlayFabApiSettings(); settings1.ProductionEnvironmentUrl = "https://test1.playfabapi.com"; settings1.TitleId = "test1"; settings1.DeveloperSecretKey = "key1"; PlayFabApiSettings settings2 = new PlayFabApiSettings(); settings2.ProductionEnvironmentUrl = "https://test2.playfabapi.com"; settings2.TitleId = "test2"; settings2.DeveloperSecretKey = "key2"; PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI(settings1, null); PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(settings2, null); testContext.StringEquals("test1", serverInstance1.apiSettings.TitleId, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("https://test1.playfabapi.com", serverInstance1.apiSettings.ProductionEnvironmentUrl, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("key1", serverInstance1.apiSettings.DeveloperSecretKey, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("test2", serverInstance2.apiSettings.TitleId, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("https://test2.playfabapi.com", serverInstance2.apiSettings.ProductionEnvironmentUrl, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("key2", serverInstance2.apiSettings.DeveloperSecretKey, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void Test200Response(UUnitTestContext testContext) { mockHttpPlugin.AssignResponse(HttpStatusCode.OK, "{\"data\": {\"RSAPublicKey\": \"Test Result\"} }", null); // GetTitlePublicKey has no auth, and trivial input/output so it's pretty ideal for a fake API call var task = PlayFabClientAPI.GetTitlePublicKeyAsync(null); task.Wait(); testContext.IsNull(task.Result.Error); testContext.NotNull(task.Result.Result); testContext.StringEquals("Test Result", task.Result.Result.RSAPublicKey); testContext.EndTest(UUnitFinishState.PASSED, null); }
private void CloudScriptContinued(PlayFabResult <ClientModels.ExecuteCloudScriptResult> cloudResult, UUnitTestContext testContext, string failMessage) { string messageValue = null; // Get the helloWorld return message testContext.NotNull(cloudResult.Result.FunctionResult); var serializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); var sjobj = serializer.DeserializeObject <Dictionary <string, object> >(serializer.SerializeObject(cloudResult.Result.FunctionResult)); if (sjobj != null) { messageValue = sjobj["messageValue"] as string; } testContext.StringEquals("Hello " + PlayFabSettings.staticPlayer.PlayFabId + "!", messageValue); }
private void CloudScriptContinued(PlayFabResult <ClientModels.ExecuteCloudScriptResult> cloudResult, UUnitTestContext testContext, string failMessage) { string messageValue = null; // Get the helloWorld return message testContext.NotNull(cloudResult.Result.FunctionResult); var sjobj = cloudResult.Result.FunctionResult as JsonObject; if (sjobj != null) { messageValue = sjobj["messageValue"] as string; } //var njobj = cloudResult.Result.FunctionResult as Newtonsoft.Json.Linq.JObject; //if (njobj != null) // messageValue = njobj["messageValue"].ToObject<string>(); testContext.StringEquals("Hello " + PlayFabId + "!", messageValue); }
//[UUnitTest] public void TestJsonSubObject(UUnitTestContext testContext) { // actualObj contains a real ObjNumFieldTest within subObject var expectedObj = new SerializeJsonSubOjbect { SubObject = new ObjNumFieldTest { ByteValue = 1, DoubleValue = 1, FloatValue = 1, IntValue = 1, LongValue = 1, SbyteValue = 1, ShortValue = 1, UintValue = 1, UlongValue = 1, UshortValue = 1 } }; var expectedJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(expectedObj); // Convert back to SerializeJsonSubOjbect which will serialize the original ObjNumFieldTest to a SimpleJson.JsonObject (or equivalent in another serializer) var actualObj = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <SerializeJsonSubOjbect>(expectedJson); testContext.False(actualObj.SubObject is ObjNumFieldTest, "ObjNumFieldTest should have deserialized as a generic JsonObject"); var actualJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(actualObj); // The real test is that reserializing actualObj should produce identical json testContext.StringEquals(expectedJson, actualJson, actualJson); testContext.EndTest(UUnitFinishState.PASSED, null); }
public void MultipleInstanceWithDifferentSettings(UUnitTestContext testContext) { PlayFabApiSettings settings = new PlayFabApiSettings(); settings.ProductionEnvironmentUrl = "https://test1.playfabapi.com"; settings.TitleId = "test1"; PlayFabApiSettings settings2 = new PlayFabApiSettings(); settings2.ProductionEnvironmentUrl = "https://test2.playfabapi.com"; settings2.TitleId = "test2"; PlayFabAuthenticationContext context = new PlayFabAuthenticationContext(); context.DeveloperSecretKey = "key1"; PlayFabAuthenticationContext context2 = new PlayFabAuthenticationContext(); context2.DeveloperSecretKey = "key2"; try { PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI(settings, context); PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(settings2, context2); testContext.StringEquals("test1", serverInstance1.GetSettings().TitleId, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("https://test1.playfabapi.com", serverInstance1.GetSettings().ProductionEnvironmentUrl, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("key1", serverInstance1.GetAuthenticationContext().DeveloperSecretKey, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("test2", serverInstance2.GetSettings().TitleId, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("https://test2.playfabapi.com", serverInstance2.GetSettings().ProductionEnvironmentUrl, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.StringEquals("key2", serverInstance2.GetAuthenticationContext().DeveloperSecretKey, "MultipleInstanceWithDifferentSettings can not be completed"); testContext.EndTest(UUnitFinishState.PASSED, null); } catch (Exception) { testContext.Fail("Multi Intance Server api can not be created"); } }
private void LoginWithAdvertisingIdContinued(PlayFabResult <LoginResult> loginResult, UUnitTestContext testContext, string failMessage) { testContext.True(clientApi.IsClientLoggedIn(), failMessage); testContext.StringEquals(PlayFabSettings.AD_TYPE_ANDROID_ID + "_Successful", PlayFabSettings.staticSettings.AdvertisingIdType); }