Esempio n. 1
0
 private static void ContinueWithContext <T>(Task <PlayFabResult <T> > srcTask, UUnitTestContext testContext, Action <PlayFabResult <T>, UUnitTestContext, string> continueAction, bool expectSuccess, string failMessage, bool endTest) where T : PlayFabResultCommon
 {
     srcTask.ContinueWith(task =>
     {
         var failed = true;
         try
         {
             if (expectSuccess)
             {
                 testContext.NotNull(task.Result, failMessage);
                 testContext.IsNull(task.Result.Error, PlayFabUtil.GetErrorReport(task.Result.Error));
                 testContext.NotNull(task.Result.Result, failMessage);
             }
             if (continueAction != null)
             {
                 continueAction.Invoke(task.Result, testContext, failMessage);
             }
             failed = false;
         }
         catch (UUnitSkipException uu)
         {
             // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process
             testContext.EndTest(UUnitFinishState.SKIPPED, uu.Message);
         }
         catch (UUnitException uu)
         {
             // Silence the assert and ensure the test is marked as complete - The exception is just to halt the test process
             testContext.EndTest(UUnitFinishState.FAILED, uu.Message + "\n" + uu.StackTrace);
         }
         catch (Exception e)
         {
             // Report this exception as an unhandled failure in the test
             testContext.EndTest(UUnitFinishState.FAILED, e.ToString());
         }
         if (!failed && endTest)
         {
             testContext.EndTest(UUnitFinishState.PASSED, null);
         }
     }
                          );
 }
        public void NullableJson(UUnitTestContext testContext)
        {
            var testObjNull = new NullableTestClass();
            var testObjInt  = new NullableTestClass {
                IntField = 42, IntProperty = 42
            };
            var testObjTime = new NullableTestClass {
                TimeField = DateTime.UtcNow, TimeProperty = DateTime.UtcNow
            };
            var testObjEnum = new NullableTestClass {
                EnumField = Region.Japan, EnumProperty = Region.Japan
            };
            var testObjBool = new NullableTestClass {
                BoolField = true, BoolProperty = true
            };
            var testObjs = new[] { testObjNull, testObjEnum, testObjBool, testObjInt, testObjTime };

            List <string> failures = new List <string>();

            foreach (var testObj in testObjs)
            {
                NullableTestClass actualObj = null;
                var actualJson = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).SerializeObject(testObj);
                try
                {
                    actualObj = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <NullableTestClass>(actualJson);
                }
                catch (Exception)
                {
                    failures.Add(actualJson + " Cannot be deserialized as NullableTestClass");
                    continue;
                }

                if (NullableNotEquals(testObj.BoolField, actualObj.BoolField))
                {
                    failures.Add("Nullable bool field does not serialize properly: " + testObj.BoolField + ", from " + actualJson);
                }
                if (NullableNotEquals(testObj.BoolProperty, actualObj.BoolProperty))
                {
                    failures.Add("Nullable bool property does not serialize properly: " + testObj.BoolProperty + ", from " + actualJson);
                }
                if (NullableNotEquals(testObj.IntField, actualObj.IntField))
                {
                    failures.Add("Nullable integer field does not serialize properly: " + testObj.IntField + ", from " + actualJson);
                }
                if (NullableNotEquals(testObj.IntProperty, actualObj.IntProperty))
                {
                    failures.Add("Nullable integer property does not serialize properly: " + testObj.IntProperty + ", from " + actualJson);
                }
                if (NullableNotEquals(testObj.EnumField, actualObj.EnumField))
                {
                    failures.Add("Nullable enum field does not serialize properly: " + testObj.EnumField + ", from " + actualJson);
                }
                if (NullableNotEquals(testObj.EnumProperty, actualObj.EnumProperty))
                {
                    failures.Add("Nullable enum property does not serialize properly: " + testObj.EnumProperty + ", from " + actualJson);
                }

                if (testObj.TimeField.HasValue != actualObj.TimeField.HasValue)
                {
                    failures.Add("Nullable struct field does not serialize properly: " + testObj.TimeField + ", from " + actualJson);
                }
                if (testObj.TimeField.HasValue && Math.Abs((testObj.TimeField - actualObj.TimeField).Value.TotalSeconds) > 1)
                {
                    failures.Add("Nullable struct field does not serialize properly: " + testObj.TimeField + ", from " + actualJson);
                }

                if (testObj.TimeProperty.HasValue != actualObj.TimeProperty.HasValue)
                {
                    failures.Add("Nullable struct field does not serialize properly: " + testObj.TimeProperty + ", from " + actualJson);
                }
                if (testObj.TimeProperty.HasValue && Math.Abs((testObj.TimeProperty - actualObj.TimeProperty).Value.TotalSeconds) > 1)
                {
                    failures.Add("Nullable struct property does not serialize properly: " + testObj.TimeProperty + ", from " + actualJson);
                }
            }

            if (failures.Count == 0)
            {
                testContext.EndTest(UUnitFinishState.PASSED, null);
            }
            else
            {
                testContext.EndTest(UUnitFinishState.FAILED, string.Join("\n", failures.ToArray()));
            }
        }
Esempio n. 3
0
        public void PlayerStatisticsApi(UUnitTestContext testContext)
        {
            var getRequest = new GetPlayerStatisticsRequest();

            PlayFabClientAPI.GetPlayerStatistics(getRequest, PlayFabUUnitUtils.ApiActionWrapper <GetPlayerStatisticsResult>(testContext, GetPlayerStatsCallback1), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext, testTitleData.extraHeaders);
        }
Esempio n. 4
0
 private void LoginOrRegisterContinued(PlayFabResult <LoginResult> loginResult, UUnitTestContext testContext, string failMessage)
 {
     PlayFabId = loginResult.Result.PlayFabId; // Needed for subsequent tests
     testContext.True(PlayFabClientAPI.IsClientLoggedIn(), "User login failed");
 }
Esempio n. 5
0
 public void GetServerTime(UUnitTestContext testContext)
 {
     clientInstance.GetTime(null, PlayFabUUnitUtils.ApiActionWrapper <GetTimeResult>(testContext, OnGetTimeCallback), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext);
 }
Esempio n. 6
0
 public override void Tick(UUnitTestContext testContext)
 {
     // No async work needed
 }
Esempio n. 7
0
        private void PlayerStatisticsApiContinued2(PlayFabResult <UpdatePlayerStatisticsResult> updateResult, UUnitTestContext testContext, string failMessage)
        {
            var getRequest   = new GetPlayerStatisticsRequest();
            var getStatTask2 = PlayFabClientAPI.GetPlayerStatisticsAsync(getRequest);

            ContinueWithContext(getStatTask2, testContext, PlayerStatisticsApiContinued3, true, "GetPlayerStatistics2 call failed", true);
        }
Esempio n. 8
0
 public override void Tick(UUnitTestContext testContext)
 {
     // No work needed, async tests will end themselves
 }
Esempio 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);
        }
Esempio n. 10
0
        private void PlayerStatisticsApiContinued1(PlayFabResult <GetPlayerStatisticsResult> getStatResult1, UUnitTestContext testContext, string failMessage)
        {
            foreach (var eachStat in getStatResult1.Result.Statistics)
            {
                if (eachStat.StatisticName == TEST_STAT_NAME)
                {
                    _testInteger = eachStat.Value;
                }
            }
            _testInteger = (_testInteger + 1) % 100; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1)

            var updateRequest = new UpdatePlayerStatisticsRequest {
                Statistics = new List <StatisticUpdate> {
                    new StatisticUpdate {
                        StatisticName = TEST_STAT_NAME, Value = _testInteger
                    }
                }
            };
            var updateTask = PlayFabClientAPI.UpdatePlayerStatisticsAsync(updateRequest);

            ContinueWithContext(updateTask, testContext, PlayerStatisticsApiContinued2, true, "UpdatePlayerStatistics call failed", false);
        }
Esempio n. 11
0
        private void UserDataApiContinued2(PlayFabResult <UpdateUserDataResult> updateResult, UUnitTestContext testContext, string failMessage)
        {
            var getRequest   = new GetUserDataRequest();
            var getDataTask2 = PlayFabClientAPI.GetUserDataAsync(getRequest);

            ContinueWithContext(getDataTask2, testContext, UserDataApiContinued3, true, "GetUserData2 call failed", true);
        }
Esempio n. 12
0
        private void UserDataApiContinued1(PlayFabResult <GetUserDataResult> getDataResult1, UUnitTestContext testContext, string failMessage)
        {
            UserDataRecord testCounter;

            if (!getDataResult1.Result.Data.TryGetValue(TEST_DATA_KEY, out testCounter))
            {
                testCounter = new UserDataRecord {
                    Value = "0"
                }
            }
            ;
            int.TryParse(testCounter.Value, out _testInteger);
            _testInteger = (_testInteger + 1) % 100; // This test is about the expected value changing - but not testing more complicated issues like bounds

            var updateRequest = new UpdateUserDataRequest {
                Data = new Dictionary <string, string> {
                    { TEST_DATA_KEY, _testInteger.ToString() }
                }
            };
            var updateTask = PlayFabClientAPI.UpdateUserDataAsync(updateRequest);

            ContinueWithContext(updateTask, testContext, UserDataApiContinued2, true, "UpdateUserData call failed", false); // The update doesn't return anything interesting except versionID.  It's better to just re-call GetUserData again below to verify the update
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        public void ParallelRequest(UUnitTestContext testContext)
        {
            List <Task> tasks = new List <Task>();

            PlayFabApiSettings settings1 = new PlayFabApiSettings();

            settings1.TitleId            = testTitleData.titleId;
            settings1.DeveloperSecretKey = testTitleData.developerSecretKey;

            PlayFabApiSettings settings2 = new PlayFabApiSettings();

            settings2.TitleId            = testTitleData.titleId;
            settings2.DeveloperSecretKey = "GETERROR";

            PlayFabApiSettings settings3 = new PlayFabApiSettings();

            settings3.TitleId            = testTitleData.titleId;
            settings3.DeveloperSecretKey = testTitleData.developerSecretKey;

            PlayFabApiSettings settings4 = new PlayFabApiSettings();

            settings4.TitleId            = testTitleData.titleId;
            settings4.DeveloperSecretKey = "TESTKEYERROR";

            PlayFabApiSettings settings5 = new PlayFabApiSettings();

            settings5.TitleId            = testTitleData.titleId;
            settings5.DeveloperSecretKey = "123421";


            PlayFabServerInstanceAPI serverInstance1 = new PlayFabServerInstanceAPI(settings1);

            tasks.Add(serverInstance1.GetAllSegmentsAsync(new GetAllSegmentsRequest()));

            PlayFabServerInstanceAPI serverInstance2 = new PlayFabServerInstanceAPI(settings2);

            tasks.Add(serverInstance2.GetAllSegmentsAsync(new GetAllSegmentsRequest()));

            PlayFabServerInstanceAPI serverInstance3 = new PlayFabServerInstanceAPI(settings3);

            tasks.Add(serverInstance3.GetAllSegmentsAsync(new GetAllSegmentsRequest()));

            PlayFabServerInstanceAPI serverInstance4 = new PlayFabServerInstanceAPI(settings4);

            tasks.Add(serverInstance4.GetAllSegmentsAsync(new GetAllSegmentsRequest()));

            PlayFabServerInstanceAPI serverInstance5 = new PlayFabServerInstanceAPI(settings5);

            tasks.Add(serverInstance5.GetAllSegmentsAsync(new GetAllSegmentsRequest()));

            Task.WhenAll(tasks).ContinueWith(whenAll =>
            {
                if (!whenAll.IsCanceled && !whenAll.IsFaulted)
                {
                    testContext.EndTest(UUnitFinishState.PASSED, null);
                }
                else
                {
                    testContext.Fail("Parallel Requests failed " + whenAll.Exception.Flatten().Message);
                }
            });
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
 public override void SetUp(UUnitTestContext testContext)
 {
     // Clear the global settings, so they can't pollute this test.
     PlayFabSettings.staticSettings.TitleId            = null;
     PlayFabSettings.staticSettings.DeveloperSecretKey = null;
 }
Esempio n. 17
0
 private void LeaderBoardContinued(PlayFabResult <GetLeaderboardResult> clientResult, UUnitTestContext testContext, string failMessage)
 {
     testContext.True(clientResult.Result.Leaderboard.Count > 0, "Leaderboard does not contain enough entries.");
 }
Esempio n. 18
0
        public void UserDataApi(UUnitTestContext testContext)
        {
            var getRequest = new GetUserDataRequest();

            clientInstance.GetUserData(getRequest, PlayFabUUnitUtils.ApiActionWrapper <GetUserDataResult>(testContext, GetUserDataCallback1), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext);
        }
Esempio n. 19
0
 private void LeaderBoardContinued(PlayFabResult <GetAccountInfoResult> accountResult, UUnitTestContext testContext, string failMessage)
 {
     testContext.True(Enum.IsDefined(typeof(UserOrigination), accountResult.Result.AccountInfo.TitleInfo.Origination.Value), "Origination Enum not valid");
 }
Esempio n. 20
0
        public void PlayerStatisticsApi(UUnitTestContext testContext)
        {
            var getRequest = new GetPlayerStatisticsRequest();

            clientInstance.GetPlayerStatistics(getRequest, PlayFabUUnitUtils.ApiActionWrapper <GetPlayerStatisticsResult>(testContext, GetPlayerStatsCallback1), PlayFabUUnitUtils.ApiActionWrapper <PlayFabError>(testContext, SharedErrorCallback), testContext);
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
 public override void TearDown(UUnitTestContext testContext)
 {
 }
Esempio n. 23
0
 private void CloudScriptErrorContinued(PlayFabResult <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");
 }
Esempio n. 24
0
 public override void TearDown(UUnitTestContext testContext)
 {
     PlayFabSettings.AdvertisingIdType  = null;
     PlayFabSettings.AdvertisingIdValue = null;
     _tickAction = null;
 }
Esempio n. 25
0
        private void InvalidRegistrationContinued(PlayFabResult <RegisterPlayFabUserResult> registerResult, UUnitTestContext testContext, string failMessage)
        {
            testContext.NotNull(registerResult, failMessage);
            testContext.IsNull(registerResult.Result, failMessage);
            testContext.NotNull(registerResult.Error, failMessage);

            var expectedEmailMsg    = "email address is not valid.";
            var expectedPasswordMsg = "password must be between";
            var fullReport          = CompileErrorReport(registerResult.Error);

            testContext.True(fullReport.ToLower().Contains(expectedEmailMsg), "Expected an error about bad email address: " + fullReport);
            testContext.True(fullReport.ToLower().Contains(expectedPasswordMsg), "Expected an error about bad password: " + fullReport);
        }