示例#1
0
        public void WriteJsonGeneric()
        {
            StringWriter   sw         = new StringWriter();
            JsonTextWriter jsonWriter = new JsonTextWriter(sw);

            TestGenericConverter converter = new TestGenericConverter();

            converter.WriteJson(jsonWriter, "String!", null);

            Assert.AreEqual(@"""String!""", sw.ToString());
        }
示例#2
0
        public void WriteJsonBadType()
        {
            StringWriter   sw         = new StringWriter();
            JsonTextWriter jsonWriter = new JsonTextWriter(sw);

            TestGenericConverter converter = new TestGenericConverter();

            ExceptionAssert.Throws <JsonSerializationException>(() =>
            {
                converter.WriteJson(jsonWriter, 123, null);
            }, "Converter cannot write specified value to JSON. System.String is required.");
        }
示例#3
0
        public void ReadJsonObjectExistingValueNull()
        {
            StringReader   sr         = new StringReader("'String!'");
            JsonTextReader jsonReader = new JsonTextReader(sr);

            jsonReader.Read();

            TestGenericConverter converter = new TestGenericConverter();
            string s = (string)converter.ReadJson(jsonReader, typeof(string), null, null);

            Assert.AreEqual(@"String!", s);
        }
示例#4
0
        public void ReadJsonGenericExistingValueString()
        {
            StringReader   sr         = new StringReader("'String!'");
            JsonTextReader jsonReader = new JsonTextReader(sr);

            jsonReader.Read();

            TestGenericConverter converter = new TestGenericConverter();
            string s = converter.ReadJson(jsonReader, typeof(string), "Existing!", true, null);

            Assert.AreEqual(@"String!Existing!", s);
        }
示例#5
0
        public void ReadJsonObjectExistingValueWrongType()
        {
            StringReader   sr         = new StringReader("'String!'");
            JsonTextReader jsonReader = new JsonTextReader(sr);

            jsonReader.Read();

            TestGenericConverter converter = new TestGenericConverter();

            ExceptionAssert.Throws <JsonSerializationException>(() =>
            {
                converter.ReadJson(jsonReader, typeof(string), 12345, null);
            }, "Converter cannot read JSON with the specified existing value. System.String is required.");
        }