0

I am trying to run multiple GET requests using RestSharp but it only runs one request and then stop. Can someone please suggest what I am doing wrong here?

using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestSharp;


namespace CertificatesAPI
{
    [TestClass]
    public class UnitTest2
    {
        [TestMethod]
        public static void Reqres()
        {            
            int[] userIDs = {1, 2, 3, 4, 5};
 
            foreach (int ID in userIDs)
            {

                var client = new RestClient("https://reqres.in/api/users");
                var request = new RestRequest(Method.GET);
                request.AddParameter("id", ID);

               
                IRestResponse response = client.Execute(request);

                HttpStatusCode statusCode = response.StatusCode;
                int StatusCode = (int)statusCode;

                if (StatusCode == 200)
                {
                    Console.WriteLine("SUCCESS");
                    Console.WriteLine(response.Content);
                }
                else
                {
                    Console.WriteLine("Status Code: " + StatusCode);
                }
                Console.Read();

            }

        }

    }
}

I created a Unit Test Project in Visual Studio and then created another project in the same solution to call this method Reqres and run this under Main method. I am a backend tester and new to C# and Visual Studio.

Sahil
  • 13
  • 5
  • 1
    Try hitting enter. You have `Console.Read()`, that will pause your execution until it has user intervention and you press enter. I suggest removing it completely and see what happens. – Skin Feb 28 '22 at 03:06
  • That worked!! Thanks @Skin. I was going to look into await async calls as well. Do you think I should still do that? – Sahil Feb 28 '22 at 14:08

0 Answers0