Esempio n. 1
0
        void JsonTimeStampHandlesAllFormats(UUnitTestContext testContext)
        {
            string       expectedJson, actualJson;
            DateTime     expectedTime;
            ObjWithTimes actualObj;

            for (var i = 0; i < _examples.Length; i++)
            {
                // Define the time deserialization expectation
                testContext.True(DateTime.TryParseExact(_examples[i], PlayFabUtil._defaultDateTimeFormats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out expectedTime), "Index: " + i + "/" + _examples.Length + ", " + _examples[i]);

                // De-serialize the time using json
                expectedJson = "{\"timestamp\":\"" + _examples[i] + "\"}"; // We are provided a json string with every random time format
                actualObj    = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <ObjWithTimes>(expectedJson);
                actualJson   = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(actualObj);

                if (i == PlayFabUtil.DEFAULT_UTC_OUTPUT_INDEX) // This is the only case where the json input will match the json output
                {
                    testContext.StringEquals(expectedJson, actualJson);
                }

                // Verify that the times match
                var diff = (expectedTime - actualObj.timestamp).TotalSeconds; // We expect that we have parsed the time correctly according to expectations
                testContext.True(diff < 1,
                                 "\nActual time: " + actualObj.timestamp + " vs Expected time: " + expectedTime + ", diff: " + diff +
                                 "\nActual json: " + actualJson + " vs Expected json: " + expectedJson
                                 );
            }
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
Esempio n. 2
0
        void JsonTimeStampHandlesAllFormats(UUnitTestContext testContext)
        {
            string expectedJson, actualJson;
            DateTime expectedTime;
            ObjWithTimes actualObj = new ObjWithTimes();

            for (int i = 0; i < _examples.Length; i++)
            {
                // Define the time deserialization expectation
                testContext.True(DateTime.TryParseExact(_examples[i], PlayFabUtil._defaultDateTimeFormats, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out expectedTime), "Index: " + i + "/" + _examples.Length + ", " + _examples[i]);

                // De-serialize the time using json
                expectedJson = "{\"timestamp\":\"" + _examples[i] + "\"}"; // We are provided a json string with every random time format
                actualObj = JsonWrapper.DeserializeObject<ObjWithTimes>(expectedJson, PlayFabUtil.ApiSerializerStrategy);
                actualJson = JsonWrapper.SerializeObject(actualObj, PlayFabUtil.ApiSerializerStrategy);

                if (i == PlayFabUtil.DEFAULT_UTC_OUTPUT_INDEX) // This is the only case where the json input will match the json output
                    testContext.StringEquals(expectedJson, actualJson);

                // Verify that the times match
                double diff = (expectedTime - actualObj.timestamp).TotalSeconds; // We expect that we have parsed the time correctly according to expectations
                testContext.True(diff < 1,
                    "\nActual time: " + actualObj.timestamp + " vs Expected time: " + expectedTime + ", diff: " + diff +
                    "\nActual json: " + actualJson + " vs Expected json: " + expectedJson
                );
            }
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
Esempio n. 3
0
    public void TestLinkDeviceIdStatus(UUnitTestContext testContext)
    {
        PlayFabClientAPI.GetAccountInfo(new GetAccountInfoRequest
        {
            AuthenticationContext = _emailAuthService.AuthenticationContext
        }, response =>
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            testContext.StringEquals(response.AccountInfo.AndroidDeviceInfo.AndroidDeviceId, PlayFabSettings.DeviceUniqueIdentifier, "Android deviceID not match!");
#elif UNITY_IPHONE || UNITY_IOS && !UNITY_EDITOR
            testContext.StringEquals(response.AccountInfo.IosDeviceInfo.IosDeviceId, PlayFabSettings.DeviceUniqueIdentifier, "iOS deviceID not match!");
#else
            testContext.StringEquals(response.AccountInfo.CustomIdInfo.CustomId, _emailAuthService.GetOrCreateRememberMeId(), "customId not match!");
#endif
            testContext.EndTest(UUnitFinishState.PASSED, "DeviceId successfully linked!");
        },
                                        (error) =>
        {
            testContext.Fail("GetAccountInfo error: " + error.ErrorMessage);
        });
    }
Esempio n. 4
0
    public void LoginWithDeviceId(UUnitTestContext testContext)
    {
        var silentAuth = new PlayFabAuthService();

        silentAuth.OnLoginSuccess += (success) =>
        {
            testContext.StringEquals(_emailAuthService.AuthenticationContext.PlayFabId, success.PlayFabId);
            testContext.EndTest(UUnitFinishState.PASSED, "Silent auth success with playFabId: " + success.PlayFabId);
        };
        silentAuth.OnPlayFabError += (error) =>
        {
            testContext.Fail("Silent auth failed with error: " + error.ErrorMessage);
        };
        silentAuth.Authenticate(AuthTypes.Silent);
    }
Esempio n. 5
0
        public void EnumConversionTest_Serialize(UUnitTestContext testContext)
        {
            string expectedJson, actualJson;
            EnumConversionTestClass expectedObj = new EnumConversionTestClass(), actualObj;

            expectedObj.enumList = new List <testRegion>()
            {
                testRegion.USEast, testRegion.USCentral, testRegion.Japan
            };
            expectedObj.enumArray    = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue    = testRegion.Australia;
            expectedObj.optEnumValue = null;

            expectedJson = "{\"enumList\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumArray\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumValue\":\"Australia\",\"optEnumValue\":null}";

            actualObj  = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <EnumConversionTestClass>(expectedJson);
            actualJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(actualObj);

            testContext.StringEquals(expectedJson.Replace(" ", "").Replace("\n", ""), actualJson.Replace(" ", "").Replace("\n", ""));
            testContext.ObjEquals(expectedObj, actualObj);
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }
Esempio n. 6
0
        public void EnumConversionTest_Serialize(UUnitTestContext testContext)
        {
            string expectedJson, actualJson;
            EnumConversionTestClass expectedObj = new EnumConversionTestClass(), actualObj;
            expectedObj.enumList = new List<testRegion>() { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumArray = new testRegion[] { testRegion.USEast, testRegion.USCentral, testRegion.Japan };
            expectedObj.enumValue = testRegion.Australia;
            expectedObj.optEnumValue = null;

            expectedJson = "{\"enumList\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumArray\":[\"USEast\",\"USCentral\",\"Japan\"],\"enumValue\":\"Australia\",\"optEnumValue\":null}";

            actualObj = JsonWrapper.DeserializeObject<EnumConversionTestClass>(expectedJson, PlayFabUtil.ApiSerializerStrategy);
            actualJson = JsonWrapper.SerializeObject(actualObj, PlayFabUtil.ApiSerializerStrategy);

            testContext.StringEquals(expectedJson.Replace(" ", "").Replace("\n", ""), actualJson.Replace(" ", "").Replace("\n", ""));
            testContext.ObjEquals(expectedObj, actualObj);
            testContext.EndTest(UUnitFinishState.PASSED, null);
        }