PUT Request in Restsharp



Precondition: Tourist exists with TouristId: 164944

Sample Request body to create UpdateTourist class

{

            “tourist_name”: “Karthik”,

            “tourist_email”: ” Karthik123@yahoo.com “,

            “tourist_location”: “Hyderabad”

}

Copy the above request body to clipboard and click on “Edit”->”Paste special” -> “Paste JSON as Classes” in Visualstudio

UpdateTourist” class will be created.

using System;
using System.Collections.Generic;
using System.Text;
namespace RestsharpDemo
{
public class UpdateTourist
{
public int id { get; set; }
public string tourist_name { get; set; }
public string tourist_email { get; set; }
public string tourist_location { get; set; }
}
}

Step2: Set the properties of the “UpdateTourist” class and send the object to the request.AddBody();

[Test]
public void UpdateTouristByTouristId()
{
var restClient = new RestClient("http://restapi.adequateshop.com");        
var request = new RestRequest("api/Tourist/164944", Method.PUT); //Pass the Tourist ID
        request.RequestFormat = DataFormat.Json;

        request.AddHeader("Content-Type", "application/json");
        UpdateTourist objUpdate = new UpdateTourist();
        objUpdate.id = 164944;
        objUpdate.tourist_email = "Karthik123@yahoo.com"; //old value is: Karthik99@yahoo.com
        objUpdate.tourist_location = "Hyderabad"; //old value is Chennai
        objUpdate.tourist_name = "Kartik";

        request.AddBody(objUpdate);

        var response = restClient.ExecuteTaskAsync(request);
        while (response.Status != TaskStatus.RanToCompletion)
        {
            Console.WriteLine("ThreadID:{0},Status: {1}", Thread.CurrentThread.ManagedThreadId, response.Status);
            Task.Delay(100).Wait();
        }
        Thread.Sleep(5000);
        Console.WriteLine("Status code is:" + response.Result.StatusCode.ToString());
        Assert.IsTrue(response.Result.StatusCode.ToString() == "OK", "Status code is not OK");

    }

Step3: Verify that tourist info is updated

http://restapi.adequateshop.com/api/Tourist/164944

Tags: ,
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18