From f862a9794f7fa621af16dc38713d13f2f899797e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Mon, 17 Oct 2022 23:52:58 +0200 Subject: [PATCH] adds check for tests to validate parameters and method sent to piwigo --- PiwigoDotnet/Piwigo.Client.Tests/ApiTestsBase.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/PiwigoDotnet/Piwigo.Client.Tests/ApiTestsBase.cs b/PiwigoDotnet/Piwigo.Client.Tests/ApiTestsBase.cs index c4e5194..88f719d 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/ApiTestsBase.cs +++ b/PiwigoDotnet/Piwigo.Client.Tests/ApiTestsBase.cs @@ -1,4 +1,5 @@ using Flurl.Http.Configuration; +using Flurl.Http.Content; using Flurl.Http.Testing; using Microsoft.Extensions.Logging.Abstractions; using Newtonsoft.Json; @@ -37,10 +38,9 @@ public class ApiTestsBase HttpTest?.Dispose(); } - internal void SetOkResult() { - SetJsonResult(@"{stat: ""ok""}"); + SetJsonResult(@"{stat: ""ok"", result: null}"); } internal void SetJsonResult(string json) @@ -48,6 +48,18 @@ public class ApiTestsBase HttpTest?.RespondWith(json); } + protected void CorrectMethodShouldGetCalled(string methodName) + { + CorrectParamShouldGetSent("method", methodName); + } + + protected void CorrectParamShouldGetSent(string paramName, string methodName) + { + HttpTest?.ShouldHaveMadeACall().With(c => + c.HttpRequestMessage.Content.As().Parts.OfType().Select(p => new { p.Headers.ContentDisposition?.Name, p.Content }) + .Where(s => s.Name?.Equals(paramName) ?? false).Any(s => s.Content.Equals(methodName, StringComparison.OrdinalIgnoreCase))); + } + internal void SetJsonResult(PiwigoResponse serverResponse) { var settings = new JsonSerializerSettings