예제 #1
0
        //[TestMethodWithReport]
        public void TestGetWithXml_Deserialize()
        {
            IRestClient  restClient  = new RestClient();
            IRestRequest restRequest = new RestRequest(getUrl);

            restRequest.AddHeader("Accept", "application/xml");

            var dotNetXmlDeserializer = new RestSharp.Deserializers.DotNetXmlDeserializer();

            //IRestResponse<LaptopDetailss> restResponse = restClient.Get<LaptopDetailss>(restRequest);
            IRestResponse restResponse = restClient.Get(restRequest);

            if (restResponse.IsSuccessful)
            {
                Console.WriteLine("Status Code " + restResponse.StatusCode);
                Assert.AreEqual(200, (int)restResponse.StatusCode);

                LaptopDetailss data = dotNetXmlDeserializer.Deserialize <LaptopDetailss>(restResponse);
                Console.WriteLine("Size of List " + data.Laptop.Count);

                Laptop laptop = data.Laptop.Find((x) =>
                {
                    return(x.Id.Equals("1", StringComparison.OrdinalIgnoreCase));
                });

                Assert.AreEqual("Alienware M17", laptop?.LaptopName);
                Assert.IsTrue(laptop.Features.Feature.Contains("Windows 10 Home 64 - bit English"), "Element is not Present");
            }
            else
            {
                Console.WriteLine("Error Msg " + restResponse.ErrorMessage);
                Console.WriteLine("Stack Trace " + restResponse.ErrorException);
            }
        }
예제 #2
0
        public void TestGetWithXmlDeserialize()
        {
            IRestClient  restClient  = new RestClient();
            IRestRequest restRequest = new RestRequest(getUrl);

            restRequest.AddHeader("Accept", "application/xml");

            var dotNetXmlDeserializer = new RestSharp.Deserializers.DotNetXmlDeserializer();

            //IRestResponse<LaptopDetailss> restResponse = restClient.Get<LaptopDetailss>(restRequest);
            IRestResponse restResponse = restClient.Get(restRequest);

            if (restResponse.IsSuccessful)
            {
                Assert.Equal(200, (int)restResponse.StatusCode);

                //  restResponse.Data retorna o objeto depois da deserialização
                LaptopDetailss data = dotNetXmlDeserializer.Deserialize <LaptopDetailss>(restResponse);

                Laptop laptop = data.Laptop.Find((x) =>
                {
                    return(x.Id.Equals("1", StringComparison.OrdinalIgnoreCase));
                });

                Assert.Equal("Alienware M17", laptop.LaptopName);
                Assert.Contains("8th Generation Intel® Core™ i5-8300H", laptop.Features.Feature);
            }
            else
            {
                output.WriteLine("Error msg: " + restResponse.ErrorMessage);
                output.WriteLine("Stack Trace: " + restResponse.ErrorException);
            }
        }
예제 #3
0
        public void DeserializationOfXmlResponseTest()
        {
            Uri getUri = new Uri("http://localhost:8080/laptop-bag/webapi/api/all");

            using (HttpClient httpclient = new HttpClient())
            {
                using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage())
                {
                    httpRequestMessage.Method     = HttpMethod.Get;
                    httpRequestMessage.RequestUri = getUri;
                    httpRequestMessage.Headers.Add("accept", "application/xml");

                    Task <HttpResponseMessage> httpResponse = httpclient.SendAsync(httpRequestMessage);
                    using (HttpResponseMessage httpResponseMessage = httpResponse.Result)
                    {
                        RestResponse restResponse = new RestResponse((int)httpResponseMessage.StatusCode, httpResponseMessage.Content.ReadAsStringAsync().Result);
                        Console.WriteLine(restResponse.ToString());
                        XmlSerializer  serializer = new XmlSerializer(typeof(LaptopDetailss));
                        TextReader     textReader = new StringReader(restResponse.ResponseData);
                        LaptopDetailss xmlData    = (LaptopDetailss)serializer.Deserialize(textReader);
                        // Console.WriteLine(xmlData.ToString());
                        Assert.AreEqual(200, restResponse.StatusCode);
                        Assert.AreEqual("Alienware", xmlData.Laptop[0].BrandName);
                    }
                }
            }
        }
예제 #4
0
        public void TestDeserilizationOfXmlResponse()
        {
            using (HttpClient httpClient = new HttpClient())
            {
                using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage())
                {
                    httpRequestMessage.RequestUri = new Uri(getUrl);
                    httpRequestMessage.Method     = HttpMethod.Get;
                    httpRequestMessage.Headers.Add("Accept", "application/xml");

                    Task <HttpResponseMessage> httpResponse = httpClient.SendAsync(httpRequestMessage);

                    using (HttpResponseMessage httpResponseMessage = httpResponse.Result)
                    {
                        Console.WriteLine(httpResponseMessage.ToString());


                        //status code
                        HttpStatusCode statusCode = httpResponseMessage.StatusCode;
                        //Console.WriteLine("Status code " + statusCode);
                        //Console.WriteLine("Status code " + (int)statusCode);

                        //response data
                        HttpContent   responseContent = httpResponseMessage.Content;
                        Task <string> responseData    = responseContent.ReadAsStringAsync();
                        String        data            = responseData.Result;
                        //Console.WriteLine(data);

                        RestResponse restResponse = new RestResponse((int)statusCode, responseData.Result);
                        //Console.WriteLine(restResponse.ToString());

                        //step 1
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(LaptopDetailss));

                        //step 2
                        TextReader textReader = new StringReader(restResponse.ResponseContent);

                        //step 3
                        LaptopDetailss xmlData = (LaptopDetailss)xmlSerializer.Deserialize(textReader);
                        Console.WriteLine(xmlData.ToString());

                        //1st checkpoint (assertion) for statu code
                        Assert.AreEqual(200, restResponse.StatusCode);


                        //2nd check point (assertion) for response data
                        Assert.IsNotNull(restResponse.ResponseContent);

                        //3rd assertion
                        Assert.IsTrue(xmlData.Laptop[0].Features.Feature.Contains("Windows 10 Home 64-bit English"), "ITem no found");

                        //4th
                        Assert.AreEqual("Alienware", xmlData.Laptop[0].BrandName);
                    }
                }
            }
        }
        public void TestGetEndpointDeserilizationOfXmlResponse()
        {
            using (HttpClient httpClient = new HttpClient())
            {
                using (HttpRequestMessage httpRequestMessage = new HttpRequestMessage())
                {
                    httpRequestMessage.RequestUri = new Uri(getUrl);
                    httpRequestMessage.Method     = HttpMethod.Get;
                    httpRequestMessage.Headers.Add("Accept", "application/xml");

                    Task <HttpResponseMessage> httpResponse = httpClient.SendAsync(httpRequestMessage);

                    using (HttpResponseMessage HttpResponseMessage = httpResponse.Result)
                    {
                        output.WriteLine(HttpResponseMessage.ToString());

                        //Status Code
                        HttpStatusCode statuscode = HttpResponseMessage.StatusCode;
                        output.WriteLine("Status Code " + statuscode);
                        output.WriteLine("Status Code " + (int)statuscode);

                        //Response Data
                        HttpContent   responseContent = HttpResponseMessage.Content;
                        Task <string> responseData    = responseContent.ReadAsStringAsync();
                        string        data            = responseData.Result;
                        output.WriteLine(data);

                        RestResponse restResponse = new RestResponse((int)statuscode, responseData.Result);
                        //output.WriteLine(restResponse.ToString());

                        //Deserialization of XML Response
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(LaptopDetailss));

                        TextReader textReader = new StringReader(restResponse.responseContent);

                        LaptopDetailss xmlData = (LaptopDetailss)xmlSerializer.Deserialize(textReader);
                        output.WriteLine(xmlData.ToString());


                        //Asserts (Status Code and Response)
                        Assert.Equal(200, restResponse.StatusCode);
                        Assert.NotNull(restResponse.responseContent);
                        Assert.Contains("Windows 10 Home 64-bit English", xmlData.Laptop[0].Features.Feature);
                        Assert.Equal("Alienware", xmlData.Laptop[0].BrandName);
                    }
                }
            }
        }
예제 #6
0
      public void TestGetUsingRestSharpXmlDeserialization()
      {
          IRestClient  restClient  = new RestClient();
          IRestRequest restRequest = new RestRequest(getUrl);

          restRequest.AddHeader("Accept", "application/xml");
          var           dotNetXmlSerializer = new RestSharp.Deserializers.DotNetXmlDeserializer(); //XML Deserialization Step:1
          IRestResponse restResponse        = restClient.Get(restRequest);                         //

          if (restResponse.IsSuccessful)
          {
              Console.WriteLine((int)restResponse.StatusCode);
              Assert.AreEqual(200, (int)restResponse.StatusCode);
              LaptopDetailss data = dotNetXmlSerializer.Deserialize <LaptopDetailss>(restResponse); //XML Deserialization Step:2
              Assert.AreEqual("Alienware M17", data.Laptop[1].LaptopName);
          }
      }
예제 #7
0
      public void TestGetUsingRestRequestHelperDeserialiZerXmlnData()
      {
          Dictionary <string, string> httpHeaders = new Dictionary <string, string>();

          httpHeaders.Add("Accept", "application/xml");
          IRestResponse <LaptopDetailss> restResponse = RestRequestHelper.PerformGetRequest <LaptopDetailss>(getUrl, httpHeaders);

          if (restResponse.IsSuccessful)
          {
              Console.WriteLine((int)restResponse.StatusCode);
              Console.WriteLine(restResponse.Content);
              Assert.AreEqual(200, (int)restResponse.StatusCode);
              LaptopDetailss data = restResponse.Data;

              Assert.AreEqual("Alienware M17", data.Laptop[2].LaptopName);
          }
      }
        public void testgetinxml_deseraialize()
        {
            IRestClient  restClient  = new RestClient();
            IRestRequest restRequest = new RestRequest(url);

            restRequest.AddHeader("Accept", "application/xml");
            //IRestResponse restResponse = restClient.Get(restRequest);
            //IRestResponse<List<JsonRootObject>> restResponse = restClient.Get<List<JsonRootObject>>(restRequest);
            //IRestResponse<List<JsonRootObject>> restResponse = restClient.Get<List<JsonRootObject>>(restRequest);
            var           dotnetxmldeserializer = new RestSharp.Deserializers.DotNetXmlDeserializer();
            IRestResponse restResponse          = restClient.Get(restRequest);

            if (restResponse.IsSuccessful)
            {
                Console.WriteLine(restResponse.StatusCode);
                Assert.AreEqual(200, (int)restResponse.StatusCode);
                Console.WriteLine(restResponse.Content);

                LaptopDetailss xmldata = dotnetxmldeserializer.Deserialize <LaptopDetailss>(restResponse);
                Console.WriteLine("no of data" + xmldata.Laptop.Count);

                Laptop laptop = xmldata.Laptop.Find((x) =>
                {
                    return(x.Id.Equals("3", StringComparison.OrdinalIgnoreCase));
                });

                //List<JsonRootObject> jsondata = restResponse.Data;

                Assert.AreEqual(laptop.LaptopName, "Alienware M16");
                Assert.IsTrue(laptop.Features.Feature.Contains("1  TB is added"), "Such entry does not exists");
            }
            else
            {
                Console.WriteLine(restResponse.IsSuccessful);
                Console.WriteLine(restResponse.ErrorMessage);
                Console.WriteLine(restResponse.ErrorException);
            }
        }
예제 #9
0
        public void xmldeserialize()
        {
            using (HttpClient httpclient = new HttpClient())
            {
                using (HttpRequestMessage requestMessage = new HttpRequestMessage())
                {
                    requestMessage.RequestUri = new Uri(url);
                    requestMessage.Method     = HttpMethod.Get;
                    requestMessage.Headers.Add("Accept", "application/xml");
                    Task <HttpResponseMessage> httprespnsemessage = httpclient.SendAsync(requestMessage);
                    using (HttpResponseMessage reponseResult = httprespnsemessage.Result)
                    {
                        Console.WriteLine(reponseResult);

                        //get response status code
                        HttpStatusCode statuscode = reponseResult.StatusCode;
                        Console.WriteLine("StatusCode: " + statuscode);
                        Console.WriteLine("StatusCode: " + (int)statuscode);

                        //get response data
                        HttpContent   responseContent = reponseResult.Content;
                        Task <string> responseData    = responseContent.ReadAsStringAsync();
                        string        data            = responseData.Result;
                        //Console.WriteLine(data);
                        RestResponse restResponse = new RestResponse((int)statuscode, data);

                        //step1
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(LaptopDetailss));
                        //step 2
                        TextReader textreader = new StringReader(restResponse.ResponseContent);

                        //step3
                        LaptopDetailss xmldata = (LaptopDetailss)xmlSerializer.Deserialize(textreader);
                        Console.WriteLine(xmldata.Laptop.ToString());
                    }
                }
            }
        }
예제 #10
0
        public void TestGetWithXml_Deserialize()
        {
            IRestClient  restClient  = new RestClient();
            IRestRequest restRequest = new RestRequest(getUrl);

            restRequest.AddHeader("accept", "application/xml");
            //Deserialize an XML response
            var           dotNetXmlDeserializer = new RestSharp.Deserializers.DotNetXmlDeserializer();
            IRestResponse restResponse          = restClient.Get(restRequest);

            if (restResponse.IsSuccessful)
            {
                Console.WriteLine("Response code: " + (int)restResponse.StatusCode);
                Assert.AreEqual(200, (int)restResponse.StatusCode);
                LaptopDetailss data = dotNetXmlDeserializer.Deserialize <LaptopDetailss>(restResponse);
                Assert.AreEqual("Alienware", data.Laptop.BrandName);
            }
            else
            {
                Console.WriteLine("Error Msg : " + restResponse.ErrorMessage);
                Console.WriteLine("Stack trace : " + restResponse.ErrorException);
            }
        }