本文整理汇总了C#中RestResponse类的典型用法代码示例。如果您正苦于以下问题:C# RestResponse类的具体用法?C# RestResponse怎么用?C# RestResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestResponse类属于命名空间,在下文中一共展示了RestResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_Deserialize_Attributes_Without_Matching_Case_On_Default_Root
public void Can_Deserialize_Attributes_Without_Matching_Case_On_Default_Root()
{
var doc = CreateLowercaseDashesXml();
var response = new RestResponse { Content = doc };
var d = new XmlDeserializer();
var p = d.Deserialize<PersonForXml>(response);
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.Equal(new Guid(GuidString), p.UniqueId);
Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
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.NotNull(p.Foes);
Assert.Equal(5, p.Foes.Count);
Assert.Equal("Yankees", p.Foes.Team);
}
示例2: Can_Deserialize_Elements_With_Namespace
public void Can_Deserialize_Elements_With_Namespace()
{
var doc = CreateElementsXml();
var response = new RestResponse { Content = doc };
var d = new XmlDeserializer();
d.Namespace = "http://restsharp.org";
var p = d.Deserialize<PersonForXml>(response);
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.Equal(new Guid(GuidString), p.UniqueId);
Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
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);
}
示例3: Can_deserialize_to_dynamic_collection
public void Can_deserialize_to_dynamic_collection()
{
var serializer = new JsonSerializer();
var response = new RestResponse<JsonObject>();
response.SetContent(DoubleInput);
var proxy = serializer.DeserializeDynamic(response);
Assert.IsNotNull(proxy);
}
示例4: Can_deserialize_to_dynamic_single
public void Can_deserialize_to_dynamic_single()
{
var serializer = new DefaultJsonSerializer();
var response = new RestResponse<dynamic>();
response.SetContent(SingleInput);
var proxy = serializer.DeserializeDynamic(response);
Assert.IsNotNull(proxy);
}
示例5: Can_Deserialize_AcoustID_Xml
public void Can_Deserialize_AcoustID_Xml()
{
var xmlpath = PathFor("AcoustID.xml");
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlDeserializer();
var output = d.Deserialize<MTB.Worker.AcoustID.Response>(response);
}
示例6: 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"));
}
示例7: Can_Deserialize_Boolean_From_Number
public void Can_Deserialize_Boolean_From_Number()
{
var xmlpath = PathFor("boolean_from_number.xml");
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlDeserializer();
var output = d.Deserialize<SampleClasses.BooleanTest>(response);
Assert.True(output.Value);
}
示例8: Can_deserialize_all_test_cases
public void Can_deserialize_all_test_cases()
{
var serializer = new DefaultJsonSerializer();
var files = Directory.GetFiles("Json", "*.json");
foreach(var file in files)
{
var json = File.ReadAllText(file);
var response = new RestResponse<dynamic>();
response.SetContent(json);
var proxy = serializer.DeserializeDynamic(response);
Assert.IsNotNull(proxy);
}
}
示例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_Attributes_With_Namespace
public void Can_Deserialize_Attributes_With_Namespace()
{
string doc = CreateAttributesXml();
RestResponse response = new RestResponse { Content = doc };
XmlDeserializer d = new XmlDeserializer { Namespace = "http://restsharp.org" };
PersonForXml p = d.Deserialize<PersonForXml>(response);
Assert.AreEqual("John Sheehan", p.Name);
Assert.AreEqual(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
Assert.AreEqual(28, p.Age);
Assert.AreEqual(long.MaxValue, p.BigNumber);
Assert.AreEqual(99.9999m, p.Percent);
Assert.AreEqual(false, p.IsCool);
Assert.AreEqual(new Guid(GUID_STRING), p.UniqueId);
Assert.AreEqual(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
Assert.AreEqual(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
Assert.NotNull(p.BestFriend);
Assert.AreEqual("The Fonz", p.BestFriend.Name);
Assert.AreEqual(1952, p.BestFriend.Since);
}
示例11: Can_Deserialize_Attributes_On_Default_Root
public void Can_Deserialize_Attributes_On_Default_Root()
{
var doc = CreateAttributesXml();
var response = new RestResponse { Content = doc };
var d = new XmlDeserializer();
var p = d.Deserialize<PersonForXml>(response);
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.Equal(new Guid(GuidString), p.UniqueId);
Assert.NotNull(p.BestFriend);
Assert.Equal("The Fonz", p.BestFriend.Name);
Assert.Equal(1952, p.BestFriend.Since);
}
示例12: Can_Deserialize_Custom_Formatted_Date
public void Can_Deserialize_Custom_Formatted_Date()
{
var format = "dd yyyy MMM, hh:mm ss tt zzz";
var date = new DateTime(2010, 2, 8, 11, 11, 11);
var doc = new XDocument();
var root = new XElement("Person");
root.Add(new XElement("StartDate", date.ToString(format)));
doc.Add(root);
var xml = new XmlDeserializer();
xml.DateFormat = format;
var response = new RestResponse { Content = doc.ToString() };
var output = xml.Deserialize<PersonForXml>(response);
Assert.Equal(date, output.StartDate);
}
示例13: Can_Deserialize_Unix_Json_Dates
public void Can_Deserialize_Unix_Json_Dates()
{
var doc = CreateUnixDateJson();
var d = new JsonDeserializer();
var response = new RestResponse { Content = doc };
var bd = d.Deserialize<Birthdate>(response);
Assert.Equal(new DateTime(2011, 6, 30, 8, 15, 46, DateTimeKind.Utc), bd.Value);
}
示例14: Can_Deserialize_To_Dictionary_String_String
public void Can_Deserialize_To_Dictionary_String_String()
{
var doc = CreateJsonStringDictionary();
var d = new JsonDeserializer();
var response = new RestResponse { Content = doc };
var bd = d.Deserialize<Dictionary<string,string>>(response);
Assert.Equal(bd["Thing1"], "Thing1");
Assert.Equal(bd["Thing2"], "Thing2");
Assert.Equal(bd["ThingRed"], "ThingRed");
Assert.Equal(bd["ThingBlue"], "ThingBlue");
}
示例15: Can_Deserialize_To_Dictionary_String_String_With_Dynamic_Values
public void Can_Deserialize_To_Dictionary_String_String_With_Dynamic_Values()
{
var doc = CreateDynamicJsonStringDictionary ();
var d = new JsonDeserializer ();
var response = new RestResponse { Content = doc };
var bd = d.Deserialize<Dictionary<string, string>> (response);
Assert.Equal ("[\"Value1\",\"Value2\"]", bd["Thing1"]);
Assert.Equal ("Thing2", bd["Thing2"]);
Assert.Equal ("{\"Name\":\"ThingRed\",\"Color\":\"Red\"}", bd["ThingRed"]);
Assert.Equal ("{\"Name\":\"ThingBlue\",\"Color\":\"Blue\"}", bd["ThingBlue"]);
}