Problem with continuous test execution
As someone who is just starting out with RestSharp, I’m encountering an unusual issue. My test method retrieves the correct response from a weather API, yet it never seems to complete. While the status code and content appear fine during debugging, the test continues to run indefinitely.
Additionally, I’m unable to successfully deserialize the JSON response to my C# classes. I generated those classes using Visual Studio’s paste special feature to minimize errors.
public async Task RetrieveWeatherData()
{
var request = new RestRequest(apiUrl, Method.Get);
RestResponse response = await httpClient.ExecuteAsync(request);
Console.WriteLine(response.StatusCode);
if (response.IsSuccessful == true)
Console.WriteLine("Request was successful!");
var jsonOutput = response.Content;
Console.WriteLine(response.Content);
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
WeatherInfo weatherInfo = JsonConvert.DeserializeObject<WeatherInfo>(jsonOutput);
}
Example of API output:
{"coord":{"lon":13.7329,"lat":46.1828},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"stations","main":{"temp":298.23,"feels_like":298.13,"temp_min":296.13,"temp_max":301.58,"pressure":1008,"humidity":51},"visibility":10000,"wind":{"speed":2.71,"deg":223,"gust":2.23},"clouds":{"all":62},"dt":1653043444,"sys":{"type":2,"id":19828,"country":"SI","sunrise":1653017233,"sunset":1653071774},"timezone":7200,"id":3189038,"name":"Tolmin","cod":200}
My data classes:
public class WeatherInfo
{
public Coordinates coord { get; set; }
public Weather[] weather { get; set; }
public string _base { get; set; }
public MainDetails main { get; set; }
public int visibility { get; set; }
public WindDetails wind { get; set; }
public CloudCoverage clouds { get; set; }
public int dt { get; set; }
public SystemInfo sys { get; set; }
public int timezone { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
public class Coordinates
{
public float lon { get; set; }
public float lat { get; set; }
}
public class MainDetails
{
public float temp { get; set; }
public float feels_like { get; set; }
public float temp_min { get; set; }
public float temp_max { get; set; }
public int pressure { get; set; }
public int humidity { get; set; }
}
public class WindDetails
{
public float speed { get; set; }
public int deg { get; set; }
public float gust { get; set; }
}
public class CloudCoverage
{
public int all { get; set; }
}
public class SystemInfo
{
public int type { get; set; }
public int id { get; set; }
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}