Ejemplo n.º 1
0
        public void postdata(int id)
        {
            string contentxml = "<Laptop>" +
                                "<BrandName>Alienware</BrandName>" +
                                "<Features>" +
                                "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" +
                                "<Feature>Windows 10 Home 64-bit English</Feature>" +
                                "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" +
                                "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" +
                                "</Features>" +
                                "<Id>" + id.ToString() + "</Id>" +
                                "<LaptopName>Alienware M16</LaptopName>" +
                                "</Laptop>";
            Dictionary <string, string> header = new Dictionary <string, string>
            {
                { "Accept", "application/xml" }
            };

            restResponse = HttpClientHelper.PerformPostRequest(posturl, contentxml, xmldataformat, header);
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent);

            Console.WriteLine(xmlresponsedata.ToString());
        }
        public void SecurePostUsingHTTPClientHelper()
        {
            string contentxml = "<Laptop>" +
                                "<BrandName>Alienware</BrandName>" +
                                "<Features>" +
                                "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" +
                                "<Feature>Windows 10 Home 64-bit English</Feature>" +
                                "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" +
                                "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" +
                                "</Features>" +
                                "<Id>" + id.ToString() + "</Id>" +
                                "<LaptopName>Alienware M16</LaptopName>" +
                                "</Laptop>";
            string authheader = Base64StringConverter.getBase64String("admin", "welcome");

            authheader = "Basic " + authheader;
            Dictionary <string, string> header = new Dictionary <string, string>
            {
                { "Accept", "application/xml" },
                { "Authorization", authheader }
            };

            restResponse = HttpClientHelper.PerformPostRequest(secureposturl, contentxml, xmldataformat, header);
            Assert.AreEqual(200, restResponse.StatusCode);

            restResponse = HttpClientHelper.PerformGetRequest(securegeturl + id, header);
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent);

            Console.WriteLine(xmlresponsedata.ToString());
            Assert.AreEqual("Alienware", xmlresponsedata.BrandName);
        }
Ejemplo n.º 3
0
        public void testSecureHTTPClientHelper_xml()
        {
            string contentxml = "<Laptop>" +
                                "<BrandName>Alienware</BrandName>" +
                                "<Features>" +
                                "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" +
                                "<Feature>Windows 10 Home 64-bit English</Feature>" +
                                "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" +
                                "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" +
                                "</Features>" +
                                "<Id>" + id.ToString() + "</Id>" +
                                "<LaptopName>Alienware M16</LaptopName>" +
                                "</Laptop>";

            string authheader = Base64StringConverter.getBase64String("admin", "welcome");

            authheader = "Basic " + authheader;
            Dictionary <string, string> header = new Dictionary <string, string>
            {
                { "Accept", "application/xml" },
                { "Authorization", authheader }
            };

            restResponse = HttpClientHelper.PerformPostRequest(secureposturl, contentxml, xmldataformat, header);
            Assert.AreEqual(200, restResponse.StatusCode);


            contentxml = "<Laptop>" +
                         "<BrandName>Alienware</BrandName>" +
                         "<Features>" +
                         "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" +
                         "<Feature>Windows 10 Home 64-bit English</Feature>" +
                         "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" +
                         "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" +
                         "<Feature>1  TB is added</Feature>" +
                         "</Features>" +
                         "<Id>" + id.ToString() + "</Id>" +
                         "<LaptopName>Alienware M16</LaptopName>" +
                         "</Laptop>";

            //using (HttpClient httpClient = new HttpClient())
            //{
            //    HttpContent httpContent = new StringContent(contentxml, Encoding.UTF8, xmldataformat);
            //    Task<HttpResponseMessage> httpResponseMessage = httpClient.PutAsync(puturl, httpContent);
            //    restResponse = new RestResponse((int)httpResponseMessage.Result.StatusCode, httpResponseMessage.Result.Content.ReadAsStringAsync().Result);
            //    Assert.AreEqual(200, restResponse.StatusCode);
            //}

            restResponse = HttpClientHelper.PerformPutRequest(secureputurl, contentxml, xmldataformat, header);
            Assert.AreEqual(200, restResponse.StatusCode);


            restResponse = HttpClientHelper.PerformGetRequest(securegeturl + id, header);
            Assert.AreEqual(200, restResponse.StatusCode);
            Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent);

            //Console.WriteLine(xmlresponsedata.Features.Feature.ToString());
            Assert.IsTrue(xmlresponsedata.Features.Feature.Contains("1  TB is added"), "Failed to add data");
        }