Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kinelski committed Sep 25, 2023
1 parent f645ac5 commit b5290c9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using Azure.Core;

namespace Azure.Data.AppConfiguration.Tests
{
Expand All @@ -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()
{
Expand Down

0 comments on commit b5290c9

Please sign in to comment.