Example #1
0
        public IEnumerator GetJSON_HttpError_ReportsFail()
        {
            // Assemble
            // Act
            var mockHttpError = new MockWebRequestHttpError();
            var getter        = new JSONRetrieverWeb <SimpleJson>(mockHttpError);
            var op            = getter.GetJSON(1);

            yield return(op.WaitForResult(1.5f, () => Assert.Fail("Unexpected timeout. JsonRetrieverWeb should have sent a failure, but did not.")));

            Assert.AreEqual(AsyncStatus.Failed, op.Status);
        }
Example #2
0
        public IEnumerator GetJSON_InvalidJSON_ThrowsBadJSON()
        {
            // Assemble
            var badJson = "{ \"anIntWithNoValue\" } ";

            // Act
            var mockWebRequest = new MockWebRequest(badJson);
            var getter         = new JSONRetrieverWeb <SimpleJson>(mockWebRequest);
            //Assert.Throws<System.ArgumentException>(() => getter.GetJSON(1), "Expected ArgumentException due to invalid Json format.");
            var op = getter.GetJSON(1);

            yield return(op.WaitForResult(1.5f, () => Assert.Fail("Unexpected timeout. Test timed out, expected InvalidJSON exception")));

            Assert.AreEqual(AsyncStatus.Failed, op.Status);
            Assert.AreEqual(JSONRetrieverWeb <SimpleJson> .ErrorCodeInvalidJsonFormat, op.FailureCode);
        }
Example #3
0
        public IEnumerator GetJSON_ValidURLValidJSON_ReturnsExpected()
        {
            // Assemble
            var simpleJson = new SimpleJson();

            simpleJson.AnInt = 5;

            // Act
            var mockWebRequest = new MockWebRequest("{ \"anInt\": 5}");
            var getter         = new JSONRetrieverWeb <SimpleJson>(mockWebRequest);
            var op             = getter.GetJSON(1);

            yield return(op.WaitForResult(1.5f, () => Assert.Fail("Test timed out. AsyncOp never returned a Status besides Pending.")));

            Assert.AreEqual(AsyncStatus.Success, op.Status);
            Assert.AreEqual(simpleJson.AnInt, op.ResultData.AnInt);
        }
Example #4
0
        public IEnumerator GetJSON_ReuseRetriever_ReturnsSameResultTwice()
        {
            // Assemble
            var simpleJson = new SimpleJson();

            simpleJson.AnInt = 3;

            // Act
            var mockWebRequest = new MockWebRequest("{ \"anInt\": 3}");
            var getter         = new JSONRetrieverWeb <SimpleJson>(mockWebRequest);
            var op             = getter.GetJSON(1);

            yield return(op.WaitForResult(1.5f, () => Assert.Fail("Test timed out on first Get. AsyncOp never returned a Status besides Pending.")));

            Assert.AreEqual(AsyncStatus.Success, op.Status);
            Assert.AreEqual(simpleJson.AnInt, op.ResultData.AnInt);

            var op2 = getter.GetJSON(1);

            yield return(op2.WaitForResult(1.5f, () => Assert.Fail("Test timed out on second Get. AsyncOp never returned a Status besides Pending.")));

            Assert.AreEqual(AsyncStatus.Success, op.Status);
            Assert.AreEqual(simpleJson.AnInt, op.ResultData.AnInt);
        }
        private IEnumerator UpdateLanguagesAsync(bool useStagingLink = false)
        {
            EditorUtility.DisplayProgressBar(
                LocalizationManager.Instance.GetTranslation("languageUpdateProgressTitle"),
                LocalizationManager.Instance.GetTranslation("languageUpdateProgressMessage1"),
                0.0f);
            this.IsDoneUpdating = false;

            LanguageBookmarks bookmarks = null;
            {
                var bookmarkRetriever = new JSONRetrieverWeb <LanguageBookmarks>(useStagingLink ? BookmarksURIStaging : BookmarksURIRelease);
                var bookmarkFetchOp   = bookmarkRetriever.GetJSON(3);
                while (bookmarkFetchOp.Status == AsyncStatus.Pending)
                {
                    yield return(null);
                }

                if (bookmarkFetchOp.Status != AsyncStatus.Success)
                {
                    ShowDisplayDialogForFailedOp(bookmarkFetchOp);
                    yield break;
                }

                bookmarks = bookmarkFetchOp.ResultData;
            }

            var languages = new List <Language>();

            {
                for (int i = 0; i < bookmarks.LanguageUrls.Count; ++i)
                {
                    var    url      = bookmarks.LanguageUrls[i];
                    var    uri      = new System.Uri(bookmarks.LanguageUrls[i]);
                    string filename = System.IO.Path.GetFileName(uri.LocalPath);

                    // Add one because we finished downloading Bookmarks.
                    var percentComplete = (i + 1) / (float)(bookmarks.LanguageUrls.Count + 1);
                    EditorUtility.DisplayProgressBar(
                        LocalizationManager.Instance.GetTranslation("languageUpdateProgressTitle"),
                        string.Format(
                            LocalizationManager.Instance.GetTranslation(
                                "languageUpdateDownloadingLanguages"),
                            filename),
                        percentComplete);

                    var languageRetriever = new JSONRetrieverWeb <Language>(url);
                    var languageFetchOp   = languageRetriever.GetJSON(3);
                    while (languageFetchOp.Status == AsyncStatus.Pending)
                    {
                        yield return(null);
                    }

                    if (languageFetchOp.Status != AsyncStatus.Success)
                    {
                        ShowDisplayDialogForFailedOp(languageFetchOp);
                        yield break;
                    }

                    languages.Add(languageFetchOp.ResultData);
                }
            }

            EditorUtility.DisplayProgressBar(
                LocalizationManager.Instance.GetTranslation("languageUpdateProgressTitle"),
                LocalizationManager.Instance.GetTranslation("languageUpdateSavingChanges"),
                1.0f);
            EditorUtility.ClearProgressBar();

            var reports = LocalizationManager.Instance.AddOrUpdateLanguages(languages);

            EditorUtility.DisplayDialog(
                LocalizationManager.Instance.GetTranslation("languageUpdateProgressTitleSuccess"),
                BuildDisplayStringForReport(reports),
                LocalizationManager.Instance.GetTranslation("ok"));
        }