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 @@ -28,7 +28,7 @@ public void It_resolves_requestdelegategenerator_correctly(string testAssetName,
});

VerifyRequestDelegateGeneratorIsUsed(asset, isEnabled);
VerifyInterceptorsFeatureEnabled(asset, isEnabled);
VerifyInterceptorsFeatureProperties(asset, isEnabled, "Microsoft.AspNetCore.Http.Generated");
}

[Theory]
Expand All @@ -50,7 +50,7 @@ public void It_resolves_configbindinggenerator_correctly(string testAssetName, b
});

VerifyConfigBindingGeneratorIsUsed(asset, isEnabled);
VerifyInterceptorsFeatureEnabled(asset, isEnabled);
VerifyInterceptorsFeatureProperties(asset, isEnabled, "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
}

[Fact]
Expand All @@ -67,7 +67,7 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P

VerifyRequestDelegateGeneratorIsUsed(asset, expectEnabled: true);
VerifyConfigBindingGeneratorIsUsed(asset, expectEnabled: true);
VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true);
VerifyInterceptorsFeatureProperties(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
}

[Fact]
Expand All @@ -84,7 +84,7 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P

VerifyRequestDelegateGeneratorIsUsed(asset, expectEnabled: true);
VerifyConfigBindingGeneratorIsUsed(asset, expectEnabled: true);
VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true);
VerifyInterceptorsFeatureProperties(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
}

private void VerifyGeneratorIsUsed(TestAsset asset, bool? expectEnabled, string generatorName)
Expand Down Expand Up @@ -112,23 +112,23 @@ private void VerifyRequestDelegateGeneratorIsUsed(TestAsset asset, bool? expectE
private void VerifyConfigBindingGeneratorIsUsed(TestAsset asset, bool? expectEnabled)
=> VerifyGeneratorIsUsed(asset, expectEnabled, "Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll");

private void VerifyInterceptorsFeatureEnabled(TestAsset asset, bool? expectEnabled)
private void VerifyInterceptorsFeatureProperties(TestAsset asset, bool? expectEnabled, params string[] expectedNamespaces)
{
var command = new GetValuesCommand(
Log,
asset.Path,
ToolsetInfo.CurrentTargetFramework,
"Features",
"InterceptorsPreviewNamespaces",
GetValuesCommand.ValueType.Property);

command
.WithWorkingDirectory(asset.Path)
.Execute()
.Should().Pass();

var features = command.GetValues();
var namespaces = command.GetValues();

Assert.Equal(expectEnabled ?? false, features.Any(feature => feature.Contains("InterceptorsPreview")));
Assert.Equal(expectEnabled ?? false, expectedNamespaces.All(expectedNamespace => namespaces.Contains(expectedNamespace)));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<EnableConfigurationBindingGenerator Condition="'$(EnableConfigurationBindingGenerator)' == ''">true</EnableConfigurationBindingGenerator>
</PropertyGroup>

<!-- Enable the interceptors compiler feature by default for projects that use the RequestDelegateGenerator or the ConfigurationBindingGenerator. -->
<PropertyGroup Condition="'$(EnableRequestDelegateGenerator)' == 'true' Or '$(EnableConfigurationBindingGenerator)' == 'true'">
<Features>$(Features);InterceptorsPreview</Features>
<PropertyGroup>
<!-- Set the namespaces emitted by the RequestDelegateGenerator for interception when applicable. -->
<InterceptorsPreviewNamespaces Condition="'$(EnableRequestDelegateGenerator)' == 'true'">$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
<!-- Set the namespaces emitted by the ConfigurationBindingGenerator for interception when applicable. -->
<InterceptorsPreviewNamespaces Condition="'$(EnableConfigurationBindingGenerator)' == 'true'">$(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsPreviewNamespaces>
</PropertyGroup>

<!--
Expand Down