vendredi 8 janvier 2021

Xunit- Add body to a HttpWebRequest

I want to make tests to my Api so I need to test a PUT endpoint. I already tested all my Get endpoints so until now I never needed to send a body in my request. How can I do it?

TEST

public void TestUpdateSinglePlayerStats()
        {
            string id = "2019";
            HttpWebRequest request = (HttpWebRequest)WebRequest
                                        .Create("http://localhost:5000/GameStats/Update/" + id);
            request.Headers.Add("Authorization", "Bearer " + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjIwMTkiLCJyb2xlIjoiVXNlciIsIm5iZiI6MTYxMDEyMzY2OSwiZXhwIjoxNjEwMjEwMDY5LCJpYXQiOjE2MTAxMjM2Njl9.Dd2wzUJ5LnPBw0CbDXZZTIiQLX8074F_E1wW-qBPQzw");
            request.ContentType = "application/json";
            request.Method = "PUT";


            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
           

        }

MY API ENDPOINT

enter image description here

Aucun commentaire:

Enregistrer un commentaire