public void TestDeleteEndPoint()
        {
            int    id       = random.Next(100);
            string jsonData = "{" +
                              "\"BrandName\": \"AnimalWare\"," +
                              "\"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\": \"LionWare M17\"" +
                              "}";

            Dictionary <string, string> requestHeaders = new Dictionary <string, string>()
            {
                { "Accept", "application/json" },
                { "Content-Type", "application/json" }
            };
            IRestResponse <Laptop> postResponse = RestRequestHelper.PerformPostRequest <Laptop>(postUrl, requestHeaders, jsonData, DataFormat.Json);

            IRestResponse <Laptop> getResponseBeforeDelete = RestRequestHelper.PerformGetRequest <Laptop>(getUrl + id, requestHeaders);

            Console.WriteLine("Brandname =>" + getResponseBeforeDelete.Data.BrandName);
            requestHeaders["Accept"] = "*/*"; //This Header is needed to receive the response from Delete request.
            IRestResponse deleteResponse = RestRequestHelper.PerformDeleteRequest(deleteUrl + id, requestHeaders);

            Assert.AreEqual(200, (int)deleteResponse.StatusCode);
            deleteResponse = RestRequestHelper.PerformDeleteRequest(deleteUrl + id, requestHeaders);
            Assert.AreEqual(404, (int)deleteResponse.StatusCode);
        }
      public void TestGetUsingRestRequestHelper()
      {
          Dictionary <string, string> httpHeaders = new Dictionary <string, string>();

          httpHeaders.Add("Accept", "application/json");
          IRestResponse restResponse = RestRequestHelper.PerformGetRequest(getUrl, httpHeaders);

          if (restResponse.IsSuccessful)
          {
              Console.WriteLine((int)restResponse.StatusCode);
              Console.WriteLine(restResponse.Content);
              Assert.AreEqual(200, (int)restResponse.StatusCode);
          }
      }
Exemple #3
0
        public void PuttEndPointsWithJsonData()
        {
            int    id       = random.Next(100);
            string jsonData = "{" +
                              "\"BrandName\": \"AnimalWare\"," +
                              "\"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\": \"LionWare M17\"" +
                              "}";
            string jsonDataForPut = "{" +
                                    "\"BrandName\": \"LionWare\"," +
                                    "\"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> requestHeaders = new Dictionary <string, string>()
            {
                { "Accept", "application/json" },
                { "Content-Type", "application/json" }
            };
            IRestResponse <Laptop> postResponse = RestRequestHelper.PerformPostRequest <Laptop>(postUrl, requestHeaders, jsonData, DataFormat.Json);

            IRestResponse <Laptop> getResponseBeforePut = RestRequestHelper.PerformGetRequest <Laptop>(getUrl + postResponse.Data.Id, requestHeaders);

            Console.WriteLine("Brandname =>" + getResponseBeforePut.Data.BrandName);
            IRestResponse <Laptop> putResponse = RestRequestHelper.PerformPutRequest <Laptop>(putUrl, requestHeaders, jsonDataForPut, DataFormat.Json);

            Assert.AreEqual("LionWare", putResponse.Data.BrandName);
            IRestResponse <Laptop> getResponseafterPut = RestRequestHelper.PerformGetRequest <Laptop>(getUrl + postResponse.Data.Id, requestHeaders);

            Console.WriteLine("LaptopName =>" + getResponseBeforePut.Data.LaptopName);
        }
      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 TestGetUsingRestRequestHelperDeserialiZerJsonData()
      {
          Dictionary <string, string> httpHeaders = new Dictionary <string, string>();

          httpHeaders.Add("Accept", "application/json");    //Deserializing JSON data

          IRestResponse <List <JsonRootObject> > restResponse = RestRequestHelper.PerformGetRequest <List <JsonRootObject> >(getUrl, httpHeaders);

          if (restResponse.IsSuccessful)
          {
              Console.WriteLine((int)restResponse.StatusCode);
              Console.WriteLine(restResponse.Content);
              Assert.AreEqual(200, (int)restResponse.StatusCode);
              List <JsonRootObject> data   = restResponse.Data;
              JsonRootObject        laptop = data.Find((x) =>
                {
                    return(x.Id == 761);
                });
              Assert.AreEqual("Alienware M17", laptop.LaptopName);
          }
      }