Esempio n. 1
0
        public void TestSecureGetEndPoint()
        {
            Dictionary <string, string> httpHeader = new Dictionary <string, string>();

            httpHeader.Add("Accept", "application/json");

            //httpHeader.Add("Authorization", "Basic YWRtaW46d2VsY29tZQ==");

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

            authHeader = "Basic " + authHeader;

            httpHeader.Add("Authorization", authHeader);

            RestResponse restResponse = HttpClientHelper.PerformGetRequest(getUrl, httpHeader);

            // List<JsonRootObject> jsonRootObject = JsonConvert.DeserializeObject<List<JsonRootObject>>(restResponse.ResponseContent);
            // Console.WriteLine(jsonRootObject[0].ToString());

            Assert.AreEqual(200, restResponse.StatusCode);

            List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.ResponseContent);

            Console.WriteLine(jsonData.ToString());
        }
Esempio n. 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());
        }
        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);
        }
Esempio n. 4
0
        public void TestSecureDeleteUsingHelperClass()
        {
            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 = "Basic " + Base64StringConverter.GetBase64String("admin", "welcome");
            Dictionary <string, string> httpHeaders = new Dictionary <string, string>()
            {
                { "Accept", xmlMediaType },
                { "Authorization", authHeader }
            };

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

            restResponse = HttpClientHelper.PerformDeleteRequest(secureDeleteUrl + id, httpHeaders);
            Assert.AreEqual(200, restResponse.StatusCode);

            restResponse = HttpClientHelper.PerformGetRequest(secureGetUrl + id, httpHeaders);
            Assert.AreNotEqual(200, restResponse.StatusCode);
        }
Esempio n. 5
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");
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void TestSecureDeletehttpclienthelper()
        {
            int idno = this.id;

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

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

            restResponse = HttpClientHelper.PerformDeleteRequest(securedelurl + idno, header);
            Assert.AreEqual(200, restResponse.StatusCode, "The data is deleted");

            restResponse = HttpClientHelper.PerformDeleteRequest(securedelurl + idno, header);
            Assert.AreEqual(404, restResponse.StatusCode, "The data is deleted");
        }
Esempio n. 8
0
        public void TestSecureDeleteUsingHelperClass()
        {
            int id = random.Next(1000);

            AddRecord(id);
            string auth = Base64StringConverter.GetBase64String("admin", "welcome");

            auth = "Basic " + auth;
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Authorization", auth }
            };

            restResponse = HttpClientHelper.PerformDeleteRequest(secureDeleteUrl + id, headers);
            Assert.AreEqual(200, restResponse.StatusCode);

            restResponse = HttpClientHelper.PerformDeleteRequest(secureDeleteUrl + id, headers);
            Assert.AreEqual(404, restResponse.StatusCode);
        }
        public void TestSecureGetEndPoint()
        {
            string authHeader = Base64StringConverter.GetBase64String("admin", "welcome");

            authHeader = "Basic " + authHeader;

            Dictionary <string, string> httpHeader = new Dictionary <string, string>
            {
                { "Accept", "application/json" },
                { "Authorization", authHeader }
            };
            //{"Authorization", "Basic YWRtaW46d2VsY29tZQ==" }


            RestResponse restResponse = HttpClientHelper.PerformGetRequest(secureGetUrl, httpHeader);

            Assert.Equal(200, restResponse.StatusCode);

            List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.responseContent);
        }
Esempio n. 10
0
        public void TestSecureGetUsingHelperMethod()
        {
            Dictionary <string, string> httpheader = new Dictionary <string, string>();

            httpheader.Add("Accept", "application/json");
            //httpheader.Add("Authorization", "Basic YWRtaW46d2VsY29tZQ==");
            string authheader = Base64StringConverter.getBase64String("admin", "welcome");

            authheader = "Basic " + authheader;
            httpheader.Add("Authorization", authheader);

            RestResponse restResponse = HttpClientHelper.PerformGetRequest(secureurl, httpheader);

            Assert.AreEqual(200, restResponse.StatusCode, "Status code is not connected");
            //List<JsonRootObject> jsonroot = JsonConvert.DeserializeObject<List<JsonRootObject>>(restResponse.ResponseContent);
            //Console.WriteLine(jsonroot[0].BrandName.ToString());

            List <JsonRootObject> jsondata = ResponseDataHelper.DeserializeJSONResponse <List <JsonRootObject> >(restResponse.ResponseContent);

            Console.WriteLine(jsondata[1].ToString());
        }
Esempio n. 11
0
        public void TestSecureDeleteEndPoint()
        {
            int id = random.Next(1000);

            RequestHelper.AddRecord(postUrl, id);

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

            authHeader = "Basic " + authHeader;

            Dictionary <string, string> headers = new Dictionary <string, string>
            {
                { "Authorization", authHeader }
            };

            var restResponse = HttpClientHelper.PerformDeleteRequest(deleteUrl + id, headers);

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

            restResponse = HttpClientHelper.PerformDeleteRequest(deleteUrl + id, headers);

            Assert.Equal(404, (int)restResponse.StatusCode);
        }