当前位置: 首页>>代码示例>>C#>>正文


C# RestSharp.RestResponse类代码示例

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


RestResponse类属于RestSharp命名空间,在下文中一共展示了RestResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HttpRequest

        private CustomResponse HttpRequest(IRestRequest request, string url, Dictionary<string, string> parameters = null)
        {
            try
            {
                IRestClient client = new RestClient();
                IRestResponse response = new RestResponse();

                client.BaseUrl = new Uri(url);
                if (parameters != null)
                {
                    foreach (var item in parameters)
                    {
                        request.AddParameter(item.Key, item.Value);
                    }
                }
                response = client.Execute(request);
                var myResponse = new CustomResponse();
                myResponse.StatusCode = response.StatusCode;
                myResponse.Content = response.Content;
                return myResponse;
            }
            catch(Exception ex)
            {
                throw ex;
            }
            
        }
开发者ID:sudeshgutta,项目名称:SingleFuncRest,代码行数:27,代码来源:RestServices.cs

示例2: ListAll_PerformsCorrectRequest

        public void ListAll_PerformsCorrectRequest()
        {
            //Setup
            var request = new CategoriesStub("DevKey", "api.careerbuilder.com", "", "");

            //Mock crap
            var response = new RestResponse<List<Category>> {Data = new List<Category>()};

            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("CountryCode", "NL"));
            restReq.SetupSet(x => x.RootElement = "Categories");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/categories");
            restClient.Setup(x => x.Execute<List<Category>>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assert
            List<Category> cats = request.WhereCountryCode(CountryCode.NL).ListAll();
            Assert.IsTrue(cats.Count == 0);
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:tkling,项目名称:Careerbuilder.com-API-for-.Net,代码行数:26,代码来源:CategoriesRequestTest.cs

示例3: JSONDeserializationTest

        public void JSONDeserializationTest() {
            var path = Path.Combine(Environment.CurrentDirectory, "Schedule.json");
            var ds = new JsonDeserializer();
            var response = new RestResponse() { ContentType = "application/json", ResponseStatus = ResponseStatus.Completed, StatusCode = System.Net.HttpStatusCode.OK };

            // Read the file as one string.
            StreamReader myFile = new StreamReader(path);
            string json = myFile.ReadToEnd();
            myFile.Close();

            response.Content = json;

            var mySchedule = ds.Deserialize<Schedule>(response);

            Assert.IsNotNull(mySchedule);
            Assert.IsNotNull(mySchedule.escalation_policies);

            Assert.AreEqual("FS4LEQD", mySchedule.id);
            Assert.AreEqual("24x7 Schedule", mySchedule.name);
            Assert.AreEqual("UTC", mySchedule.time_zone);
            Assert.AreEqual(new DateTime(635726880000000000), mySchedule.today);
            Assert.AreEqual(1, mySchedule.escalation_policies.Count);
            Assert.AreEqual("PAD5HK6", mySchedule.escalation_policies[0].id);
            Assert.AreEqual("Escalation Policy - 24x7", mySchedule.escalation_policies[0].name);
        }
开发者ID:Famien,项目名称:PagerDuty.Net,代码行数:25,代码来源:ScheduleTests.cs

示例4: OnContentReceived

		private void OnContentReceived(string content) {
			JsonDeserializer deserializer = new JsonDeserializer();

			var response = new RestResponse();
			response.Content = content;

			MessageContent messageContent = null;
			try {
				messageContent = deserializer.Deserialize<MessageContent>(response);
			} catch {
				MessageContent = null;
			}

			if (messageContent != null) {
				MessageContent = messageContent;

				if (Event == "message" || Event == "comment") {
					ExtractedBody = messageContent.Text;
				}
			} else if(Event == "message") {
				ExtractedBody = content;
			}

			Displayable = ExtractedBody != null;

			TimeStamp = UnixTimeToLocal(Sent);
		}
开发者ID:pratik136,项目名称:Flowdock.NET,代码行数:27,代码来源:Message.cs

示例5: Submit_PerformsCorrectRequest

        public void Submit_PerformsCorrectRequest()
        {
            //setup
            var request = new SavedSearchRetrieveRequestStub("DevKey", "api.careerbuilder.com", "", "", 12345);
            var dummyApp = new SavedSearchRetrieveRequestModel();

            //Mock
            var response = new RestResponse<SavedSearchRetrieveResponseModel> { Data = new SavedSearchRetrieveResponseModel(), ResponseStatus = ResponseStatus.Completed };
            var restReq = new Mock<IRestRequest>();

            restReq.Setup(x => x.AddParameter("DeveloperKey", dummyApp.DeveloperKey));
            restReq.Setup(x => x.AddParameter("ExternalUserID", dummyApp.ExternalUserID));
            restReq.Setup(x => x.AddParameter("ExternalID", dummyApp.ExternalID));



            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/SavedSearch/retrieve");
            restClient.Setup(x => x.Execute<SavedSearchRetrieveResponseModel>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assertions
            SavedSearchRetrieveResponseModel rest = request.Submit(dummyApp);
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:NicholasBusby,项目名称:Careerbuilder.com-API-for-.Net,代码行数:28,代码来源:SavedSearchRetrieveRequestTest.cs

示例6: RunSubmitAdRequest_Returns_Empty_List_If_No_Ads

        public void RunSubmitAdRequest_Returns_Empty_List_If_No_Ads()
        {
            var mockery = new MockRepository();
              var restClient = mockery.StrictMock<IRestClient>();
              var restRequestFactory = mockery.StrictMock<IRestRequestFactory>();
              var restRequest = mockery.StrictMock<IRestRequest>();
              var serializer = mockery.Stub<ISerializer>();

              var str = "some data";

              var adRequest = new AdRequest { NetworkId = Guid.NewGuid().ToString() };

              var advertisementResponse = new AdvertisementResponseMessage { advertisement = null };
              var restResponse = new RestResponse<AdvertisementResponseMessage>();
              restResponse.Data = advertisementResponse;

              using (mockery.Record()) {
            Expect.Call(restRequestFactory.Create(null, Method.POST))
              .Constraints(Is.Anything(), Is.Equal(Method.POST))
              .Return(restRequest);
            restRequest.RequestFormat = DataFormat.Json;
            Expect.Call(restRequest.JsonSerializer).Return(serializer);
            Expect.Call(serializer.Serialize(null)).Constraints(
              Rhino.Mocks.Constraints.Property.Value("network_id", adRequest.NetworkId) &&
              Is.TypeOf<AdRequestMessage>()
            ).Return(str);
            Expect.Call(restRequest.AddParameter("text/json", str, ParameterType.RequestBody)).Return(new RestRequest());
            Expect.Call(restClient.Execute<AdvertisementResponseMessage>(restRequest)).Return(restResponse);
              }

              using (mockery.Playback()) {
            var results = new AdRequestor(restClient, restRequestFactory).RunSubmitAdRequest(adRequest);
            Assert.IsEmpty(results);
              }
        }
开发者ID:vistarmedia,项目名称:net-client,代码行数:35,代码来源:AdRequestorTest.cs

示例7: Deserialize

        public object Deserialize(RestResponse response)
        {
            var root = XDocument.Parse(response.Content).Root;
            var cities = root.Descendants("cities");

            var result = new CitySearchResult()
            {
                Cities = new SearchResultsList<City>()
                {
                    Total = int.Parse(root.Attribute("total").Value),
                    Page = int.Parse(root.Attribute("page").Value),
                    ItemsPerPage = int.Parse(root.Attribute("itemsPerPage").Value)
                }
            };

            result.Cities.AddRange(cities.Select(city => new City()
            {
                State = city.Attribute("state").Value,
                StateCode = city.Attribute("stateCode").Value,
                Name = city.Attribute("name").Value,
                Id = city.Attribute("id").Value,
                Coords = new Coordinates()
                {
                    Lat = double.Parse(city.Element("coords").Attribute("lat").Value),
                    Long = double.Parse(city.Element("coords").Attribute("long").Value)
                },
                Country = new Country()
                {
                    Code = city.Element("country").Attribute("code").Value,
                    Name = city.Element("country").Attribute("name").Value
                }
            }));

            return result;
        }
开发者ID:ravensorb,项目名称:SetlistFmApi,代码行数:35,代码来源:CitySearchResultXmlDeserializer.cs

示例8: MercadolibreItemsClientTest

		public MercadolibreItemsClientTest()
		{
			this.restClientMock = new Mock<MercadolibreRestClient> { CallBase = true };
			var response = new RestResponse<MeliSearchingData<Item>> { Data = new MeliSearchingData<Item>() };
			this.restClientMock.Setup(x => x.Execute<MeliSearchingData<Item>>(It.IsAny<IRestRequest>())).Returns(response);
			this.mercadolibreItemsClient = new MercadolibreItemsClient(this.restClientMock.Object);
		}
开发者ID:JuanchiRios,项目名称:listing-notes,代码行数:7,代码来源:MercadolibreItemsClientTest.cs

示例9: JSONDeserializationTest

        public void JSONDeserializationTest() {
            var path = Path.Combine(Environment.CurrentDirectory, "Incident.json");
            var ds = new JsonDeserializer();
            var response = new RestResponse() { ContentType = "application/json", ResponseStatus = ResponseStatus.Completed, StatusCode = System.Net.HttpStatusCode.OK };

            // Read the file as one string.
            StreamReader myFile = new StreamReader(path);
            string json = myFile.ReadToEnd();
            myFile.Close();
            
            response.Content = json;

            var myAlert = ds.Deserialize<Incident>(response);

            Assert.IsNotNull(myAlert);
            Assert.IsNotNull(myAlert.service);
            Assert.IsNotNull(myAlert.last_status_change_by);
            
            Assert.AreEqual("1", myAlert.incident_number);
            Assert.AreEqual(new DateTime(634830005610000000), myAlert.created_on);
            Assert.AreEqual("resolved", myAlert.status);
            Assert.AreEqual("https://acme.pagerduty.com/incidents/P2A6J96", myAlert.html_url);
            Assert.AreEqual(null, myAlert.incident_key);
            Assert.AreEqual(null, myAlert.assigned_to_user);
            Assert.AreEqual("https://acme.pagerduty.com/incidents/P2A6J96/log_entries/P2NQP6P", myAlert.trigger_details_html_url);
            Assert.AreEqual(new DateTime(634830006590000000), myAlert.last_status_change_on);
        }
开发者ID:jameswestbv,项目名称:PagerDuty.Net,代码行数:27,代码来源:IncidentTests.cs

示例10: RestRequest

        /// <summary>
        /// Override the method which does the actually call against the Tictail API using REST client
        /// These are both 3-party and should be working just fine
        /// </summary>
        /// <param name="request">RestRequst, is not needed for this</param>
        /// <returns>A RestResonse object</returns>
        protected override IRestResponse RestRequest(IRestRequest request)
        {
            IRestResponse response = new RestResponse();
            response.StatusCode = StatusCode;
            response.ResponseStatus = ResponseStatus;
            response.Content = Content;

            if (ResponseHeaders == null)
            {
                return response;
            }

            foreach (var header in ResponseHeaders)
            {
                response.Headers.Add(new Parameter()
                {
                    Name = header.Key,
                    Value = header.Value,
                    Type = ParameterType.HttpHeader
                });

            }

            return response;
        }
开发者ID:skjohansen,项目名称:TictailSharp,代码行数:31,代码来源:TictailClientTest.cs

示例11: GetRecommendations_PerformsCorrectRequest

        public void GetRecommendations_PerformsCorrectRequest() {
            //Setup
            var request = new JobRecWithUserPrefRequestStub("J1234567890123456789", "U1234567890123456789",
                "DevKey", "api.careerbuilder.com", "", "");

            //Mock crap
            var response = new RestResponse<List<RecommendJobResult>> { Data = new List<RecommendJobResult>() };

            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("JobDID", "J1234567890123456789"));
            restReq.Setup(x => x.AddParameter("UserDID", "U1234567890123456789"));
            restReq.SetupSet(x => x.RootElement = "RecommendJobResults");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/recommendations/forjobwithuserprefs");
            restClient.Setup(x => x.Execute<List<RecommendJobResult>>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assert
            List<RecommendJobResult> resp = request.GetRecommendations();
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:tkling,项目名称:Careerbuilder.com-API-for-.Net,代码行数:26,代码来源:JobRecommendationsWithUserPreferencesRequestTest.cs

示例12: Retrieve_PerformsCorrectRequest

        public void Retrieve_PerformsCorrectRequest()
        {
            //Setup
            var request = new BlankAppStub("JXXXXXXXXXXXXXXXXXX", "DevKey", "api.careerbuilder.com", "", "");

            //Mock crap
            var response = new RestResponse<BlankApplication> {Data = new BlankApplication()};

            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("JobDID", "JXXXXXXXXXXXXXXXXXX"));
            restReq.SetupSet(x => x.RootElement = "BlankApplication");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/application/blank");
            restClient.Setup(x => x.Execute<BlankApplication>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assert
            BlankApplication resp = request.Retrieve();
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:tkling,项目名称:Careerbuilder.com-API-for-.Net,代码行数:25,代码来源:BlankApplicationTest.cs

示例13: Search_PerformsCorrectRequest

        public void Search_PerformsCorrectRequest()
        {
            //Setup
            JobSearchStub request = new JobSearchStub("DevKey", "api.careerbuilder.com","","");
            
            //Mock crap
            RestResponse<ResponseJobSearch> response = new RestResponse<ResponseJobSearch>();
            response.Data = new ResponseJobSearch();
                        
            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("CountryCode", "NL"));
            restReq.SetupSet(x => x.RootElement = "ResponseJobSearch");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/jobsearch");
            restClient.Setup(x => x.Execute<ResponseJobSearch>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;
            
            //Assert
            ResponseJobSearch resp = request.WhereCountryCode(CountryCode.NL).Search();
            restReq.Verify();
            restClient.VerifyAll();
        }
开发者ID:stevenwu2012,项目名称:Careerbuilder.com-API-for-.Net,代码行数:26,代码来源:JobSearchRequestTest.cs

示例14: Submit_PerformsCorrectRequest

        public void Submit_PerformsCorrectRequest()
        {
            //setup
            var request = new SavedSearchCreateRequestStub("DevKey", "api.careerbuilder.com", "", "", 12345);
            var dummyApp = new SavedSearchCreate();
            dummyApp = SetUpApp(dummyApp);

            //Mock
            var response = new RestResponse<SavedSearchCreateResponse> { Data = new SavedSearchCreateResponse(), ResponseStatus = ResponseStatus.Completed };
            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddBody(dummyApp));

            

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v2/SavedSearch/Create");
            restClient.Setup(x => x.Execute<SavedSearchCreateResponse>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assertions
            SavedSearchCreateResponse rest = request.Submit(dummyApp);
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:usbsnowcrash,项目名称:Careerbuilder.Net,代码行数:26,代码来源:SavedSearchCreateRequestTest.cs

示例15: Retrieve_AddsProperHeaders

        public void Retrieve_AddsProperHeaders()
        {
            //Setup
            var site = new TargetSiteMock("10.0.0.1") { SetHost = "api.koolkid.com", SetSecure = true };
            site.SetHeaders.Add("ILikeHeaders", "true");

            var request = new BlankAppStub("JXXXXXXXXXXXXXXXXXX", "DevKey", "api.careerbuilder.com", "",site);

            //Mock crap
            var response = new RestResponse<BlankApplication> {Data = new BlankApplication()};

            var restReq = new Mock<IRestRequest>();
            restReq.Setup(x => x.AddHeader("Host", "api.koolkid.com"));
            restReq.Setup(x => x.AddHeader("ILikeHeaders", "true"));
            restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
            restReq.Setup(x => x.AddParameter("JobDID", "JXXXXXXXXXXXXXXXXXX"));
            restReq.SetupSet(x => x.RootElement = "BlankApplication");

            var restClient = new Mock<IRestClient>();
            restClient.SetupSet(x => x.BaseUrl = "https://10.0.0.1/v1/application/blank");
            restClient.Setup(x => x.Execute<BlankApplication>(It.IsAny<IRestRequest>())).Returns(response);

            request.Request = restReq.Object;
            request.Client = restClient.Object;

            //Assert
            BlankApplication resp = request.Retrieve();
            restReq.VerifyAll();
            restClient.VerifyAll();
        }
开发者ID:NicholasBusby,项目名称:Careerbuilder.com-API-for-.Net,代码行数:30,代码来源:TargetSiteTest.cs


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