Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AzureAppConfigurationOptions
{
private const int MaxRetries = 2;
private static readonly TimeSpan MaxRetryDelay = TimeSpan.FromMinutes(1);
private static readonly KeyValueSelector DefaultQuery = new KeyValueSelector { KeyFilter = KeyFilter.Any, LabelFilter = LabelFilter.Null };

private List<KeyValueWatcher> _individualKvWatchers = new List<KeyValueWatcher>();
private List<KeyValueWatcher> _ffWatchers = new List<KeyValueWatcher>();
Expand Down Expand Up @@ -159,7 +160,7 @@ public AzureAppConfigurationOptions()
};

// Adds the default query to App Configuration if <see cref="Select"/> and <see cref="SelectSnapshot"/> are never called.
_selectors = new List<KeyValueSelector> { new KeyValueSelector { KeyFilter = KeyFilter.Any, LabelFilter = LabelFilter.Null } };
_selectors = new List<KeyValueSelector> { DefaultQuery };
}

/// <summary>
Expand Down Expand Up @@ -201,7 +202,7 @@ public AzureAppConfigurationOptions Select(string keyFilter, string labelFilter

if (!_selectCalled)
{
_selectors.Clear();
_selectors.Remove(DefaultQuery);

_selectCalled = true;
}
Expand Down Expand Up @@ -229,7 +230,7 @@ public AzureAppConfigurationOptions SelectSnapshot(string name)

if (!_selectCalled)
{
_selectors.Clear();
_selectors.Remove(DefaultQuery);

_selectCalled = true;
}
Expand Down
57 changes: 57 additions & 0 deletions tests/Tests.AzureAppConfiguration/FeatureManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,63 @@ public void SelectFeatureFlags()
Assert.Null(config["FeatureManagement:App2_Feature2"]);
}

[Fact]
public void SelectOrderDoesNotAffectLoad()
{
var mockResponse = new Mock<Response>();
var mockClient = new Mock<ConfigurationClient>(MockBehavior.Strict);

List<ConfigurationSetting> kvCollection = new List<ConfigurationSetting>
{
ConfigurationModelFactory.ConfigurationSetting("TestKey1", "TestValue1", "label",
eTag: new ETag("0a76e3d7-7ec1-4e37-883c-9ea6d0d89e63")),
ConfigurationModelFactory.ConfigurationSetting("TestKey2", "TestValue2", "label",
eTag: new ETag("31c38369-831f-4bf1-b9ad-79db56c8b989"))
};

MockAsyncPageable GetTestKeys(SettingSelector selector, CancellationToken ct)
{
List<ConfigurationSetting> settingCollection;

if (selector.KeyFilter.StartsWith(FeatureManagementConstants.FeatureFlagMarker))
{
settingCollection = _featureFlagCollection;
}
else
{
settingCollection = kvCollection;
}

var copy = new List<ConfigurationSetting>();
var newSetting = settingCollection.FirstOrDefault(s => (s.Key == selector.KeyFilter && s.Label == selector.LabelFilter));
if (newSetting != null)
copy.Add(TestHelpers.CloneSetting(newSetting));
return new MockAsyncPageable(copy);
}

mockClient.Setup(c => c.GetConfigurationSettingsAsync(It.IsAny<SettingSelector>(), It.IsAny<CancellationToken>()))
.Returns((Func<SettingSelector, CancellationToken, MockAsyncPageable>)GetTestKeys);

var config = new ConfigurationBuilder()
.AddAzureAppConfiguration(options =>
{
options.ClientManager = TestHelpers.CreateMockedConfigurationClientManager(mockClient.Object);
options.UseFeatureFlags(ff =>
{
ff.Select("App1_Feature1", "App1_Label");
ff.Select("App2_Feature1", "App2_Label");
});
options.Select("TestKey1", "label");
options.Select("TestKey2", "label");
})
.Build();

Assert.Equal("True", config["FeatureManagement:App1_Feature1"]);
Assert.Equal("False", config["FeatureManagement:App2_Feature1"]);
Assert.Equal("TestValue1", config["TestKey1"]);
Assert.Equal("TestValue2", config["TestKey2"]);
}

[Fact]
public void TestNullAndMissingValuesForConditions()
{
Expand Down