public IEnumerator AutoyaHTTPPostFailWithTimeout()
    {
        var timeoutError = string.Empty;

        /*
         *              fake server should be response 1msec
         */
        Autoya.Http_Post(
            "https://httpbin.org/delay/1",
            "data",
            (conId, resultData) =>
        {
            True(false, "got success result.");
        },
            (conId, code, reason, autoyaStatus) =>
        {
            True(code == BackyardSettings.HTTP_TIMEOUT_CODE, "not match. code:" + code + " reason:" + reason);
            timeoutError = reason;
        },
            null,
            0.0001// 1ms
            );

        yield return(WaitUntil(
                         () =>
        {
            return !string.IsNullOrEmpty(timeoutError);
        },
                         () => { throw new TimeoutException("timeout."); }
                         ));
    }
Esempio n. 2
0
    // Use this for initialization
    IEnumerator Start()
    {
        while (!Autoya.Auth_IsAuthenticated())
        {
            yield return(null);
        }

        var connectionId1 = Autoya.Http_Get(
            "https://httpbin.org/get",                          // url
            (conId, data) => {                                  // on succeeded
            Debug.Log("get data:" + data);
        },
            (conId, code, reason, autoyaStatus) => {            // on failed
            Debug.LogError("code:" + code + " reason:" + reason);
        },
            new Dictionary <string, string>(),           // headers
            3.0                                          // timeout
            );

        Debug.Log("start get with connectionId:" + connectionId1);

        var postData      = "hello world.";
        var connectionId2 = Autoya.Http_Post(
            "https://httpbin.org/post",
            postData,
            (conId, resultData) => {
            Debug.Log("post data:" + resultData);
        },
            (conId, code, reason, autoyaStatus) => {
            Debug.LogError("code:" + code + " reason:" + reason);
        }
            );

        Debug.Log("start post with connectionId:" + connectionId2);
    }
Esempio n. 3
0
    public IEnumerator AutoyaHTTPPostFailWithUnauth()
    {
        Autoya.forceSetHttpCodeAsUnauthorized = true;
        var unauthorized = false;

        /*
         *              dummy server returns 401 forcibly.
         */
        Autoya.Http_Post(
            "https://httpbin.org/status/401",
            "dummy_data",
            (conId, resultData) =>
        {
            Fail();
        },
            (conId, code, reason, autoyaStatus) =>
        {
            unauthorized = autoyaStatus.isAuthFailed;
            Autoya.forceSetHttpCodeAsUnauthorized = false;
        }
            );

        yield return(WaitUntil(
                         () => unauthorized,
                         () => { throw new TimeoutException("timeout."); }
                         ));


        // token refresh feature is already running. wait end.
        yield return(WaitUntil(
                         () => Autoya.Auth_IsAuthenticated(),
                         () => { throw new TimeoutException("failed to refresh token."); }
                         ));
    }
    public IEnumerator AutoyaHTTPPostFailWith404()
    {
        var resultCode = 0;

        Autoya.Http_Post(
            "https://httpbin.org/status/404",
            "data",
            (conId, resultData) =>
        {
            // do nothing.
        },
            (conId, code, reason, autoyaStatus) =>
        {
            resultCode = code;
        }
            );

        yield return(WaitUntil(
                         () => (resultCode == 404),
                         () => { throw new TimeoutException("failed to detect 404."); }
                         ));

        // result should be have reason,
        True(resultCode == 404, "code unmatched. resultCode:" + resultCode);
    }
    [MTest] public void AutoyaHTTPPostFailWithTimeout()
    {
        var timeoutError = string.Empty;

        /*
         *      fake server should be response 1msec
         */
        Autoya.Http_Post(
            "https://httpbin.org/delay/1",
            "data",
            (conId, resultData) => {
            Assert(false, "got success result.");
        },
            (conId, code, reason, autoyaStatus) => {
            Assert(code == BackyardSettings.HTTP_TIMEOUT_CODE, "not match. code:" + code + " reason:" + reason);
            timeoutError = reason;
        },
            null,
            0.0001            // 1ms
            );

        WaitUntil(
            () => {
            return(!string.IsNullOrEmpty(timeoutError));
        },
            3
            );
    }
    [MTest] public void AutoyaHTTPPostFailWithUnauth()
    {
        var unauthorized = false;

        /*
         *      dummy server returns 401 forcibly.
         */
        Autoya.Http_Post(
            "https://httpbin.org/status/401",
            "dummy_data",
            (string conId, string resultData) => {
            // do nothing.
        },
            (conId, code, reason, autoyaStatus) => {
            unauthorized = autoyaStatus.isAuthFailed;
        }
            );

        WaitUntil(
            () => unauthorized,
            5
            );


        // token refresh feature is already running. wait end.
        WaitUntil(
            () => Autoya.Auth_IsAuthenticated(),
            5,
            "failed to refresh token."
            );
    }
    [MTest] public void AutoyaHTTPPost()
    {
        var result = string.Empty;

        Autoya.Http_Post(
            "https://httpbin.org/post",
            "data",
            (string conId, string resultData) => {
            result = "done!:" + resultData;
        },
            (conId, code, reason, autoyaStatus) => {
            // do nothing.
        }
            );

        WaitUntil(
            () => !string.IsNullOrEmpty(result),
            5
            );
    }
    public IEnumerator AutoyaHTTPPost()
    {
        var result = string.Empty;

        Autoya.Http_Post(
            "https://httpbin.org/post",
            "data",
            (conId, resultData) =>
        {
            result = "done!:" + resultData;
        },
            (conId, code, reason, autoyaStatus) =>
        {
            // do nothing.
        }
            );

        yield return(WaitUntil(
                         () => !string.IsNullOrEmpty(result),
                         () => { throw new TimeoutException("timeout."); }
                         ));
    }
    /*
     *      target test site does not support show post request. hmmm,,,
     */
    // [MTest] public void AutoyaHTTPPostWithAdditionalHeader () {
    //  var result = string.Empty;
    //  Autoya.Http_Post(
    //      "https://httpbin.org/headers",
    //      "data",
    //      (string conId, string resultData) => {
    //          TestLogger.Log("resultData:" + resultData);
    //          result = resultData;
    //      },
    //      (conId, code, reason) => {
    //          TestLogger.Log("fmmmm,,,,, AutoyaHTTPPostWithAdditionalHeader failed conId:" + conId + " reason:" + reason);
    //          // do nothing.
    //      },
    //      new Dictionary<string, string>{
    //          {"Hello", "World"}
    //      }
    //  );

    //  var wait = WaitUntil(
    //      () => (result.Contains("Hello") && result.Contains("World")),
    //      5
    //  );
    //  if (!wait) return false;

    //  return true;
    // }

    [MTest] public void AutoyaHTTPPostFailWith404()
    {
        var resultCode = 0;

        Autoya.Http_Post(
            "https://httpbin.org/status/404",
            "data",
            (string conId, string resultData) => {
            // do nothing.
        },
            (conId, code, reason, autoyaStatus) => {
            resultCode = code;
        }
            );

        WaitUntil(
            () => (resultCode == 404),
            5,
            "failed to detect 404."
            );

        // result should be have reason,
        Assert(resultCode == 404, "code unmatched. resultCode:" + resultCode);
    }