diff --git a/NuGet.config b/NuGet.config
index d62ece6b60..83bc90a901 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -6,6 +6,7 @@
+
diff --git a/eng/Baseline.Designer.props b/eng/Baseline.Designer.props
index b5c8196535..0550859109 100644
--- a/eng/Baseline.Designer.props
+++ b/eng/Baseline.Designer.props
@@ -2,106 +2,106 @@
$(MSBuildAllProjects);$(MSBuildThisFileFullPath)
- 3.1.0
+ 3.1.1
- 3.0.0
+ 3.0.2
- 3.0.0
+ 3.0.2
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
-
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
@@ -109,39 +109,39 @@
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
+
@@ -186,273 +186,273 @@
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
-
+
+
-
-
+
+
- 3.1.0
+ 3.1.1
-
+
-
+
- 3.1.0
+ 3.1.1
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
-
+
-
+
-
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
+
-
+
- 3.1.0
+ 3.1.1
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
-
-
+
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
-
+
-
+
- 3.1.0
+ 3.1.1
-
+
-
+
- 3.1.0
+ 3.1.1
-
-
+
+
-
-
+
+
- 3.1.0
+ 3.1.1
-
-
-
-
+
+
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
@@ -460,236 +460,238 @@
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
+
-
-
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
-
-
+
+
- 3.1.0
+ 3.1.1
-
+
-
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
-
-
-
+
+
+
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
+
- 3.1.0
+ 3.1.1
-
-
+
+
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
-
-
-
+
+
+
-
-
-
+
+
+
- 3.1.0
+ 3.1.1
-
-
+
+
+
-
-
+
+
+
\ No newline at end of file
diff --git a/eng/Baseline.xml b/eng/Baseline.xml
index 9a5276d729..d479dfe6ce 100644
--- a/eng/Baseline.xml
+++ b/eng/Baseline.xml
@@ -4,86 +4,86 @@ This file contains a list of all the packages and their versions which were rele
Update this list when preparing for a new patch.
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/eng/Dependencies.props b/eng/Dependencies.props
index 2e11857b1b..6ec858033d 100644
--- a/eng/Dependencies.props
+++ b/eng/Dependencies.props
@@ -147,6 +147,16 @@ and are generated based on the last package release.
+
+
+
+
+
+
+
+
+
+
diff --git a/eng/ProjectReferences.props b/eng/ProjectReferences.props
index 350c026a7d..a14d2cf642 100644
--- a/eng/ProjectReferences.props
+++ b/eng/ProjectReferences.props
@@ -5,143 +5,12 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/eng/Versions.props b/eng/Versions.props
index acef5287d1..664c95dbeb 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -8,8 +8,8 @@
3
1
- 0
- 3
+ 2
+ 0
@@ -19,21 +19,21 @@
false
preview$(PreReleasePreviewNumber)
Preview $(PreReleasePreviewNumber)
+
+ 4
+ preview$(BlazorClientPreReleasePreviewNumber)
$(AspNetCoreMajorVersion).$(AspNetCoreMinorVersion)
+
+ 3.1.0
false
-
- true
-
- true
+
+ true
$(AspNetCoreMajorVersion).$(AspNetCoreMinorVersion).$(AspNetCorePatchVersion)
$(VersionPrefix)
- $(AspNetCoreMajorVersion).$(AspNetCoreMinorVersion).0
+ $(AspNetCoreMajorVersion).$(AspNetCoreMinorVersion).2
0.3.$(AspNetCorePatchVersion)
$([MSBuild]::Add(10, $(AspNetCoreMajorVersion)))
@@ -62,14 +62,15 @@
-->
- 1.0.0-beta.19577.5
+ 1.0.0-beta.19607.3
- 3.4.0-beta4-19569-03
+ 3.4.1-beta4-19614-01
- 3.1.1-servicing.19575.1
- 3.1.1-servicing.19576.9
+ 3.1.2
+ 3.1.2-servicing.20067.4
3.1.0
- 3.1.1-servicing.19575.1
+ 3.1.2
+ 3.1.2
2.1.0
1.1.0
@@ -91,7 +92,7 @@
4.7.0
4.7.0
4.7.0
- 4.7.0
+ 4.7.1
4.7.0
4.7.0
@@ -99,80 +100,80 @@
3.2.0-preview1.20067.1
- 3.1.0-rtm.19575.5
- 3.1.0-rtm.19575.5
- 3.1.0-rtm.19575.5
- 3.1.0-rtm.19575.5
- 3.1.0-rtm.19575.5
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0-rtm.19575.5
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0-rtm.19575.5
- 3.1.0
- 3.1.0
- 3.1.0-rtm.19575.5
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0-rtm.19575.5
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0-rtm.19575.5
- 3.1.0
- 3.1.0-rtm.19575.5
- 3.1.0-rtm.19575.5
- 3.1.0
+ 3.1.2-servicing.20067.6
+ 3.1.2-servicing.20067.6
+ 3.1.2-servicing.20067.6
+ 3.1.2-servicing.20067.6
+ 3.1.2-servicing.20067.6
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2-servicing.20067.6
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2-servicing.20067.6
+ 3.1.2
+ 3.1.2
+ 3.1.2-servicing.20067.6
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2-servicing.20067.6
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2-servicing.20067.6
+ 3.1.2
+ 3.1.2-servicing.20067.6
+ 3.1.2-servicing.20067.6
+ 3.1.2
3.1.0-rtm.19565.4
- 3.1.0
- 3.1.0-preview4.19575.5
+ 3.1.2
+ 3.1.2-preview4.20067.6
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
- 3.1.0
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
- 3.1.0-rtm.19573.1
- 3.1.0-rtm.19573.1
- 3.1.0-rtm.19573.1
- 3.1.0-rtm.19573.1
+ 3.1.2
+ 3.1.2
+ 3.1.2
+ 3.1.2
$(MicrosoftNETCoreAppRuntimewinx64PackageVersion)
+ 3.1.2
@@ -264,10 +266,19 @@
$(XunitVersion)
$(XunitVersion)
1.0.19249.1
+
+
+ 3.1.2-servicing.20068.1
+ 3.1.2
+ $(MicrosoftAspNetCoreComponentsPackageVersion)
+ $(MicrosoftAspNetCoreComponentsPackageVersion)
+ $(MicrosoftAspNetCoreComponentsPackageVersion)
+ $(MicrosoftAspNetCoreComponentsPackageVersion)
https://dotnetcli.blob.core.windows.net/dotnet/
+ https://dotnetclimsrc.blob.core.windows.net/dotnet/
-
+
\ No newline at end of file
diff --git a/global.json b/global.json
index 88df91565f..324a0158be 100644
--- a/global.json
+++ b/global.json
@@ -1,9 +1,9 @@
{
"sdk": {
- "version": "3.1.100"
+ "version": "3.1.102-servicing-014873"
},
"tools": {
- "dotnet": "3.1.100",
+ "dotnet": "3.1.102-servicing-014873",
"runtimes": {
"dotnet/x64": [
"$(MicrosoftNETCoreAppInternalPackageVersion)"
diff --git a/src/Components/Analyzers/src/ComponentFacts.cs b/src/Components/Analyzers/src/ComponentFacts.cs
deleted file mode 100644
index 75403ce282..0000000000
--- a/src/Components/Analyzers/src/ComponentFacts.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Linq;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- internal static class ComponentFacts
- {
- public static bool IsAnyParameter(ComponentSymbols symbols, IPropertySymbol property)
- {
- if (symbols == null)
- {
- throw new ArgumentNullException(nameof(symbols));
- }
-
- if (property == null)
- {
- throw new ArgumentNullException(nameof(property));
- }
-
- return property.GetAttributes().Any(a =>
- {
- return a.AttributeClass == symbols.ParameterAttribute || a.AttributeClass == symbols.CascadingParameterAttribute;
- });
- }
-
- public static bool IsParameter(ComponentSymbols symbols, IPropertySymbol property)
- {
- if (symbols == null)
- {
- throw new ArgumentNullException(nameof(symbols));
- }
-
- if (property == null)
- {
- throw new ArgumentNullException(nameof(property));
- }
-
- return property.GetAttributes().Any(a => a.AttributeClass == symbols.ParameterAttribute);
- }
-
- public static bool IsParameterWithCaptureUnmatchedValues(ComponentSymbols symbols, IPropertySymbol property)
- {
- if (symbols == null)
- {
- throw new ArgumentNullException(nameof(symbols));
- }
-
- if (property == null)
- {
- throw new ArgumentNullException(nameof(property));
- }
-
- var attribute = property.GetAttributes().FirstOrDefault(a => a.AttributeClass == symbols.ParameterAttribute);
- if (attribute == null)
- {
- return false;
- }
-
- foreach (var kvp in attribute.NamedArguments)
- {
- if (string.Equals(kvp.Key, ComponentsApi.ParameterAttribute.CaptureUnmatchedValues, StringComparison.Ordinal))
- {
- return kvp.Value.Value as bool? ?? false;
- }
- }
-
- return false;
- }
-
- public static bool IsCascadingParameter(ComponentSymbols symbols, IPropertySymbol property)
- {
- if (symbols == null)
- {
- throw new ArgumentNullException(nameof(symbols));
- }
-
- if (property == null)
- {
- throw new ArgumentNullException(nameof(property));
- }
-
- return property.GetAttributes().Any(a => a.AttributeClass == symbols.CascadingParameterAttribute);
- }
-
- public static bool IsComponent(ComponentSymbols symbols, Compilation compilation, INamedTypeSymbol type)
- {
- if (symbols is null)
- {
- throw new ArgumentNullException(nameof(symbols));
- }
-
- if (type is null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- var conversion = compilation.ClassifyConversion(symbols.IComponentType, type);
- if (!conversion.Exists || !conversion.IsExplicit)
- {
- return false;
- }
-
- return true;
- }
- }
-}
diff --git a/src/Components/Analyzers/src/ComponentInternalUsageDiagnosticAnalzyer.cs b/src/Components/Analyzers/src/ComponentInternalUsageDiagnosticAnalzyer.cs
deleted file mode 100644
index 8f6272c326..0000000000
--- a/src/Components/Analyzers/src/ComponentInternalUsageDiagnosticAnalzyer.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Collections.Immutable;
-using Microsoft.AspNetCore.Components.Analyzers;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-
-namespace Microsoft.Extensions.Internal
-{
- ///
- /// This API supports infrastructure and is not intended to be used
- /// directly from your code. This API may change or be removed in future releases.
- ///
- [DiagnosticAnalyzer(LanguageNames.CSharp)]
- public class ComponentInternalUsageDiagnosticAnalyzer : DiagnosticAnalyzer
- {
- private readonly InternalUsageAnalyzer _inner;
-
- public ComponentInternalUsageDiagnosticAnalyzer()
- {
- // We don't have in *internal* attribute in Blazor.
- _inner = new InternalUsageAnalyzer(IsInInternalNamespace, hasInternalAttribute: null, DiagnosticDescriptors.DoNotUseRenderTreeTypes);
- }
-
- public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(DiagnosticDescriptors.DoNotUseRenderTreeTypes);
-
- public override void Initialize(AnalysisContext context)
- {
- _inner.Register(context);
- }
-
- private static bool IsInInternalNamespace(ISymbol symbol)
- {
- if (symbol?.ContainingNamespace?.ToDisplayString() is string ns)
- {
- return string.Equals(ns, "Microsoft.AspNetCore.Components.RenderTree");
- }
-
- return false;
- }
- }
-}
diff --git a/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs b/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs
deleted file mode 100644
index c6d8670dcb..0000000000
--- a/src/Components/Analyzers/src/ComponentParameterAnalyzer.cs
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Linq;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.Diagnostics;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- [DiagnosticAnalyzer(LanguageNames.CSharp)]
- public class ComponentParameterAnalyzer : DiagnosticAnalyzer
- {
- public ComponentParameterAnalyzer()
- {
- SupportedDiagnostics = ImmutableArray.Create(new[]
- {
- DiagnosticDescriptors.ComponentParametersShouldBePublic,
- DiagnosticDescriptors.ComponentParameterSettersShouldBePublic,
- DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesMustBeUnique,
- DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesHasWrongType,
- });
- }
-
- public override ImmutableArray SupportedDiagnostics { get; }
-
- public override void Initialize(AnalysisContext context)
- {
- context.RegisterCompilationStartAction(context =>
- {
- if (!ComponentSymbols.TryCreate(context.Compilation, out var symbols))
- {
- // Types we need are not defined.
- return;
- }
-
- // This operates per-type because one of the validations we need has to look for duplicates
- // defined on the same type.
- context.RegisterSymbolStartAction(context =>
- {
- var properties = new List();
-
- var type = (INamedTypeSymbol)context.Symbol;
- foreach (var member in type.GetMembers())
- {
- if (member is IPropertySymbol property && ComponentFacts.IsParameter(symbols, property))
- {
- // Annotated with [Parameter]. We ignore [CascadingParameter]'s because they don't interact with tooling and don't currently have any analyzer restrictions.
- properties.Add(property);
- }
- }
-
- if (properties.Count == 0)
- {
- return;
- }
-
- context.RegisterSymbolEndAction(context =>
- {
- var captureUnmatchedValuesParameters = new List();
-
- // Per-property validations
- foreach (var property in properties)
- {
- var propertyLocation = property.Locations.FirstOrDefault();
- if (propertyLocation == null)
- {
- continue;
- }
-
- if (property.DeclaredAccessibility != Accessibility.Public)
- {
- context.ReportDiagnostic(Diagnostic.Create(
- DiagnosticDescriptors.ComponentParametersShouldBePublic,
- propertyLocation,
- property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
- }
- else if (property.SetMethod?.DeclaredAccessibility != Accessibility.Public)
- {
- context.ReportDiagnostic(Diagnostic.Create(
- DiagnosticDescriptors.ComponentParameterSettersShouldBePublic,
- propertyLocation,
- property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
- }
-
- if (ComponentFacts.IsParameterWithCaptureUnmatchedValues(symbols, property))
- {
- captureUnmatchedValuesParameters.Add(property);
-
- // Check the type, we need to be able to assign a Dictionary
- var conversion = context.Compilation.ClassifyConversion(symbols.ParameterCaptureUnmatchedValuesRuntimeType, property.Type);
- if (!conversion.Exists || conversion.IsExplicit)
- {
- context.ReportDiagnostic(Diagnostic.Create(
- DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesHasWrongType,
- propertyLocation,
- property.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
- property.Type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
- symbols.ParameterCaptureUnmatchedValuesRuntimeType.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)));
- }
- }
- }
-
- // Check if the type defines multiple CaptureUnmatchedValues parameters. Doing this outside the loop means we place the
- // errors on the type.
- if (captureUnmatchedValuesParameters.Count > 1)
- {
- context.ReportDiagnostic(Diagnostic.Create(
- DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesMustBeUnique,
- context.Symbol.Locations[0],
- type.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat),
- Environment.NewLine,
- string.Join(
- Environment.NewLine,
- captureUnmatchedValuesParameters.Select(p => p.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat)).OrderBy(n => n))));
- }
- });
- }, SymbolKind.NamedType);
- });
- }
- }
-}
diff --git a/src/Components/Analyzers/src/ComponentParameterUsageAnalyzer.cs b/src/Components/Analyzers/src/ComponentParameterUsageAnalyzer.cs
deleted file mode 100644
index 8df3167b83..0000000000
--- a/src/Components/Analyzers/src/ComponentParameterUsageAnalyzer.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Collections.Immutable;
-using System.Linq;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.Diagnostics;
-using Microsoft.CodeAnalysis.Operations;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- [DiagnosticAnalyzer(LanguageNames.CSharp)]
- public class ComponentParameterUsageAnalyzer : DiagnosticAnalyzer
- {
- public ComponentParameterUsageAnalyzer()
- {
- SupportedDiagnostics = ImmutableArray.Create(new[]
- {
- DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent,
- });
- }
-
- public override ImmutableArray SupportedDiagnostics { get; }
-
- public override void Initialize(AnalysisContext context)
- {
- context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
- context.RegisterCompilationStartAction(context =>
- {
- if (!ComponentSymbols.TryCreate(context.Compilation, out var symbols))
- {
- // Types we need are not defined.
- return;
- }
-
- context.RegisterOperationBlockStartAction(startBlockContext =>
- {
- startBlockContext.RegisterOperationAction(context =>
- {
- IOperation leftHandSide;
-
- if (context.Operation is IAssignmentOperation assignmentOperation)
- {
- leftHandSide = assignmentOperation.Target;
- }
- else
- {
- var incrementOrDecrementOperation = (IIncrementOrDecrementOperation)context.Operation;
- leftHandSide = incrementOrDecrementOperation.Target;
- }
-
- if (leftHandSide == null)
- {
- // Malformed assignment, no left hand side.
- return;
- }
-
- if (leftHandSide.Kind != OperationKind.PropertyReference)
- {
- // We don't want to capture situations where a user does
- // MyOtherProperty = aComponent.SomeParameter
- return;
- }
-
- var propertyReference = (IPropertyReferenceOperation)leftHandSide;
- var componentProperty = (IPropertySymbol)propertyReference.Member;
-
- if (!ComponentFacts.IsParameter(symbols, componentProperty))
- {
- // This is not a property reference that we care about, it is not decorated with [Parameter].
- return;
- }
-
- var propertyContainingType = componentProperty.ContainingType;
- if (!ComponentFacts.IsComponent(symbols, context.Compilation, propertyContainingType))
- {
- // Someone referenced a property as [Parameter] inside something that is not a component.
- return;
- }
-
- var assignmentContainingType = startBlockContext.OwningSymbol?.ContainingType;
- if (assignmentContainingType == null)
- {
- // Assignment location has no containing type. Most likely we're operating on malformed code, don't try and validate.
- return;
- }
-
- var conversion = context.Compilation.ClassifyConversion(propertyContainingType, assignmentContainingType);
- if (conversion.Exists && conversion.IsIdentity)
- {
- // The assignment is taking place inside of the declaring component.
- return;
- }
-
- if (conversion.Exists && conversion.IsExplicit)
- {
- // The assignment is taking place within the components type hierarchy. This means the user is setting this in a supported
- // scenario.
- return;
- }
-
- // At this point the user is referencing a component parameter outside of its declaring class.
-
- context.ReportDiagnostic(Diagnostic.Create(
- DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent,
- propertyReference.Syntax.GetLocation(),
- propertyReference.Member.Name));
- }, OperationKind.SimpleAssignment, OperationKind.CompoundAssignment, OperationKind.CoalesceAssignment, OperationKind.Increment, OperationKind.Decrement);
- });
- });
- }
- }
-}
diff --git a/src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs b/src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs
deleted file mode 100644
index 173633f0e9..0000000000
--- a/src/Components/Analyzers/src/ComponentParametersShouldBePublicCodeFixProvider.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Collections.Immutable;
-using System.Composition;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CodeActions;
-using Microsoft.CodeAnalysis.CodeFixes;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ComponentParametersShouldBePublicCodeFixProvider)), Shared]
- public class ComponentParametersShouldBePublicCodeFixProvider : CodeFixProvider
- {
- private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.ComponentParametersShouldBePublic_FixTitle), Resources.ResourceManager, typeof(Resources));
-
- public override ImmutableArray FixableDiagnosticIds
- => ImmutableArray.Create(DiagnosticDescriptors.ComponentParametersShouldBePublic.Id);
-
- public sealed override FixAllProvider GetFixAllProvider()
- {
- // See https://github.com/dotnet/roslyn/blob/master/docs/analyzers/FixAllProvider.md for more information on Fix All Providers
- return WellKnownFixAllProviders.BatchFixer;
- }
-
- public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
- {
- var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
- var diagnostic = context.Diagnostics.First();
- var diagnosticSpan = diagnostic.Location.SourceSpan;
-
- // Find the type declaration identified by the diagnostic.
- var declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType().First();
-
- // Register a code action that will invoke the fix.
- var title = Title.ToString();
- context.RegisterCodeFix(
- CodeAction.Create(
- title: title,
- createChangedDocument: c => GetTransformedDocumentAsync(context.Document, root, declaration),
- equivalenceKey: title),
- diagnostic);
- }
-
- private Task GetTransformedDocumentAsync(
- Document document,
- SyntaxNode root,
- PropertyDeclarationSyntax declarationNode)
- {
- var updatedDeclarationNode = HandlePropertyDeclaration(declarationNode);
- var newSyntaxRoot = root.ReplaceNode(declarationNode, updatedDeclarationNode);
- return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot));
- }
-
- private SyntaxNode HandlePropertyDeclaration(PropertyDeclarationSyntax node)
- {
- TypeSyntax type = node.Type;
- if (type == null || type.IsMissing)
- {
- return null;
- }
-
- var newModifiers = node.Modifiers;
- for (var i = 0; i < node.Modifiers.Count; i++)
- {
- var modifier = node.Modifiers[i];
- if (modifier.IsKind(SyntaxKind.PrivateKeyword) ||
- modifier.IsKind(SyntaxKind.ProtectedKeyword) ||
- modifier.IsKind(SyntaxKind.InternalKeyword) ||
-
- // We also remove public in case the user has written something totally backwards such as private public protected Foo
- modifier.IsKind(SyntaxKind.PublicKeyword))
- {
- newModifiers = newModifiers.Remove(modifier);
- }
- }
-
- var publicModifier = SyntaxFactory.Token(SyntaxKind.PublicKeyword);
- newModifiers = newModifiers.Insert(0, publicModifier);
- node = node.WithModifiers(newModifiers);
- return node;
- }
- }
-}
diff --git a/src/Components/Analyzers/src/ComponentSymbols.cs b/src/Components/Analyzers/src/ComponentSymbols.cs
deleted file mode 100644
index d115e27f53..0000000000
--- a/src/Components/Analyzers/src/ComponentSymbols.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using Microsoft.CodeAnalysis;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- internal class ComponentSymbols
- {
- public static bool TryCreate(Compilation compilation, out ComponentSymbols symbols)
- {
- if (compilation == null)
- {
- throw new ArgumentNullException(nameof(compilation));
- }
-
- var parameterAttribute = compilation.GetTypeByMetadataName(ComponentsApi.ParameterAttribute.MetadataName);
- if (parameterAttribute == null)
- {
- symbols = null;
- return false;
- }
-
- var cascadingParameterAttribute = compilation.GetTypeByMetadataName(ComponentsApi.CascadingParameterAttribute.MetadataName);
- if (cascadingParameterAttribute == null)
- {
- symbols = null;
- return false;
- }
-
- var icomponentType = compilation.GetTypeByMetadataName(ComponentsApi.IComponent.MetadataName);
- if (icomponentType == null)
- {
- symbols = null;
- return false;
- }
-
- var dictionary = compilation.GetTypeByMetadataName("System.Collections.Generic.Dictionary`2");
- var @string = compilation.GetSpecialType(SpecialType.System_String);
- var @object = compilation.GetSpecialType(SpecialType.System_Object);
- if (dictionary == null || @string == null || @object == null)
- {
- symbols = null;
- return false;
- }
-
- var parameterCaptureUnmatchedValuesRuntimeType = dictionary.Construct(@string, @object);
-
- symbols = new ComponentSymbols(
- parameterAttribute,
- cascadingParameterAttribute,
- parameterCaptureUnmatchedValuesRuntimeType,
- icomponentType);
- return true;
- }
-
- private ComponentSymbols(
- INamedTypeSymbol parameterAttribute,
- INamedTypeSymbol cascadingParameterAttribute,
- INamedTypeSymbol parameterCaptureUnmatchedValuesRuntimeType,
- INamedTypeSymbol icomponentType)
- {
- ParameterAttribute = parameterAttribute;
- CascadingParameterAttribute = cascadingParameterAttribute;
- ParameterCaptureUnmatchedValuesRuntimeType = parameterCaptureUnmatchedValuesRuntimeType;
- IComponentType = icomponentType;
- }
-
- public INamedTypeSymbol ParameterAttribute { get; }
-
- // Dictionary
- public INamedTypeSymbol ParameterCaptureUnmatchedValuesRuntimeType { get; }
-
- public INamedTypeSymbol CascadingParameterAttribute { get; }
-
- public INamedTypeSymbol IComponentType { get; }
- }
-}
diff --git a/src/Components/Analyzers/src/ComponentsApi.cs b/src/Components/Analyzers/src/ComponentsApi.cs
deleted file mode 100644
index 73ceff39fd..0000000000
--- a/src/Components/Analyzers/src/ComponentsApi.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- // Constants for type and method names used in code-generation
- // Keep these in sync with the actual definitions
- internal static class ComponentsApi
- {
- public static readonly string AssemblyName = "Microsoft.AspNetCore.Components";
-
- public static class ParameterAttribute
- {
- public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.ParameterAttribute";
- public static readonly string MetadataName = FullTypeName;
-
- public static readonly string CaptureUnmatchedValues = "CaptureUnmatchedValues";
- }
-
- public static class CascadingParameterAttribute
- {
- public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.CascadingParameterAttribute";
- public static readonly string MetadataName = FullTypeName;
- }
-
- public static class IComponent
- {
- public static readonly string FullTypeName = "Microsoft.AspNetCore.Components.IComponent";
- public static readonly string MetadataName = FullTypeName;
- }
- }
-}
diff --git a/src/Components/Analyzers/src/DiagnosticDescriptors.cs b/src/Components/Analyzers/src/DiagnosticDescriptors.cs
deleted file mode 100644
index 8eb86b3212..0000000000
--- a/src/Components/Analyzers/src/DiagnosticDescriptors.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.CodeAnalysis;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- internal static class DiagnosticDescriptors
- {
- // Note: The Razor Compiler (including Components features) use the RZ prefix for diagnostics, so there's currently
- // no change of clashing between that and the BL prefix used here.
- //
- // Tracking https://github.com/aspnet/AspNetCore/issues/10382 to rationalize this
- public static readonly DiagnosticDescriptor ComponentParameterSettersShouldBePublic = new DiagnosticDescriptor(
- "BL0001",
- new LocalizableResourceString(nameof(Resources.ComponentParameterSettersShouldBePublic_Title), Resources.ResourceManager, typeof(Resources)),
- new LocalizableResourceString(nameof(Resources.ComponentParameterSettersShouldBePublic_Format), Resources.ResourceManager, typeof(Resources)),
- "Encapsulation",
- DiagnosticSeverity.Error,
- isEnabledByDefault: true,
- description: new LocalizableResourceString(nameof(Resources.ComponentParameterSettersShouldBePublic_Description), Resources.ResourceManager, typeof(Resources)));
-
- public static readonly DiagnosticDescriptor ComponentParameterCaptureUnmatchedValuesMustBeUnique = new DiagnosticDescriptor(
- "BL0002",
- new LocalizableResourceString(nameof(Resources.ComponentParameterCaptureUnmatchedValuesMustBeUnique_Title), Resources.ResourceManager, typeof(Resources)),
- new LocalizableResourceString(nameof(Resources.ComponentParameterCaptureUnmatchedValuesMustBeUnique_Format), Resources.ResourceManager, typeof(Resources)),
- "Usage",
- DiagnosticSeverity.Warning,
- isEnabledByDefault: true,
- description: new LocalizableResourceString(nameof(Resources.ComponentParameterCaptureUnmatchedValuesMustBeUnique_Description), Resources.ResourceManager, typeof(Resources)));
-
- public static readonly DiagnosticDescriptor ComponentParameterCaptureUnmatchedValuesHasWrongType = new DiagnosticDescriptor(
- "BL0003",
- new LocalizableResourceString(nameof(Resources.ComponentParameterCaptureUnmatchedValuesHasWrongType_Title), Resources.ResourceManager, typeof(Resources)),
- new LocalizableResourceString(nameof(Resources.ComponentParameterCaptureUnmatchedValuesHasWrongType_Format), Resources.ResourceManager, typeof(Resources)),
- "Usage",
- DiagnosticSeverity.Warning,
- isEnabledByDefault: true,
- description: new LocalizableResourceString(nameof(Resources.ComponentParameterCaptureUnmatchedValuesHasWrongType_Description), Resources.ResourceManager, typeof(Resources)));
-
- public static readonly DiagnosticDescriptor ComponentParametersShouldBePublic = new DiagnosticDescriptor(
- "BL0004",
- new LocalizableResourceString(nameof(Resources.ComponentParameterShouldBePublic_Title), Resources.ResourceManager, typeof(Resources)),
- new LocalizableResourceString(nameof(Resources.ComponentParameterShouldBePublic_Format), Resources.ResourceManager, typeof(Resources)),
- "Encapsulation",
- DiagnosticSeverity.Error,
- isEnabledByDefault: true,
- description: new LocalizableResourceString(nameof(Resources.ComponentParametersShouldBePublic_Description), Resources.ResourceManager, typeof(Resources)));
-
- public static readonly DiagnosticDescriptor ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent = new DiagnosticDescriptor(
- "BL0005",
- new LocalizableResourceString(nameof(Resources.ComponentParameterShouldNotBeSetOutsideOfTheirDeclaredComponent_Title), Resources.ResourceManager, typeof(Resources)),
- new LocalizableResourceString(nameof(Resources.ComponentParameterShouldNotBeSetOutsideOfTheirDeclaredComponent_Format), Resources.ResourceManager, typeof(Resources)),
- "Usage",
- DiagnosticSeverity.Warning,
- isEnabledByDefault: true,
- description: new LocalizableResourceString(nameof(Resources.ComponentParameterShouldNotBeSetOutsideOfTheirDeclaredComponent_Description), Resources.ResourceManager, typeof(Resources)));
-
- public static readonly DiagnosticDescriptor DoNotUseRenderTreeTypes = new DiagnosticDescriptor(
- "BL0006",
- new LocalizableResourceString(nameof(Resources.DoNotUseRenderTreeTypes_Title), Resources.ResourceManager, typeof(Resources)),
- new LocalizableResourceString(nameof(Resources.DoNotUseRenderTreeTypes_Description), Resources.ResourceManager, typeof(Resources)),
- "Usage",
- DiagnosticSeverity.Warning,
- isEnabledByDefault: true,
- description: new LocalizableResourceString(nameof(Resources.DoNotUseRenderTreeTypes_Description), Resources.ResourceManager, typeof(Resources)));
- }
-}
diff --git a/src/Components/Analyzers/src/InternalUsageAnalyzer.cs b/src/Components/Analyzers/src/InternalUsageAnalyzer.cs
deleted file mode 100644
index 92b07a7ab2..0000000000
--- a/src/Components/Analyzers/src/InternalUsageAnalyzer.cs
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Microsoft.CodeAnalysis.Diagnostics;
-
-namespace Microsoft.Extensions.Internal
-{
- internal class InternalUsageAnalyzer
- {
- private readonly Func _isInternalNamespace;
- private readonly Func _hasInternalAttribute;
- private readonly DiagnosticDescriptor _descriptor;
-
- ///
- /// Creates a new instance of . The creator should provide delegates to help determine whether
- /// a given symbol is internal or not, and a to create errors.
- ///
- /// The delegate used to check if a symbol belongs to an internal namespace.
- /// The delegate used to check if a symbol has an internal attribute.
- ///
- /// The used to create errors. The error message should expect a single parameter
- /// used for the display name of the member.
- ///
- public InternalUsageAnalyzer(Func isInInternalNamespace, Func hasInternalAttribute, DiagnosticDescriptor descriptor)
- {
- _isInternalNamespace = isInInternalNamespace ?? new Func((_) => false);
- _hasInternalAttribute = hasInternalAttribute ?? new Func((_) => false);
- _descriptor = descriptor ?? throw new ArgumentNullException(nameof(descriptor));
- }
-
- public void Register(AnalysisContext context)
- {
- context.EnableConcurrentExecution();
- context.RegisterSyntaxNodeAction(AnalyzeNode,
- SyntaxKind.SimpleMemberAccessExpression,
- SyntaxKind.ObjectCreationExpression,
- SyntaxKind.ClassDeclaration,
- SyntaxKind.Parameter);
- }
-
- private void AnalyzeNode(SyntaxNodeAnalysisContext context)
- {
- switch (context.Node)
- {
- case MemberAccessExpressionSyntax memberAccessSyntax:
- {
- if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol &&
- symbol.ContainingAssembly != context.Compilation.Assembly)
- {
- var containingType = symbol.ContainingType;
-
- if (HasInternalAttribute(symbol))
- {
- context.ReportDiagnostic(Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), $"{containingType}.{symbol.Name}"));
- return;
- }
-
- if (IsInInternalNamespace(containingType) || HasInternalAttribute(containingType))
- {
- context.ReportDiagnostic(Diagnostic.Create(_descriptor, memberAccessSyntax.Name.GetLocation(), containingType));
- return;
- }
- }
- return;
- }
-
- case ObjectCreationExpressionSyntax creationSyntax:
- {
- if (context.SemanticModel.GetSymbolInfo(context.Node, context.CancellationToken).Symbol is ISymbol symbol &&
- symbol.ContainingAssembly != context.Compilation.Assembly)
- {
- var containingType = symbol.ContainingType;
-
- if (HasInternalAttribute(symbol))
- {
- context.ReportDiagnostic(Diagnostic.Create(_descriptor, creationSyntax.GetLocation(), containingType));
- return;
- }
-
- if (IsInInternalNamespace(containingType) || HasInternalAttribute(containingType))
- {
- context.ReportDiagnostic(Diagnostic.Create(_descriptor, creationSyntax.Type.GetLocation(), containingType));
- return;
- }
- }
-
- return;
- }
-
- case ClassDeclarationSyntax declarationSyntax:
- {
- if (context.SemanticModel.GetDeclaredSymbol(declarationSyntax)?.BaseType is ISymbol symbol &&
- symbol.ContainingAssembly != context.Compilation.Assembly &&
- (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol)) &&
- declarationSyntax.BaseList?.Types.Count > 0)
- {
- context.ReportDiagnostic(Diagnostic.Create(_descriptor, declarationSyntax.BaseList.Types[0].GetLocation(), symbol));
- }
-
- return;
- }
-
- case ParameterSyntax parameterSyntax:
- {
- if (context.SemanticModel.GetDeclaredSymbol(parameterSyntax)?.Type is ISymbol symbol &&
- symbol.ContainingAssembly != context.Compilation.Assembly &&
- (IsInInternalNamespace(symbol) || HasInternalAttribute(symbol)))
- {
-
- context.ReportDiagnostic(Diagnostic.Create(_descriptor, parameterSyntax.GetLocation(), symbol));
- }
-
- return;
- }
- }
- }
-
- private bool HasInternalAttribute(ISymbol symbol) => _hasInternalAttribute(symbol);
-
- private bool IsInInternalNamespace(ISymbol symbol) => _isInternalNamespace(symbol);
- }
-}
diff --git a/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj b/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj
deleted file mode 100644
index a83904f245..0000000000
--- a/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
- netstandard2.0
- false
- true
- false
- Roslyn analyzers for ASP.NET Core Components.
- true
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Components/Analyzers/src/Properties/AssemblyInfo.cs b/src/Components/Analyzers/src/Properties/AssemblyInfo.cs
deleted file mode 100644
index 6e6689b592..0000000000
--- a/src/Components/Analyzers/src/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-using System.Runtime.CompilerServices;
-
-[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Components.Analyzers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
diff --git a/src/Components/Analyzers/src/Resources.resx b/src/Components/Analyzers/src/Resources.resx
deleted file mode 100644
index ed4f36c531..0000000000
--- a/src/Components/Analyzers/src/Resources.resx
+++ /dev/null
@@ -1,177 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- Component parameters should have public setters.
-
-
- Component parameter '{0}' should have a public setter.
-
-
- Component parameter should have public setters.
-
-
- Components may only define a single parameter with CaptureUnmatchedValues.
-
-
- Component type '{0}' defines properties multiple parameters with CaptureUnmatchedValues. Properties: {1}{2}
-
-
- Component has multiple CaptureUnmatchedValues parameters
-
-
- Component parameters with CaptureUnmatchedValues must be a correct type.
-
-
- Component parameter '{0}' defines CaptureUnmatchedValues but has an unsupported type '{1}'. Use a type assignable from '{2}'.
-
-
- Component parameter with CaptureUnmatchedValues has the wrong type
-
-
- Component parameter '{0}' should be public.
-
-
- Component parameter should be public.
-
-
- Component parameters should be public.
-
-
- Make component parameters public.
-
-
- Component parameters should not be set outside of their declared component. Doing so may result in unexpected behavior at runtime.
-
-
- Component parameter '{0}' should not be set outside of its component.
-
-
- Component parameter should not be set outside of its component.
-
-
- The types in 'Microsoft.AspNetCore.Components.RenderTree' are not recommended for use outside of the Blazor framework. These type definitions will change in future releases.
-
-
- The type or member {0} is is not recommended for use outside of the Blazor frameworks. Types defined in 'Microsoft.AspNetCore.Components.RenderTree' will change in future releases.
-
-
- Do not use RenderTree types
-
-
\ No newline at end of file
diff --git a/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props b/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props
deleted file mode 100644
index 0ba7b4da05..0000000000
--- a/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- true
-
-
diff --git a/src/Components/Analyzers/test/AnalyzerTestBase.cs b/src/Components/Analyzers/test/AnalyzerTestBase.cs
deleted file mode 100644
index 8c1ae95376..0000000000
--- a/src/Components/Analyzers/test/AnalyzerTestBase.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.IO;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Analyzer.Testing;
-using Microsoft.AspNetCore.Testing;
-using Microsoft.CodeAnalysis;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- public abstract class AnalyzerTestBase
- {
- private static readonly string ProjectDirectory = GetProjectDirectory();
-
- public TestSource Read(string source)
- {
- if (!source.EndsWith(".cs"))
- {
- source = source + ".cs";
- }
-
- var filePath = Path.Combine(ProjectDirectory, "TestFiles", GetType().Name, source);
- if (!File.Exists(filePath))
- {
- throw new FileNotFoundException($"TestFile {source} could not be found at {filePath}.", filePath);
- }
-
- var fileContent = File.ReadAllText(filePath);
- return TestSource.Read(fileContent);
- }
-
- public Project CreateProject(string source)
- {
- if (!source.EndsWith(".cs"))
- {
- source = source + ".cs";
- }
-
- var read = Read(source);
- return DiagnosticProject.Create(GetType().Assembly, new[] { read.Source, });
- }
-
- public Task CreateCompilationAsync(string source)
- {
- return CreateProject(source).GetCompilationAsync();
- }
-
- private static string GetProjectDirectory()
- {
- // On helix we use the published test files
- if (SkipOnHelixAttribute.OnHelix())
- {
- return AppContext.BaseDirectory;
- }
-
- // This test code needs to be updated to support distributed testing.
- // See https://github.com/aspnet/AspNetCore/issues/10422
-#pragma warning disable 0618
- var solutionDirectory = TestPathUtilities.GetSolutionRootDirectory("Components");
-#pragma warning restore 0618
- var projectDirectory = Path.Combine(solutionDirectory, "Analyzers", "test");
- return projectDirectory;
- }
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentAnalyzerDiagnosticAnalyzerRunner.cs b/src/Components/Analyzers/test/ComponentAnalyzerDiagnosticAnalyzerRunner.cs
deleted file mode 100644
index 727f060bd4..0000000000
--- a/src/Components/Analyzers/test/ComponentAnalyzerDiagnosticAnalyzerRunner.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Analyzer.Testing;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- internal class ComponentAnalyzerDiagnosticAnalyzerRunner : DiagnosticAnalyzerRunner
- {
- public ComponentAnalyzerDiagnosticAnalyzerRunner(DiagnosticAnalyzer analyzer)
- {
- Analyzer = analyzer;
- }
-
- public DiagnosticAnalyzer Analyzer { get; }
-
- public Task GetDiagnosticsAsync(string source)
- {
- return GetDiagnosticsAsync(sources: new[] { source }, Analyzer, Array.Empty());
- }
-
- public Task GetDiagnosticsAsync(Project project)
- {
- return GetDiagnosticsAsync(new[] { project }, Analyzer, Array.Empty());
- }
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentInternalUsageDiagnoticsAnalyzerTest.cs b/src/Components/Analyzers/test/ComponentInternalUsageDiagnoticsAnalyzerTest.cs
deleted file mode 100644
index 92e2252304..0000000000
--- a/src/Components/Analyzers/test/ComponentInternalUsageDiagnoticsAnalyzerTest.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Analyzer.Testing;
-using Microsoft.Extensions.Internal;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- public class ComponentInternalUsageDiagnoticsAnalyzerTest : AnalyzerTestBase
- {
- public ComponentInternalUsageDiagnoticsAnalyzerTest()
- {
- Analyzer = new ComponentInternalUsageDiagnosticAnalyzer();
- Runner = new ComponentAnalyzerDiagnosticAnalyzerRunner(Analyzer);
- }
-
- private ComponentInternalUsageDiagnosticAnalyzer Analyzer { get; }
- private ComponentAnalyzerDiagnosticAnalyzerRunner Runner { get; }
-
- [Fact]
- public async Task InternalUsage_FindsUseOfRenderTreeFrameAsParameter()
- {
- // Arrange
- var source = Read("UsesRenderTreeFrameAsParameter");
-
- // Act
- var diagnostics = await Runner.GetDiagnosticsAsync(source.Source);
-
- // Assert
- Assert.Collection(
- diagnostics,
- diagnostic =>
- {
- Assert.Same(DiagnosticDescriptors.DoNotUseRenderTreeTypes, diagnostic.Descriptor);
- AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location);
- });
- }
-
- [Fact]
- public async Task InternalUsage_FindsUseOfRenderTreeType()
- {
- // Arrange
- var source = Read("UsesRenderTreeFrameTypeAsLocal");
-
- // Act
- var diagnostics = await Runner.GetDiagnosticsAsync(source.Source);
-
- // Assert
- Assert.Collection(
- diagnostics,
- diagnostic =>
- {
- Assert.Same(DiagnosticDescriptors.DoNotUseRenderTreeTypes, diagnostic.Descriptor);
- AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location);
- });
- }
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentParameterCaptureUnmatchedValuesHasWrongTypeTest.cs b/src/Components/Analyzers/test/ComponentParameterCaptureUnmatchedValuesHasWrongTypeTest.cs
deleted file mode 100644
index e4673c3747..0000000000
--- a/src/Components/Analyzers/test/ComponentParameterCaptureUnmatchedValuesHasWrongTypeTest.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-using TestHelper;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers.Test
-{
- public class ComponentParameterCaptureUnmatchedValuesHasWrongTypeTest : DiagnosticVerifier
- {
- [Theory]
- [InlineData("System.Collections.Generic.IEnumerable>")]
- [InlineData("System.Collections.Generic.Dictionary")]
- [InlineData("System.Collections.Generic.IDictionary")]
- [InlineData("System.Collections.Generic.IReadOnlyDictionary")]
- public void IgnoresPropertiesWithSupportedType(string propertyType)
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter(CaptureUnmatchedValues = true)] public {propertyType} MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void IgnoresPropertiesWithCaptureUnmatchedValuesFalse()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter(CaptureUnmatchedValues = false)] public string MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void AddsDiagnosticForInvalidType()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter(CaptureUnmatchedValues = true)] public string MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesHasWrongType.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty' defines CaptureUnmatchedValues but has an unsupported type 'string'. Use a type assignable from 'System.Collections.Generic.Dictionary'.",
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 7, 70)
- }
- });
- }
-
- protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
- {
- return new ComponentParameterAnalyzer();
- }
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentParameterCaptureUnmatchedValuesMustBeUniqueTest.cs b/src/Components/Analyzers/test/ComponentParameterCaptureUnmatchedValuesMustBeUniqueTest.cs
deleted file mode 100644
index f7b055caa7..0000000000
--- a/src/Components/Analyzers/test/ComponentParameterCaptureUnmatchedValuesMustBeUniqueTest.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-using TestHelper;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers.Test
-{
- public class ComponentParameterCaptureUnmatchedValuesMustBeUniqueTest : DiagnosticVerifier
- {
- [Fact]
- public void IgnoresPropertiesWithCaptureUnmatchedValuesFalse()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using System.Collections.Generic;
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter(CaptureUnmatchedValues = false)] public string MyProperty {{ get; set; }}
- [Parameter(CaptureUnmatchedValues = true)] public Dictionary MyOtherProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void AddsDiagnosticForMultipleCaptureUnmatchedValuesProperties()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using System.Collections.Generic;
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter(CaptureUnmatchedValues = true)] public Dictionary MyProperty {{ get; set; }}
- [Parameter(CaptureUnmatchedValues = true)] public Dictionary MyOtherProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- var message = @"Component type 'ConsoleApplication1.TypeName' defines properties multiple parameters with CaptureUnmatchedValues. Properties: " + Environment.NewLine +
-"ConsoleApplication1.TypeName.MyOtherProperty" + Environment.NewLine +
-"ConsoleApplication1.TypeName.MyProperty";
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterCaptureUnmatchedValuesMustBeUnique.Id,
- Message = message,
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 6, 15)
- }
- });
- }
-
- protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
- {
- return new ComponentParameterAnalyzer();
- }
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs b/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs
deleted file mode 100644
index f32bc6048e..0000000000
--- a/src/Components/Analyzers/test/ComponentParameterSettersShouldBePublicTest.cs
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-using TestHelper;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- public class ComponentParameterSettersShouldBePublicTest : DiagnosticVerifier
- {
- [Fact]
- public void IgnoresCascadingParameterProperties()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(CascadingParameterAttribute).Namespace};
- class TypeName
- {{
- [CascadingParameter] string MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void IgnoresPublicSettersProperties()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter] public string MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void IgnoresPrivateSettersNonParameterProperties()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- private string MyProperty {{ get; private set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void ErrorsForNonPublicSetterParameters()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter] public string MyProperty1 {{ get; private set; }}
- [Parameter] public string MyProperty2 {{ get; protected set; }}
- [Parameter] public string MyProperty3 {{ get; internal set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterSettersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty1' should have a public setter.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 7, 39)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterSettersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty2' should have a public setter.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 8, 39)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterSettersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty3' should have a public setter.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 9, 39)
- }
- });
- }
-
- protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() => new ComponentParameterAnalyzer();
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentParameterUsageAnalyzerTest.cs b/src/Components/Analyzers/test/ComponentParameterUsageAnalyzerTest.cs
deleted file mode 100644
index d1c2d2bede..0000000000
--- a/src/Components/Analyzers/test/ComponentParameterUsageAnalyzerTest.cs
+++ /dev/null
@@ -1,361 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-using TestHelper;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- public class ComponentParameterUsageAnalyzerTest : DiagnosticVerifier
- {
- public ComponentParameterUsageAnalyzerTest()
- {
- ComponentTestSource = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TestComponent : IComponent
- {{
- [Parameter] public string TestProperty {{ get; set; }}
- [Parameter] public int TestInt {{ get; set; }}
- public string NonParameter {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
- }
-
- private string ComponentTestSource { get; }
-
- [Fact]
- public void ComponentPropertySimpleAssignment_Warns()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private TestComponent _testComponent;
- void Render()
- {{
- _testComponent = new TestComponent();
- _testComponent.TestProperty = ""Hello World"";
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent.Id,
- Message = "Component parameter 'TestProperty' should not be set outside of its component.",
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 11, 17)
- }
- });
- }
-
- [Fact]
- public void ComponentPropertyCoalesceAssignment__Warns()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private TestComponent _testComponent;
- void Render()
- {{
- _testComponent = new TestComponent();
- _testComponent.TestProperty ??= ""Hello World"";
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent.Id,
- Message = "Component parameter 'TestProperty' should not be set outside of its component.",
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 11, 17)
- }
- });
- }
-
- [Fact]
- public void ComponentPropertyCompoundAssignment__Warns()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private TestComponent _testComponent;
- void Render()
- {{
- _testComponent = new TestComponent();
- _testComponent.TestProperty += ""Hello World"";
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent.Id,
- Message = "Component parameter 'TestProperty' should not be set outside of its component.",
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 11, 17)
- }
- });
- }
-
- [Fact]
- public void ComponentPropertyIncrement_Warns()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private TestComponent _testComponent;
- void Render()
- {{
- _testComponent = new TestComponent();
- _testComponent.TestInt++;
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent.Id,
- Message = "Component parameter 'TestInt' should not be set outside of its component.",
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 11, 17)
- }
- });
- }
-
- [Fact]
- public void ComponentPropertyDecrement_Warns()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private TestComponent _testComponent;
- void Render()
- {{
- _testComponent = new TestComponent();
- _testComponent.TestInt--;
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent.Id,
- Message = "Component parameter 'TestInt' should not be set outside of its component.",
- Severity = DiagnosticSeverity.Warning,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 11, 17)
- }
- });
- }
-
- [Fact]
- public void ComponentPropertyExpression_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- void Method()
- {{
- System.IO.Console.WriteLine(new TestComponent().TestProperty);
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void ComponentPropertyExpressionInStatement_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- void Method()
- {{
- var testComponent = new TestComponent();
- for (var i = 0; i < testComponent.TestProperty.Length; i++)
- {{
- }}
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void RetrievalOfComponentPropertyValueInAssignment_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- void Method()
- {{
- var testComponent = new TestComponent();
- AnotherProperty = testComponent.TestProperty;
- }}
-
- public string AnotherProperty {{ get; set; }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void ShadowedComponentPropertyAssignment_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- void Method()
- {{
- var testComponent = new InheritedComponent();
- testComponent.TestProperty = ""Hello World"";
- }}
- }}
-
- class InheritedComponent : TestComponent
- {{
- public new string TestProperty {{ get; set; }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void InheritedImplicitComponentPropertyAssignment_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName : TestComponent
- {{
- void Method()
- {{
- this.TestProperty = ""Hello World"";
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void ImplicitComponentPropertyAssignment_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName : IComponent
- {{
- void Method()
- {{
- TestProperty = ""Hello World"";
- }}
-
- [Parameter] public string TestProperty {{ get; set; }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void ComponentPropertyAssignment_NonParameter_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private TestComponent _testComponent;
- void Render()
- {{
- _testComponent = new TestComponent();
- _testComponent.NonParameter = ""Hello World"";
- }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void NonComponentPropertyAssignment_Ignores()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class OtherComponent : IComponent
- {{
- private SomethingElse _testNonComponent;
- void Render()
- {{
- _testNonComponent = new NotAComponent();
- _testNonComponent.TestProperty = ""Hello World"";
- }}
- }}
- class NotAComponent
- {{
- [Parameter] public string TestProperty {{ get; set; }}
- }}
- }}" + ComponentTestSource;
-
- VerifyCSharpDiagnostic(test);
- }
-
- protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() => new ComponentParameterUsageAnalyzer();
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs b/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs
deleted file mode 100644
index 2e1ee00be0..0000000000
--- a/src/Components/Analyzers/test/ComponentParametersShouldBePublicCodeFixProviderTest.cs
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CodeFixes;
-using Microsoft.CodeAnalysis.Diagnostics;
-using TestHelper;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers.Test
-{
- public class ComponentParametersShouldBePublicCodeFixProviderTest : CodeFixVerifier
- {
- [Fact]
- public void IgnoresPrivatePropertiesWithoutParameterAttribute()
- {
- var test = @"
- namespace ConsoleApplication1
- {
- class TypeName
- {
- private string MyProperty { get; set; }
- }
- }" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void AddsDiagnosticAndFixForPrivatePropertiesWithParameterAttribute()
- {
- var test = @"
- namespace ConsoleApplication1
- {
- using " + typeof(ParameterAttribute).Namespace + @";
-
- class TypeName
- {
- [Parameter] private string BadProperty1 { get; set; }
- }
- }" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.BadProperty1' should be public.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 8, 40)
- }
- });
-
- VerifyCSharpFix(test, @"
- namespace ConsoleApplication1
- {
- using " + typeof(ParameterAttribute).Namespace + @";
-
- class TypeName
- {
- [Parameter] public string BadProperty1 { get; set; }
- }
- }" + ComponentsTestDeclarations.Source);
- }
-
- [Fact]
- public void IgnoresPublicPropertiesWithNonPublicSetterWithParameterAttribute()
- {
- var test = @"
- namespace ConsoleApplication1
- {
- using " + typeof(ParameterAttribute).Namespace + @";
-
- class TypeName
- {
- [Parameter] public string MyProperty1 { get; private set; }
- [Parameter] public object MyProperty2 { get; protected set; }
- [Parameter] public object MyProperty3 { get; internal set; }
- }
- }" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterSettersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty1' should have a public setter.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 8, 39)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterSettersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty2' should have a public setter.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 9, 39)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParameterSettersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty3' should have a public setter.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 10, 39)
- }
- });
- }
-
- protected override CodeFixProvider GetCSharpCodeFixProvider()
- {
- return new ComponentParametersShouldBePublicCodeFixProvider();
- }
-
- protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
- {
- return new ComponentParameterAnalyzer();
- }
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentParametersShouldBePublicTest.cs b/src/Components/Analyzers/test/ComponentParametersShouldBePublicTest.cs
deleted file mode 100644
index 97b01c4699..0000000000
--- a/src/Components/Analyzers/test/ComponentParametersShouldBePublicTest.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-using TestHelper;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- public class ComponentParametersShouldBePublicTest : DiagnosticVerifier
- {
- [Fact]
- public void IgnoresPublicProperties()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter] public string MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void IgnoresPrivateNonParameterProperties()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- private string MyProperty {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test);
- }
-
- [Fact]
- public void ErrorsForNonPublicParameters()
- {
- var test = $@"
- namespace ConsoleApplication1
- {{
- using {typeof(ParameterAttribute).Namespace};
- class TypeName
- {{
- [Parameter] string MyProperty1 {{ get; set; }}
- [Parameter] private string MyProperty2 {{ get; set; }}
- [Parameter] protected string MyProperty3 {{ get; set; }}
- [Parameter] internal string MyProperty4 {{ get; set; }}
- }}
- }}" + ComponentsTestDeclarations.Source;
-
- VerifyCSharpDiagnostic(test,
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty1' should be public.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 7, 32)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty2' should be public.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 8, 40)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty3' should be public.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 9, 42)
- }
- },
- new DiagnosticResult
- {
- Id = DiagnosticDescriptors.ComponentParametersShouldBePublic.Id,
- Message = "Component parameter 'ConsoleApplication1.TypeName.MyProperty4' should be public.",
- Severity = DiagnosticSeverity.Error,
- Locations = new[]
- {
- new DiagnosticResultLocation("Test0.cs", 10, 41)
- }
- });
- }
-
- protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() => new ComponentParameterAnalyzer();
- }
-}
diff --git a/src/Components/Analyzers/test/ComponentsTestDeclarations.cs b/src/Components/Analyzers/test/ComponentsTestDeclarations.cs
deleted file mode 100644
index 3c71a82566..0000000000
--- a/src/Components/Analyzers/test/ComponentsTestDeclarations.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-namespace Microsoft.AspNetCore.Components.Analyzers
-{
- public static class ComponentsTestDeclarations
- {
- public static readonly string Source = $@"
- namespace {typeof(ParameterAttribute).Namespace}
- {{
- public class {typeof(ParameterAttribute).Name} : System.Attribute
- {{
- public bool CaptureUnmatchedValues {{ get; set; }}
- }}
-
- public class {typeof(CascadingParameterAttribute).Name} : System.Attribute
- {{
- }}
-
- public interface {typeof(IComponent).Name}
- {{
- }}
- }}
-";
- }
-}
diff --git a/src/Components/Analyzers/test/Helpers/CodeFixVerifier.Helper.cs b/src/Components/Analyzers/test/Helpers/CodeFixVerifier.Helper.cs
deleted file mode 100644
index b523daa09b..0000000000
--- a/src/Components/Analyzers/test/Helpers/CodeFixVerifier.Helper.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-// Most of the code in this file comes from the default Roslyn Analyzer project template
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CodeActions;
-using Microsoft.CodeAnalysis.Formatting;
-using Microsoft.CodeAnalysis.Simplification;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-
-namespace TestHelper
-{
- ///
- /// Diagnostic Producer class with extra methods dealing with applying codefixes
- /// All methods are static
- ///
- public abstract partial class CodeFixVerifier : DiagnosticVerifier
- {
- ///
- /// Apply the inputted CodeAction to the inputted document.
- /// Meant to be used to apply codefixes.
- ///
- /// The Document to apply the fix on
- /// A CodeAction that will be applied to the Document.
- /// A Document with the changes from the CodeAction
- private static Document ApplyFix(Document document, CodeAction codeAction)
- {
- var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
- var solution = operations.OfType().Single().ChangedSolution;
- return solution.GetDocument(document.Id);
- }
-
- ///
- /// Compare two collections of Diagnostics,and return a list of any new diagnostics that appear only in the second collection.
- /// Note: Considers Diagnostics to be the same if they have the same Ids. In the case of multiple diagnostics with the same Id in a row,
- /// this method may not necessarily return the new one.
- ///
- /// The Diagnostics that existed in the code before the CodeFix was applied
- /// The Diagnostics that exist in the code after the CodeFix was applied
- /// A list of Diagnostics that only surfaced in the code after the CodeFix was applied
- private static IEnumerable GetNewDiagnostics(IEnumerable diagnostics, IEnumerable newDiagnostics)
- {
- var oldArray = diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
- var newArray = newDiagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
-
- int oldIndex = 0;
- int newIndex = 0;
-
- while (newIndex < newArray.Length)
- {
- if (oldIndex < oldArray.Length && oldArray[oldIndex].Id == newArray[newIndex].Id)
- {
- ++oldIndex;
- ++newIndex;
- }
- else
- {
- yield return newArray[newIndex++];
- }
- }
- }
-
- ///
- /// Get the existing compiler diagnostics on the inputted document.
- ///
- /// The Document to run the compiler diagnostic analyzers on
- /// The compiler diagnostics that were found in the code
- private static IEnumerable GetCompilerDiagnostics(Document document)
- {
- return document.GetSemanticModelAsync().Result.GetDiagnostics();
- }
-
- ///
- /// Given a document, turn it into a string based on the syntax root
- ///
- /// The Document to be converted to a string
- /// A string containing the syntax of the Document after formatting
- private static string GetStringFromDocument(Document document)
- {
- var simplifiedDoc = Simplifier.ReduceAsync(document, Simplifier.Annotation).Result;
- var root = simplifiedDoc.GetSyntaxRootAsync().Result;
- root = Formatter.Format(root, Formatter.Annotation, simplifiedDoc.Project.Solution.Workspace);
- return root.GetText().ToString();
- }
- }
-}
-
diff --git a/src/Components/Analyzers/test/Helpers/DiagnosticResult.cs b/src/Components/Analyzers/test/Helpers/DiagnosticResult.cs
deleted file mode 100644
index 4e3349ae25..0000000000
--- a/src/Components/Analyzers/test/Helpers/DiagnosticResult.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-// Most of the code in this file comes from the default Roslyn Analyzer project template
-
-using Microsoft.CodeAnalysis;
-using System;
-
-namespace TestHelper
-{
- ///
- /// Location where the diagnostic appears, as determined by path, line number, and column number.
- ///
- public struct DiagnosticResultLocation
- {
- public DiagnosticResultLocation(string path, int line, int column)
- {
- if (line < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(line), "line must be >= -1");
- }
-
- if (column < -1)
- {
- throw new ArgumentOutOfRangeException(nameof(column), "column must be >= -1");
- }
-
- this.Path = path;
- this.Line = line;
- this.Column = column;
- }
-
- public string Path { get; }
- public int Line { get; }
- public int Column { get; }
- }
-
- ///
- /// Struct that stores information about a Diagnostic appearing in a source
- ///
- public struct DiagnosticResult
- {
- private DiagnosticResultLocation[] locations;
-
- public DiagnosticResultLocation[] Locations
- {
- get
- {
- if (this.locations == null)
- {
- this.locations = new DiagnosticResultLocation[] { };
- }
- return this.locations;
- }
-
- set
- {
- this.locations = value;
- }
- }
-
- public DiagnosticSeverity Severity { get; set; }
-
- public string Id { get; set; }
-
- public string Message { get; set; }
-
- public string Path
- {
- get
- {
- return this.Locations.Length > 0 ? this.Locations[0].Path : "";
- }
- }
-
- public int Line
- {
- get
- {
- return this.Locations.Length > 0 ? this.Locations[0].Line : -1;
- }
- }
-
- public int Column
- {
- get
- {
- return this.Locations.Length > 0 ? this.Locations[0].Column : -1;
- }
- }
- }
-}
diff --git a/src/Components/Analyzers/test/Helpers/DiagnosticVerifier.Helper.cs b/src/Components/Analyzers/test/Helpers/DiagnosticVerifier.Helper.cs
deleted file mode 100644
index b55bf99cf4..0000000000
--- a/src/Components/Analyzers/test/Helpers/DiagnosticVerifier.Helper.cs
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-// Most of the code in this file comes from the default Roslyn Analyzer project template
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.Diagnostics;
-using Microsoft.CodeAnalysis.Text;
-using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Linq;
-
-namespace TestHelper
-{
- ///
- /// Class for turning strings into documents and getting the diagnostics on them
- /// All methods are static
- ///
- public abstract partial class DiagnosticVerifier
- {
- private static readonly MetadataReference CorlibReference = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
- private static readonly MetadataReference SystemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location);
- private static readonly MetadataReference CSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location);
- private static readonly MetadataReference CodeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location);
-
- internal static string DefaultFilePathPrefix = "Test";
- internal static string CSharpDefaultFileExt = "cs";
- internal static string VisualBasicDefaultExt = "vb";
- internal static string TestProjectName = "TestProject";
-
- #region Get Diagnostics
-
- ///
- /// Given classes in the form of strings, their language, and an IDiagnosticAnalyzer to apply to it, return the diagnostics found in the string after converting it to a document.
- ///
- /// Classes in the form of strings
- /// The language the source classes are in
- /// The analyzer to be run on the sources
- /// An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location
- private static Diagnostic[] GetSortedDiagnostics(string[] sources, string language, DiagnosticAnalyzer analyzer)
- {
- return GetSortedDiagnosticsFromDocuments(analyzer, GetDocuments(sources, language));
- }
-
- ///
- /// Given an analyzer and a document to apply it to, run the analyzer and gather an array of diagnostics found in it.
- /// The returned diagnostics are then ordered by location in the source document.
- ///
- /// The analyzer to run on the documents
- /// The Documents that the analyzer will be run on
- /// An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location
- protected static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer analyzer, Document[] documents)
- {
- var projects = new HashSet();
- foreach (var document in documents)
- {
- projects.Add(document.Project);
- }
-
- var diagnostics = new List();
- foreach (var project in projects)
- {
- var compilationWithAnalyzers = project.GetCompilationAsync().Result.WithAnalyzers(ImmutableArray.Create(analyzer));
- var diags = compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync().Result;
- foreach (var diag in diags)
- {
- if (diag.Location == Location.None || diag.Location.IsInMetadata)
- {
- diagnostics.Add(diag);
- }
- else
- {
- for (int i = 0; i < documents.Length; i++)
- {
- var document = documents[i];
- var tree = document.GetSyntaxTreeAsync().Result;
- if (tree == diag.Location.SourceTree)
- {
- diagnostics.Add(diag);
- }
- }
- }
- }
- }
-
- var results = SortDiagnostics(diagnostics);
- diagnostics.Clear();
- return results;
- }
-
- ///
- /// Sort diagnostics by location in source document
- ///
- /// The list of Diagnostics to be sorted
- /// An IEnumerable containing the Diagnostics in order of Location
- private static Diagnostic[] SortDiagnostics(IEnumerable diagnostics)
- {
- return diagnostics.OrderBy(d => d.Location.SourceSpan.Start).ToArray();
- }
-
- #endregion
-
- #region Set up compilation and documents
- ///
- /// Given an array of strings as sources and a language, turn them into a project and return the documents and spans of it.
- ///
- /// Classes in the form of strings
- /// The language the source code is in
- /// A Tuple containing the Documents produced from the sources and their TextSpans if relevant
- private static Document[] GetDocuments(string[] sources, string language)
- {
- if (language != LanguageNames.CSharp && language != LanguageNames.VisualBasic)
- {
- throw new ArgumentException("Unsupported Language");
- }
-
- var project = CreateProject(sources, language);
- var documents = project.Documents.ToArray();
-
- if (sources.Length != documents.Length)
- {
- throw new InvalidOperationException("Amount of sources did not match amount of Documents created");
- }
-
- return documents;
- }
-
- ///
- /// Create a Document from a string through creating a project that contains it.
- ///
- /// Classes in the form of a string
- /// The language the source code is in
- /// A Document created from the source string
- protected static Document CreateDocument(string source, string language = LanguageNames.CSharp)
- {
- return CreateProject(new[] { source }, language).Documents.First();
- }
-
- ///
- /// Create a project using the inputted strings as sources.
- ///
- /// Classes in the form of strings
- /// The language the source code is in
- /// A Project created out of the Documents created from the source strings
- private static Project CreateProject(string[] sources, string language = LanguageNames.CSharp)
- {
- string fileNamePrefix = DefaultFilePathPrefix;
- string fileExt = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt;
-
- var projectId = ProjectId.CreateNewId(debugName: TestProjectName);
-
- var solution = new AdhocWorkspace()
- .CurrentSolution
- .AddProject(projectId, TestProjectName, TestProjectName, language)
- .AddMetadataReference(projectId, CorlibReference)
- .AddMetadataReference(projectId, SystemCoreReference)
- .AddMetadataReference(projectId, CSharpSymbolsReference)
- .AddMetadataReference(projectId, CodeAnalysisReference);
-
- int count = 0;
- foreach (var source in sources)
- {
- var newFileName = fileNamePrefix + count + "." + fileExt;
- var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName);
- solution = solution.AddDocument(documentId, newFileName, SourceText.From(source));
- count++;
- }
- return solution.GetProject(projectId);
- }
- #endregion
- }
-}
-
diff --git a/src/Components/Analyzers/test/Microsoft.AspNetCore.Components.Analyzers.Tests.csproj b/src/Components/Analyzers/test/Microsoft.AspNetCore.Components.Analyzers.Tests.csproj
deleted file mode 100644
index 10085017d1..0000000000
--- a/src/Components/Analyzers/test/Microsoft.AspNetCore.Components.Analyzers.Tests.csproj
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
- $(DefaultNetCoreTargetFramework)
-
-
-
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnoticsAnalyzerTest/UsesRenderTreeFrameAsParameter.cs b/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnoticsAnalyzerTest/UsesRenderTreeFrameAsParameter.cs
deleted file mode 100644
index 415030a011..0000000000
--- a/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnoticsAnalyzerTest/UsesRenderTreeFrameAsParameter.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Microsoft.AspNetCore.Components.RenderTree;
-
-namespace Microsoft.AspNetCore.Components.Analyzers.Tests.TestFiles.ComponentInternalUsageDiagnoticsAnalyzerTest
-{
- class UsesRenderTreeFrameAsParameter
- {
- private void Test(/*MM*/RenderTreeFrame frame)
- {
- }
- }
-}
diff --git a/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnoticsAnalyzerTest/UsesRenderTreeFrameTypeAsLocal.cs b/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnoticsAnalyzerTest/UsesRenderTreeFrameTypeAsLocal.cs
deleted file mode 100644
index bdd40c2df1..0000000000
--- a/src/Components/Analyzers/test/TestFiles/ComponentInternalUsageDiagnoticsAnalyzerTest/UsesRenderTreeFrameTypeAsLocal.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using Microsoft.AspNetCore.Components.RenderTree;
-
-namespace Microsoft.AspNetCore.Components.Analyzers.Tests.TestFiles.ComponentInternalUsageDiagnoticsAnalyzerTest
-{
- class UsesRenderTreeFrameTypeAsLocal
- {
- private void Test()
- {
- var test = RenderTreeFrameType./*MM*/Attribute;
- GC.KeepAlive(test);
- }
-
- }
-}
diff --git a/src/Components/Analyzers/test/Verifiers/CodeFixVerifier.cs b/src/Components/Analyzers/test/Verifiers/CodeFixVerifier.cs
deleted file mode 100644
index cb6c9d4329..0000000000
--- a/src/Components/Analyzers/test/Verifiers/CodeFixVerifier.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-// Most of the code in this file comes from the default Roslyn Analyzer project template
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.CodeActions;
-using Microsoft.CodeAnalysis.CodeFixes;
-using Microsoft.CodeAnalysis.Diagnostics;
-using Microsoft.CodeAnalysis.Formatting;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using Xunit;
-
-namespace TestHelper
-{
- ///
- /// Superclass of all Unit tests made for diagnostics with codefixes.
- /// Contains methods used to verify correctness of codefixes
- ///
- public abstract partial class CodeFixVerifier : DiagnosticVerifier
- {
- ///
- /// Returns the codefix being tested (C#) - to be implemented in non-abstract class
- ///
- /// The CodeFixProvider to be used for CSharp code
- protected virtual CodeFixProvider GetCSharpCodeFixProvider()
- {
- return null;
- }
-
- ///
- /// Returns the codefix being tested (VB) - to be implemented in non-abstract class
- ///
- /// The CodeFixProvider to be used for VisualBasic code
- protected virtual CodeFixProvider GetBasicCodeFixProvider()
- {
- return null;
- }
-
- ///
- /// Called to test a C# codefix when applied on the inputted string as a source
- ///
- /// A class in the form of a string before the CodeFix was applied to it
- /// A class in the form of a string after the CodeFix was applied to it
- /// Index determining which codefix to apply if there are multiple
- /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied
- protected void VerifyCSharpFix(string oldSource, string newSource, int? codeFixIndex = null, bool allowNewCompilerDiagnostics = false)
- {
- VerifyFix(LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), GetCSharpCodeFixProvider(), oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics);
- }
-
- ///
- /// Called to test a VB codefix when applied on the inputted string as a source
- ///
- /// A class in the form of a string before the CodeFix was applied to it
- /// A class in the form of a string after the CodeFix was applied to it
- /// Index determining which codefix to apply if there are multiple
- /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied
- protected void VerifyBasicFix(string oldSource, string newSource, int? codeFixIndex = null, bool allowNewCompilerDiagnostics = false)
- {
- VerifyFix(LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), GetBasicCodeFixProvider(), oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics);
- }
-
- ///
- /// General verifier for codefixes.
- /// Creates a Document from the source string, then gets diagnostics on it and applies the relevant codefixes.
- /// Then gets the string after the codefix is applied and compares it with the expected result.
- /// Note: If any codefix causes new diagnostics to show up, the test fails unless allowNewCompilerDiagnostics is set to true.
- ///
- /// The language the source code is in
- /// The analyzer to be applied to the source code
- /// The codefix to be applied to the code wherever the relevant Diagnostic is found
- /// A class in the form of a string before the CodeFix was applied to it
- /// A class in the form of a string after the CodeFix was applied to it
- /// Index determining which codefix to apply if there are multiple
- /// A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied
- private void VerifyFix(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string oldSource, string newSource, int? codeFixIndex, bool allowNewCompilerDiagnostics)
- {
- var document = CreateDocument(oldSource, language);
- var analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
- var compilerDiagnostics = GetCompilerDiagnostics(document);
- var attempts = analyzerDiagnostics.Length;
-
- for (int i = 0; i < attempts; ++i)
- {
- var actions = new List();
- var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
- codeFixProvider.RegisterCodeFixesAsync(context).Wait();
-
- if (!actions.Any())
- {
- break;
- }
-
- if (codeFixIndex != null)
- {
- document = ApplyFix(document, actions.ElementAt((int)codeFixIndex));
- break;
- }
-
- document = ApplyFix(document, actions.ElementAt(0));
- analyzerDiagnostics = GetSortedDiagnosticsFromDocuments(analyzer, new[] { document });
-
- var newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, GetCompilerDiagnostics(document));
-
- //check if applying the code fix introduced any new compiler diagnostics
- if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
- {
- // Format and get the compiler diagnostics again so that the locations make sense in the output
- document = document.WithSyntaxRoot(Formatter.Format(document.GetSyntaxRootAsync().Result, Formatter.Annotation, document.Project.Solution.Workspace));
- newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, GetCompilerDiagnostics(document));
-
- Assert.True(false,
- string.Format("Fix introduced new compiler diagnostics:\r\n{0}\r\n\r\nNew document:\r\n{1}\r\n",
- string.Join("\r\n", newCompilerDiagnostics.Select(d => d.ToString())),
- document.GetSyntaxRootAsync().Result.ToFullString()));
- }
-
- //check if there are analyzer diagnostics left after the code fix
- if (!analyzerDiagnostics.Any())
- {
- break;
- }
- }
-
- //after applying all of the code fixes, compare the resulting string to the inputted one
- var actual = GetStringFromDocument(document);
- Assert.Equal(newSource, actual);
- }
- }
-}
diff --git a/src/Components/Analyzers/test/Verifiers/DiagnosticVerifier.cs b/src/Components/Analyzers/test/Verifiers/DiagnosticVerifier.cs
deleted file mode 100644
index f56d4ff93d..0000000000
--- a/src/Components/Analyzers/test/Verifiers/DiagnosticVerifier.cs
+++ /dev/null
@@ -1,274 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-// Most of the code in this file comes from the default Roslyn Analyzer project template
-
-using Microsoft.CodeAnalysis;
-using Microsoft.CodeAnalysis.Diagnostics;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Xunit;
-
-namespace TestHelper
-{
- ///
- /// Superclass of all Unit Tests for DiagnosticAnalyzers
- ///
- public abstract partial class DiagnosticVerifier
- {
- #region To be implemented by Test classes
- ///
- /// Get the CSharp analyzer being tested - to be implemented in non-abstract class
- ///
- protected virtual DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
- {
- return null;
- }
-
- ///
- /// Get the Visual Basic analyzer being tested (C#) - to be implemented in non-abstract class
- ///
- protected virtual DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
- {
- return null;
- }
- #endregion
-
- #region Verifier wrappers
-
- ///
- /// Called to test a C# DiagnosticAnalyzer when applied on the single inputted string as a source
- /// Note: input a DiagnosticResult for each Diagnostic expected
- ///
- /// A class in the form of a string to run the analyzer on
- /// DiagnosticResults that should appear after the analyzer is run on the source
- protected void VerifyCSharpDiagnostic(string source, params DiagnosticResult[] expected)
- {
- VerifyDiagnostics(new[] { source }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
- }
-
- ///
- /// Called to test a VB DiagnosticAnalyzer when applied on the single inputted string as a source
- /// Note: input a DiagnosticResult for each Diagnostic expected
- ///
- /// A class in the form of a string to run the analyzer on
- /// DiagnosticResults that should appear after the analyzer is run on the source
- protected void VerifyBasicDiagnostic(string source, params DiagnosticResult[] expected)
- {
- VerifyDiagnostics(new[] { source }, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected);
- }
-
- ///
- /// Called to test a C# DiagnosticAnalyzer when applied on the inputted strings as a source
- /// Note: input a DiagnosticResult for each Diagnostic expected
- ///
- /// An array of strings to create source documents from to run the analyzers on
- /// DiagnosticResults that should appear after the analyzer is run on the sources
- protected void VerifyCSharpDiagnostic(string[] sources, params DiagnosticResult[] expected)
- {
- VerifyDiagnostics(sources, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer(), expected);
- }
-
- ///
- /// Called to test a VB DiagnosticAnalyzer when applied on the inputted strings as a source
- /// Note: input a DiagnosticResult for each Diagnostic expected
- ///
- /// An array of strings to create source documents from to run the analyzers on
- /// DiagnosticResults that should appear after the analyzer is run on the sources
- protected void VerifyBasicDiagnostic(string[] sources, params DiagnosticResult[] expected)
- {
- VerifyDiagnostics(sources, LanguageNames.VisualBasic, GetBasicDiagnosticAnalyzer(), expected);
- }
-
- ///
- /// General method that gets a collection of actual diagnostics found in the source after the analyzer is run,
- /// then verifies each of them.
- ///
- /// An array of strings to create source documents from to run the analyzers on
- /// The language of the classes represented by the source strings
- /// The analyzer to be run on the source code
- /// DiagnosticResults that should appear after the analyzer is run on the sources
- private void VerifyDiagnostics(string[] sources, string language, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expected)
- {
- var diagnostics = GetSortedDiagnostics(sources, language, analyzer);
- VerifyDiagnosticResults(diagnostics, analyzer, expected);
- }
-
- #endregion
-
- #region Actual comparisons and verifications
- ///
- /// Checks each of the actual Diagnostics found and compares them with the corresponding DiagnosticResult in the array of expected results.
- /// Diagnostics are considered equal only if the DiagnosticResultLocation, Id, Severity, and Message of the DiagnosticResult match the actual diagnostic.
- ///
- /// The Diagnostics found by the compiler after running the analyzer on the source code
- /// The analyzer that was being run on the sources
- /// Diagnostic Results that should have appeared in the code
- private static void VerifyDiagnosticResults(IEnumerable actualResults, DiagnosticAnalyzer analyzer, params DiagnosticResult[] expectedResults)
- {
- int expectedCount = expectedResults.Count();
- int actualCount = actualResults.Count();
-
- if (expectedCount != actualCount)
- {
- string diagnosticsOutput = actualResults.Any() ? FormatDiagnostics(analyzer, actualResults.ToArray()) : " NONE.";
-
- Assert.True(false,
- string.Format("Mismatch between number of diagnostics returned, expected \"{0}\" actual \"{1}\"\r\n\r\nDiagnostics:\r\n{2}\r\n", expectedCount, actualCount, diagnosticsOutput));
- }
-
- for (int i = 0; i < expectedResults.Length; i++)
- {
- var actual = actualResults.ElementAt(i);
- var expected = expectedResults[i];
-
- if (expected.Line == -1 && expected.Column == -1)
- {
- if (actual.Location != Location.None)
- {
- Assert.True(false,
- string.Format("Expected:\nA project diagnostic with No location\nActual:\n{0}",
- FormatDiagnostics(analyzer, actual)));
- }
- }
- else
- {
- VerifyDiagnosticLocation(analyzer, actual, actual.Location, expected.Locations.First());
- var additionalLocations = actual.AdditionalLocations.ToArray();
-
- if (additionalLocations.Length != expected.Locations.Length - 1)
- {
- Assert.True(false,
- string.Format("Expected {0} additional locations but got {1} for Diagnostic:\r\n {2}\r\n",
- expected.Locations.Length - 1, additionalLocations.Length,
- FormatDiagnostics(analyzer, actual)));
- }
-
- for (int j = 0; j < additionalLocations.Length; ++j)
- {
- VerifyDiagnosticLocation(analyzer, actual, additionalLocations[j], expected.Locations[j + 1]);
- }
- }
-
- if (actual.Id != expected.Id)
- {
- Assert.True(false,
- string.Format("Expected diagnostic id to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Id, actual.Id, FormatDiagnostics(analyzer, actual)));
- }
-
- if (actual.Severity != expected.Severity)
- {
- Assert.True(false,
- string.Format("Expected diagnostic severity to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Severity, actual.Severity, FormatDiagnostics(analyzer, actual)));
- }
-
- if (actual.GetMessage() != expected.Message)
- {
- Assert.True(false,
- string.Format("Expected diagnostic message to be \"{0}\" was \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Message, actual.GetMessage(), FormatDiagnostics(analyzer, actual)));
- }
- }
- }
-
- ///
- /// Helper method to VerifyDiagnosticResult that checks the location of a diagnostic and compares it with the location in the expected DiagnosticResult.
- ///
- /// The analyzer that was being run on the sources
- /// The diagnostic that was found in the code
- /// The Location of the Diagnostic found in the code
- /// The DiagnosticResultLocation that should have been found
- private static void VerifyDiagnosticLocation(DiagnosticAnalyzer analyzer, Diagnostic diagnostic, Location actual, DiagnosticResultLocation expected)
- {
- var actualSpan = actual.GetLineSpan();
-
- Assert.True(actualSpan.Path == expected.Path || (actualSpan.Path != null && actualSpan.Path.Contains("Test0.") && expected.Path.Contains("Test.")),
- string.Format("Expected diagnostic to be in file \"{0}\" was actually in file \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Path, actualSpan.Path, FormatDiagnostics(analyzer, diagnostic)));
-
- var actualLinePosition = actualSpan.StartLinePosition;
-
- // Only check line position if there is an actual line in the real diagnostic
- if (actualLinePosition.Line > 0)
- {
- if (actualLinePosition.Line + 1 != expected.Line)
- {
- Assert.True(false,
- string.Format("Expected diagnostic to be on line \"{0}\" was actually on line \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Line, actualLinePosition.Line + 1, FormatDiagnostics(analyzer, diagnostic)));
- }
- }
-
- // Only check column position if there is an actual column position in the real diagnostic
- if (actualLinePosition.Character > 0)
- {
- if (actualLinePosition.Character + 1 != expected.Column)
- {
- Assert.True(false,
- string.Format("Expected diagnostic to start at column \"{0}\" was actually at column \"{1}\"\r\n\r\nDiagnostic:\r\n {2}\r\n",
- expected.Column, actualLinePosition.Character + 1, FormatDiagnostics(analyzer, diagnostic)));
- }
- }
- }
- #endregion
-
- #region Formatting Diagnostics
- ///
- /// Helper method to format a Diagnostic into an easily readable string
- ///
- /// The analyzer that this verifier tests
- /// The Diagnostics to be formatted
- /// The Diagnostics formatted as a string
- private static string FormatDiagnostics(DiagnosticAnalyzer analyzer, params Diagnostic[] diagnostics)
- {
- var builder = new StringBuilder();
- for (int i = 0; i < diagnostics.Length; ++i)
- {
- builder.AppendLine("// " + diagnostics[i].ToString());
-
- var analyzerType = analyzer.GetType();
- var rules = analyzer.SupportedDiagnostics;
-
- foreach (var rule in rules)
- {
- if (rule != null && rule.Id == diagnostics[i].Id)
- {
- var location = diagnostics[i].Location;
- if (location == Location.None)
- {
- builder.AppendFormat("GetGlobalResult({0}.{1})", analyzerType.Name, rule.Id);
- }
- else
- {
- Assert.True(location.IsInSource,
- $"Test base does not currently handle diagnostics in metadata locations. Diagnostic in metadata: {diagnostics[i]}\r\n");
-
- string resultMethodName = diagnostics[i].Location.SourceTree.FilePath.EndsWith(".cs") ? "GetCSharpResultAt" : "GetBasicResultAt";
- var linePosition = diagnostics[i].Location.GetLineSpan().StartLinePosition;
-
- builder.AppendFormat("{0}({1}, {2}, {3}.{4})",
- resultMethodName,
- linePosition.Line + 1,
- linePosition.Character + 1,
- analyzerType.Name,
- rule.Id);
- }
-
- if (i != diagnostics.Length - 1)
- {
- builder.Append(',');
- }
-
- builder.AppendLine();
- break;
- }
- }
- }
- return builder.ToString();
- }
- #endregion
- }
-}
diff --git a/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.csproj b/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.csproj
deleted file mode 100644
index 513c24575d..0000000000
--- a/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.csproj
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
- netstandard2.0;$(DefaultNetCoreTargetFramework)
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.netcoreapp.cs b/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.netcoreapp.cs
deleted file mode 100644
index ca0535937a..0000000000
--- a/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.netcoreapp.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- public partial class AuthenticationState
- {
- public AuthenticationState(System.Security.Claims.ClaimsPrincipal user) { }
- public System.Security.Claims.ClaimsPrincipal User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
- }
- public delegate void AuthenticationStateChangedHandler(System.Threading.Tasks.Task task);
- public abstract partial class AuthenticationStateProvider
- {
- protected AuthenticationStateProvider() { }
- public event Microsoft.AspNetCore.Components.Authorization.AuthenticationStateChangedHandler AuthenticationStateChanged { add { } remove { } }
- public abstract System.Threading.Tasks.Task GetAuthenticationStateAsync();
- protected void NotifyAuthenticationStateChanged(System.Threading.Tasks.Task task) { }
- }
- public sealed partial class AuthorizeRouteView : Microsoft.AspNetCore.Components.RouteView
- {
- public AuthorizeRouteView() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment Authorizing { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment NotAuthorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override void Render(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
- }
- public partial class AuthorizeView : Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore
- {
- public AuthorizeView() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public string Policy { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public string Roles { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override Microsoft.AspNetCore.Authorization.IAuthorizeData[] GetAuthorizeData() { throw null; }
- }
- public abstract partial class AuthorizeViewCore : Microsoft.AspNetCore.Components.ComponentBase
- {
- protected AuthorizeViewCore() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment Authorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment Authorizing { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment NotAuthorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public object Resource { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
- protected abstract Microsoft.AspNetCore.Authorization.IAuthorizeData[] GetAuthorizeData();
- [System.Diagnostics.DebuggerStepThroughAttribute]
- protected override System.Threading.Tasks.Task OnParametersSetAsync() { throw null; }
- }
- public partial class CascadingAuthenticationState : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable
- {
- public CascadingAuthenticationState() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) { }
- protected override void OnInitialized() { }
- void System.IDisposable.Dispose() { }
- }
- public partial interface IHostEnvironmentAuthenticationStateProvider
- {
- void SetAuthenticationState(System.Threading.Tasks.Task authenticationStateTask);
- }
-}
diff --git a/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.netstandard2.0.cs b/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.netstandard2.0.cs
deleted file mode 100644
index ca0535937a..0000000000
--- a/src/Components/Authorization/ref/Microsoft.AspNetCore.Components.Authorization.netstandard2.0.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- public partial class AuthenticationState
- {
- public AuthenticationState(System.Security.Claims.ClaimsPrincipal user) { }
- public System.Security.Claims.ClaimsPrincipal User { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
- }
- public delegate void AuthenticationStateChangedHandler(System.Threading.Tasks.Task task);
- public abstract partial class AuthenticationStateProvider
- {
- protected AuthenticationStateProvider() { }
- public event Microsoft.AspNetCore.Components.Authorization.AuthenticationStateChangedHandler AuthenticationStateChanged { add { } remove { } }
- public abstract System.Threading.Tasks.Task GetAuthenticationStateAsync();
- protected void NotifyAuthenticationStateChanged(System.Threading.Tasks.Task task) { }
- }
- public sealed partial class AuthorizeRouteView : Microsoft.AspNetCore.Components.RouteView
- {
- public AuthorizeRouteView() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment Authorizing { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment NotAuthorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override void Render(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
- }
- public partial class AuthorizeView : Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore
- {
- public AuthorizeView() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public string Policy { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public string Roles { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override Microsoft.AspNetCore.Authorization.IAuthorizeData[] GetAuthorizeData() { throw null; }
- }
- public abstract partial class AuthorizeViewCore : Microsoft.AspNetCore.Components.ComponentBase
- {
- protected AuthorizeViewCore() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment Authorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment Authorizing { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment NotAuthorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public object Resource { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
- protected abstract Microsoft.AspNetCore.Authorization.IAuthorizeData[] GetAuthorizeData();
- [System.Diagnostics.DebuggerStepThroughAttribute]
- protected override System.Threading.Tasks.Task OnParametersSetAsync() { throw null; }
- }
- public partial class CascadingAuthenticationState : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable
- {
- public CascadingAuthenticationState() { }
- [Microsoft.AspNetCore.Components.ParameterAttribute]
- public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
- protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) { }
- protected override void OnInitialized() { }
- void System.IDisposable.Dispose() { }
- }
- public partial interface IHostEnvironmentAuthenticationStateProvider
- {
- void SetAuthenticationState(System.Threading.Tasks.Task authenticationStateTask);
- }
-}
diff --git a/src/Components/Authorization/src/AttributeAuthorizeDataCache.cs b/src/Components/Authorization/src/AttributeAuthorizeDataCache.cs
deleted file mode 100644
index c1495fb303..0000000000
--- a/src/Components/Authorization/src/AttributeAuthorizeDataCache.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Collections.Concurrent;
-using System.Linq;
-using Microsoft.AspNetCore.Authorization;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- internal static class AttributeAuthorizeDataCache
- {
- private static ConcurrentDictionary _cache
- = new ConcurrentDictionary();
-
- public static IAuthorizeData[] GetAuthorizeDataForType(Type type)
- {
- IAuthorizeData[] result;
- if (!_cache.TryGetValue(type, out result))
- {
- result = ComputeAuthorizeDataForType(type);
- _cache[type] = result; // Safe race - doesn't matter if it overwrites
- }
-
- return result;
- }
-
- private static IAuthorizeData[] ComputeAuthorizeDataForType(Type type)
- {
- // Allow Anonymous skips all authorization
- var allAttributes = type.GetCustomAttributes(inherit: true);
- if (allAttributes.OfType().Any())
- {
- return null;
- }
-
- var authorizeDataAttributes = allAttributes.OfType().ToArray();
- return authorizeDataAttributes.Length > 0 ? authorizeDataAttributes : null;
- }
- }
-}
diff --git a/src/Components/Authorization/src/AuthenticationState.cs b/src/Components/Authorization/src/AuthenticationState.cs
deleted file mode 100644
index 6a05dce35d..0000000000
--- a/src/Components/Authorization/src/AuthenticationState.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Security.Claims;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- ///
- /// Provides information about the currently authenticated user, if any.
- ///
- public class AuthenticationState
- {
- ///
- /// Constructs an instance of .
- ///
- /// A representing the user.
- public AuthenticationState(ClaimsPrincipal user)
- {
- User = user ?? throw new ArgumentNullException(nameof(user));
- }
-
- ///
- /// Gets a that describes the current user.
- ///
- public ClaimsPrincipal User { get; }
- }
-}
diff --git a/src/Components/Authorization/src/AuthenticationStateProvider.cs b/src/Components/Authorization/src/AuthenticationStateProvider.cs
deleted file mode 100644
index 6fc9af07c7..0000000000
--- a/src/Components/Authorization/src/AuthenticationStateProvider.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Threading.Tasks;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- ///
- /// Provides information about the authentication state of the current user.
- ///
- public abstract class AuthenticationStateProvider
- {
- ///
- /// Asynchronously gets an that describes the current user.
- ///
- /// A task that, when resolved, gives an instance that describes the current user.
- public abstract Task GetAuthenticationStateAsync();
-
- ///
- /// An event that provides notification when the
- /// has changed. For example, this event may be raised if a user logs in or out.
- ///
- public event AuthenticationStateChangedHandler AuthenticationStateChanged;
-
- ///
- /// Raises the event.
- ///
- /// A that supplies the updated .
- protected void NotifyAuthenticationStateChanged(Task task)
- {
- if (task == null)
- {
- throw new ArgumentNullException(nameof(task));
- }
-
- AuthenticationStateChanged?.Invoke(task);
- }
- }
-
- ///
- /// A handler for the event.
- ///
- /// A that supplies the updated .
- public delegate void AuthenticationStateChangedHandler(Task task);
-}
diff --git a/src/Components/Authorization/src/AuthorizeDataAdapter.cs b/src/Components/Authorization/src/AuthorizeDataAdapter.cs
deleted file mode 100644
index 55d369f9af..0000000000
--- a/src/Components/Authorization/src/AuthorizeDataAdapter.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using Microsoft.AspNetCore.Authorization;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- // This is so the AuthorizeView can avoid implementing IAuthorizeData (even privately)
- internal class AuthorizeDataAdapter : IAuthorizeData
- {
- private readonly AuthorizeView _component;
-
- public AuthorizeDataAdapter(AuthorizeView component)
- {
- _component = component ?? throw new ArgumentNullException(nameof(component));
- }
-
- public string Policy
- {
- get => _component.Policy;
- set => throw new NotSupportedException();
- }
-
- public string Roles
- {
- get => _component.Roles;
- set => throw new NotSupportedException();
- }
-
- // AuthorizeView doesn't expose any such parameter, as it wouldn't be used anyway,
- // since we already have the ClaimsPrincipal by the time AuthorizeView gets involved.
- public string AuthenticationSchemes
- {
- get => null;
- set => throw new NotSupportedException();
- }
- }
-}
diff --git a/src/Components/Authorization/src/AuthorizeRouteView.cs b/src/Components/Authorization/src/AuthorizeRouteView.cs
deleted file mode 100644
index 2d7ea76698..0000000000
--- a/src/Components/Authorization/src/AuthorizeRouteView.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Components.Rendering;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- ///
- /// Combines the behaviors of and ,
- /// so that it displays the page matching the specified route but only if the user
- /// is authorized to see it.
- ///
- /// Additionally, this component supplies a cascading parameter of type ,
- /// which makes the user's current authentication state available to descendants.
- ///
- public sealed class AuthorizeRouteView : RouteView
- {
- // We expect applications to supply their own authorizing/not-authorized content, but
- // it's better to have defaults than to make the parameters mandatory because in some
- // cases they will never be used (e.g., "authorizing" in out-of-box server-side Blazor)
- private static readonly RenderFragment _defaultNotAuthorizedContent
- = state => builder => builder.AddContent(0, "Not authorized");
- private static readonly RenderFragment _defaultAuthorizingContent
- = builder => builder.AddContent(0, "Authorizing...");
-
- private readonly RenderFragment _renderAuthorizeRouteViewCoreDelegate;
- private readonly RenderFragment _renderAuthorizedDelegate;
- private readonly RenderFragment _renderNotAuthorizedDelegate;
- private readonly RenderFragment _renderAuthorizingDelegate;
-
- public AuthorizeRouteView()
- {
- // Cache the rendering delegates so that we only construct new closure instances
- // when they are actually used (e.g., we never prepare a RenderFragment bound to
- // the NotAuthorized content except when you are displaying that particular state)
- RenderFragment renderBaseRouteViewDelegate = builder => base.Render(builder);
- _renderAuthorizedDelegate = authenticateState => renderBaseRouteViewDelegate;
- _renderNotAuthorizedDelegate = authenticationState => builder => RenderNotAuthorizedInDefaultLayout(builder, authenticationState);
- _renderAuthorizingDelegate = RenderAuthorizingInDefaultLayout;
- _renderAuthorizeRouteViewCoreDelegate = RenderAuthorizeRouteViewCore;
- }
-
- ///
- /// The content that will be displayed if the user is not authorized.
- ///
- [Parameter]
- public RenderFragment NotAuthorized { get; set; }
-
- ///
- /// The content that will be displayed while asynchronous authorization is in progress.
- ///
- [Parameter]
- public RenderFragment Authorizing { get; set; }
-
- [CascadingParameter]
- private Task ExistingCascadedAuthenticationState { get; set; }
-
- ///
- protected override void Render(RenderTreeBuilder builder)
- {
- if (ExistingCascadedAuthenticationState != null)
- {
- // If this component is already wrapped in a (or another
- // compatible provider), then don't interfere with the cascaded authentication state.
- _renderAuthorizeRouteViewCoreDelegate(builder);
- }
- else
- {
- // Otherwise, implicitly wrap the output in a
- builder.OpenComponent(0);
- builder.AddAttribute(1, nameof(CascadingAuthenticationState.ChildContent), _renderAuthorizeRouteViewCoreDelegate);
- builder.CloseComponent();
- }
- }
-
- private void RenderAuthorizeRouteViewCore(RenderTreeBuilder builder)
- {
- builder.OpenComponent(0);
- builder.AddAttribute(1, nameof(AuthorizeRouteViewCore.RouteData), RouteData);
- builder.AddAttribute(2, nameof(AuthorizeRouteViewCore.Authorized), _renderAuthorizedDelegate);
- builder.AddAttribute(3, nameof(AuthorizeRouteViewCore.Authorizing), _renderAuthorizingDelegate);
- builder.AddAttribute(4, nameof(AuthorizeRouteViewCore.NotAuthorized), _renderNotAuthorizedDelegate);
- builder.CloseComponent();
- }
-
- private void RenderContentInDefaultLayout(RenderTreeBuilder builder, RenderFragment content)
- {
- builder.OpenComponent(0);
- builder.AddAttribute(1, nameof(LayoutView.Layout), DefaultLayout);
- builder.AddAttribute(2, nameof(LayoutView.ChildContent), content);
- builder.CloseComponent();
- }
-
- private void RenderNotAuthorizedInDefaultLayout(RenderTreeBuilder builder, AuthenticationState authenticationState)
- {
- var content = NotAuthorized ?? _defaultNotAuthorizedContent;
- RenderContentInDefaultLayout(builder, content(authenticationState));
- }
-
- private void RenderAuthorizingInDefaultLayout(RenderTreeBuilder builder)
- {
- var content = Authorizing ?? _defaultAuthorizingContent;
- RenderContentInDefaultLayout(builder, content);
- }
-
- private class AuthorizeRouteViewCore : AuthorizeViewCore
- {
- [Parameter]
- public RouteData RouteData { get; set; }
-
- protected override IAuthorizeData[] GetAuthorizeData()
- => AttributeAuthorizeDataCache.GetAuthorizeDataForType(RouteData.PageType);
- }
- }
-}
diff --git a/src/Components/Authorization/src/AuthorizeView.cs b/src/Components/Authorization/src/AuthorizeView.cs
deleted file mode 100644
index b66a00d2a4..0000000000
--- a/src/Components/Authorization/src/AuthorizeView.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using Microsoft.AspNetCore.Authorization;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- ///
- /// Displays differing content depending on the user's authorization status.
- ///
- public class AuthorizeView : AuthorizeViewCore
- {
- private readonly IAuthorizeData[] selfAsAuthorizeData;
-
- ///
- /// Constructs an instance of .
- ///
- public AuthorizeView()
- {
- selfAsAuthorizeData = new[] { new AuthorizeDataAdapter(this) };
- }
-
- ///
- /// The policy name that determines whether the content can be displayed.
- ///
- [Parameter] public string Policy { get; set; }
-
- ///
- /// A comma delimited list of roles that are allowed to display the content.
- ///
- [Parameter] public string Roles { get; set; }
-
- ///
- /// Gets the data used for authorization.
- ///
- protected override IAuthorizeData[] GetAuthorizeData()
- => selfAsAuthorizeData;
- }
-}
diff --git a/src/Components/Authorization/src/AuthorizeViewCore.cs b/src/Components/Authorization/src/AuthorizeViewCore.cs
deleted file mode 100644
index b225bb19bd..0000000000
--- a/src/Components/Authorization/src/AuthorizeViewCore.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System;
-using System.Security.Claims;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Components.Rendering;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- ///
- /// A base class for components that display differing content depending on the user's authorization status.
- ///
- public abstract class AuthorizeViewCore : ComponentBase
- {
- private AuthenticationState currentAuthenticationState;
- private bool isAuthorized;
-
- ///
- /// The content that will be displayed if the user is authorized.
- ///
- [Parameter] public RenderFragment ChildContent { get; set; }
-
- ///
- /// The content that will be displayed if the user is not authorized.
- ///
- [Parameter] public RenderFragment NotAuthorized { get; set; }
-
- ///
- /// The content that will be displayed if the user is authorized.
- /// If you specify a value for this parameter, do not also specify a value for .
- ///
- [Parameter] public RenderFragment Authorized { get; set; }
-
- ///
- /// The content that will be displayed while asynchronous authorization is in progress.
- ///
- [Parameter] public RenderFragment Authorizing { get; set; }
-
- ///
- /// The resource to which access is being controlled.
- ///
- [Parameter] public object Resource { get; set; }
-
- [CascadingParameter] private Task AuthenticationState { get; set; }
-
- [Inject] private IAuthorizationPolicyProvider AuthorizationPolicyProvider { get; set; }
-
- [Inject] private IAuthorizationService AuthorizationService { get; set; }
-
- ///
- protected override void BuildRenderTree(RenderTreeBuilder builder)
- {
- // We're using the same sequence number for each of the content items here
- // so that we can update existing instances if they are the same shape
- if (currentAuthenticationState == null)
- {
- builder.AddContent(0, Authorizing);
- }
- else if (isAuthorized)
- {
- var authorized = Authorized ?? ChildContent;
- builder.AddContent(0, authorized?.Invoke(currentAuthenticationState));
- }
- else
- {
- builder.AddContent(0, NotAuthorized?.Invoke(currentAuthenticationState));
- }
- }
-
- ///
- protected override async Task OnParametersSetAsync()
- {
- // We allow 'ChildContent' for convenience in basic cases, and 'Authorized' for symmetry
- // with 'NotAuthorized' in other cases. Besides naming, they are equivalent. To avoid
- // confusion, explicitly prevent the case where both are supplied.
- if (ChildContent != null && Authorized != null)
- {
- throw new InvalidOperationException($"Do not specify both '{nameof(Authorized)}' and '{nameof(ChildContent)}'.");
- }
-
- if (AuthenticationState == null)
- {
- throw new InvalidOperationException($"Authorization requires a cascading parameter of type Task<{nameof(AuthenticationState)}>. Consider using {typeof(CascadingAuthenticationState).Name} to supply this.");
- }
-
- // First render in pending state
- // If the task has already completed, this render will be skipped
- currentAuthenticationState = null;
-
- // Then render in completed state
- // Importantly, we *don't* call StateHasChanged between the following async steps,
- // otherwise we'd display an incorrect UI state while waiting for IsAuthorizedAsync
- currentAuthenticationState = await AuthenticationState;
- isAuthorized = await IsAuthorizedAsync(currentAuthenticationState.User);
- }
-
- ///
- /// Gets the data required to apply authorization rules.
- ///
- protected abstract IAuthorizeData[] GetAuthorizeData();
-
- private async Task IsAuthorizedAsync(ClaimsPrincipal user)
- {
- var authorizeData = GetAuthorizeData();
- if (authorizeData == null)
- {
- // No authorization applies, so no need to consult the authorization service
- return true;
- }
-
- EnsureNoAuthenticationSchemeSpecified(authorizeData);
-
- var policy = await AuthorizationPolicy.CombineAsync(
- AuthorizationPolicyProvider, authorizeData);
- var result = await AuthorizationService.AuthorizeAsync(user, Resource, policy);
- return result.Succeeded;
- }
-
- private static void EnsureNoAuthenticationSchemeSpecified(IAuthorizeData[] authorizeData)
- {
- // It's not meaningful to specify a nonempty scheme, since by the time Components
- // authorization runs, we already have a specific ClaimsPrincipal (we're stateful).
- // To avoid any confusion, ensure the developer isn't trying to specify a scheme.
- for (var i = 0; i < authorizeData.Length; i++)
- {
- var entry = authorizeData[i];
- if (!string.IsNullOrEmpty(entry.AuthenticationSchemes))
- {
- throw new NotSupportedException($"The authorization data specifies an authentication scheme with value '{entry.AuthenticationSchemes}'. Authentication schemes cannot be specified for components.");
- }
- }
- }
- }
-}
diff --git a/src/Components/Authorization/src/CascadingAuthenticationState.razor b/src/Components/Authorization/src/CascadingAuthenticationState.razor
deleted file mode 100644
index 87506d2c61..0000000000
--- a/src/Components/Authorization/src/CascadingAuthenticationState.razor
+++ /dev/null
@@ -1,36 +0,0 @@
-@implements IDisposable
-@inject AuthenticationStateProvider AuthenticationStateProvider
-
-
-
-@code {
- private Task _currentAuthenticationStateTask;
-
- ///
- /// The content to which the authentication state should be provided.
- ///
- [Parameter]
- public RenderFragment ChildContent { get; set; }
-
- protected override void OnInitialized()
- {
- AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
-
- _currentAuthenticationStateTask = AuthenticationStateProvider
- .GetAuthenticationStateAsync();
- }
-
- private void OnAuthenticationStateChanged(Task newAuthStateTask)
- {
- _ = InvokeAsync(() =>
- {
- _currentAuthenticationStateTask = newAuthStateTask;
- StateHasChanged();
- });
- }
-
- void IDisposable.Dispose()
- {
- AuthenticationStateProvider.AuthenticationStateChanged -= OnAuthenticationStateChanged;
- }
-}
diff --git a/src/Components/Authorization/src/IHostEnvironmentAuthenticationStateProvider.cs b/src/Components/Authorization/src/IHostEnvironmentAuthenticationStateProvider.cs
deleted file mode 100644
index fc036572a2..0000000000
--- a/src/Components/Authorization/src/IHostEnvironmentAuthenticationStateProvider.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Threading.Tasks;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- ///
- /// An interface implemented by classes that can receive authentication
- /// state information from the host environment.
- ///
- public interface IHostEnvironmentAuthenticationStateProvider
- {
- ///
- /// Supplies updated authentication state data to the .
- ///
- /// A task that resolves with the updated .
- void SetAuthenticationState(Task authenticationStateTask);
- }
-}
diff --git a/src/Components/Authorization/src/Microsoft.AspNetCore.Components.Authorization.csproj b/src/Components/Authorization/src/Microsoft.AspNetCore.Components.Authorization.csproj
deleted file mode 100644
index 8f3142849a..0000000000
--- a/src/Components/Authorization/src/Microsoft.AspNetCore.Components.Authorization.csproj
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- netstandard2.0;$(DefaultNetCoreTargetFramework)
- $(DefaultNetCoreTargetFramework)
- true
- Authentication and authorization support for Blazor applications.
- true
- true
- 3.0
-
-
-
-
-
-
-
-
diff --git a/src/Components/Authorization/test/AuthorizeRouteViewTest.cs b/src/Components/Authorization/test/AuthorizeRouteViewTest.cs
deleted file mode 100644
index 5a3a5683c7..0000000000
--- a/src/Components/Authorization/test/AuthorizeRouteViewTest.cs
+++ /dev/null
@@ -1,356 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Claims;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Components.Rendering;
-using Microsoft.AspNetCore.Components.RenderTree;
-using Microsoft.AspNetCore.Components.Test.Helpers;
-using Microsoft.Extensions.DependencyInjection;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Components.Authorization
-{
- public class AuthorizeRouteViewTest
- {
- private readonly static IReadOnlyDictionary EmptyParametersDictionary = new Dictionary();
- private readonly TestAuthenticationStateProvider _authenticationStateProvider;
- private readonly TestRenderer _renderer;
- private readonly RouteView _authorizeRouteViewComponent;
- private readonly int _authorizeRouteViewComponentId;
- private readonly TestAuthorizationService _testAuthorizationService;
-
- public AuthorizeRouteViewTest()
- {
- _authenticationStateProvider = new TestAuthenticationStateProvider();
- _authenticationStateProvider.CurrentAuthStateTask = Task.FromResult(
- new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
-
- _testAuthorizationService = new TestAuthorizationService();
-
- var serviceCollection = new ServiceCollection();
- serviceCollection.AddSingleton(_authenticationStateProvider);
- serviceCollection.AddSingleton();
- serviceCollection.AddSingleton(_testAuthorizationService);
-
- _renderer = new TestRenderer(serviceCollection.BuildServiceProvider());
- _authorizeRouteViewComponent = new AuthorizeRouteView();
- _authorizeRouteViewComponentId = _renderer.AssignRootComponentId(_authorizeRouteViewComponent);
- }
-
- [Fact]
- public void WhenAuthorized_RendersPageInsideLayout()
- {
- // Arrange
- var routeData = new RouteData(typeof(TestPageRequiringAuthorization), new Dictionary
- {
- { nameof(TestPageRequiringAuthorization.Message), "Hello, world!" }
- });
- _testAuthorizationService.NextResult = AuthorizationResult.Success();
-
- // Act
- _renderer.RenderRootComponent(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData },
- { nameof(AuthorizeRouteView.DefaultLayout), typeof(TestLayout) },
- }));
-
- // Assert: renders layout
- var batch = _renderer.Batches.Single();
- var layoutDiff = batch.GetComponentDiffs().Single();
- Assert.Collection(layoutDiff.Edits,
- edit => AssertPrependText(batch, edit, "Layout starts here"),
- edit =>
- {
- Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type);
- AssertFrame.Component(batch.ReferenceFrames[edit.ReferenceFrameIndex]);
- },
- edit => AssertPrependText(batch, edit, "Layout ends here"));
-
- // Assert: renders page
- var pageDiff = batch.GetComponentDiffs().Single();
- Assert.Collection(pageDiff.Edits,
- edit => AssertPrependText(batch, edit, "Hello from the page with message: Hello, world!"));
- }
-
- [Fact]
- public void WhenNotAuthorized_RendersDefaultNotAuthorizedContentInsideLayout()
- {
- // Arrange
- var routeData = new RouteData(typeof(TestPageRequiringAuthorization), EmptyParametersDictionary);
- _testAuthorizationService.NextResult = AuthorizationResult.Failed();
-
- // Act
- _renderer.RenderRootComponent(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData },
- { nameof(AuthorizeRouteView.DefaultLayout), typeof(TestLayout) },
- }));
-
- // Assert: renders layout containing "not authorized" message
- var batch = _renderer.Batches.Single();
- var layoutDiff = batch.GetComponentDiffs().Single();
- Assert.Collection(layoutDiff.Edits,
- edit => AssertPrependText(batch, edit, "Layout starts here"),
- edit => AssertPrependText(batch, edit, "Not authorized"),
- edit => AssertPrependText(batch, edit, "Layout ends here"));
- }
-
- [Fact]
- public void WhenNotAuthorized_RendersCustomNotAuthorizedContentInsideLayout()
- {
- // Arrange
- var routeData = new RouteData(typeof(TestPageRequiringAuthorization), EmptyParametersDictionary);
- _testAuthorizationService.NextResult = AuthorizationResult.Failed();
- _authenticationStateProvider.CurrentAuthStateTask = Task.FromResult(new AuthenticationState(
- new ClaimsPrincipal(new TestIdentity { Name = "Bert" })));
-
- // Act
- RenderFragment customNotAuthorized =
- state => builder => builder.AddContent(0, $"Go away, {state.User.Identity.Name}");
- _renderer.RenderRootComponent(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData },
- { nameof(AuthorizeRouteView.DefaultLayout), typeof(TestLayout) },
- { nameof(AuthorizeRouteView.NotAuthorized), customNotAuthorized },
- }));
-
- // Assert: renders layout containing "not authorized" message
- var batch = _renderer.Batches.Single();
- var layoutDiff = batch.GetComponentDiffs().Single();
- Assert.Collection(layoutDiff.Edits,
- edit => AssertPrependText(batch, edit, "Layout starts here"),
- edit => AssertPrependText(batch, edit, "Go away, Bert"),
- edit => AssertPrependText(batch, edit, "Layout ends here"));
- }
-
- [Fact]
- public async Task WhenAuthorizing_RendersDefaultAuthorizingContentInsideLayout()
- {
- // Arrange
- var routeData = new RouteData(typeof(TestPageRequiringAuthorization), EmptyParametersDictionary);
- var authStateTcs = new TaskCompletionSource();
- _authenticationStateProvider.CurrentAuthStateTask = authStateTcs.Task;
- RenderFragment customNotAuthorized =
- state => builder => builder.AddContent(0, $"Go away, {state.User.Identity.Name}");
-
- // Act
- var firstRenderTask = _renderer.RenderRootComponentAsync(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData },
- { nameof(AuthorizeRouteView.DefaultLayout), typeof(TestLayout) },
- { nameof(AuthorizeRouteView.NotAuthorized), customNotAuthorized },
- }));
-
- // Assert: renders layout containing "authorizing" message
- Assert.False(firstRenderTask.IsCompleted);
- var batch = _renderer.Batches.Single();
- var layoutDiff = batch.GetComponentDiffs().Single();
- Assert.Collection(layoutDiff.Edits,
- edit => AssertPrependText(batch, edit, "Layout starts here"),
- edit => AssertPrependText(batch, edit, "Authorizing..."),
- edit => AssertPrependText(batch, edit, "Layout ends here"));
-
- // Act 2: updates when authorization completes
- authStateTcs.SetResult(new AuthenticationState(
- new ClaimsPrincipal(new TestIdentity { Name = "Bert" })));
- await firstRenderTask;
-
- // Assert 2: Only the layout is updated
- batch = _renderer.Batches.Skip(1).Single();
- var nonEmptyDiff = batch.DiffsInOrder.Where(d => d.Edits.Any()).Single();
- Assert.Equal(layoutDiff.ComponentId, nonEmptyDiff.ComponentId);
- Assert.Collection(nonEmptyDiff.Edits, edit =>
- {
- Assert.Equal(RenderTreeEditType.UpdateText, edit.Type);
- Assert.Equal(1, edit.SiblingIndex);
- AssertFrame.Text(batch.ReferenceFrames[edit.ReferenceFrameIndex], "Go away, Bert");
- });
- }
-
- [Fact]
- public void WhenAuthorizing_RendersCustomAuthorizingContentInsideLayout()
- {
- // Arrange
- var routeData = new RouteData(typeof(TestPageRequiringAuthorization), EmptyParametersDictionary);
- var authStateTcs = new TaskCompletionSource();
- _authenticationStateProvider.CurrentAuthStateTask = authStateTcs.Task;
- RenderFragment customAuthorizing =
- builder => builder.AddContent(0, "Hold on, we're checking your papers.");
-
- // Act
- var firstRenderTask = _renderer.RenderRootComponentAsync(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData },
- { nameof(AuthorizeRouteView.DefaultLayout), typeof(TestLayout) },
- { nameof(AuthorizeRouteView.Authorizing), customAuthorizing },
- }));
-
- // Assert: renders layout containing "authorizing" message
- Assert.False(firstRenderTask.IsCompleted);
- var batch = _renderer.Batches.Single();
- var layoutDiff = batch.GetComponentDiffs().Single();
- Assert.Collection(layoutDiff.Edits,
- edit => AssertPrependText(batch, edit, "Layout starts here"),
- edit => AssertPrependText(batch, edit, "Hold on, we're checking your papers."),
- edit => AssertPrependText(batch, edit, "Layout ends here"));
- }
-
- [Fact]
- public void WithoutCascadedAuthenticationState_WrapsOutputInCascadingAuthenticationState()
- {
- // Arrange/Act
- var routeData = new RouteData(typeof(TestPageWithNoAuthorization), EmptyParametersDictionary);
- _renderer.RenderRootComponent(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData }
- }));
-
- // Assert
- var batch = _renderer.Batches.Single();
- var componentInstances = batch.ReferenceFrames
- .Where(f => f.FrameType == RenderTreeFrameType.Component)
- .Select(f => f.Component);
-
- Assert.Collection(componentInstances,
- // This is the hierarchy inside the AuthorizeRouteView, which contains its
- // own CascadingAuthenticationState
- component => Assert.IsType(component),
- component => Assert.IsType>>(component),
- component => Assert.IsAssignableFrom(component),
- component => Assert.IsType(component),
- component => Assert.IsType(component));
- }
-
- [Fact]
- public void WithCascadedAuthenticationState_DoesNotWrapOutputInCascadingAuthenticationState()
- {
- // Arrange
- var routeData = new RouteData(typeof(TestPageWithNoAuthorization), EmptyParametersDictionary);
- var rootComponent = new AuthorizeRouteViewWithExistingCascadedAuthenticationState(
- _authenticationStateProvider.CurrentAuthStateTask,
- routeData);
- var rootComponentId = _renderer.AssignRootComponentId(rootComponent);
-
- // Act
- _renderer.RenderRootComponent(rootComponentId);
-
- // Assert
- var batch = _renderer.Batches.Single();
- var componentInstances = batch.ReferenceFrames
- .Where(f => f.FrameType == RenderTreeFrameType.Component)
- .Select(f => f.Component);
-
- Assert.Collection(componentInstances,
- // This is the externally-supplied cascading value
- component => Assert.IsType>>(component),
- component => Assert.IsType(component),
-
- // This is the hierarchy inside the AuthorizeRouteView. It doesn't contain a
- // further CascadingAuthenticationState
- component => Assert.IsAssignableFrom(component),
- component => Assert.IsType(component),
- component => Assert.IsType(component));
- }
-
- [Fact]
- public void UpdatesOutputWhenRouteDataChanges()
- {
- // Arrange/Act 1: Start on some route
- // Not asserting about the initial output, as that is covered by other tests
- var routeData = new RouteData(typeof(TestPageWithNoAuthorization), EmptyParametersDictionary);
- _renderer.RenderRootComponent(_authorizeRouteViewComponentId, ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData },
- { nameof(AuthorizeRouteView.DefaultLayout), typeof(TestLayout) },
- }));
-
- // Act 2: Move to another route
- var routeData2 = new RouteData(typeof(TestPageRequiringAuthorization), EmptyParametersDictionary);
- var render2Task = _renderer.Dispatcher.InvokeAsync(() => _authorizeRouteViewComponent.SetParametersAsync(ParameterView.FromDictionary(new Dictionary
- {
- { nameof(AuthorizeRouteView.RouteData), routeData2 },
- })));
-
- // Assert: we retain the layout instance, and mutate its contents
- Assert.True(render2Task.IsCompletedSuccessfully);
- Assert.Equal(2, _renderer.Batches.Count);
- var batch2 = _renderer.Batches[1];
- var diff = batch2.DiffsInOrder.Where(d => d.Edits.Any()).Single();
- Assert.Collection(diff.Edits,
- edit =>
- {
- // Inside the layout, we add the new content
- Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type);
- Assert.Equal(1, edit.SiblingIndex);
- AssertFrame.Text(batch2.ReferenceFrames[edit.ReferenceFrameIndex], "Not authorized");
- },
- edit =>
- {
- // ... and remove the old content
- Assert.Equal(RenderTreeEditType.RemoveFrame, edit.Type);
- Assert.Equal(2, edit.SiblingIndex);
- });
- }
-
- private static void AssertPrependText(CapturedBatch batch, RenderTreeEdit edit, string text)
- {
- Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type);
- ref var referenceFrame = ref batch.ReferenceFrames[edit.ReferenceFrameIndex];
- AssertFrame.Text(referenceFrame, text);
- }
-
- class TestPageWithNoAuthorization : ComponentBase { }
-
- [Authorize]
- class TestPageRequiringAuthorization : ComponentBase
- {
- [Parameter] public string Message { get; set; }
-
- protected override void BuildRenderTree(RenderTreeBuilder builder)
- {
- builder.AddContent(0, $"Hello from the page with message: {Message}");
- }
- }
-
- class TestLayout : LayoutComponentBase
- {
- protected override void BuildRenderTree(RenderTreeBuilder builder)
- {
- builder.AddContent(0, "Layout starts here");
- builder.AddContent(1, Body);
- builder.AddContent(2, "Layout ends here");
- }
- }
-
- class AuthorizeRouteViewWithExistingCascadedAuthenticationState : AutoRenderComponent
- {
- private readonly Task _authenticationState;
- private readonly RouteData _routeData;
-
- public AuthorizeRouteViewWithExistingCascadedAuthenticationState(
- Task authenticationState,
- RouteData routeData)
- {
- _authenticationState = authenticationState;
- _routeData = routeData;
- }
-
- protected override void BuildRenderTree(RenderTreeBuilder builder)
- {
- builder.OpenComponent>>(0);
- builder.AddAttribute(1, nameof(CascadingValue