From 8d7bd65ff2ae61aa62b773646cc167d0a8745e81 Mon Sep 17 00:00:00 2001 From: Boris Date: Sun, 1 Sep 2024 00:43:56 +0200 Subject: [PATCH] Rider cleanup --- README.md | 17 +- build/Build.cs | 1 - build/Configuration.cs | 13 +- build/Directory.Build.props | 6 +- build/Directory.Build.targets | 6 +- build/_build.csproj | 32 +-- src/WeerLive.Example/WeerLive.Example.csproj | 12 +- .../DependencyInjectionExtensions.cs | 3 +- src/WeerLive.Lib/WeerLive.Lib.csproj | 4 +- src/WeerLive.Test/WeerLive.Test.csproj | 6 +- src/WeerLive.Test/WeerLiveTests.cs | 192 +++++++++--------- 11 files changed, 146 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index 4e11180..1879d11 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # WeerLive.Net + WeerLive.Net is a library for the Dutch weather service [WeerLive](https://weerlive.nl/delen.php). This library provides the following features: + - Get the live weather for a location - Get the weather forecast for the coming 24 hours for a location - Get the weather forecast for the coming 5 days for a location @@ -8,8 +10,11 @@ This library provides the following features: The location can be either a city name or latitude and longitude coordinates. ## Usage -Here you can see a simple example of how to use the library combined with the Microsoft.Extensions.DependencyInjection library. -This example can also be found in the [example project](https://github.com/BorisGerretzen/WeerLive.Net/tree/main/src/WeerLive.Example). + +Here you can see a simple example of how to use the library combined with the Microsoft.Extensions.DependencyInjection +library. +This example can also be found in +the [example project](https://github.com/BorisGerretzen/WeerLive.Net/tree/main/src/WeerLive.Example). ```csharp var builder = Host.CreateDefaultBuilder(args); @@ -34,6 +39,7 @@ logger.LogInformation("Today in Amsterdam: {Temperature}°C with a RH of {Humidi ``` And without dependency injection: + ```csharp var httpClient = new HttpClient(); var options = new WeerLiveOptions @@ -53,5 +59,8 @@ Console.WriteLine($"Today in Amsterdam: {forecast.LiveWeather.Temperature}°C wi ``` ## API key -To use the WeerLive API, you need an API key. You can get a free API key by registering on the [WeerLive website](https://weerlive.nl/delen.php). -With an API key you can make up to 300 requests per day. In the responses you can find how many requests you have left for the day. \ No newline at end of file + +To use the WeerLive API, you need an API key. You can get a free API key by registering on +the [WeerLive website](https://weerlive.nl/delen.php). +With an API key you can make up to 300 requests per day. In the responses you can find how many requests you have left +for the day. \ No newline at end of file diff --git a/build/Build.cs b/build/Build.cs index 1966b48..9fb2519 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using Nuke.Common; using Nuke.Common.CI.GitHubActions; diff --git a/build/Configuration.cs b/build/Configuration.cs index 9c08b1a..7ea2754 100644 --- a/build/Configuration.cs +++ b/build/Configuration.cs @@ -1,16 +1,11 @@ -using System; using System.ComponentModel; -using System.Linq; using Nuke.Common.Tooling; [TypeConverter(typeof(TypeConverter))] public class Configuration : Enumeration { - public static Configuration Debug = new Configuration { Value = nameof(Debug) }; - public static Configuration Release = new Configuration { Value = nameof(Release) }; + public static Configuration Debug = new() { Value = nameof(Debug) }; + public static Configuration Release = new() { Value = nameof(Release) }; - public static implicit operator string(Configuration configuration) - { - return configuration.Value; - } -} + public static implicit operator string(Configuration configuration) => configuration.Value; +} \ No newline at end of file diff --git a/build/Directory.Build.props b/build/Directory.Build.props index e147d63..b1034a8 100644 --- a/build/Directory.Build.props +++ b/build/Directory.Build.props @@ -1,8 +1,8 @@ - - - + + + diff --git a/build/Directory.Build.targets b/build/Directory.Build.targets index 2532609..275d93e 100644 --- a/build/Directory.Build.targets +++ b/build/Directory.Build.targets @@ -1,8 +1,8 @@ - - - + + + diff --git a/build/_build.csproj b/build/_build.csproj index f4c817f..0365afb 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -1,22 +1,22 @@ - - Exe - net8.0 - - CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 - .. - .. - 1 - false - + + Exe + net8.0 + + CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 + .. + .. + 1 + false + - - - + + + - - - + + + diff --git a/src/WeerLive.Example/WeerLive.Example.csproj b/src/WeerLive.Example/WeerLive.Example.csproj index 8aa8bcc..c13d183 100644 --- a/src/WeerLive.Example/WeerLive.Example.csproj +++ b/src/WeerLive.Example/WeerLive.Example.csproj @@ -8,18 +8,18 @@ - + - - + + - - Always - + + Always + diff --git a/src/WeerLive.Lib/DependencyInjectionExtensions.cs b/src/WeerLive.Lib/DependencyInjectionExtensions.cs index fcf3cd5..6de5a1d 100644 --- a/src/WeerLive.Lib/DependencyInjectionExtensions.cs +++ b/src/WeerLive.Lib/DependencyInjectionExtensions.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using WeerLive.Lib.Client; namespace WeerLive.Lib; diff --git a/src/WeerLive.Lib/WeerLive.Lib.csproj b/src/WeerLive.Lib/WeerLive.Lib.csproj index d798d5c..a153772 100644 --- a/src/WeerLive.Lib/WeerLive.Lib.csproj +++ b/src/WeerLive.Lib/WeerLive.Lib.csproj @@ -13,7 +13,7 @@ weer, weerlive, weersvoorspelling git - + True @@ -24,7 +24,7 @@ \ - + diff --git a/src/WeerLive.Test/WeerLive.Test.csproj b/src/WeerLive.Test/WeerLive.Test.csproj index b618af8..b2dae07 100644 --- a/src/WeerLive.Test/WeerLive.Test.csproj +++ b/src/WeerLive.Test/WeerLive.Test.csproj @@ -12,11 +12,11 @@ - + - + @@ -24,7 +24,7 @@ - + diff --git a/src/WeerLive.Test/WeerLiveTests.cs b/src/WeerLive.Test/WeerLiveTests.cs index 9fedfcf..153c3ca 100644 --- a/src/WeerLive.Test/WeerLiveTests.cs +++ b/src/WeerLive.Test/WeerLiveTests.cs @@ -1,108 +1,11 @@ using Microsoft.Extensions.Options; -using Moq; using RichardSzalay.MockHttp; -using WeerLive.Lib; using WeerLive.Lib.Client; namespace WeerLive.Test; public class WeerLiveTests { - [Test] - public async Task GetAsync_DemoLocation() - { - var httpClient = MockClient("?key=demo&locatie=Amsterdam", DemoResponse); - var options = Options.Create(new WeerLiveOptions { ApiKey = "demo" }); - var client = new WeerLiveClient(httpClient, options); - - var response = await client.GetAsync("Amsterdam"); - - Assert.Multiple(() => - { - Assert.That(response, Is.Not.Null); - Assert.That(response!.LiveWeatherList, Has.Count.EqualTo(1)); - Assert.That(response.LiveWeather!.Place, Is.EqualTo("Amsterdam")); - Assert.That(response.LiveWeather.Temperature, Is.EqualTo(18.9)); - Assert.That(response.LiveWeather.TemperaturePerceived, Is.EqualTo(17.3)); - Assert.That(response.LiveWeather.Summary, Is.EqualTo("Licht bewolkt")); - Assert.That(response.LiveWeather.Humidity, Is.EqualTo(71)); - Assert.That(response.LiveWeather.WindDirection, Is.EqualTo("ONO")); - Assert.That(response.LiveWeather.WindDirectionDegrees, Is.EqualTo(62.1)); - Assert.That(response.LiveWeather.WindSpeedMs, Is.EqualTo(6.33)); - Assert.That(response.LiveWeather.WindSpeedBft, Is.EqualTo(4)); - Assert.That(response.LiveWeather.WindSpeedKn, Is.EqualTo(12.3)); - Assert.That(response.LiveWeather.WindSpeedKmh, Is.EqualTo(22.8)); - Assert.That(response.LiveWeather.AirPressure, Is.EqualTo(1021.51)); - Assert.That(response.LiveWeather.AirPressureMmHg, Is.EqualTo(766)); - Assert.That(response.LiveWeather.DewPoint, Is.EqualTo(13.6)); - Assert.That(response.LiveWeather.Visibility, Is.EqualTo(30400)); - Assert.That(response.LiveWeather.SolarIrradiance, Is.EqualTo(0)); - Assert.That(response.LiveWeather.DayForecast, - Is.EqualTo("Vrij zonnig en vrijwel overal droog. Zondag in het zuiden tropisch warm")); - Assert.That(response.LiveWeather.Sunrise, Is.EqualTo("06:49")); - Assert.That(response.LiveWeather.Sunset, Is.EqualTo("20:32")); - Assert.That(response.LiveWeather.Image, Is.EqualTo("wolkennacht")); - Assert.That(response.LiveWeather.WeatherAlert, Is.EqualTo(0)); - Assert.That(response.LiveWeather.WeatherAlertHeader, Is.EqualTo("Er zijn geen waarschuwingen")); - Assert.That(response.LiveWeather.WeatherAlertDescription, - Is.EqualTo(" Er zijn momenteel geen waarschuwingen van kracht.")); - Assert.That(response.LiveWeather.WarningColor, Is.EqualTo("groen")); - Assert.That(response.LiveWeather.WeatherAlertStart, Is.EqualTo("-")); - Assert.That(response.LiveWeather.WeatherAlertTimestamp, Is.EqualTo(0)); - Assert.That(response.LiveWeather.WeatherAlertColorCode, Is.EqualTo("-")); - }); - - Assert.Multiple(() => - { - Assert.That(response.WeekForecast, Has.Count.EqualTo(5)); - Assert.That(response.WeekForecast[0].Day, Is.EqualTo("31-08-2024")); - Assert.That(response.WeekForecast[0].Image, Is.EqualTo("halfbewolkt")); - Assert.That(response.WeekForecast[0].MaxTemperature, Is.EqualTo(19)); - Assert.That(response.WeekForecast[0].MinTemperature, Is.EqualTo(19)); - Assert.That(response.WeekForecast[0].WindSpeedBft, Is.EqualTo(3)); - Assert.That(response.WeekForecast[0].WindSpeedKmh, Is.EqualTo(18)); - Assert.That(response.WeekForecast[0].WindSpeedKn, Is.EqualTo(10)); - Assert.That(response.WeekForecast[0].WindSpeedMs, Is.EqualTo(5)); - Assert.That(response.WeekForecast[0].WindDirectionDegrees, Is.EqualTo(67)); - Assert.That(response.WeekForecast[0].WindDirection, Is.EqualTo("NO")); - Assert.That(response.WeekForecast[0].ProbabilityPrecipitation, Is.EqualTo(0)); - Assert.That(response.WeekForecast[0].ProbabilitySunshine, Is.EqualTo(91)); - }); - - Assert.Multiple(() => - { - Assert.That(response.HourForecast, Has.Count.EqualTo(24)); - Assert.That(response.HourForecast[0].Hour, Is.EqualTo("31-08-2024 23:00")); - Assert.That(response.HourForecast[0].Image, Is.EqualTo("nachtbewolkt")); - Assert.That(response.HourForecast[0].Temperature, Is.EqualTo(19)); - Assert.That(response.HourForecast[0].WindSpeedBft, Is.EqualTo(4)); - Assert.That(response.HourForecast[0].WindSpeedKmh, Is.EqualTo(21)); - Assert.That(response.HourForecast[0].WindSpeedKn, Is.EqualTo(12)); - Assert.That(response.HourForecast[0].WindSpeedMs, Is.EqualTo(6)); - Assert.That(response.HourForecast[0].WindDirectionDegrees, Is.EqualTo(71)); - Assert.That(response.HourForecast[0].WindDirectionString, Is.EqualTo("NO")); - Assert.That(response.HourForecast[0].Precipitation, Is.EqualTo(0)); - Assert.That(response.HourForecast[0].SolarIrradiance, Is.EqualTo(0)); - }); - - Assert.Multiple(() => - { - Assert.That(response.ApiInformationList, Has.Count.EqualTo(1)); - Assert.That(response.ApiInformation!.Source, Is.EqualTo("Bron: Weerdata KNMI/NOAA via Weerlive.nl")); - Assert.That(response.ApiInformation.MaxRequests, Is.EqualTo(300)); - Assert.That(response.ApiInformation.RemainingRequests, Is.EqualTo(0)); - }); - } - - private static HttpClient MockClient(string query, string expectedResponse) - { - var handlerMock = new MockHttpMessageHandler(); - handlerMock - .When(HttpMethod.Get, $"https://weerlive.nl/api/weerlive_api_v2.php{query}") - .Respond("application/json", expectedResponse); - return new HttpClient(handlerMock); - } - private const string DemoResponse = """ { "liveweer": [ @@ -557,4 +460,99 @@ private static HttpClient MockClient(string query, string expectedResponse) ] } """; + + [Test] + public async Task GetAsync_DemoLocation() + { + var httpClient = MockClient("?key=demo&locatie=Amsterdam", DemoResponse); + var options = Options.Create(new WeerLiveOptions { ApiKey = "demo" }); + var client = new WeerLiveClient(httpClient, options); + + var response = await client.GetAsync("Amsterdam"); + + Assert.Multiple(() => + { + Assert.That(response, Is.Not.Null); + Assert.That(response!.LiveWeatherList, Has.Count.EqualTo(1)); + Assert.That(response.LiveWeather!.Place, Is.EqualTo("Amsterdam")); + Assert.That(response.LiveWeather.Temperature, Is.EqualTo(18.9)); + Assert.That(response.LiveWeather.TemperaturePerceived, Is.EqualTo(17.3)); + Assert.That(response.LiveWeather.Summary, Is.EqualTo("Licht bewolkt")); + Assert.That(response.LiveWeather.Humidity, Is.EqualTo(71)); + Assert.That(response.LiveWeather.WindDirection, Is.EqualTo("ONO")); + Assert.That(response.LiveWeather.WindDirectionDegrees, Is.EqualTo(62.1)); + Assert.That(response.LiveWeather.WindSpeedMs, Is.EqualTo(6.33)); + Assert.That(response.LiveWeather.WindSpeedBft, Is.EqualTo(4)); + Assert.That(response.LiveWeather.WindSpeedKn, Is.EqualTo(12.3)); + Assert.That(response.LiveWeather.WindSpeedKmh, Is.EqualTo(22.8)); + Assert.That(response.LiveWeather.AirPressure, Is.EqualTo(1021.51)); + Assert.That(response.LiveWeather.AirPressureMmHg, Is.EqualTo(766)); + Assert.That(response.LiveWeather.DewPoint, Is.EqualTo(13.6)); + Assert.That(response.LiveWeather.Visibility, Is.EqualTo(30400)); + Assert.That(response.LiveWeather.SolarIrradiance, Is.EqualTo(0)); + Assert.That(response.LiveWeather.DayForecast, + Is.EqualTo("Vrij zonnig en vrijwel overal droog. Zondag in het zuiden tropisch warm")); + Assert.That(response.LiveWeather.Sunrise, Is.EqualTo("06:49")); + Assert.That(response.LiveWeather.Sunset, Is.EqualTo("20:32")); + Assert.That(response.LiveWeather.Image, Is.EqualTo("wolkennacht")); + Assert.That(response.LiveWeather.WeatherAlert, Is.EqualTo(0)); + Assert.That(response.LiveWeather.WeatherAlertHeader, Is.EqualTo("Er zijn geen waarschuwingen")); + Assert.That(response.LiveWeather.WeatherAlertDescription, + Is.EqualTo(" Er zijn momenteel geen waarschuwingen van kracht.")); + Assert.That(response.LiveWeather.WarningColor, Is.EqualTo("groen")); + Assert.That(response.LiveWeather.WeatherAlertStart, Is.EqualTo("-")); + Assert.That(response.LiveWeather.WeatherAlertTimestamp, Is.EqualTo(0)); + Assert.That(response.LiveWeather.WeatherAlertColorCode, Is.EqualTo("-")); + }); + + Assert.Multiple(() => + { + Assert.That(response.WeekForecast, Has.Count.EqualTo(5)); + Assert.That(response.WeekForecast[0].Day, Is.EqualTo("31-08-2024")); + Assert.That(response.WeekForecast[0].Image, Is.EqualTo("halfbewolkt")); + Assert.That(response.WeekForecast[0].MaxTemperature, Is.EqualTo(19)); + Assert.That(response.WeekForecast[0].MinTemperature, Is.EqualTo(19)); + Assert.That(response.WeekForecast[0].WindSpeedBft, Is.EqualTo(3)); + Assert.That(response.WeekForecast[0].WindSpeedKmh, Is.EqualTo(18)); + Assert.That(response.WeekForecast[0].WindSpeedKn, Is.EqualTo(10)); + Assert.That(response.WeekForecast[0].WindSpeedMs, Is.EqualTo(5)); + Assert.That(response.WeekForecast[0].WindDirectionDegrees, Is.EqualTo(67)); + Assert.That(response.WeekForecast[0].WindDirection, Is.EqualTo("NO")); + Assert.That(response.WeekForecast[0].ProbabilityPrecipitation, Is.EqualTo(0)); + Assert.That(response.WeekForecast[0].ProbabilitySunshine, Is.EqualTo(91)); + }); + + Assert.Multiple(() => + { + Assert.That(response.HourForecast, Has.Count.EqualTo(24)); + Assert.That(response.HourForecast[0].Hour, Is.EqualTo("31-08-2024 23:00")); + Assert.That(response.HourForecast[0].Image, Is.EqualTo("nachtbewolkt")); + Assert.That(response.HourForecast[0].Temperature, Is.EqualTo(19)); + Assert.That(response.HourForecast[0].WindSpeedBft, Is.EqualTo(4)); + Assert.That(response.HourForecast[0].WindSpeedKmh, Is.EqualTo(21)); + Assert.That(response.HourForecast[0].WindSpeedKn, Is.EqualTo(12)); + Assert.That(response.HourForecast[0].WindSpeedMs, Is.EqualTo(6)); + Assert.That(response.HourForecast[0].WindDirectionDegrees, Is.EqualTo(71)); + Assert.That(response.HourForecast[0].WindDirectionString, Is.EqualTo("NO")); + Assert.That(response.HourForecast[0].Precipitation, Is.EqualTo(0)); + Assert.That(response.HourForecast[0].SolarIrradiance, Is.EqualTo(0)); + }); + + Assert.Multiple(() => + { + Assert.That(response.ApiInformationList, Has.Count.EqualTo(1)); + Assert.That(response.ApiInformation!.Source, Is.EqualTo("Bron: Weerdata KNMI/NOAA via Weerlive.nl")); + Assert.That(response.ApiInformation.MaxRequests, Is.EqualTo(300)); + Assert.That(response.ApiInformation.RemainingRequests, Is.EqualTo(0)); + }); + } + + private static HttpClient MockClient(string query, string expectedResponse) + { + var handlerMock = new MockHttpMessageHandler(); + handlerMock + .When(HttpMethod.Get, $"https://weerlive.nl/api/weerlive_api_v2.php{query}") + .Respond("application/json", expectedResponse); + return new HttpClient(handlerMock); + } } \ No newline at end of file