From 366165ab71de0b24dd0e1431c84030c85a819bb5 Mon Sep 17 00:00:00 2001 From: "Eric Sibly [chullybun]" Date: Tue, 10 Dec 2024 14:12:10 -0800 Subject: [PATCH] v3.30.2 (#134) - *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. --- CHANGELOG.md | 4 +++ Common.targets | 2 +- src/CoreEx/Entities/QueryArgs.cs | 25 +++++++++++++++++++ src/CoreEx/Http/HttpRequestOptions.cs | 5 +++- .../Framework/Data/QueryArgsConfigTest.cs | 12 ++++----- .../Framework/Http/HttpRequestOptionsTest.cs | 13 +++++++++- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a343378..8aa0eba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Represents the **NuGet** versions. +## 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. + ## v3.30.1 - *Fixed:* Added support for `SettingsBase.DateTimeTransform`, `StringTransform`, `StringTrim` and `StringCase` to allow specification via configuration. - *Fixed:* Added support for `CoreEx:` hierarchy (optional) for all _CoreEx_ settings to enable a more structured and explicit configuration. diff --git a/Common.targets b/Common.targets index c0f9c6aa..acc4bcb2 100644 --- a/Common.targets +++ b/Common.targets @@ -1,6 +1,6 @@  - 3.30.1 + 3.30.2 preview Avanade Avanade diff --git a/src/CoreEx/Entities/QueryArgs.cs b/src/CoreEx/Entities/QueryArgs.cs index c956a123..0910c9ef 100644 --- a/src/CoreEx/Entities/QueryArgs.cs +++ b/src/CoreEx/Entities/QueryArgs.cs @@ -1,5 +1,6 @@ // Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx +using CoreEx.RefData; using System.Collections.Generic; namespace CoreEx.Entities @@ -39,6 +40,12 @@ public class QueryArgs /// Currently these are only used within CoreEx for JSON serialization filtering (see ). public List? ExcludeFields { get; set; } + /// + /// Indicates whether to include any related texts for the item(s). + /// + /// For example, include corresponding for any ReferenceData values returned in the JSON response payload. + public bool IsTextIncluded { get; set; } + /// /// Appends the to the . /// @@ -60,5 +67,23 @@ public QueryArgs Exclude(params string[] fields) (ExcludeFields ??= []).AddRange(fields); return this; } + + /// + /// Indicates whether to include any related texts for the item(s); see . + /// + /// The to support fluent-style method-chaining. + /// For example, include corresponding for any ReferenceData values returned in the JSON response payload. + public QueryArgs IncludeText() + { + IsTextIncluded = true; + return this; + } + + /// + /// An implicit cast from a filter to a . + /// + /// The . + /// The corresponding . + public static implicit operator QueryArgs(string? filter) => Create(filter); } } \ No newline at end of file diff --git a/src/CoreEx/Http/HttpRequestOptions.cs b/src/CoreEx/Http/HttpRequestOptions.cs index b5972903..6cd811bd 100644 --- a/src/CoreEx/Http/HttpRequestOptions.cs +++ b/src/CoreEx/Http/HttpRequestOptions.cs @@ -152,6 +152,9 @@ public HttpRequestOptions WithQuery(QueryArgs? query) if (Query.ExcludeFields is not null) query.Exclude([.. Query.ExcludeFields]); + + if (Query.IsTextIncluded) + query.IsTextIncluded = true; } Query = query; @@ -255,7 +258,7 @@ public HttpRequestOptions WithPaging(PagingArgs? paging) AddNameValuePairs(sb, QueryStringNameExcludeFields, Query.ExcludeFields.Where(x => !string.IsNullOrEmpty(x)).Select(x => HttpUtility.UrlEncode(x)).ToArray(), false, true); } - if (IncludeText) + if (IncludeText || (Query is not null && Query.IsTextIncluded)) AddNameValuePair(sb, QueryStringNameIncludeText, "true", false); if (IncludeInactive) diff --git a/tests/CoreEx.Test/Framework/Data/QueryArgsConfigTest.cs b/tests/CoreEx.Test/Framework/Data/QueryArgsConfigTest.cs index 318cf78d..7eb0f344 100644 --- a/tests/CoreEx.Test/Framework/Data/QueryArgsConfigTest.cs +++ b/tests/CoreEx.Test/Framework/Data/QueryArgsConfigTest.cs @@ -57,8 +57,8 @@ private static void AssertException(QueryArgsConfig config, string? filter, stri Assert.That(ex.Messages, Has.Count.EqualTo(1)); Assert.Multiple(() => { - Assert.That(ex.Messages.First().Property, Is.EqualTo("$filter")); - Assert.That(ex.Messages.First().Text, Does.StartWith(expected)); + Assert.That(ex.Messages!.First().Property, Is.EqualTo("$filter")); + Assert.That(ex.Messages!.First().Text, Does.StartWith(expected)); }); } @@ -305,12 +305,12 @@ public void OrderByParser_Invalid() void AssertException(string? orderBy, string expected) { var ex = Assert.Throws(() => _queryConfig.OrderByParser.Parse(orderBy).ThrowOnError()); - Assert.That(ex.Messages, Is.Not.Null); - Assert.That(ex.Messages, Has.Count.EqualTo(1)); + Assert.That(ex?.Messages, Is.Not.Null); + Assert.That(ex!.Messages, Has.Count.EqualTo(1)); Assert.Multiple(() => { - Assert.That(ex.Messages.First().Property, Is.EqualTo("$orderby")); - Assert.That(ex.Messages.First().Text, Does.StartWith(expected)); + Assert.That(ex.Messages!.First().Property, Is.EqualTo("$orderby")); + Assert.That(ex.Messages!.First().Text, Does.StartWith(expected)); }); } diff --git a/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs b/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs index 788c40fd..b1c5ff08 100644 --- a/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs +++ b/tests/CoreEx.Test/Framework/Http/HttpRequestOptionsTest.cs @@ -161,12 +161,23 @@ public void UrlQueryString() [Test] public void QueryArgsQueryString() { - var qa = QueryArgs.Create("name eq 'bob'"); + QueryArgs qa = "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")); } + + [Test] + public void QueryArgsQueryStringWithIncludeText() + { + var qa = QueryArgs.Create("name eq 'bob'").IncludeText(); + 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&$text=true&$inactive=true")); + } } } \ No newline at end of file