Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }