Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        //[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 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);
        }
Exemplo n.º 5
0
        public void CheckWithAuthContextAndWithoutAuthContext(UUnitTestContext testContext)
        {
            PlayFabSettings.DeveloperSecretKey = testTitleData.developerSecretKey;

            //IT will  use static developer key - Should has no error
            PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI();
            var result = serverInstance1.GetAllSegmentsAsync(new GetAllSegmentsRequest()).Result;

            PlayFabAuthenticationContext context = new PlayFabAuthenticationContext();

            context.DeveloperSecretKey = "WRONGKEYTOFAIL";

            //IT will  use context developer key - Should has error because of wrong key
            PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(context);
            var result2 = serverInstance2.GetAllSegmentsAsync(new GetAllSegmentsRequest()).Result;

            try
            {
                testContext.NotNull(result.Result, "Server Instance1 result is null");
                testContext.IsNull(result.Error, "Server Instance1 result got error message : " + result.Error?.ErrorMessage ?? string.Empty);
                testContext.IsNull(result2.Result, "Server Instance2 result is not null");
                testContext.NotNull(result2.Error, "Server Instance2 got no error message");
                testContext.IntEquals(401, result2.Error.HttpCode, "Server Instance2 got wrong error");
                testContext.EndTest(UUnitFinishState.PASSED, null);
            }
            catch (Exception ex)
            {
                testContext.Fail("CheckWithAuthContextAndWithoutAuthContext failed : " + ex.Message);
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        //[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);
        }
Exemplo n.º 8
0
        private void PlayerStatisticsApiContinued3(PlayFabResult <GetPlayerStatisticsResult> getStatResult2, UUnitTestContext testContext, string failMessage)
        {
            var testStatActual = int.MinValue;

            foreach (var eachStat in getStatResult2.Result.Statistics)
            {
                if (eachStat.StatisticName == TEST_STAT_NAME)
                {
                    testStatActual = eachStat.Value;
                }
            }
            testContext.IntEquals(_testInteger, testStatActual);
        }
Exemplo n.º 9
0
        private void UserDataApiContinued3(PlayFabResult <GetUserDataResult> getDataResult2, UUnitTestContext testContext, string failMessage)
        {
            int            testCounterValueActual;
            UserDataRecord testCounter;

            getDataResult2.Result.Data.TryGetValue(TEST_DATA_KEY, out testCounter);
            testContext.NotNull(testCounter, "The updated UserData was not found in the Api results");
            int.TryParse(testCounter.Value, out testCounterValueActual);
            testContext.IntEquals(_testInteger, testCounterValueActual);

            var timeUpdated = testCounter.LastUpdated;
            var testMin     = DateTime.UtcNow - TimeSpan.FromMinutes(5);
            var testMax     = testMin + TimeSpan.FromMinutes(10);

            testContext.True(testMin <= timeUpdated && timeUpdated <= testMax);
        }
Exemplo n.º 10
0
        public void TestInstCallbacks_GeneralOnly(UUnitTestContext testContext)
        {
            _listener.Register();
            PlayFabHttp.ApiProcessingEventHandler += TestInstCallbacks_GeneralOnly_OnGlobalEventHandler;

            var request = new LoginWithCustomIDRequest {
                CreateAccount = true, CustomId = PlayFabSettings.BuildIdentifier
            };

            clientApi.LoginWithCustomID(request,
                                        PlayFabUUnitUtils.ApiActionWrapper <LoginResult>(testContext, TestInstCallbacks_GeneralOnlyCallback),
                                        PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext);
            CheckCallbacks(testContext, "OnRequest_InstGl", Callbacks);
            CheckCallbacks(testContext, "OnRequest_InstLogin", Callbacks);
            testContext.IntEquals(2, Callbacks.Count, string.Join(", ", Callbacks.ToArray()));
            Callbacks.Clear();
        }
        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);
        }
Exemplo n.º 12
0
        public void TestObjOptNumField(UUnitTestContext testContext)
        {
            var expectedObjects = new[] { ObjOptNumFieldTest.Max, ObjOptNumFieldTest.Min, ObjOptNumFieldTest.Zero, ObjOptNumFieldTest.Null };

            for (int i = 0; i < expectedObjects.Length; i++)
            {
                // Convert the object to json and back, and verify that everything is the same
                var actualJson   = JsonWrapper.SerializeObject(expectedObjects[i], PlayFabUtil.ApiSerializerStrategy).Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                var actualObject = JsonWrapper.DeserializeObject <ObjOptNumFieldTest>(actualJson, PlayFabUtil.ApiSerializerStrategy);

                testContext.SbyteEquals(expectedObjects[i].SbyteValue, actualObject.SbyteValue);
                testContext.ByteEquals(expectedObjects[i].ByteValue, actualObject.ByteValue);
                testContext.ShortEquals(expectedObjects[i].ShortValue, actualObject.ShortValue);
                testContext.UshortEquals(expectedObjects[i].UshortValue, actualObject.UshortValue);
                testContext.IntEquals(expectedObjects[i].IntValue, actualObject.IntValue);
                testContext.UintEquals(expectedObjects[i].UintValue, actualObject.UintValue);
                testContext.LongEquals(expectedObjects[i].LongValue, actualObject.LongValue);
                testContext.ULongEquals(expectedObjects[i].UlongValue, actualObject.UlongValue);
                testContext.FloatEquals(expectedObjects[i].FloatValue, actualObject.FloatValue, float.MaxValue * 0.000000001f);
                testContext.DoubleEquals(expectedObjects[i].DoubleValue, actualObject.DoubleValue, double.MaxValue * 0.000000001f);
            }
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
Exemplo n.º 13
0
        public void Test404Response(UUnitTestContext testContext)
        {
            var expectedError = new PlayFabError
            {
                HttpCode     = (int)HttpStatusCode.NotFound,
                HttpStatus   = "NotFound",
                Error        = PlayFabErrorCode.ServiceUnavailable,
                ErrorMessage = "Test error result",
            };

            mockHttpPlugin.AssignResponse(HttpStatusCode.NotFound, null, expectedError);

            // 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.Result);
            testContext.NotNull(task.Result.Error);
            testContext.IntEquals(expectedError.HttpCode, task.Result.Error.HttpCode);

            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
Exemplo n.º 14
0
        //[UUnitTest]
        public void TestStructNumField(UUnitTestContext testContext)
        {
            var expectedObjects = new[] { StructNumFieldTest.Max, StructNumFieldTest.Min, StructNumFieldTest.Zero };

            for (var i = 0; i < expectedObjects.Length; i++)
            {
                // Convert the object to json and back, and verify that everything is the same
                var actualJson   = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(expectedObjects[i]).Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", "");
                var actualObject = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <ObjNumPropTest>(actualJson);

                testContext.SbyteEquals(expectedObjects[i].SbyteValue, actualObject.SbyteValue);
                testContext.ByteEquals(expectedObjects[i].ByteValue, actualObject.ByteValue);
                testContext.ShortEquals(expectedObjects[i].ShortValue, actualObject.ShortValue);
                testContext.UshortEquals(expectedObjects[i].UshortValue, actualObject.UshortValue);
                testContext.IntEquals(expectedObjects[i].IntValue, actualObject.IntValue);
                testContext.UintEquals(expectedObjects[i].UintValue, actualObject.UintValue);
                testContext.LongEquals(expectedObjects[i].LongValue, actualObject.LongValue);
                testContext.ULongEquals(expectedObjects[i].UlongValue, actualObject.UlongValue);
                testContext.FloatEquals(expectedObjects[i].FloatValue, actualObject.FloatValue, float.MaxValue * 0.000000001f);
                testContext.DoubleEquals(expectedObjects[i].DoubleValue, actualObject.DoubleValue, double.MaxValue * 0.000000001f);
            }
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
        public void QosTest(UUnitTestContext testContext)
        {
            var loginWithCustomIdRequest = new LoginWithCustomIDRequest()
            {
                CreateAccount = true,
                CustomId      = "test_Instance1"
            };

            try
            {
                PlayFabClientAPI.LoginWithCustomIDAsync(loginWithCustomIdRequest, null, testTitleData.extraHeaders).Wait();
            }
            catch (AggregateException aggregateException) when(aggregateException.InnerException != null)
            {
                throw aggregateException.InnerException;
            }

            PlayFabQosApi playFabQosApi = new PlayFabQosApi();
            QosResult     qoSResult     = playFabQosApi.GetQosResultAsync().Result;

            testContext.IntEquals(0, qoSResult.ErrorCode, $"Qos ErrorMessage: {qoSResult.ErrorMessage}");
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
        public void CheckWithAuthContextAndWithoutAuthContext(UUnitTestContext testContext)
        {
            PlayFabSettings.staticSettings.TitleId            = testTitleData.titleId;
            PlayFabSettings.staticSettings.DeveloperSecretKey = testTitleData.developerSecretKey;

            //IT will  use static developer key - Should has no error
            PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI();

            //IT will  use context developer key - Should has error because of wrong key
            PlayFabApiSettings settings2 = new PlayFabApiSettings();

            settings2.TitleId            = testTitleData.titleId;
            settings2.DeveloperSecretKey = "WRONGKEYTOFAIL";
            PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(settings2);

            PlayFabResult <GetAllSegmentsResult> result1, result2;

            try
            {
                result1 = serverInstance1.GetAllSegmentsAsync(new GetAllSegmentsRequest()).Result;
                result2 = serverInstance2.GetAllSegmentsAsync(new GetAllSegmentsRequest()).Result;
            }
            catch (AggregateException e)
            {
                throw e.InnerException;
            }

            testContext.IsNull(result1.Error, result1?.Error?.GenerateErrorReport());
            testContext.NotNull(result1.Result, "Server Instance1 result is null");

            testContext.NotNull(result2.Error, result2?.Error?.GenerateErrorReport());
            testContext.IsNull(result2.Result, result2?.Error?.GenerateErrorReport());
            testContext.IntEquals(401, result2.Error.HttpCode, "Server Instance2 got wrong error");

            testContext.EndTest(UUnitFinishState.PASSED, null);
        }