예제 #1
0
        public void TestPostUsingHelperClass()
        {
            int    id      = random.Next(1000);
            string xmlData = "<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 + "</Id>" +
                             "<LaptopName>Alienware M17</LaptopName>" +
                             "</Laptop>";

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };

            restResponse = HttpClientHelper.PerformPostRequest(postUrl, xmlData, xmlMediaType, headers);

            //HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType);

            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlDatat = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseContent);

            Console.WriteLine(xmlData.ToString());
        }
예제 #2
0
        public void TestSecurePostEndPoint()
        {
            int    id      = random.Next(1000);
            string xmlData = "<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 + "</Id>" +
                             "<LaptopName>Alienware M17</LaptopName>" +
                             "</Laptop>";
            Dictionary <string, string> httpHeader = new Dictionary <string, string>();

            httpHeader.Add("Accept", xmlMediaType);
            string authHeader = "Basic " + Base64StringConverter.GetBase64String("admin", "welcome");

            httpHeader.Add("Authorization", authHeader);

            restResponse = HttpClientHelper.PerformPostRequest(securePostUrl, httpHeader, xmlData, xmlMediaType);
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseData);

            Console.WriteLine(xmlObj.ToString());
        }
예제 #3
0
        public void PutEndPointTestusingClientHelper()
        {
            int    id       = 965;
            string jsonData = "{" +
                              "\"BrandName\": \"Ramware\"," +
                              "\"Features\": {" +
                              "\"Feature\": [" +
                              "\"8th Generation Intel® Core™ i5-8300H\"," +
                              "\"Windows 10 Home 64-bit English\"," +
                              "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," +
                              "\"8GB, 2x4GB, DDR4, 2666MHz\"" +
                              "]" +
                              "}," +
                              "\"Id\":" + id + "," +
                              "\"LaptopName\": \"Alienware M17\"" +
                              "}";



            HttpContent  httpcontent  = new StringContent(jsonData, Encoding.UTF8, jsonMediaType);
            RestResponse restResponse = HttpClientHelper.PerformPutRequest(putUrl, jsonData, jsonMediaType, null);

            Assert.AreEqual(200, restResponse.StatusCode);
            RestResponse restResponseForGet = HttpClientHelper.PerformGetRequest(getUrl + id, null);
            Laptop       laptop             = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponseForGet.ResponseData);

            Assert.AreEqual(200, restResponseForGet.StatusCode);
            Assert.AreEqual("Ramware", laptop.BrandName);
        }
예제 #4
0
        public void TestPostEndPointWithHelperClass()
        {
            int    id       = random.Next(1000);
            string jsonData = "{" +
                              "\"BrandName\": \"Alienware\"," +
                              "\"Features\": {" +
                              "\"Feature\": [" +
                              "\"8th Generation Intel® Core™ i5-8300H\"," +
                              "\"Windows 10 Home 64-bit English\"," +
                              "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," +
                              "\"8GB, 2x4GB, DDR4, 2666MHz\"" +
                              "]" +
                              "}," +
                              "\"Id\": " + id + "," +
                              "\"LaptopName\": \"Alienware M17\"" +
                              "}";
            Dictionary <string, string> httpHeader = new Dictionary <string, string>();

            httpHeader.Add("Accept", jsonMediaType);
            restResponse = HttpClientHelper.PerformPostRequest(postUrl, httpHeader, jsonData, jsonMediaType);
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlData = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseData);

            Console.WriteLine(xmlData.ToString());
        }
        private void SendPostRequest()
        {
            int id = random.Next(1000);

            string xmlData =
                "<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 + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            Dictionary <string, string> httpHeader = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };


            RestResponse restResponse = httpAsyncClientHelper.PerformPostRequest(delayPostUrl, xmlData, xmlMediaType, httpHeader).GetAwaiter().GetResult();

            //HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType);
            //httpAsyncClientHelper.PerformPostRequest(postUrl, httpContent, httpHeader);

            Assert.Equal(200, restResponse.StatusCode);

            Laptop xmlDatat = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent);
        }
예제 #6
0
        public void TestPutUsingXmlData()
        {
            int    id      = random.Next(1000);
            string xmlData =
                "<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 + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };

            restResponse = HttpClientHelper.PerformPostRequest(postUrl, xmlData, xmlMediaType, headers);
            Assert.Equal(200, restResponse.StatusCode);

            xmlData =
                "<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 of SSD</Feature>" +
                "</Features>" +
                "<Id>" + id + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            using (HttpClient httpClient = new HttpClient())
            {
                HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType);

                Task <HttpResponseMessage> httpResponseMessage = httpClient.PutAsync(putUrl, httpContent);

                restResponse = new RestResponse((int)httpResponseMessage.Result.StatusCode,
                                                httpResponseMessage.Result.Content.ReadAsStringAsync().Result);

                Assert.Equal(200, restResponse.StatusCode);
            }

            restResponse = HttpClientHelper.PerformGetRequest(getUrl + id, headers);
            Assert.Equal(200, restResponse.StatusCode);

            Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent);

            Assert.Contains("1 TB of SSD", xmlObj.Features.Feature);
        }
예제 #7
0
        public void TestSecurePutEndPoint()
        {
            int    id      = random.Next(1000);
            string xmlData =
                "<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 + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            string authHeader = Base64StringConverter.GetBase64String("admin", "welcome");

            authHeader = "Basic " + authHeader;

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" },
                { "Authorization", authHeader }
            };

            restResponse = HttpClientHelper.PerformPostRequest(securePostUrl, xmlData, xmlMediaType, headers);
            Assert.Equal(200, restResponse.StatusCode);

            xmlData =
                "<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 of SSD</Feature>" +
                "</Features>" +
                "<Id>" + id + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            restResponse = HttpClientHelper.PerformPutRequest(securePutUrl, xmlData, xmlMediaType, headers);
            Assert.Equal(200, restResponse.StatusCode);

            restResponse = HttpClientHelper.PerformGetRequest(secureGetUrl + id, headers);
            Assert.Equal(200, restResponse.StatusCode);

            Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent);

            Assert.Contains("1 TB of SSD", xmlObj.Features.Feature);
        }
예제 #8
0
        public void TestPutWithHelperClass_Xml()
        {
            int id = random.Next(1000);

            string xmlData = "<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 + "</Id>" +
                             "<LaptopName>Alienware M17</LaptopName>" +
                             "</Laptop>";

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };


            restResponse = HttpClientHelper.PerformPostRequest(postUrl, xmlData, xmlMediaType, headers);
            Assert.AreEqual(200, restResponse.StatusCode);

            xmlData = "<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 of SSD</Feature>" +
                      "</Features>" +
                      "<Id>" + id + "</Id>" +
                      "<LaptopName>Alienware M17</LaptopName>" +
                      "</Laptop>";


            restResponse = HttpClientHelper.PerformPutRequest(putUrl, xmlData, xmlMediaType, headers);
            Assert.AreEqual(200, restResponse.StatusCode);


            restResponse = HttpClientHelper.PerformGetRequest(getUrl + id, headers);
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseContent);

            Assert.IsTrue(xmlObj.Features.Feature.Contains("1 TB of SSD"), "feature not found");
        }
        private void SendPutRequest()
        {
            int    id      = random.Next(1000);
            string xmlData =
                "<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 + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/xml" }
            };

            RestResponse restResponse = httpAsyncClientHelper.PerformPostRequest(delayPostUrl, xmlData, xmlMediaType, headers).GetAwaiter().GetResult();

            Assert.Equal(200, restResponse.StatusCode);

            xmlData =
                "<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 of SSD</Feature>" +
                "</Features>" +
                "<Id>" + id + "</Id>" +
                "<LaptopName>Alienware M17</LaptopName>" +
                "</Laptop>";

            restResponse = httpAsyncClientHelper.PerformPutRequest(delayPutUrl, xmlData, xmlMediaType, headers).GetAwaiter().GetResult();
            Assert.Equal(200, restResponse.StatusCode);

            restResponse = httpAsyncClientHelper.PerformGetRequest(delayGetWithId + id, headers).GetAwaiter().GetResult();
            Assert.Equal(200, restResponse.StatusCode);

            Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent);

            Assert.Contains("1 TB of SSD", xmlObj.Features.Feature);
        }
예제 #10
0
        private void SendPutMethod()
        {
            int    id      = random.Next(1000);
            string xmlData = "<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 + "</Id>" +
                             "<LaptopName>Alienware M17</LaptopName>" +
                             "</Laptop>";

            Dictionary <string, string> httpHeaders = new Dictionary <string, string>()
            {
                { "Accept", xmlMediaType }
            };

            restResponse = httpClientHelperAsync.PerformPostRequest(delayPostUrl, httpHeaders, xmlData, xmlMediaType).GetAwaiter().GetResult();
            Assert.AreEqual(200, restResponse.StatusCode);

            xmlData = "<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>1TB of SSD</Feature>" +
                      "</Features>" +
                      "<Id>" + id + "</Id>" +
                      "<LaptopName>Alienware M17</LaptopName>" +
                      "</Laptop>";

            restResponse = httpClientHelperAsync.PerformPutRequest(delayPutUrl, httpHeaders, xmlData, xmlMediaType).GetAwaiter().GetResult();
            Assert.AreEqual(200, restResponse.StatusCode);
            restResponse = httpClientHelperAsync.PerformGetRequest(delayGetUrlWithId, httpHeaders).GetAwaiter().GetResult();
            Assert.AreEqual(200, restResponse.StatusCode);

            Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseData);

            Assert.IsTrue(xmlObj.Features.Feature.Contains("1TB of SSD"), "Item not found");
        }
예제 #11
0
        public void PostEndPointTestUsingXml()
        {
            int    id      = random.Next(1001);
            string xmlData = "<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 + "</Id>" +
                             "<LaptopName> Alienware M17 </LaptopName>" +
                             "</Laptop>";



            using (HttpClient httpclient = new HttpClient())
            {
                HttpContent httpcontent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType);
                Task <HttpResponseMessage> httpResponse = httpclient.PostAsync(postUri, httpcontent);
                using (HttpResponseMessage httpResponseMessage = httpResponse.Result)
                {
                    restResponse = new RestResponse((int)httpResponseMessage.StatusCode, httpResponseMessage.Content.ReadAsStringAsync().Result);
                    Console.WriteLine(restResponse.ToString());
                    Assert.AreEqual(200, restResponse.StatusCode);
                    Assert.IsNotNull(restResponse.ResponseData, "Response data is not null/empty");
                    Task <HttpResponseMessage> httpGetResponse = httpclient.GetAsync(getUrl + id);
                    if (!httpGetResponse.Result.IsSuccessStatusCode)
                    {
                        Assert.Fail("Assert Failed");
                    }
                    restResponseForGet = new RestResponse((int)httpGetResponse.Result.StatusCode, httpGetResponse.Result.Content.ReadAsStringAsync().Result);
                    Console.WriteLine(httpGetResponse.Result.Content.ReadAsStringAsync().Result);
                    Laptop laptop = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponseForGet.ResponseData);
                    //XmlSerializer serializer = new XmlSerializer(typeof(Laptop));
                    //TextReader textReader = new StringReader(restResponseForGet.ResponseData);
                    //Laptop laptop = (Laptop)serializer.Deserialize(textReader);
                    Assert.AreEqual("Alienware", laptop.BrandName);
                }
            }
        }
예제 #12
0
        public Laptop AddRecord(int id)
        {
            string xmlData = "<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 + "</Id>" +
                             "<LaptopName>Alienware M17</LaptopName>" +
                             "</Laptop>";
            RestResponse restResponse = HttpClientHelper.PerformPostRequest(postUrl, xmlData, xmlMediaType, headers);

            Assert.AreEqual(200, restResponse.StatusCode);
            Laptop xmlDatat = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseContent);

            return(xmlDatat);
        }