Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public void Responder_SendJson_Sends_JSONP_File_Correctly()
        {
            var original = new JsonExample()
            {
                IntegerField = 102, DateField = new DateTime(2011, 11, 3, 4, 5, 6, 789)
            };

            _Responder.SendJson(_Request.Object, _Response.Object, original, "mycallback", null);

            var text = Encoding.UTF8.GetString(_OutputStream.ToArray());

            Assert.AreNotEqual(0, text.Length);
            Assert.AreEqual(text.Length, _Response.Object.ContentLength);

            Assert.IsTrue(text.StartsWith("mycallback("));
            Assert.IsTrue(text.EndsWith(")"));
            text = text.Substring(11, text.Length - 12);

            JsonExample copy;

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text))) {
                DataContractJsonSerializer serialiser = new DataContractJsonSerializer(typeof(JsonExample));
                copy = (JsonExample)serialiser.ReadObject(stream);
            }

            Assert.AreEqual(MimeType.Json, _Response.Object.MimeType);
            Assert.AreEqual(HttpStatusCode.OK, _Response.Object.StatusCode);

            Assert.AreEqual(102, copy.IntegerField);
            Assert.AreEqual(new DateTime(2011, 11, 3, 4, 5, 6, 789), copy.DateField);

            _Response.Verify(r => r.AddHeader("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate"), Times.Once());
        }
Exemplo n.º 2
0
        public void Map_Null_ReturnsNull()
        {
            var mapper = CreateMapper();

            JsonExample actual = mapper.Map(null, LanguageDoesNotMatter);

            Check.That(actual).IsNull();
        }
Exemplo n.º 3
0
        public void Map_Null_ReturnsNull()
        {
            var mapper = CreateMapper();

            JsonExample actual = mapper.Map(null);

            Check.That(actual).IsNull();
        }
Exemplo n.º 4
0
        public void Responder_SendJson_Uses_Mime_Type_If_Supplied()
        {
            var original = new JsonExample()
            {
                IntegerField = 102, DateField = new DateTime(2011, 11, 3, 4, 5, 6, 789)
            };

            _Responder.SendJson(_Request.Object, _Response.Object, original, null, MimeType.Text);

            Assert.AreEqual(MimeType.Text, _Response.Object.MimeType);
        }
Exemplo n.º 5
0
    void Start()
    {
        Il2cppWorkaround.Initialize();

        LogText.text = "";
        Log.OnLog    = OnLog;
        Log.WriteLine("Started!");

        BasicExample.Run();
        JsonExample.Run();
        ProtobufExample.Run();

        Log.WriteLine("**** OK ****");
    }
Exemplo n.º 6
0
        public void NullPropertyShouldBeOk()
        {
            var nullableSchema = this.SchemaForNullTest(expectNulls: true);

            var exampleObj = new
            {
                prop1 = (string)null,
                prop2 = 12345
            };


            string json        = JsonConvert.SerializeObject(exampleObj);
            var    testExample = new JsonExample(json);
            var    issues      = new IssueLogger();

            Assert.IsTrue(nullableSchema.ValidateJson(testExample, issues, new Dictionary <string, JsonSchema>(), new ValidationOptions()));
            Assert.AreEqual(0, issues.Issues.Count());
        }
Exemplo n.º 7
0
        public void NullPropertyShouldBeOk()
        {
            var nullableSchema = this.SchemaForNullTest(expectNulls: true);

            var exampleObj = new
            {
                prop1 = (string)null,
                prop2 = 12345
            };


            string json        = JsonConvert.SerializeObject(exampleObj);
            var    testExample = new JsonExample(json);

            ValidationError[] errors;

            Assert.IsTrue(nullableSchema.ValidateJson(testExample, out errors, new Dictionary <string, JsonSchema>(), new ValidationOptions()));
            Assert.AreEqual(0, errors.Length);
        }
Exemplo n.º 8
0
    void SendJsonRequest()
    {
        JsonExample json       = new JsonExample(101, "Json101", 10.1f, 10.00101f, new Vector3(1, 0, 1));
        string      jsonString = JsonUtility.ToJson(json);

        Debug.LogFormat("Post JSON request: {0}", jsonString);
//		Debug.Log("value "+ json.fValue +" "+ json.dValue);
        //
        StartCoroutine(PostRequest(this.exampleUrl, jsonString, WebExampleCallback <string>));
//
//		StartCoroutine(PostRequest(this.exampleUrl, jsonString,(UWebResponse<string> response) =>{
//			if(response.isError || response.ResponseCode != 200)
//			{
//				//handle error msg
//				Debug.LogFormat("{0} request error({1}): {2}",
//					response.RequestURL, response.ResponseCode, response.ErrorMsg);
//				return;
//			}
//			//handle success
//			this.texResponse.text = response.GetResponseData();
//		}));
    }
Exemplo n.º 9
0
        public void NullPropertyShouldGenerateWarning()
        {
            var nullableSchema = this.SchemaForNullTest(expectNulls: false);

            var exampleObj = new
            {
                prop1 = (string)null,
                prop2 = 12345
            };


            string json        = JsonConvert.SerializeObject(exampleObj);
            var    testExample = new JsonExample(json);
            var    issues      = new IssueLogger();

            Assert.IsFalse(nullableSchema.ValidateJson(testExample, issues, new Dictionary <string, JsonSchema>(), new ValidationOptions()));
            Assert.AreEqual(1, issues.Issues.Count());

            var error = issues.Issues.First();

            Assert.AreEqual(ValidationErrorCode.NullPropertyValue, error.Code);
        }
Exemplo n.º 10
0
 private void ExampleTest()
 {
     JsonExample example = new JsonExample();
     Debug.Log("Test InputOutputFileTest done");
 }
Exemplo n.º 11
0
    private void ExampleTest()
    {
        JsonExample example = new JsonExample();

        Debug.Log("Test InputOutputFileTest done");
    }
        public void Responder_SendJson_Sends_JSONP_File_Correctly()
        {
            var original = new JsonExample() { IntegerField = 102, DateField = new DateTime(2011, 11, 3, 4, 5, 6, 789) };

            _Responder.SendJson(_Response.Object, original, "mycallback");

            var text = Encoding.UTF8.GetString(_OutputStream.ToArray());
            Assert.AreNotEqual(0, text.Length);
            Assert.AreEqual(text.Length, _Response.Object.ContentLength);

            Assert.IsTrue(text.StartsWith("mycallback("));
            Assert.IsTrue(text.EndsWith(")"));
            text = text.Substring(11, text.Length - 12);

            JsonExample copy;
            using(var stream = new MemoryStream(Encoding.UTF8.GetBytes(text))) {
                DataContractJsonSerializer serialiser = new DataContractJsonSerializer(typeof(JsonExample));
                copy = (JsonExample)serialiser.ReadObject(stream);
            }

            Assert.AreEqual(MimeType.Json, _Response.Object.MimeType);
            Assert.AreEqual(HttpStatusCode.OK, _Response.Object.StatusCode);

            Assert.AreEqual(102, copy.IntegerField);
            Assert.AreEqual(new DateTime(2011, 11, 3, 4, 5, 6, 789), copy.DateField);

            _Response.Verify(r => r.AddHeader("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate"), Times.Once());
        }