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());
        }
Esempio n. 3
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. 4
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. 5
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. 7
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);
        }