From ad60021f0cc144f34ef5c678aa50fdeb0c75f1d7 Mon Sep 17 00:00:00 2001 From: "Eric Sibly [chullybun]" Date: Tue, 17 Sep 2024 10:20:23 -0700 Subject: [PATCH] v3.25.2 (#119) - *Fixed:* `HttpRequestOptions.WithQuery` fixed to ensure any previously set `Include` and `Exclude` fields are not lost (results in a merge); i.e. only the `Filter` and `OrderBy` properties are explicitly overridden. --- CHANGELOG.md | 3 +++ Common.targets | 2 +- src/CoreEx/Http/HttpRequestOptions.cs | 10 ++++++++++ .../Framework/Http/HttpRequestOptionsTest.cs | 11 +++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d31ccf64..4c7b6a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Represents the **NuGet** versions. +## v3.25.2 +- *Fixed:* `HttpRequestOptions.WithQuery` fixed to ensure any previously set `Include` and `Exclude` fields are not lost (results in a merge); i.e. only the `Filter` and `OrderBy` properties are explicitly overridden. + ## v3.25.1 - *Fixed:* Extend `QueryFilterFieldConfigBase` to include `AsNullable()` to specifiy whether the field supports `null`. - *Fixed:* Extend `QueryFilterFieldConfigBase` to include `WithResultWriter()` to specify a function to override the corresponding LINQ statement result writing. diff --git a/Common.targets b/Common.targets index 6ba7b822..1bdf29e6 100644 --- a/Common.targets +++ b/Common.targets @@ -1,6 +1,6 @@  - 3.25.1 + 3.25.2 preview Avanade Avanade diff --git a/src/CoreEx/Http/HttpRequestOptions.cs b/src/CoreEx/Http/HttpRequestOptions.cs index a5e33030..b5972903 100644 --- a/src/CoreEx/Http/HttpRequestOptions.cs +++ b/src/CoreEx/Http/HttpRequestOptions.cs @@ -142,8 +142,18 @@ public HttpRequestOptions OrderBy(string orderby) /// /// The . /// The current instance to support fluent-style method-chaining. + /// Any existing and/or fields will be integrated into the . public HttpRequestOptions WithQuery(QueryArgs? query) { + if (Query is not null && query is not null) + { + if (Query.IncludeFields is not null) + query.Include([.. Query.IncludeFields]); + + if (Query.ExcludeFields is not null) + query.Exclude([.. Query.ExcludeFields]); + } + Query = query; return this; } diff --git a/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs b/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs index 36afd15c..788c40fd 100644 --- a/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs +++ b/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs @@ -157,5 +157,16 @@ public void UrlQueryString() hr.ApplyRequestOptions(ro); Assert.That(hr.RequestUri!.AbsoluteUri, Is.EqualTo("https://unittest/testing?fruit=banana&fruit=apple")); } + + [Test] + public void QueryArgsQueryString() + { + var qa = QueryArgs.Create("name eq 'bob'"); + var hr = new HttpRequestMessage(HttpMethod.Get, "https://unittest/testing"); + var ro = new HttpRequestOptions() { IncludeInactive = true }.Include("name", "text"); + ro = ro.WithQuery(qa); + hr.ApplyRequestOptions(ro); + Assert.That(hr.RequestUri!.AbsoluteUri, Is.EqualTo("https://unittest/testing?$filter=name+eq+%27bob%27&$fields=name,text&$inactive=true")); + } } } \ No newline at end of file