本文整理汇总了C#中Newtonsoft.Json.Schema.JSchemaValidatingReader.ReadAsDateTimeOffset方法的典型用法代码示例。如果您正苦于以下问题:C# JSchemaValidatingReader.ReadAsDateTimeOffset方法的具体用法?C# JSchemaValidatingReader.ReadAsDateTimeOffset怎么用?C# JSchemaValidatingReader.ReadAsDateTimeOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Schema.JSchemaValidatingReader
的用法示例。
在下文中一共展示了JSchemaValidatingReader.ReadAsDateTimeOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDateTimes_ReadAsDateTimeOffset
public void ReadDateTimes_ReadAsDateTimeOffset()
{
string schemaJson = @"{
""type"":""array"",
""items"":{
""type"":""string"",
""minLength"":21
}
}";
string json = @"[
""2000-12-02T05:06:02+00:00"",
""2000-12-02T05:06:02Z"",
1
]";
SchemaValidationEventArgs a = null;
JSchemaValidatingReader reader = new JSchemaValidatingReader(new JsonTextReader(new StringReader(json)));
reader.ValidationEventHandler += (sender, args) => { a = args; };
reader.Schema = JSchema.Parse(schemaJson);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsNull(a);
reader.ReadAsDateTimeOffset();
Assert.AreEqual(JsonToken.Date, reader.TokenType);
Assert.IsNull(a);
reader.ReadAsString();
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.IsNotNull(a);
StringAssert.AreEqual(@"String '2000-12-02T05:06:02Z' is less than minimum length of 21. Path '[1]', line 3, position 25.", a.Message);
Assert.AreEqual("2000-12-02T05:06:02Z", a.ValidationError.Value);
a = null;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.IsNotNull(a);
StringAssert.AreEqual("Invalid type. Expected String but got Integer. Path '[2]', line 4, position 4.", a.Message);
Assert.AreEqual(1, a.ValidationError.Value);
a = null;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsNull(a);
}