Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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.");
        }