public void ContentType_Additional_Information() { _server.SetHandler(Handlers.Generic <ResponseHandler>()); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json, Resource = "contenttype_odata" }; request.AddBody("bodyadsodajjd"); request.AddHeader("X-RequestDigest", "xrequestdigestasdasd"); request.AddHeader("Accept", $"{ContentType.Json}; odata=verbose"); request.AddHeader("Content-Type", $"{ContentType.Json}; odata=verbose"); var response = _client.Execute <Response>(request); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public async Task ContentType_Additional_Information() { _server.SetHandler(Handlers.Generic <ResponseHandler>()); var request = new RestRequest("", Method.Post) { RequestFormat = DataFormat.Json, Resource = "contenttype_odata" }; request.AddBody("bodyadsodajjd"); request.AddHeader("X-RequestDigest", "xrequestdigestasdasd"); request.AddHeader(KnownHeaders.Accept, $"{ContentType.Json}; odata=verbose"); request.AddHeader(KnownHeaders.ContentType, $"{ContentType.Json}; odata=verbose"); var response = await _client.ExecuteAsync <TestResponse>(request); response.StatusCode.Should().Be(HttpStatusCode.OK); response.IsSuccessful.Should().BeTrue(); }
public void Handles_Different_Root_Element_On_Http_Error() { _server.SetHandler(Handlers.Generic <ResponseHandler>()); RestRequest request = new RestRequest("error") { RootElement = "Success" }; request.OnBeforeDeserialization = resp => { if (resp.StatusCode == HttpStatusCode.BadRequest) { request.RootElement = "Error"; } }; IRestResponse <Response> response = _client.Execute <Response>(request); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); Assert.AreEqual("Not found!", response.Data.Message); }
public void Copy_RootElement_From_Request_To_IWithRootElement_Deserializer() { _server.SetHandler(Handlers.Generic <ResponseHandler>()); RestRequest request = new RestRequest("success") { RootElement = "Success" }; var deserializer = new CustomDeserializer(); _client.AddHandler(ContentType.Xml, () => deserializer); _client.Execute <Response>(request); Assert.AreEqual(deserializer.RootElement, request.RootElement); }