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);
        }
        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);
        }
Ejemplo n.º 3
0
        public static PlayFabNotificationPackage GetPushCache()
        {
            AndroidJavaObject package = new AndroidJavaObject("com.playfab.unityplugin.GCM.PlayFabNotificationPackage");

            package = PlayFabPushCacheClass.CallStatic <AndroidJavaObject>("getPushCache");

            PlayFabNotificationPackage cache = new PlayFabNotificationPackage();

            if (package != null)
            {
                cache.Title      = package.Get <string>("Title");
                cache.Message    = package.Get <string>("Message");
                cache.Icon       = package.Get <string>("Icon");
                cache.Sound      = package.Get <string>("Sound");
                cache.CustomData = package.Get <string>("CustomData");
            }
            else
            {
                Debug.Log("Package was null");
            }

            return(cache);
        }
Ejemplo n.º 4
0
 private void OnGcmMessage(PlayFabNotificationPackage package)
 {
     PushMessageText.text = package.Message;
 }
Ejemplo n.º 5
0
		public static PlayFabNotificationPackage GetPushCache()
        {
			AndroidJavaObject package = new AndroidJavaObject("com.playfab.unityplugin.GCM.PlayFabNotificationPackage");
			package = PlayFabPushCacheClass.CallStatic<AndroidJavaObject>("getPushCache");
			
			PlayFabNotificationPackage cache = new PlayFabNotificationPackage();
			if(package != null)
			{
				cache.Title = package.Get<string>("Title");
				cache.Message = package.Get<string>("Message");
				cache.Icon = package.Get<string>("Icon");
				cache.Sound = package.Get<string>("Sound");
				cache.CustomData = package.Get<string>("CustomData");
			}
			else
			{
				Debug.Log("Package was null");
			}
			
			return cache;
        }
Ejemplo n.º 6
0
 void OnPushReceived(PlayFabNotificationPackage package)
 {
     _lastMessageReceived = JsonWrapper.SerializeObject(package);
 }