Skip to content

Commit

Permalink
v3.25.2 (#119)
Browse files Browse the repository at this point in the history
- *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.
  • Loading branch information
chullybun authored Sep 17, 2024
1 parent 5fa5d7a commit ad60021
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.25.1</Version>
<Version>3.25.2</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
10 changes: 10 additions & 0 deletions src/CoreEx/Http/HttpRequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,18 @@ public HttpRequestOptions OrderBy(string orderby)
/// </summary>
/// <param name="query">The <see cref="QueryArgs"/>.</param>
/// <returns>The current <see cref="HttpRequestOptions"/> instance to support fluent-style method-chaining.</returns>
/// <remarks>Any existing <see cref="Include(string[])"/> and/or <see cref="Exclude(string[])"/> fields will be integrated into the <paramref name="query"/>.</remarks>
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;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
}

0 comments on commit ad60021

Please sign in to comment.