Skip to content

Commit c3c9c91

Browse files
committed
v3.30.2
- *Fixed:* Missing `QueryArgs.IncludeText` added to set the `$text=true` equivalent. - *Fixed:* Simplification of creating and setting the `QueryArgs.Filter` using an implict string operator.
1 parent e7d6be9 commit c3c9c91

File tree

6 files changed

+52
-9
lines changed

6 files changed

+52
-9
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Represents the **NuGet** versions.
44

5+
## v3.30.2
6+
- *Fixed:* Missing `QueryArgs.IncludeText` added to set the `$text=true` equivalent.
7+
- *Fixed:* Simplification of creating and setting the `QueryArgs.Filter` using an implict string operator.
8+
59
## v3.30.1
610
- *Fixed:* Added support for `SettingsBase.DateTimeTransform`, `StringTransform`, `StringTrim` and `StringCase` to allow specification via configuration.
711
- *Fixed:* Added support for `CoreEx:` hierarchy (optional) for all _CoreEx_ settings to enable a more structured and explicit configuration.

Common.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.30.1</Version>
3+
<Version>3.30.2</Version>
44
<LangVersion>preview</LangVersion>
55
<Authors>Avanade</Authors>
66
<Company>Avanade</Company>

src/CoreEx/Entities/QueryArgs.cs

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx
22

3+
using CoreEx.RefData;
34
using System.Collections.Generic;
45

56
namespace CoreEx.Entities
@@ -39,6 +40,12 @@ public class QueryArgs
3940
/// <remarks>Currently these are <b>only</b> used within <i>CoreEx</i> for JSON serialization filtering (see <see cref="CoreEx.Json.IJsonSerializer.TryApplyFilter{T}(T, IEnumerable{string}?, out object, Json.JsonPropertyFilter, System.StringComparison, System.Action{Json.IJsonPreFilterInspector}?)"/>).</remarks>
4041
public List<string>? ExcludeFields { get; set; }
4142

43+
/// <summary>
44+
/// Indicates whether to include any related texts for the item(s).
45+
/// </summary>
46+
/// <remarks>For example, include corresponding <see cref="IReferenceData.Text"/> for any <b>ReferenceData</b> values returned in the JSON response payload.</remarks>
47+
public bool IsTextIncluded { get; set; }
48+
4249
/// <summary>
4350
/// Appends the <paramref name="fields"/> to the <see cref="IncludeFields"/>.
4451
/// </summary>
@@ -60,5 +67,23 @@ public QueryArgs Exclude(params string[] fields)
6067
(ExcludeFields ??= []).AddRange(fields);
6168
return this;
6269
}
70+
71+
/// <summary>
72+
/// Indicates whether to include any related texts for the item(s); see <see cref="IsTextIncluded"/>.
73+
/// </summary>
74+
/// <returns>The <see cref="QueryArgs"/> to support fluent-style method-chaining.</returns>
75+
/// <remarks>For example, include corresponding <see cref="IReferenceData.Text"/> for any <b>ReferenceData</b> values returned in the JSON response payload.</remarks>
76+
public QueryArgs IncludeText()
77+
{
78+
IsTextIncluded = true;
79+
return this;
80+
}
81+
82+
/// <summary>
83+
/// An implicit cast from a filter <see cref="string"/> to a <see cref="QueryArgs"/>.
84+
/// </summary>
85+
/// <param name="filter">The <see cref="Filter"/>.</param>
86+
/// <returns>The corresponding <see cref="QueryArgs"/>.</returns>
87+
public static implicit operator QueryArgs(string? filter) => Create(filter);
6388
}
6489
}

src/CoreEx/Http/HttpRequestOptions.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public HttpRequestOptions WithQuery(QueryArgs? query)
152152

153153
if (Query.ExcludeFields is not null)
154154
query.Exclude([.. Query.ExcludeFields]);
155+
156+
if (Query.IsTextIncluded)
157+
query.IsTextIncluded = true;
155158
}
156159

157160
Query = query;
@@ -255,7 +258,7 @@ public HttpRequestOptions WithPaging(PagingArgs? paging)
255258
AddNameValuePairs(sb, QueryStringNameExcludeFields, Query.ExcludeFields.Where(x => !string.IsNullOrEmpty(x)).Select(x => HttpUtility.UrlEncode(x)).ToArray(), false, true);
256259
}
257260

258-
if (IncludeText)
261+
if (IncludeText || (Query is not null && Query.IsTextIncluded))
259262
AddNameValuePair(sb, QueryStringNameIncludeText, "true", false);
260263

261264
if (IncludeInactive)

tests/CoreEx.Test/Framework/Data/QueryArgsConfigTest.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ private static void AssertException(QueryArgsConfig config, string? filter, stri
5757
Assert.That(ex.Messages, Has.Count.EqualTo(1));
5858
Assert.Multiple(() =>
5959
{
60-
Assert.That(ex.Messages.First().Property, Is.EqualTo("$filter"));
61-
Assert.That(ex.Messages.First().Text, Does.StartWith(expected));
60+
Assert.That(ex.Messages!.First().Property, Is.EqualTo("$filter"));
61+
Assert.That(ex.Messages!.First().Text, Does.StartWith(expected));
6262
});
6363
}
6464

@@ -305,12 +305,12 @@ public void OrderByParser_Invalid()
305305
void AssertException(string? orderBy, string expected)
306306
{
307307
var ex = Assert.Throws<QueryOrderByParserException>(() => _queryConfig.OrderByParser.Parse(orderBy).ThrowOnError());
308-
Assert.That(ex.Messages, Is.Not.Null);
309-
Assert.That(ex.Messages, Has.Count.EqualTo(1));
308+
Assert.That(ex?.Messages, Is.Not.Null);
309+
Assert.That(ex!.Messages, Has.Count.EqualTo(1));
310310
Assert.Multiple(() =>
311311
{
312-
Assert.That(ex.Messages.First().Property, Is.EqualTo("$orderby"));
313-
Assert.That(ex.Messages.First().Text, Does.StartWith(expected));
312+
Assert.That(ex.Messages!.First().Property, Is.EqualTo("$orderby"));
313+
Assert.That(ex.Messages!.First().Text, Does.StartWith(expected));
314314
});
315315
}
316316

tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,23 @@ public void UrlQueryString()
161161
[Test]
162162
public void QueryArgsQueryString()
163163
{
164-
var qa = QueryArgs.Create("name eq 'bob'");
164+
QueryArgs qa = "name eq 'bob'";
165165
var hr = new HttpRequestMessage(HttpMethod.Get, "https://unittest/testing");
166166
var ro = new HttpRequestOptions() { IncludeInactive = true }.Include("name", "text");
167167
ro = ro.WithQuery(qa);
168168
hr.ApplyRequestOptions(ro);
169169
Assert.That(hr.RequestUri!.AbsoluteUri, Is.EqualTo("https://unittest/testing?$filter=name+eq+%27bob%27&$fields=name,text&$inactive=true"));
170170
}
171+
172+
[Test]
173+
public void QueryArgsQueryStringWithIncludeText()
174+
{
175+
var qa = QueryArgs.Create("name eq 'bob'").IncludeText();
176+
var hr = new HttpRequestMessage(HttpMethod.Get, "https://unittest/testing");
177+
var ro = new HttpRequestOptions() { IncludeInactive = true }.Include("name", "text");
178+
ro = ro.WithQuery(qa);
179+
hr.ApplyRequestOptions(ro);
180+
Assert.That(hr.RequestUri!.AbsoluteUri, Is.EqualTo("https://unittest/testing?$filter=name+eq+%27bob%27&$fields=name,text&$text=true&$inactive=true"));
181+
}
171182
}
172183
}

0 commit comments

Comments
 (0)