Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
    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();
    }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }