コード例 #1
0
        public void CloudScript()
        {
            if (string.IsNullOrEmpty(PlayFabSettings.GetLogicURL()))
            {
                var getUrlTask = PlayFabClientAPI.GetCloudScriptUrlAsync(new ClientModels.GetCloudScriptUrlRequest());
                getUrlTask.Wait();
                UUnitAssert.Null(getUrlTask.Result.Error, "Failed to get LogicServerURL");
                UUnitAssert.NotNull(getUrlTask.Result.Result, "Failed to get LogicServerURL");
                UUnitAssert.False(string.IsNullOrEmpty(getUrlTask.Result.Result.Url), "Failed to get LogicServerURL");
                UUnitAssert.False(string.IsNullOrEmpty(PlayFabSettings.GetLogicURL()), "Failed to get LogicServerURL");
            }

            var request = new ClientModels.RunCloudScriptRequest();

            request.ActionId = "helloWorld";
            var cloudTask = PlayFabClientAPI.RunCloudScriptAsync(request);

            cloudTask.Wait();
            UUnitAssert.Null(cloudTask.Result.Error, "Failed to Execute CloudScript");
            UUnitAssert.NotNull(cloudTask.Result.Result, "Failed to Execute CloudScript");
            UUnitAssert.False(string.IsNullOrEmpty(cloudTask.Result.Result.ResultsEncoded), "Failed to Execute CloudScript");

            // Get the helloWorld return message
            JObject jobj = cloudTask.Result.Result.Results as JObject;

            UUnitAssert.NotNull(jobj);
            JToken jtok;

            jobj.TryGetValue("messageValue", out jtok);
            UUnitAssert.NotNull(jtok);
            JValue jval = jtok as JValue;

            UUnitAssert.NotNull(jval);
            string actualMessage = jval.Value as string;

            UUnitAssert.Equals("Hello " + playFabId + "!", actualMessage);
        }