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
8 changes: 8 additions & 0 deletions src/Microsoft.FeatureManagement/FeatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ private async Task<bool> IsEnabledAsync<TContext>(string feature, TContext appCo

if (filter == null)
{
if (_featureFilters.Any(f => IsMatchingName(f.GetType(), featureFilterConfiguration.Name)))
{
//
// Cannot find the appropriate registered feature filter which matches the filter name and the provided context type.
// But there is a registered feature filter which matches the filter name.
continue;
}

string errorMessage = $"The feature filter '{featureFilterConfiguration.Name}' specified for feature '{feature}' was not found.";

if (!_options.IgnoreMissingFeatureFilters)
Expand Down
26 changes: 17 additions & 9 deletions tests/Tests.FeatureManagement/FeatureManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,25 +237,33 @@ public async Task AllowsDuplicatedFilterAlias()
});

Assert.Equal($"Multiple contextual feature filters match the configured filter named '{duplicatedFilterName}' and context type '{typeof(DummyContext)}'.", ex.Message);
}

services = new ServiceCollection();
[Fact]
public async Task SkipsContextualFilterEvaluationForUnrecognizedContext()
{
string featureName = Features.FeatureUsesFiltersWithDuplicatedAlias;

IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

var services = new ServiceCollection();

services
.AddSingleton(config)
.AddFeatureManagement()
.AddFeatureFilter<ContextualDuplicatedAliasFeatureFilterWithAccountContext>();

serviceProvider = services.BuildServiceProvider();
ServiceProvider serviceProvider = services.BuildServiceProvider();

featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();

ex = await Assert.ThrowsAsync<FeatureManagementException>(
async () =>
{
await featureManager.IsEnabledAsync(featureName);
});
var appContext = new AppContext();

var dummyContext = new DummyContext();

Assert.Equal($"The feature filter '{duplicatedFilterName}' specified for feature '{featureName}' was not found.", ex.Message);
Assert.True(await featureManager.IsEnabledAsync(featureName));

Assert.True(await featureManager.IsEnabledAsync(featureName, dummyContext));
}

[Fact]
Expand Down