本文整理汇总了C#中Xunit.JsonDeserializer类的典型用法代码示例。如果您正苦于以下问题:C# JsonDeserializer类的具体用法?C# JsonDeserializer怎么用?C# JsonDeserializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonDeserializer类属于Xunit命名空间,在下文中一共展示了JsonDeserializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Ignore_Protected_Property_That_Exists_In_Data
public void Ignore_Protected_Property_That_Exists_In_Data() {
var doc = CreateJson();
var d = new JsonDeserializer();
var p = d.Deserialize<PersonForJson>(doc);
Assert.Null(p.IgnoreProxy);
}
示例2: Can_Deserialize_JScript_Json_Dates
public void Can_Deserialize_JScript_Json_Dates()
{
var doc = CreateJScriptDateJson();
var d = new JsonDeserializer();
var bd = d.Deserialize<Birthdate>(doc);
Assert.Equal(new DateTime(1910, 9, 25, 9, 30, 25, DateTimeKind.Utc), bd.Value);
}
示例3: Can_Deserialize_Json_MySql_Php_Date
public void Can_Deserialize_Json_MySql_Php_Date()
{
var doc = new JObject();
doc["StartDate"] = "2010-01-10 14:23:54";
var d = new JsonDeserializer();
var p = d.Deserialize<PersonForJson>(doc.ToString());
Assert.Equal(DateTime.Parse("01-10-2010 14:23:54"), p.StartDate);
}
示例4: Can_Deserialize_Guid_String_Fields
public void Can_Deserialize_Guid_String_Fields()
{
var doc = new JObject();
doc["Guid"] = "b1457983-8c5c-4c11-b10e-58585ed646d2";
var d = new JsonDeserializer();
var p = d.Deserialize<PersonForJson>(doc.ToString());
Assert.Equal(new Guid("b1457983-8c5c-4c11-b10e-58585ed646d2"), p.Guid);
}
示例5: Can_Deserialize_Empty_Elements_to_Nullable_Values
public void Can_Deserialize_Empty_Elements_to_Nullable_Values()
{
var doc = CreateJsonWithNullValues();
var json = new JsonDeserializer();
var output = json.Deserialize<NullableValues>(new RestResponse { Content = doc });
Assert.Null(output.Id);
Assert.Null(output.StartDate);
Assert.Null(output.UniqueId);
}
示例6: Can_Deserialize_4sq_Json_With_Root_Element_Specified
public void Can_Deserialize_4sq_Json_With_Root_Element_Specified()
{
var doc = File.ReadAllText(Path.Combine("SampleData", "4sq.txt"));
var json = new JsonDeserializer();
json.RootElement = "response";
var output = json.Deserialize<VenuesResponse>(new RestResponse { Content = doc });
Assert.NotEmpty(output.Groups);
}
示例7: Can_Deserialize_DateTime
public void Can_Deserialize_DateTime()
{
var doc = File.ReadAllText(Path.Combine("SampleData", "datetimes.txt"));
var d = new JsonDeserializer();
var response = new RestResponse { Content = doc };
var payload = d.Deserialize<DateTimeTestStructure>(response);
Assert.Equal(
new DateTime(2011, 6, 30, 8, 15, 46, DateTimeKind.Utc).ToString("u"),
payload.DateTime.ToString("u"));
}
示例8: Can_Deserialize_Elements_to_Nullable_Values
public void Can_Deserialize_Elements_to_Nullable_Values()
{
var doc = CreateJsonWithoutEmptyValues();
var json = new JsonDeserializer();
var output = json.Deserialize<NullableValues>(new RestResponse { Content = doc });
Assert.NotNull(output.Id);
Assert.NotNull(output.StartDate);
Assert.NotNull(output.UniqueId);
Assert.Equal(123, output.Id);
Assert.Equal(new DateTime(2010, 2, 21, 9, 35, 00), output.StartDate);
Assert.Equal(new Guid(GuidString), output.UniqueId);
}
示例9: Can_Deserialize_Custom_Formatted_Date
public void Can_Deserialize_Custom_Formatted_Date()
{
var format = "dd yyyy MMM, hh:mm ss tt";
var date = new DateTime(2010, 2, 8, 11, 11, 11);
var formatted = new {
StartDate = date.ToString(format)
};
var data = JsonConvert.SerializeObject(formatted);
var response = new RestResponse { Content = data };
var json = new JsonDeserializer { DateFormat = format };
var output = json.Deserialize<PersonForJson>(response);
Assert.Equal(date, output.StartDate);
}
示例10: Can_Deserialize_Names_With_Underscores_With_Default_Root
public void Can_Deserialize_Names_With_Underscores_With_Default_Root() {
var doc = CreateJsonWithUnderscores();
var d = new JsonDeserializer();
var p = d.Deserialize<PersonForJson>(doc);
Assert.Equal("John Sheehan", p.Name);
Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
Assert.Equal(28, p.Age);
Assert.Equal(long.MaxValue, p.BigNumber);
Assert.Equal(99.9999m, p.Percent);
Assert.Equal(false, p.IsCool);
Assert.NotNull(p.Friends);
Assert.Equal(10, p.Friends.Count);
Assert.NotNull(p.BestFriend);
Assert.Equal("The Fonz", p.BestFriend.Name);
Assert.Equal(1952, p.BestFriend.Since);
Assert.NotEmpty(p.Foes);
Assert.Equal("Foe 1", p.Foes["dict1"].Nickname);
Assert.Equal("Foe 2", p.Foes["dict2"].Nickname);
}
示例11: Can_Deserialize_Simple_Generic_List_of_Simple_Types_With_Nulls
public void Can_Deserialize_Simple_Generic_List_of_Simple_Types_With_Nulls()
{
const string content = "{\"users\":[\"johnsheehan\",\"jagregory\",null,\"drusellers\",\"structuremap\"]}";
var json = new JsonDeserializer { RootElement = "users" };
var output = json.Deserialize<List<string>> (new RestResponse { Content = content });
Assert.NotEmpty (output);
Assert.Equal (null, output[2]);
Assert.Equal (5, output.Count);
}
示例12: Can_Deserialize_Simple_Generic_List_Given_Toplevel_Item_Without_Array
public void Can_Deserialize_Simple_Generic_List_Given_Toplevel_Item_Without_Array()
{
const string content = "\"johnsheehan\"";
var json = new JsonDeserializer ();
var output = json.Deserialize<List<string>> (new RestResponse { Content = content });
Assert.True (output.SequenceEqual (new[] { "johnsheehan" }));
}
示例13: Can_Deserialize_Root_Json_Array_To_List
public void Can_Deserialize_Root_Json_Array_To_List()
{
var data = File.ReadAllText(Path.Combine("SampleData", "jsonarray.txt"));
var response = new RestResponse { Content = data };
var json = new JsonDeserializer();
var output = json.Deserialize<List<status>>(response);
Assert.Equal(4, output.Count);
}
示例14: Can_Deserialize_Quoted_Primitive
public void Can_Deserialize_Quoted_Primitive()
{
var doc = new JObject();
doc["Age"] = "28";
var d = new JsonDeserializer();
var response = new RestResponse { Content = doc.ToString() };
var p = d.Deserialize<PersonForJson>(response);
Assert.Equal(28, p.Age);
}
示例15: Can_Deserialize_Root_Json_Array_To_List
public void Can_Deserialize_Root_Json_Array_To_List()
{
var data = File.ReadAllText(@"..\..\SampleData\jsonarray.txt");
var json = new JsonDeserializer();
var output = json.Deserialize<List<status>>(data);
Assert.Equal(4, output.Count);
}