From dd7f1c1ea047b92100f79acaacbe08e80ca21029 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 22 Nov 2024 13:19:42 +0100 Subject: [PATCH] =?UTF-8?q?fix(BaseHttpClientService):=20Null-Kontrolle=20?= =?UTF-8?q?zum=20Pfad=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseHttpClientService.cs | 4 ++-- .../Client/BaseHttpClientServiceTest.cs | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/DigitalData.Core.Client/BaseHttpClientService.cs b/DigitalData.Core.Client/BaseHttpClientService.cs index b5926a3..5d379f2 100644 --- a/DigitalData.Core.Client/BaseHttpClientService.cs +++ b/DigitalData.Core.Client/BaseHttpClientService.cs @@ -48,10 +48,10 @@ namespace DigitalData.Core.Client uriBuilder.Scheme = scheme; if (port is int portInt) uriBuilder.Port = portInt; - uriBuilder.Path = UriCombine(Path, path.Trim(URI_TRIM_CHARS)); + uriBuilder.Path = UriCombine(Path, path?.Trim(URI_TRIM_CHARS) ?? string.Empty); // Add query parameters if provided - if (queryParams?.Count > 0) + if (queryParams?.Any() ?? false) { var query = HttpUtility.ParseQueryString(uriBuilder.Query); foreach (var param in queryParams) diff --git a/DigitalData.Core.Tests/Client/BaseHttpClientServiceTest.cs b/DigitalData.Core.Tests/Client/BaseHttpClientServiceTest.cs index f7ce9ae..8429419 100644 --- a/DigitalData.Core.Tests/Client/BaseHttpClientServiceTest.cs +++ b/DigitalData.Core.Tests/Client/BaseHttpClientServiceTest.cs @@ -37,16 +37,23 @@ namespace DigitalData.Core.Tests.Client { var queryParams = new Dictionary { - { "userId", "1" } + { "id", "1" } }; // Act - var expectedUserId = (int)await _service.FetchAsync(queryParams: queryParams, sendWithCookie: false, saveCookie: false) - .ThenAsync(res => res.Json()) - .ThenAsync(todo => todo.userId); - - // Assert - Assert.That(expectedUserId, Is.EqualTo(1), "The userId of the fetched JSON object should be 1."); + var dyn_id = await _service.FetchAsync(queryParams: queryParams, sendWithCookie: false, saveCookie: false) + .ThenAsync(res => res.JsonList()) + .ThenAsync(todo => todo.FirstOrDefault()?.userId); + + try + { + Assert.That((int)dyn_id, Is.EqualTo(1), "The userId of the fetched JSON object should be 1."); + } + catch (InvalidCastException) + { + // Handle the case where the cast is not possible + Assert.Fail("The id could not be cast to an integer."); + } } } } \ No newline at end of file