From f845b51ff1a0cfd22a53119579c69195811674bd Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Fri, 22 Sep 2023 04:59:38 -0700 Subject: [PATCH 1/5] [AppConfiguration] Added test to reproduce bug --- .../src/ConfigurationClient.cs | 1 - .../tests/ConfigurationLiveTests.cs | 44 ++++++++++++++++++- .../tests/ConfigurationSettingTests.cs | 1 - 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs index 34e6080482797..6398d8393f2c3 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Azure.Core; diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs index d42439a635c5e..e4ac987230083 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs @@ -1046,7 +1046,7 @@ public async Task GetBatchSettingWithFields() Assert.IsNotNull(batch[0].Key); Assert.IsNotNull(batch[0].Label); - Assert.IsNotNull(batch[0].ETag); + Assert.AreNotEqual(batch[0].ETag, default(ETag)); Assert.IsNull(batch[0].Value); Assert.IsNull(batch[0].ContentType); Assert.IsNull(batch[0].LastModified); @@ -1118,7 +1118,7 @@ public async Task GetBatchSettingWithAllFields() Assert.IsNotNull(batch[0].Label); Assert.IsNotNull(batch[0].Value); Assert.IsNotNull(batch[0].ContentType); - Assert.IsNotNull(batch[0].ETag); + Assert.AreNotEqual(batch[0].ETag, default(ETag)); Assert.IsNotNull(batch[0].LastModified); Assert.IsNotNull(batch[0].IsReadOnly); } @@ -1128,6 +1128,46 @@ public async Task GetBatchSettingWithAllFields() } } + [RecordedTest] + public async Task GetBatchSettingWithAllFieldsSetIndividually() + { + ConfigurationClient service = GetClient(); + string key = GenerateKeyId("keyFields-"); + ConfigurationSetting setting = await service.AddConfigurationSettingAsync(new ConfigurationSetting(key, "my_value", "my_label") + { + ContentType = "content-type", + Tags = { { "my_tag", "my_tag_value" } } + }); + + try + { + SettingSelector selector = new SettingSelector + { + KeyFilter = key, + Fields = SettingFields.Key | SettingFields.Label | SettingFields.Value | SettingFields.ContentType + | SettingFields.ETag | SettingFields.LastModified | SettingFields.IsReadOnly | SettingFields.Tags + }; + + ConfigurationSetting[] batch = (await service.GetConfigurationSettingsAsync(selector, CancellationToken.None).ToEnumerableAsync()) + .ToArray(); + + Assert.AreEqual(1, batch.Length); + + Assert.IsNotNull(batch[0].Key); + Assert.IsNotNull(batch[0].Label); + Assert.IsNotNull(batch[0].Value); + Assert.IsNotNull(batch[0].ContentType); + Assert.AreNotEqual(batch[0].ETag, default(ETag)); + Assert.IsNotNull(batch[0].LastModified); + Assert.IsNotNull(batch[0].IsReadOnly); + Assert.IsNotEmpty(batch[0].Tags); + } + finally + { + AssertStatus200(await service.DeleteConfigurationSettingAsync(setting.Key, setting.Label)); + } + } + [RecordedTest] public async Task GetBatchSettingSpecialCharacters() { diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs index d0b5e6c29ca58..18ea5bb798cc9 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Text.Json; -using System.Text.Json.Serialization; using Azure.Core; namespace Azure.Data.AppConfiguration.Tests From 2e581a436db50615ed8c18a9ad8af81e5ad652d6 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Fri, 22 Sep 2023 06:01:05 -0700 Subject: [PATCH 2/5] [AppConfiguration] Implemented SettingFieldsExtensions --- .../src/ConfigurationClient.cs | 12 ++-- .../src/ConfigurationClient_private.cs | 7 +- .../src/Models/SettingFieldsExtensions.cs | 45 +++++++++++++ .../tests/ConfigurationSettingTests.cs | 2 +- .../tests/SettingFieldsExtensionsTests.cs | 67 +++++++++++++++++++ 5 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs create mode 100644 sdk/appconfiguration/Azure.Data.AppConfiguration/tests/SettingFieldsExtensionsTests.cs diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs index 6398d8393f2c3..15724903e77e6 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs @@ -652,7 +652,7 @@ public virtual AsyncPageable GetConfigurationSettingsAsync var label = selector.LabelFilter; RequestContext context = CreateRequestContext(ErrorOptions.Default, cancellationToken); - IEnumerable fieldsString = selector.Fields == SettingFields.All ? null : selector.Fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked").Split(','); + IEnumerable fieldsString = selector.Fields.Split(); HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetConfigurationSettingsRequest(key, label, null, dateTime, fieldsString, null, null, context); HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetConfigurationSettingsNextPageRequest(nextLink, key, label, null, dateTime, fieldsString, null, null, context); @@ -672,7 +672,7 @@ public virtual Pageable GetConfigurationSettings(SettingSe var dateTime = selector.AcceptDateTime?.UtcDateTime.ToString(AcceptDateTimeFormat, CultureInfo.InvariantCulture); RequestContext context = CreateRequestContext(ErrorOptions.Default, cancellationToken); - IEnumerable fieldsString = selector.Fields == SettingFields.All ? null : selector.Fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked").Split(','); + IEnumerable fieldsString = selector.Fields.Split(); HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetConfigurationSettingsRequest(key, label, null, dateTime, fieldsString, null, null, context); HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetConfigurationSettingsNextPageRequest(nextLink, key, label, null, dateTime, fieldsString, null, null, context); @@ -724,7 +724,7 @@ public virtual AsyncPageable GetConfigurationSettingsForSn Argument.AssertNotNullOrEmpty(snapshotName, nameof(snapshotName)); RequestContext context = CreateRequestContext(ErrorOptions.Default, cancellationToken); - IEnumerable fieldsString = fields == SettingFields.All ? null : fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked").Split(','); + IEnumerable fieldsString = fields.Split(); HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetConfigurationSettingsRequest(null, null, null, null, fieldsString, snapshotName, null, context); HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetConfigurationSettingsNextPageRequest(nextLink, null, null, null, null, fieldsString, snapshotName, null, context); @@ -742,7 +742,7 @@ public virtual Pageable GetConfigurationSettingsForSnapsho Argument.AssertNotNullOrEmpty(snapshotName, nameof(snapshotName)); RequestContext context = CreateRequestContext(ErrorOptions.Default, cancellationToken); - IEnumerable fieldsString = fields == SettingFields.All ? null : fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked").Split(','); + IEnumerable fieldsString = fields.Split(); HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetConfigurationSettingsRequest(null, null, null, null, fieldsString, snapshotName, null, context); HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetConfigurationSettingsNextPageRequest(nextLink, null, null, null, null, fieldsString, snapshotName, null, context); @@ -1243,7 +1243,7 @@ public virtual AsyncPageable GetRevisionsAsync(SettingSele var label = selector.LabelFilter; var dateTime = selector.AcceptDateTime?.UtcDateTime.ToString(AcceptDateTimeFormat, CultureInfo.InvariantCulture); RequestContext context = CreateRequestContext(ErrorOptions.Default, cancellationToken); - IEnumerable fieldsString = selector.Fields == SettingFields.All ? null : selector.Fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked").Split(','); + IEnumerable fieldsString = selector.Fields.Split(); HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetRevisionsRequest(key, label, null, dateTime, fieldsString, context); HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetRevisionsNextPageRequest(nextLink, key, label, null, dateTime, fieldsString, context); @@ -1262,7 +1262,7 @@ public virtual Pageable GetRevisions(SettingSelector selec var label = selector.LabelFilter; var dateTime = selector.AcceptDateTime?.UtcDateTime.ToString(AcceptDateTimeFormat, CultureInfo.InvariantCulture); RequestContext context = CreateRequestContext(ErrorOptions.Default, cancellationToken); - IEnumerable fieldsString = selector.Fields == SettingFields.All ? null : selector.Fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked").Split(','); + IEnumerable fieldsString = selector.Fields.Split(); HttpMessage FirstPageRequest(int? pageSizeHint) => CreateGetRevisionsRequest(key, label, null, dateTime, fieldsString, context); HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => CreateGetRevisionsNextPageRequest(nextLink, key, label, null, dateTime, fieldsString, context); diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs index 114a7bb7a5472..1d91239c3a1c8 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Threading; @@ -63,9 +64,11 @@ internal static void BuildBatchQuery(RequestUriBuilder builder, SettingSelector builder.AppendQuery(LabelQueryFilter, selector.LabelFilter); } - if (selector.Fields != SettingFields.All) + IEnumerable splitFields = selector.Fields.Split(); + + if (splitFields != null) { - var filter = selector.Fields.ToString().ToLowerInvariant().Replace("isreadonly", "locked"); + string filter = string.Join(",", splitFields); builder.AppendQuery(FieldsQueryFilter, filter); } diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs new file mode 100644 index 0000000000000..1880b4d4cba3f --- /dev/null +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; + +namespace Azure.Data.AppConfiguration +{ + internal static class SettingFieldsExtensions + { + /// + /// Maps a SettingFields member to its corresponding service name in accordance with the REST API specification. + /// + private static readonly IReadOnlyDictionary s_serviceNameMap = new Dictionary() + { + { SettingFields.Key , "key" }, + { SettingFields.Label , "label" }, + { SettingFields.Value , "value" }, + { SettingFields.ContentType , "content_type" }, + { SettingFields.ETag , "etag" }, + { SettingFields.LastModified, "last_modified" }, + { SettingFields.IsReadOnly , "locked" }, + { SettingFields.Tags , "tags" } + }; + + public static IEnumerable Split(this SettingFields fields) + { + if (fields == SettingFields.All) + { + return null; + } + + var splitFields = new List(); + + foreach (SettingFields currentField in s_serviceNameMap.Keys) + { + if ((fields & currentField) == currentField) + { + splitFields.Add(s_serviceNameMap[currentField]); + } + } + + return splitFields; + } + } +} diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs index 18ea5bb798cc9..3cd8ba0cc4665 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs @@ -115,7 +115,7 @@ public void SettingSomeFields() ConfigurationClient.BuildBatchQuery(builder, selector, null); - Assert.AreEqual($"http://localhost/?key=key&$select=key%2C%20value", builder.ToUri().AbsoluteUri); + Assert.AreEqual($"http://localhost/?key=key&$select=key%2Cvalue", builder.ToUri().AbsoluteUri); } [Test] diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/SettingFieldsExtensionsTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/SettingFieldsExtensionsTests.cs new file mode 100644 index 0000000000000..36da6df865bed --- /dev/null +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/SettingFieldsExtensionsTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; + +namespace Azure.Data.AppConfiguration.Tests +{ + public class SettingFieldsExtensionsTests + { + [Test] + public void SplitReturnsNullForAll() + { + Assert.IsNull(SettingFields.All.Split()); + } + + [Test] + [TestCase(SettingFields.Key, "key")] + [TestCase(SettingFields.Label, "label")] + [TestCase(SettingFields.Value, "value")] + [TestCase(SettingFields.ContentType, "content_type")] + [TestCase(SettingFields.ETag, "etag")] + [TestCase(SettingFields.LastModified, "last_modified")] + [TestCase(SettingFields.IsReadOnly, "locked")] + [TestCase(SettingFields.Tags, "tags")] + public void SplitWithSingleField(SettingFields fields, string expectedFieldString) + { + IEnumerable splitFields = fields.Split(); + string fieldString = splitFields.Single(); + + Assert.AreEqual(fieldString, expectedFieldString); + } + + [Test] + public void SplitWithMultipleFields() + { + SettingFields fields = SettingFields.Key | SettingFields.ContentType | SettingFields.LastModified | SettingFields.IsReadOnly; + IEnumerable splitFields = fields.Split(); + + Assert.AreEqual(splitFields.Count(), 4); + CollectionAssert.Contains(splitFields, "key"); + CollectionAssert.Contains(splitFields, "content_type"); + CollectionAssert.Contains(splitFields, "last_modified"); + CollectionAssert.Contains(splitFields, "locked"); + } + + [Test] + public void SplitSupportsAllPossibleSettingFields() + { + foreach (SettingFields fields in Enum.GetValues(typeof(SettingFields))) + { + if (fields == SettingFields.All) + { + continue; + } + + IEnumerable splitFields = fields.Split(); + + // If this assertion fails, it's likely that a new enum value has been added to SettingFields + // but a corresponding entry has not been added to s_serviceNameMap in SettingFieldsExtensions. + Assert.AreEqual(splitFields.Count(), 1, $"{nameof(SettingFields)} enum value {fields} could not be mapped to a string."); + } + } + } +} From ee3c32616489b356e6c29de8350530972136355e Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Fri, 22 Sep 2023 06:18:50 -0700 Subject: [PATCH 3/5] Updated assets.json --- sdk/appconfiguration/Azure.Data.AppConfiguration/assets.json | 2 +- .../Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/assets.json b/sdk/appconfiguration/Azure.Data.AppConfiguration/assets.json index 6be2f9404c2b4..1eac8ff51bcd9 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/assets.json +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/appconfiguration/Azure.Data.AppConfiguration", - "Tag": "net/appconfiguration/Azure.Data.AppConfiguration_c13e90b6f4" + "Tag": "net/appconfiguration/Azure.Data.AppConfiguration_bebb69bca2" } diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs index e4ac987230083..6070aca7fc430 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationLiveTests.cs @@ -1129,7 +1129,7 @@ public async Task GetBatchSettingWithAllFields() } [RecordedTest] - public async Task GetBatchSettingWithAllFieldsSetIndividually() + public async Task GetBatchSettingWithAllFieldsSetExplicitly() { ConfigurationClient service = GetClient(); string key = GenerateKeyId("keyFields-"); From f645ac5b2c1a562a2d27f2dfda55fdffaeafa936 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Fri, 22 Sep 2023 06:40:16 -0700 Subject: [PATCH 4/5] Forgot changelog --- sdk/appconfiguration/Azure.Data.AppConfiguration/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/CHANGELOG.md b/sdk/appconfiguration/Azure.Data.AppConfiguration/CHANGELOG.md index 0f8524ef1e7e8..117755569b405 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/CHANGELOG.md +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +- Fixed `GetConfigurationSettings(SettingSelector)` not setting `ContentType` and `LastModified` properties [(#38524)](https://github.com/Azure/azure-sdk-for-net/issues/38524). + ### Other Changes ## 1.2.1 (2023-09-13) From b5290c9be249e9aae8187ef57b1e6b424aeec122 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Mon, 25 Sep 2023 12:08:57 -0700 Subject: [PATCH 5/5] Addressed PR comments --- .../src/ConfigurationClient_private.cs | 26 ----- .../src/Models/SettingFieldsExtensions.cs | 5 + .../tests/ConfigurationSettingTests.cs | 108 ------------------ 3 files changed, 5 insertions(+), 134 deletions(-) diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs index 1d91239c3a1c8..f211883ea397f 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient_private.cs @@ -52,32 +52,6 @@ private static void ParseConnectionString(string connectionString, out Uri uri, } } - internal static void BuildBatchQuery(RequestUriBuilder builder, SettingSelector selector, string pageLink) - { - if (!string.IsNullOrEmpty(selector.KeyFilter)) - { - builder.AppendQuery(KeyQueryFilter, selector.KeyFilter); - } - - if (!string.IsNullOrEmpty(selector.LabelFilter)) - { - builder.AppendQuery(LabelQueryFilter, selector.LabelFilter); - } - - IEnumerable splitFields = selector.Fields.Split(); - - if (splitFields != null) - { - string filter = string.Join(",", splitFields); - builder.AppendQuery(FieldsQueryFilter, filter); - } - - if (!string.IsNullOrEmpty(pageLink)) - { - builder.AppendQuery("after", pageLink, escapeValue: false); - } - } - #region nobody wants to see these /// /// Check if two ConfigurationSetting instances are equal. diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs index 1880b4d4cba3f..081c605d29ce1 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/src/Models/SettingFieldsExtensions.cs @@ -22,6 +22,11 @@ internal static class SettingFieldsExtensions { SettingFields.Tags , "tags" } }; + /// + /// Splits flags into their corresponding service names. + /// + /// The flags to split. + /// An enumerable containing the names of the flags. The method returns null for . public static IEnumerable Split(this SettingFields fields) { if (fields == SettingFields.All) diff --git a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs index 3cd8ba0cc4665..096f99e0b1b72 100644 --- a/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs +++ b/sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationSettingTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Text.Json; -using Azure.Core; namespace Azure.Data.AppConfiguration.Tests { @@ -28,113 +27,6 @@ public class ConfigurationSettingTests } }; - [Test] - public void FilterReservedCharacter() - { - var selector = new SettingSelector - { - KeyFilter = @"my_key,key\,key", - LabelFilter = @"my_label,label\,label" - }; - - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual(@"http://localhost/?key=my_key%2Ckey%5C%2Ckey&label=my_label%2Clabel%5C%2Clabel", builder.ToUri().AbsoluteUri); - } - - [Test] - public void FilterContains() - { - var selector = new SettingSelector{ KeyFilter = "*key*", LabelFilter = "*label*" }; - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual("http://localhost/?key=%2Akey%2A&label=%2Alabel%2A", builder.ToUri().AbsoluteUri); - } - - [Test] - public void FilterNullLabel() - { - var selector = new SettingSelector { LabelFilter = "\0" }; - - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual("http://localhost/?label=%00", builder.ToUri().AbsoluteUri); - } - - [Test] - public void FilterOnlyKey() - { - var key = "my-key"; - var selector = new SettingSelector { KeyFilter = key }; - - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual($"http://localhost/?key={key}", builder.ToUri().AbsoluteUri); - } - - [Test] - public void FilterOnlyLabel() - { - var label = "my-label"; - var selector = new SettingSelector - { - LabelFilter = label - }; - - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual($"http://localhost/?label={label}", builder.ToUri().AbsoluteUri); - } - - [Test] - public void SettingSomeFields() - { - var selector = new SettingSelector - { - KeyFilter = "key", - Fields = SettingFields.Key | SettingFields.Value - }; - - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual($"http://localhost/?key=key&$select=key%2Cvalue", builder.ToUri().AbsoluteUri); - } - - [Test] - public void SettingAllFields() - { - var selector = new SettingSelector - { - KeyFilter = "key", - Fields = SettingFields.All - }; - - var builder = new RequestUriBuilder(); - builder.Reset(new Uri("http://localhost/")); - - ConfigurationClient.BuildBatchQuery(builder, selector, null); - - Assert.AreEqual($"http://localhost/?key=key", builder.ToUri().AbsoluteUri); - } - [Test] public void ConfigurationSettingEquals() {