Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppConfiguration] Fix: GetConfigurationSettings does not set the ContentType property #38917

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Addressed PR comments
kinelski committed Sep 25, 2023
commit b5290c9be249e9aae8187ef57b1e6b424aeec122
Original file line number Diff line number Diff line change
@@ -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<string> 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
/// <summary>
/// Check if two ConfigurationSetting instances are equal.
Original file line number Diff line number Diff line change
@@ -22,6 +22,11 @@ internal static class SettingFieldsExtensions
{ SettingFields.Tags , "tags" }
};

/// <summary>
/// Splits <see cref="SettingFields"/> flags into their corresponding service names.
/// </summary>
/// <param name="fields">The flags to split.</param>
/// <returns>An enumerable containing the names of the flags. The method returns <c>null</c> for <see cref="SettingFields.All"/>.</returns>
public static IEnumerable<string> Split(this SettingFields fields)
{
if (fields == SettingFields.All)
Original file line number Diff line number Diff line change
@@ -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()
{