• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RestResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RestResponse的典型用法代码示例。如果您正苦于以下问题:C# RestResponse类的具体用法?C# RestResponse怎么用?C# RestResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RestResponse类属于命名空间,在下文中一共展示了RestResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
        }
开发者ID:florinn,项目名称:RestSharp,代码行数:29,代码来源:XmlTests.cs


示例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);
        }
开发者ID:khasan,项目名称:RestSharp,代码行数:27,代码来源:NamespacedXmlTests.cs


示例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);
 }
开发者ID:pcl,项目名称:hammock,代码行数:8,代码来源:SerializationTests.cs


示例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);
 }
开发者ID:pcl,项目名称:hammock,代码行数:8,代码来源:SerializationTests.cs


示例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);
        }
开发者ID:BerndK,项目名称:RestSharp,代码行数:9,代码来源:XmlTests.cs


示例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"));
        }
开发者ID:89sos98,项目名称:RestSharp,代码行数:11,代码来源:JsonTests.cs


示例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);
        }
开发者ID:ntziolis,项目名称:RestSharp,代码行数:11,代码来源:XmlTests.cs


示例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);
            }
        }
开发者ID:pcl,项目名称:hammock,代码行数:14,代码来源:SerializationTests.cs


示例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);
        }
开发者ID:geoffreysimpson,项目名称:RestSharp,代码行数:18,代码来源:JsonTests.cs


示例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);
        }
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:20,代码来源:NamespacedXmlTests.cs


示例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);
        }
开发者ID:geoffreysimpson,项目名称:RestSharp,代码行数:20,代码来源:XmlTests.cs


示例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);
        }
开发者ID:khasan,项目名称:RestSharp,代码行数:20,代码来源:XmlTests.cs


示例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);
        }
开发者ID:t9mike,项目名称:RestSharp,代码行数:9,代码来源:JsonTests.cs


示例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");
        }
开发者ID:t9mike,项目名称:RestSharp,代码行数:12,代码来源:JsonTests.cs


示例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"]);
        }
开发者ID:t9mike,项目名称:RestSharp,代码行数:12,代码来源:JsonTests.cs


示例16: Can_Deserialize_TimeSpan

        public void Can_Deserialize_TimeSpan()
        {
            var doc = File.ReadAllText(Path.Combine("SampleData", "timespans.txt"));
                var d = new JsonDeserializer();
                var response = new RestResponse { Content = doc };
                var payload = d.Deserialize<TimeSpanTestStructure>(response);

                Assert.Equal(new TimeSpan(468006), payload.Tick);
                Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
                Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
                Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
                Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
                Assert.Null(payload.NullableWithoutValue);
                Assert.NotNull(payload.NullableWithValue);
                Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
        }
开发者ID:t9mike,项目名称:RestSharp,代码行数:16,代码来源:JsonTests.cs


示例17: Can_Deserialize_Various_Enum_Values

        public void Can_Deserialize_Various_Enum_Values()
        {
            var data = File.ReadAllText (Path.Combine ("SampleData", "jsonenums.txt"));
            var response = new RestResponse { Content = data };
            var json = new JsonDeserializer ();
            var output = json.Deserialize<JsonEnumsTestStructure>(response);

            Assert.Equal (output.Upper, Disposition.Friendly);
            Assert.Equal (output.Lower, Disposition.Friendly);
            Assert.Equal (output.CamelCased, Disposition.SoSo);
            Assert.Equal (output.Underscores, Disposition.SoSo);
            Assert.Equal (output.LowerUnderscores, Disposition.SoSo);
            Assert.Equal (output.Dashes, Disposition.SoSo);
            Assert.Equal (output.LowerDashes, Disposition.SoSo);
        }
开发者ID:t9mike,项目名称:RestSharp,代码行数:15,代码来源:JsonTests.cs


示例18: Ignore_Protected_Property_That_Exists_In_Data

        public void Ignore_Protected_Property_That_Exists_In_Data()
        {
            var doc = CreateJson();
            var d = new JsonDeserializer();
            var response = new RestResponse { Content = doc };
            var p = d.Deserialize<PersonForJson>(response);

            Assert.Null(p.IgnoreProxy);
        }
开发者ID:t9mike,项目名称:RestSharp,代码行数:9,代码来源:JsonTests.cs


示例19: Can_Deserialize_TimeSpan

        public void Can_Deserialize_TimeSpan()
        {
            var culture = CultureInfo.InvariantCulture;
            var doc = new XDocument(culture);

            TimeSpan? nullTimespan = null;
            TimeSpan? nullValueTimeSpan = new TimeSpan(21, 30, 7);

            var root = new XElement("Person");
            root.Add(new XElement("Tick", new TimeSpan(468006)));
            root.Add(new XElement("Millisecond", new TimeSpan(0, 0, 0, 0, 125)));
            root.Add(new XElement("Second", new TimeSpan(0, 0, 8)));
            root.Add(new XElement("Minute", new TimeSpan(0, 55, 2)));
            root.Add(new XElement("Hour", new TimeSpan(21, 30, 7)));
            root.Add(new XElement("NullableWithoutValue", nullTimespan));
            root.Add(new XElement("NullableWithValue", nullValueTimeSpan));

            doc.Add(root);

            var xml = new XmlDeserializer
            {
                Culture = culture,
            };

            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlDeserializer()
            {
                Culture = culture,
            };
            var payload = d.Deserialize<TimeSpanTestStructure>(response);
            Assert.Equal(new TimeSpan(468006), payload.Tick);
            Assert.Equal(new TimeSpan(0, 0, 0, 0, 125), payload.Millisecond);
            Assert.Equal(new TimeSpan(0, 0, 8), payload.Second);
            Assert.Equal(new TimeSpan(0, 55, 2), payload.Minute);
            Assert.Equal(new TimeSpan(21, 30, 7), payload.Hour);
            Assert.Null(payload.NullableWithoutValue);
            Assert.NotNull(payload.NullableWithValue);
            Assert.Equal(new TimeSpan(21, 30, 7), payload.NullableWithValue.Value);
        }
开发者ID:ntziolis,项目名称:RestSharp,代码行数:40,代码来源:XmlTests.cs


示例20: Can_Deserialize_Google_Weather_Xml

        public void Can_Deserialize_Google_Weather_Xml()
        {
            var xmlpath = PathFor("GoogleWeather.xml");
            var doc = XDocument.Load(xmlpath);
            var response = new RestResponse { Content = doc.ToString() };

            var d = new XmlDeserializer();
            var output = d.Deserialize<SampleClasses.xml_api_reply>(response);

            Assert.NotEmpty(output.weather);
            Assert.Equal(4, output.weather.Count);
            Assert.Equal("Sunny", output.weather[0].condition.data);
        }
开发者ID:ntziolis,项目名称:RestSharp,代码行数:13,代码来源:XmlTests.cs



注:本文中的RestResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RestServiceClient类代码示例发布时间:2022-05-24
下一篇:
C# RestRequest类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap