diff --git a/OpenMeteo/OpenMeteoClient.cs b/OpenMeteo/OpenMeteoClient.cs index 45bf524..8368acf 100644 --- a/OpenMeteo/OpenMeteoClient.cs +++ b/OpenMeteo/OpenMeteoClient.cs @@ -268,77 +268,6 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey) return null; } } - - /// - /// Converts a given weathercode to it's string representation - /// - /// - /// Weathercode string representation - public string WeathercodeToString(int weathercode) - { - switch (weathercode) - { - case 0: - return "Clear sky"; - case 1: - return "Mainly clear"; - case 2: - return "Partly cloudy"; - case 3: - return "Overcast"; - case 45: - return "Fog"; - case 48: - return "Depositing rime Fog"; - case 51: - return "Light drizzle"; - case 53: - return "Moderate drizzle"; - case 55: - return "Dense drizzle"; - case 56: - return "Light freezing drizzle"; - case 57: - return "Dense freezing drizzle"; - case 61: - return "Slight rain"; - case 63: - return "Moderate rain"; - case 65: - return "Heavy rain"; - case 66: - return "Light freezing rain"; - case 67: - return "Heavy freezing rain"; - case 71: - return "Slight snow fall"; - case 73: - return "Moderate snow fall"; - case 75: - return "Heavy snow fall"; - case 77: - return "Snow grains"; - case 80: - return "Slight rain showers"; - case 81: - return "Moderate rain showers"; - case 82: - return "Violent rain showers"; - case 85: - return "Slight snow showers"; - case 86: - return "Heavy snow showers"; - case 95: - return "Thunderstorm"; - case 96: - return "Thunderstorm with light hail"; - case 99: - return "Thunderstorm with heavy hail"; - default: - return "Invalid weathercode"; - } - } - private async Task GetWeatherForecastAsync(WeatherForecastOptions options) { try diff --git a/OpenMeteo/WeatherCodeHelper.cs b/OpenMeteo/WeatherCodeHelper.cs new file mode 100644 index 0000000..22e1f7a --- /dev/null +++ b/OpenMeteo/WeatherCodeHelper.cs @@ -0,0 +1,44 @@ +namespace OpenMeteo; +public static class WeatherCodeHelper +{ + /// + /// Converts a given weathercode to it's string representation + /// + /// + /// Weathercode string representation + public static string WeathercodeToString(int weathercode) + { + return weathercode switch + { + 0 => "Clear sky", + 1 => "Mainly clear", + 2 => "Partly cloudy", + 3 => "Overcast", + 45 => "Fog", + 48 => "Depositing rime Fog", + 51 => "Light drizzle", + 53 => "Moderate drizzle", + 55 => "Dense drizzle", + 56 => "Light freezing drizzle", + 57 => "Dense freezing drizzle", + 61 => "Slight rain", + 63 => "Moderate rain", + 65 => "Heavy rain", + 66 => "Light freezing rain", + 67 => "Heavy freezing rain", + 71 => "Slight snow fall", + 73 => "Moderate snow fall", + 75 => "Heavy snow fall", + 77 => "Snow grains", + 80 => "Slight rain showers", + 81 => "Moderate rain showers", + 82 => "Violent rain showers", + 85 => "Slight snow showers", + 86 => "Heavy snow showers", + 95 => "Thunderstorm", + 96 => "Thunderstorm with light hail", + 99 => "Thunderstorm with heavy hail", + _ => "Invalid weathercode", + }; + } +} diff --git a/OpenMeteoTests/OpenMeteoClientTests.cs b/OpenMeteoTests/OpenMeteoClientTests.cs deleted file mode 100644 index 68254d7..0000000 --- a/OpenMeteoTests/OpenMeteoClientTests.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using OpenMeteo; - -namespace OpenMeteoTests -{ - [TestClass] - public class OpenMeteoClientTests - { - [TestMethod] - public void Weather_Codes_To_String_Tests() - { - OpenMeteoClient client = new OpenMeteoClient(); - int[] testWeatherCodes = { 0, 1, 2, 3, 51, 53, 96, 99, 100 }; - foreach (var weatherCode in testWeatherCodes) - { - string weatherCodeString = client.WeathercodeToString(weatherCode); - Assert.IsInstanceOfType(weatherCodeString, typeof(string)); - - if (weatherCode == 0) - Assert.AreEqual("Clear sky", weatherCodeString); - - if (weatherCode == 100) - Assert.AreEqual("Invalid weathercode", weatherCodeString); - } - } - } -} \ No newline at end of file diff --git a/OpenMeteoTests/WeatherCodeHelperTests.cs b/OpenMeteoTests/WeatherCodeHelperTests.cs new file mode 100644 index 0000000..676412f --- /dev/null +++ b/OpenMeteoTests/WeatherCodeHelperTests.cs @@ -0,0 +1,26 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using OpenMeteo; + +namespace OpenMeteoTests +{ + [TestClass] + public class WeatherCodeHelperTests + { + [DataTestMethod] + [DataRow(0, "Clear sky")] + [DataRow(1, "Mainly clear")] + [DataRow(2, "Partly cloudy")] + [DataRow(3, "Overcast")] + [DataRow(51, "Light drizzle")] + [DataRow(53, "Moderate drizzle")] + [DataRow(96, "Thunderstorm with light hail")] + [DataRow(99, "Thunderstorm with heavy hail")] + [DataRow(100, "Invalid weathercode")] + public void Weather_Codes_To_String_Tests(int weatherCode, string expectedString) + { + string weatherCodeString = WeatherCodeHelper.WeathercodeToString(weatherCode); + Assert.IsInstanceOfType(weatherCodeString, typeof(string)); + Assert.AreEqual(expectedString, weatherCodeString); + } + } +} \ No newline at end of file