Merge remote-tracking branch 'origin/release/2.2'
This commit is contained in:
commit
64c3ee98b0
|
|
@ -1,4 +1,5 @@
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.27130.2036
|
VisualStudioVersion = 15.0.27130.2036
|
||||||
MinimumVisualStudioVersion = 15.0.26730.03
|
MinimumVisualStudioVersion = 15.0.26730.03
|
||||||
|
|
@ -114,7 +115,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.Analyzers.Test", "test\
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Views.TestCommon", "test\Microsoft.AspNetCore.Mvc.Views.TestCommon\Microsoft.AspNetCore.Mvc.Views.TestCommon.csproj", "{0772E545-A674-4165-9469-E3D79D88A4A8}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Views.TestCommon", "test\Microsoft.AspNetCore.Mvc.Views.TestCommon\Microsoft.AspNetCore.Mvc.Views.TestCommon.csproj", "{0772E545-A674-4165-9469-E3D79D88A4A8}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Mvc.Testing", "src\Microsoft.AspNetCore.Mvc.Testing\Microsoft.AspNetCore.Mvc.Testing.csproj", "{92D959F2-66B8-490A-BA33-DA4421EBC948}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Testing", "src\Microsoft.AspNetCore.Mvc.Testing\Microsoft.AspNetCore.Mvc.Testing.csproj", "{92D959F2-66B8-490A-BA33-DA4421EBC948}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Api.Analyzers", "src\Microsoft.AspNetCore.Mvc.Api.Analyzers\Microsoft.AspNetCore.Mvc.Api.Analyzers.csproj", "{1B398182-9EAE-400B-A2BD-EFFAC0168A36}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.Api.Analyzers.Test", "test\Mvc.Api.Analyzers.Test\Mvc.Api.Analyzers.Test.csproj", "{71C626FC-6408-494B-A127-38CB64F71324}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
@ -574,6 +579,30 @@ Global
|
||||||
{92D959F2-66B8-490A-BA33-DA4421EBC948}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
{92D959F2-66B8-490A-BA33-DA4421EBC948}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
{92D959F2-66B8-490A-BA33-DA4421EBC948}.Release|x86.ActiveCfg = Release|Any CPU
|
{92D959F2-66B8-490A-BA33-DA4421EBC948}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{92D959F2-66B8-490A-BA33-DA4421EBC948}.Release|x86.Build.0 = Release|Any CPU
|
{92D959F2-66B8-490A-BA33-DA4421EBC948}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -618,6 +647,8 @@ Global
|
||||||
{829D9A67-2D07-4CE6-86C0-59F2549B0CFA} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
{829D9A67-2D07-4CE6-86C0-59F2549B0CFA} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
{0772E545-A674-4165-9469-E3D79D88A4A8} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
{0772E545-A674-4165-9469-E3D79D88A4A8} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
{92D959F2-66B8-490A-BA33-DA4421EBC948} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
{92D959F2-66B8-490A-BA33-DA4421EBC948} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||||
|
{1B398182-9EAE-400B-A2BD-EFFAC0168A36} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||||
|
{71C626FC-6408-494B-A127-38CB64F71324} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {D003597F-372F-4068-A2F0-353BE3C3B39A}
|
SolutionGuid = {D003597F-372F-4068-A2F0-353BE3C3B39A}
|
||||||
|
|
|
||||||
15
Mvc.sln
15
Mvc.sln
|
|
@ -176,6 +176,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicApi", "benchmarkapps\B
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicViews", "benchmarkapps\BasicViews\BasicViews.csproj", "{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicViews", "benchmarkapps\BasicViews\BasicViews.csproj", "{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.Api.Analyzers.Test", "test\Mvc.Api.Analyzers.Test\Mvc.Api.Analyzers.Test.csproj", "{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -924,6 +926,18 @@ Global
|
||||||
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}.Release|x86.ActiveCfg = Release|Any CPU
|
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}.Release|x86.Build.0 = Release|Any CPU
|
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -995,6 +1009,7 @@ Global
|
||||||
{51E3E785-A9D1-4196-BAFE-A17FF4304B89} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
{51E3E785-A9D1-4196-BAFE-A17FF4304B89} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
{910F023A-88E3-4CB4-8793-AC4005C7B421} = {2859F266-673A-45A2-9E3C-7B39C6DDD38E}
|
{910F023A-88E3-4CB4-8793-AC4005C7B421} = {2859F266-673A-45A2-9E3C-7B39C6DDD38E}
|
||||||
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB} = {2859F266-673A-45A2-9E3C-7B39C6DDD38E}
|
{E89EB74D-C1CE-456F-B42D-CCF1575E0CFB} = {2859F266-673A-45A2-9E3C-7B39C6DDD38E}
|
||||||
|
{DD7B9F20-354C-4D9E-8C8A-8AE6E7595A87} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {63D344F6-F86D-40E6-85B9-0AABBE338C4A}
|
SolutionGuid = {63D344F6-F86D-40E6-85B9-0AABBE338C4A}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.CodeAnalysis;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.CodeAnalysis
|
||||||
{
|
{
|
||||||
internal static class CodeAnalysisExtensions
|
internal static class CodeAnalysisExtensions
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -42,43 +42,5 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
"Usage",
|
"Usage",
|
||||||
DiagnosticSeverity.Warning,
|
DiagnosticSeverity.Warning,
|
||||||
isEnabledByDefault: true);
|
isEnabledByDefault: true);
|
||||||
|
|
||||||
public static readonly DiagnosticDescriptor MVC1004_ActionReturnsUndocumentedStatusCode =
|
|
||||||
new DiagnosticDescriptor(
|
|
||||||
"MVC1004",
|
|
||||||
"Action returns undeclared status code.",
|
|
||||||
"Action method returns undeclared status code '{0}'.",
|
|
||||||
"Usage",
|
|
||||||
DiagnosticSeverity.Warning,
|
|
||||||
isEnabledByDefault: true);
|
|
||||||
|
|
||||||
public static readonly DiagnosticDescriptor MVC1005_ActionReturnsUndocumentedSuccessResult =
|
|
||||||
new DiagnosticDescriptor(
|
|
||||||
"MVC1005",
|
|
||||||
"Action returns undeclared success result.",
|
|
||||||
"Action method returns a success result without a corresponding ProducesResponseType.",
|
|
||||||
"Usage",
|
|
||||||
DiagnosticSeverity.Warning,
|
|
||||||
isEnabledByDefault: true);
|
|
||||||
|
|
||||||
public static readonly DiagnosticDescriptor MVC1006_ActionDoesNotReturnDocumentedStatusCode =
|
|
||||||
new DiagnosticDescriptor(
|
|
||||||
"MVC1006",
|
|
||||||
"Action documents status code that is not returned.",
|
|
||||||
"Action method documents status code '{0}' without a corresponding return type.",
|
|
||||||
"Usage",
|
|
||||||
DiagnosticSeverity.Info,
|
|
||||||
isEnabledByDefault: false);
|
|
||||||
|
|
||||||
public static readonly DiagnosticDescriptor MVC1007_ApiActionsDoNotRequireExplicitModelValidationCheck =
|
|
||||||
new DiagnosticDescriptor(
|
|
||||||
"MVC1007",
|
|
||||||
"Action methods on ApiController instances do not require explicit model validation check.",
|
|
||||||
"Action methods on ApiController instances do not require explicit model validation check.",
|
|
||||||
"Usage",
|
|
||||||
DiagnosticSeverity.Info,
|
|
||||||
isEnabledByDefault: true,
|
|
||||||
customTags: new[] { WellKnownDiagnosticTags.Unnecessary });
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal readonly struct ActualApiResponseMetadata
|
internal readonly struct ActualApiResponseMetadata
|
||||||
{
|
{
|
||||||
|
|
@ -13,7 +13,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.Editing;
|
using Microsoft.CodeAnalysis.Editing;
|
||||||
using Microsoft.CodeAnalysis.Simplification;
|
using Microsoft.CodeAnalysis.Simplification;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal sealed class AddResponseTypeAttributeCodeFixAction : CodeAction
|
internal sealed class AddResponseTypeAttributeCodeFixAction : CodeAction
|
||||||
{
|
{
|
||||||
|
|
@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
private static AttributeSyntax CreateProducesResponseTypeAttribute(int statusCode)
|
private static AttributeSyntax CreateProducesResponseTypeAttribute(int statusCode)
|
||||||
{
|
{
|
||||||
return SyntaxFactory.Attribute(
|
return SyntaxFactory.Attribute(
|
||||||
SyntaxFactory.ParseName(SymbolNames.ProducesResponseTypeAttribute)
|
SyntaxFactory.ParseName(ApiSymbolNames.ProducesResponseTypeAttribute)
|
||||||
.WithAdditionalAnnotations(Simplifier.Annotation),
|
.WithAdditionalAnnotations(Simplifier.Annotation),
|
||||||
SyntaxFactory.AttributeArgumentList().AddArguments(
|
SyntaxFactory.AttributeArgumentList().AddArguments(
|
||||||
SyntaxFactory.AttributeArgument(
|
SyntaxFactory.AttributeArgument(
|
||||||
|
|
@ -118,7 +118,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
private static AttributeSyntax CreateProducesDefaultResponseTypeAttribute()
|
private static AttributeSyntax CreateProducesDefaultResponseTypeAttribute()
|
||||||
{
|
{
|
||||||
return SyntaxFactory.Attribute(
|
return SyntaxFactory.Attribute(
|
||||||
SyntaxFactory.ParseName(SymbolNames.ProducesDefaultResponseTypeAttribute)
|
SyntaxFactory.ParseName(ApiSymbolNames.ProducesDefaultResponseTypeAttribute)
|
||||||
.WithAdditionalAnnotations(Simplifier.Annotation));
|
.WithAdditionalAnnotations(Simplifier.Annotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7,15 +7,15 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CodeFixes;
|
using Microsoft.CodeAnalysis.CodeFixes;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ExportCodeFixProvider(LanguageNames.CSharp)]
|
[ExportCodeFixProvider(LanguageNames.CSharp)]
|
||||||
[Shared]
|
[Shared]
|
||||||
public class AddResponseTypeAttributeCodeFixProvider : CodeFixProvider
|
public class AddResponseTypeAttributeCodeFixProvider : CodeFixProvider
|
||||||
{
|
{
|
||||||
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
|
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(
|
||||||
DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode.Id,
|
ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode.Id,
|
||||||
DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult.Id);
|
ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult.Id);
|
||||||
|
|
||||||
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
|
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
|
||||||
{
|
{
|
||||||
|
|
@ -25,8 +25,8 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
}
|
}
|
||||||
|
|
||||||
var diagnostic = context.Diagnostics[0];
|
var diagnostic = context.Diagnostics[0];
|
||||||
if ((diagnostic.Descriptor.Id != DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode.Id) &&
|
if ((diagnostic.Descriptor.Id != ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode.Id) &&
|
||||||
(diagnostic.Descriptor.Id != DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult.Id))
|
(diagnostic.Descriptor.Id != ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult.Id))
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
@ -8,13 +8,13 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.Diagnostics;
|
using Microsoft.CodeAnalysis.Diagnostics;
|
||||||
using Microsoft.CodeAnalysis.Operations;
|
using Microsoft.CodeAnalysis.Operations;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||||
public class ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer : DiagnosticAnalyzer
|
public class ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer : DiagnosticAnalyzer
|
||||||
{
|
{
|
||||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
|
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
|
||||||
DiagnosticDescriptors.MVC1007_ApiActionsDoNotRequireExplicitModelValidationCheck);
|
ApiDiagnosticDescriptors.API1003_ApiActionsDoNotRequireExplicitModelValidationCheck);
|
||||||
|
|
||||||
public override void Initialize(AnalysisContext context)
|
public override void Initialize(AnalysisContext context)
|
||||||
{
|
{
|
||||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
|
|
||||||
operationAnalysisContext.ReportDiagnostic(
|
operationAnalysisContext.ReportDiagnostic(
|
||||||
Diagnostic.Create(
|
Diagnostic.Create(
|
||||||
DiagnosticDescriptors.MVC1007_ApiActionsDoNotRequireExplicitModelValidationCheck,
|
ApiDiagnosticDescriptors.API1003_ApiActionsDoNotRequireExplicitModelValidationCheck,
|
||||||
ifStatement.GetLocation(),
|
ifStatement.GetLocation(),
|
||||||
additionalLocations: additionalLocations));
|
additionalLocations: additionalLocations));
|
||||||
}, OperationKind.Conditional);
|
}, OperationKind.Conditional);
|
||||||
|
|
@ -11,14 +11,14 @@ using Microsoft.CodeAnalysis.CodeFixes;
|
||||||
using Microsoft.CodeAnalysis.Editing;
|
using Microsoft.CodeAnalysis.Editing;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ExportCodeFixProvider(LanguageNames.CSharp)]
|
[ExportCodeFixProvider(LanguageNames.CSharp)]
|
||||||
[Shared]
|
[Shared]
|
||||||
public class ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProvider : CodeFixProvider
|
public class ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProvider : CodeFixProvider
|
||||||
{
|
{
|
||||||
public sealed override ImmutableArray<string> FixableDiagnosticIds =>
|
public sealed override ImmutableArray<string> FixableDiagnosticIds =>
|
||||||
ImmutableArray.Create(DiagnosticDescriptors.MVC1007_ApiActionsDoNotRequireExplicitModelValidationCheck.Id);
|
ImmutableArray.Create(ApiDiagnosticDescriptors.API1003_ApiActionsDoNotRequireExplicitModelValidationCheck.Id);
|
||||||
|
|
||||||
public sealed override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;
|
public sealed override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer;
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
}
|
}
|
||||||
|
|
||||||
var diagnostic = context.Diagnostics[0];
|
var diagnostic = context.Diagnostics[0];
|
||||||
if (diagnostic.Id != DiagnosticDescriptors.MVC1007_ApiActionsDoNotRequireExplicitModelValidationCheck.Id)
|
if (diagnostic.Id != ApiDiagnosticDescriptors.API1003_ApiActionsDoNotRequireExplicitModelValidationCheck.Id)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
using Microsoft.CodeAnalysis;
|
// 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.Mvc.Analyzers
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal static class ApiControllerFacts
|
internal static class ApiControllerFacts
|
||||||
{
|
{
|
||||||
|
|
@ -4,35 +4,31 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal readonly struct ApiControllerSymbolCache
|
internal readonly struct ApiControllerSymbolCache
|
||||||
{
|
{
|
||||||
public ApiControllerSymbolCache(Compilation compilation)
|
public ApiControllerSymbolCache(Compilation compilation)
|
||||||
{
|
{
|
||||||
ActionResultOfT = compilation.GetTypeByMetadataName(SymbolNames.ActionResultOfT);
|
ApiConventionMethodAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ApiConventionMethodAttribute);
|
||||||
ApiConventionMethodAttribute = compilation.GetTypeByMetadataName(SymbolNames.ApiConventionMethodAttribute);
|
ApiConventionNameMatchAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ApiConventionNameMatchAttribute);
|
||||||
ApiConventionNameMatchAttribute = compilation.GetTypeByMetadataName(SymbolNames.ApiConventionNameMatchAttribute);
|
ApiConventionTypeAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ApiConventionTypeAttribute);
|
||||||
ApiConventionTypeAttribute = compilation.GetTypeByMetadataName(SymbolNames.ApiConventionTypeAttribute);
|
ApiConventionTypeMatchAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ApiConventionTypeMatchAttribute);
|
||||||
ApiConventionTypeMatchAttribute = compilation.GetTypeByMetadataName(SymbolNames.ApiConventionTypeMatchAttribute);
|
ControllerAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ControllerAttribute);
|
||||||
ControllerAttribute = compilation.GetTypeByMetadataName(SymbolNames.ControllerAttribute);
|
DefaultStatusCodeAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.DefaultStatusCodeAttribute);
|
||||||
DefaultStatusCodeAttribute = compilation.GetTypeByMetadataName(SymbolNames.DefaultStatusCodeAttribute);
|
IActionResult = compilation.GetTypeByMetadataName(ApiSymbolNames.IActionResult);
|
||||||
IActionResult = compilation.GetTypeByMetadataName(SymbolNames.IActionResult);
|
IApiBehaviorMetadata = compilation.GetTypeByMetadataName(ApiSymbolNames.IApiBehaviorMetadata);
|
||||||
IApiBehaviorMetadata = compilation.GetTypeByMetadataName(SymbolNames.IApiBehaviorMetadata);
|
ModelStateDictionary = compilation.GetTypeByMetadataName(ApiSymbolNames.ModelStateDictionary);
|
||||||
IConvertToActionResult = compilation.GetTypeByMetadataName(SymbolNames.IConvertToActionResult);
|
NonActionAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.NonActionAttribute);
|
||||||
ModelStateDictionary = compilation.GetTypeByMetadataName(SymbolNames.ModelStateDictionary);
|
NonControllerAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.NonControllerAttribute);
|
||||||
NonActionAttribute = compilation.GetTypeByMetadataName(SymbolNames.NonActionAttribute);
|
ProducesDefaultResponseTypeAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ProducesDefaultResponseTypeAttribute);
|
||||||
NonControllerAttribute = compilation.GetTypeByMetadataName(SymbolNames.NonControllerAttribute);
|
ProducesResponseTypeAttribute = compilation.GetTypeByMetadataName(ApiSymbolNames.ProducesResponseTypeAttribute);
|
||||||
ProducesDefaultResponseTypeAttribute = compilation.GetTypeByMetadataName(SymbolNames.ProducesDefaultResponseTypeAttribute);
|
|
||||||
ProducesResponseTypeAttribute = compilation.GetTypeByMetadataName(SymbolNames.ProducesResponseTypeAttribute);
|
|
||||||
|
|
||||||
var disposable = compilation.GetSpecialType(SpecialType.System_IDisposable);
|
var disposable = compilation.GetSpecialType(SpecialType.System_IDisposable);
|
||||||
var members = disposable.GetMembers(nameof(IDisposable.Dispose));
|
var members = disposable.GetMembers(nameof(IDisposable.Dispose));
|
||||||
IDisposableDispose = members.Length == 1 ? (IMethodSymbol)members[0] : null;
|
IDisposableDispose = members.Length == 1 ? (IMethodSymbol)members[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public INamedTypeSymbol ActionResultOfT { get; }
|
|
||||||
|
|
||||||
public INamedTypeSymbol ApiConventionMethodAttribute { get; }
|
public INamedTypeSymbol ApiConventionMethodAttribute { get; }
|
||||||
|
|
||||||
public INamedTypeSymbol ApiConventionNameMatchAttribute { get; }
|
public INamedTypeSymbol ApiConventionNameMatchAttribute { get; }
|
||||||
|
|
@ -49,8 +45,6 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
|
|
||||||
public INamedTypeSymbol IApiBehaviorMetadata { get; }
|
public INamedTypeSymbol IApiBehaviorMetadata { get; }
|
||||||
|
|
||||||
public INamedTypeSymbol IConvertToActionResult { get; }
|
|
||||||
|
|
||||||
public IMethodSymbol IDisposableDispose { get; }
|
public IMethodSymbol IDisposableDispose { get; }
|
||||||
|
|
||||||
public ITypeSymbol ModelStateDictionary { get; }
|
public ITypeSymbol ModelStateDictionary { get; }
|
||||||
|
|
@ -8,15 +8,15 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.CodeAnalysis.Diagnostics;
|
using Microsoft.CodeAnalysis.Diagnostics;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||||
public class ApiConventionAnalyzer : DiagnosticAnalyzer
|
public class ApiConventionAnalyzer : DiagnosticAnalyzer
|
||||||
{
|
{
|
||||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
|
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
|
||||||
DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode,
|
ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode,
|
||||||
DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult,
|
ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult,
|
||||||
DiagnosticDescriptors.MVC1006_ActionDoesNotReturnDocumentedStatusCode);
|
ApiDiagnosticDescriptors.API1002_ActionDoesNotReturnDocumentedStatusCode);
|
||||||
|
|
||||||
public override void Initialize(AnalysisContext context)
|
public override void Initialize(AnalysisContext context)
|
||||||
{
|
{
|
||||||
|
|
@ -64,13 +64,13 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
if (actualMetadata.IsDefaultResponse)
|
if (actualMetadata.IsDefaultResponse)
|
||||||
{
|
{
|
||||||
syntaxNodeContext.ReportDiagnostic(Diagnostic.Create(
|
syntaxNodeContext.ReportDiagnostic(Diagnostic.Create(
|
||||||
DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult,
|
ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult,
|
||||||
location));
|
location));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
syntaxNodeContext.ReportDiagnostic(Diagnostic.Create(
|
syntaxNodeContext.ReportDiagnostic(Diagnostic.Create(
|
||||||
DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode,
|
ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode,
|
||||||
location,
|
location,
|
||||||
actualMetadata.StatusCode));
|
actualMetadata.StatusCode));
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
if (!Contains(actualResponseMetadata, declaredMetadata))
|
if (!Contains(actualResponseMetadata, declaredMetadata))
|
||||||
{
|
{
|
||||||
syntaxNodeContext.ReportDiagnostic(Diagnostic.Create(
|
syntaxNodeContext.ReportDiagnostic(Diagnostic.Create(
|
||||||
DiagnosticDescriptors.MVC1006_ActionDoesNotReturnDocumentedStatusCode,
|
ApiDiagnosticDescriptors.API1002_ActionDoesNotReturnDocumentedStatusCode,
|
||||||
methodSyntax.Identifier.GetLocation(),
|
methodSyntax.Identifier.GetLocation(),
|
||||||
declaredMetadata.StatusCode));
|
declaredMetadata.StatusCode));
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
// 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.Mvc.Api.Analyzers
|
||||||
|
{
|
||||||
|
internal static class ApiDiagnosticDescriptors
|
||||||
|
{
|
||||||
|
public static readonly DiagnosticDescriptor API1000_ActionReturnsUndocumentedStatusCode =
|
||||||
|
new DiagnosticDescriptor(
|
||||||
|
"API1000",
|
||||||
|
"Action returns undeclared status code.",
|
||||||
|
"Action method returns undeclared status code '{0}'.",
|
||||||
|
"Usage",
|
||||||
|
DiagnosticSeverity.Warning,
|
||||||
|
isEnabledByDefault: true);
|
||||||
|
|
||||||
|
public static readonly DiagnosticDescriptor API1001_ActionReturnsUndocumentedSuccessResult =
|
||||||
|
new DiagnosticDescriptor(
|
||||||
|
"API1001",
|
||||||
|
"Action returns undeclared success result.",
|
||||||
|
"Action method returns a success result without a corresponding ProducesResponseType.",
|
||||||
|
"Usage",
|
||||||
|
DiagnosticSeverity.Warning,
|
||||||
|
isEnabledByDefault: true);
|
||||||
|
|
||||||
|
public static readonly DiagnosticDescriptor API1002_ActionDoesNotReturnDocumentedStatusCode =
|
||||||
|
new DiagnosticDescriptor(
|
||||||
|
"API1002",
|
||||||
|
"Action documents status code that is not returned.",
|
||||||
|
"Action method documents status code '{0}' without a corresponding return type.",
|
||||||
|
"Usage",
|
||||||
|
DiagnosticSeverity.Info,
|
||||||
|
isEnabledByDefault: false);
|
||||||
|
|
||||||
|
public static readonly DiagnosticDescriptor API1003_ApiActionsDoNotRequireExplicitModelValidationCheck =
|
||||||
|
new DiagnosticDescriptor(
|
||||||
|
"API1003",
|
||||||
|
"Action methods on ApiController instances do not require explicit model validation check.",
|
||||||
|
"Action methods on ApiController instances do not require explicit model validation check.",
|
||||||
|
"Usage",
|
||||||
|
DiagnosticSeverity.Info,
|
||||||
|
isEnabledByDefault: true,
|
||||||
|
customTags: new[] { WellKnownDiagnosticTags.Unnecessary });
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// 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.Mvc.Api.Analyzers
|
||||||
|
{
|
||||||
|
internal static class ApiSymbolNames
|
||||||
|
{
|
||||||
|
public const string AllowAnonymousAttribute = "Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute";
|
||||||
|
|
||||||
|
public const string ApiConventionMethodAttribute = "Microsoft.AspNetCore.Mvc.ApiConventionMethodAttribute";
|
||||||
|
|
||||||
|
public const string ApiConventionNameMatchAttribute = "Microsoft.AspNetCore.Mvc.ApiExplorer.ApiConventionNameMatchAttribute";
|
||||||
|
|
||||||
|
public const string ApiConventionTypeMatchAttribute = "Microsoft.AspNetCore.Mvc.ApiExplorer.ApiConventionTypeMatchAttribute";
|
||||||
|
|
||||||
|
public const string ApiConventionTypeAttribute = "Microsoft.AspNetCore.Mvc.ApiConventionTypeAttribute";
|
||||||
|
|
||||||
|
public const string ControllerAttribute = "Microsoft.AspNetCore.Mvc.ControllerAttribute";
|
||||||
|
|
||||||
|
public const string DefaultStatusCodeAttribute = "Microsoft.AspNetCore.Mvc.Infrastructure.DefaultStatusCodeAttribute";
|
||||||
|
|
||||||
|
public const string IApiBehaviorMetadata = "Microsoft.AspNetCore.Mvc.Internal.IApiBehaviorMetadata";
|
||||||
|
|
||||||
|
public const string IActionResult = "Microsoft.AspNetCore.Mvc.IActionResult";
|
||||||
|
|
||||||
|
public const string ModelStateDictionary = "Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary";
|
||||||
|
|
||||||
|
public const string NonActionAttribute = "Microsoft.AspNetCore.Mvc.NonActionAttribute";
|
||||||
|
|
||||||
|
public const string NonControllerAttribute = "Microsoft.AspNetCore.Mvc.NonControllerAttribute";
|
||||||
|
|
||||||
|
public const string ProducesDefaultResponseTypeAttribute = "Microsoft.AspNetCore.Mvc.ProducesDefaultResponseTypeAttribute";
|
||||||
|
|
||||||
|
public const string ProducesResponseTypeAttribute = "Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal readonly struct DeclaredApiResponseMetadata
|
internal readonly struct DeclaredApiResponseMetadata
|
||||||
{
|
{
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Description>CSharp Analyzers for ASP.NET Core MVC.</Description>
|
||||||
|
<PackageTags>aspnetcore;aspnetcoremvc</PackageTags>
|
||||||
|
|
||||||
|
<TargetFramework>netstandard1.3</TargetFramework>
|
||||||
|
<IncludeBuildOutput>false</IncludeBuildOutput>
|
||||||
|
<EnableApiCheck>false</EnableApiCheck>
|
||||||
|
<GenerateDocumentationFile>false</GenerateDocumentationFile>
|
||||||
|
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\Microsoft.AspNetCore.Mvc.Analyzers\CodeAnalysisExtensions.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" PrivateAssets="All" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<SignedPackageFile Include="analyzers/dotnet/cs/$(TargetFileName)" Certificate="$(AssemblySigningCertName)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PopulateNuspec" BeforeTargets="GenerateNuspec" DependsOnTargets="Build">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- Make sure we create a symbols.nupkg. -->
|
||||||
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
|
|
||||||
|
<NuspecProperties>
|
||||||
|
id=$(PackageId);
|
||||||
|
version=$(PackageVersion);
|
||||||
|
authors=$(Authors);
|
||||||
|
description=$(Description);
|
||||||
|
tags=$(PackageTags.Replace(';', ' '));
|
||||||
|
licenseUrl=$(PackageLicenseUrl);
|
||||||
|
projectUrl=$(PackageProjectUrl);
|
||||||
|
iconUrl=$(PackageIconUrl);
|
||||||
|
repositoryUrl=$(RepositoryUrl);
|
||||||
|
repositoryCommit=$(RepositoryCommit);
|
||||||
|
copyright=$(Copyright);
|
||||||
|
|
||||||
|
OutputBinary=$(OutputPath)$(AssemblyName).dll;
|
||||||
|
OutputSymbol=$(OutputPath)$(AssemblyName).pdb;
|
||||||
|
</NuspecProperties>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||||
|
<metadata>
|
||||||
|
<id>$id$</id>
|
||||||
|
<version>$version$</version>
|
||||||
|
<authors>$authors$</authors>
|
||||||
|
<requireLicenseAcceptance>true</requireLicenseAcceptance>
|
||||||
|
<licenseUrl>$licenseUrl$</licenseUrl>
|
||||||
|
<projectUrl>$projectUrl$</projectUrl>
|
||||||
|
<iconUrl>$iconUrl$</iconUrl>
|
||||||
|
<description>$description$</description>
|
||||||
|
<copyright>$copyright$</copyright>
|
||||||
|
<tags>$tags$</tags>
|
||||||
|
<repository type="git" url="$repositoryUrl$" commit="$repositoryCommit$" />
|
||||||
|
<dependencies>
|
||||||
|
<group targetFramework=".NETStandard1.3" />
|
||||||
|
</dependencies>
|
||||||
|
</metadata>
|
||||||
|
|
||||||
|
<files>
|
||||||
|
<file src="$OutputBinary$" target="analyzers\dotnet\cs\" />
|
||||||
|
<file src="$OutputSymbol$" target="analyzers\dotnet\cs\" />
|
||||||
|
</files>
|
||||||
|
</package>
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal static class MvcFacts
|
internal static class MvcFacts
|
||||||
{
|
{
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
// 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.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
[assembly: InternalsVisibleTo("Mvc.Api.Analyzers.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal static class SymbolApiConventionMatcher
|
internal static class SymbolApiConventionMatcher
|
||||||
{
|
{
|
||||||
|
|
@ -9,7 +9,7 @@ using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
internal static class SymbolApiResponseMetadataProvider
|
internal static class SymbolApiResponseMetadataProvider
|
||||||
{
|
{
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
|
|
@ -17,15 +18,18 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public class MvcViewOptions : IEnumerable<ICompatibilitySwitch>
|
public class MvcViewOptions : IEnumerable<ICompatibilitySwitch>
|
||||||
{
|
{
|
||||||
private readonly CompatibilitySwitch<bool> _suppressTempDataAttributePrefix;
|
private readonly CompatibilitySwitch<bool> _suppressTempDataAttributePrefix;
|
||||||
|
private readonly CompatibilitySwitch<bool> _allowRenderingMaxLengthAttribute;
|
||||||
private readonly ICompatibilitySwitch[] _switches;
|
private readonly ICompatibilitySwitch[] _switches;
|
||||||
private HtmlHelperOptions _htmlHelperOptions = new HtmlHelperOptions();
|
private HtmlHelperOptions _htmlHelperOptions = new HtmlHelperOptions();
|
||||||
|
|
||||||
public MvcViewOptions()
|
public MvcViewOptions()
|
||||||
{
|
{
|
||||||
_suppressTempDataAttributePrefix = new CompatibilitySwitch<bool>(nameof(SuppressTempDataAttributePrefix));
|
_suppressTempDataAttributePrefix = new CompatibilitySwitch<bool>(nameof(SuppressTempDataAttributePrefix));
|
||||||
|
_allowRenderingMaxLengthAttribute = new CompatibilitySwitch<bool>(nameof(AllowRenderingMaxLengthAttribute));
|
||||||
_switches = new[]
|
_switches = new[]
|
||||||
{
|
{
|
||||||
_suppressTempDataAttributePrefix,
|
_suppressTempDataAttributePrefix,
|
||||||
|
_allowRenderingMaxLengthAttribute
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +91,18 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
set => _suppressTempDataAttributePrefix.Value = value;
|
set => _suppressTempDataAttributePrefix.Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value that indicates whether the maxlength attribute should be rendered for compatible HTML elements,
|
||||||
|
/// when they're bound to models marked with either
|
||||||
|
/// <see cref="StringLengthAttribute"/> or <see cref="MaxLengthAttribute"/> attributes.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>If both attributes are specified, the one with the smaller value will be used for the rendered `maxlength` attribute.</remarks>
|
||||||
|
public bool AllowRenderingMaxLengthAttribute
|
||||||
|
{
|
||||||
|
get => _allowRenderingMaxLengthAttribute.Value;
|
||||||
|
set => _allowRenderingMaxLengthAttribute.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list <see cref="IViewEngine"/>s used by this application.
|
/// Gets a list <see cref="IViewEngine"/>s used by this application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -30,6 +31,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
private static readonly string[] _placeholderInputTypes =
|
private static readonly string[] _placeholderInputTypes =
|
||||||
new[] { "text", "search", "url", "tel", "email", "password", "number" };
|
new[] { "text", "search", "url", "tel", "email", "password", "number" };
|
||||||
|
|
||||||
|
// See: (http://www.w3.org/TR/html5/sec-forms.html#apply)
|
||||||
|
private static readonly string[] _maxLengthInputTypes =
|
||||||
|
new[] { "text", "search", "url", "tel", "email", "password" };
|
||||||
|
|
||||||
private readonly IAntiforgery _antiforgery;
|
private readonly IAntiforgery _antiforgery;
|
||||||
private readonly IModelMetadataProvider _metadataProvider;
|
private readonly IModelMetadataProvider _metadataProvider;
|
||||||
private readonly IUrlHelperFactory _urlHelperFactory;
|
private readonly IUrlHelperFactory _urlHelperFactory;
|
||||||
|
|
@ -92,8 +97,18 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
|
|
||||||
// Underscores are fine characters in id's.
|
// Underscores are fine characters in id's.
|
||||||
IdAttributeDotReplacement = optionsAccessor.Value.HtmlHelperOptions.IdAttributeDotReplacement;
|
IdAttributeDotReplacement = optionsAccessor.Value.HtmlHelperOptions.IdAttributeDotReplacement;
|
||||||
|
|
||||||
|
AllowRenderingMaxLengthAttribute = optionsAccessor.Value.AllowRenderingMaxLengthAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value that indicates whether the maxlength attribute should be rendered for compatible HTML input elements,
|
||||||
|
/// when they're bound to models marked with either
|
||||||
|
/// <see cref="StringLengthAttribute"/> or <see cref="MaxLengthAttribute"/> attributes.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>If both attributes are specified, the one with the smaller value will be used for the rendered `maxlength` attribute.</remarks>
|
||||||
|
protected bool AllowRenderingMaxLengthAttribute { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string IdAttributeDotReplacement { get; }
|
public string IdAttributeDotReplacement { get; }
|
||||||
|
|
||||||
|
|
@ -724,6 +739,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPlaceholderAttribute(viewContext.ViewData, tagBuilder, modelExplorer, expression);
|
AddPlaceholderAttribute(viewContext.ViewData, tagBuilder, modelExplorer, expression);
|
||||||
|
if (AllowRenderingMaxLengthAttribute)
|
||||||
|
{
|
||||||
|
AddMaxLengthAttribute(viewContext.ViewData, tagBuilder, modelExplorer, expression);
|
||||||
|
}
|
||||||
|
|
||||||
AddValidationAttributes(viewContext, tagBuilder, modelExplorer, expression);
|
AddValidationAttributes(viewContext, tagBuilder, modelExplorer, expression);
|
||||||
|
|
||||||
// If there are any errors for a named field, we add this CSS attribute.
|
// If there are any errors for a named field, we add this CSS attribute.
|
||||||
|
|
@ -1239,6 +1259,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
AddPlaceholderAttribute(viewContext.ViewData, tagBuilder, modelExplorer, expression);
|
AddPlaceholderAttribute(viewContext.ViewData, tagBuilder, modelExplorer, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (AllowRenderingMaxLengthAttribute && _maxLengthInputTypes.Contains(suppliedTypeString))
|
||||||
|
{
|
||||||
|
AddMaxLengthAttribute(viewContext.ViewData, tagBuilder, modelExplorer, expression);
|
||||||
|
}
|
||||||
|
|
||||||
var valueParameter = FormatValue(value, format);
|
var valueParameter = FormatValue(value, format);
|
||||||
var usedModelState = false;
|
var usedModelState = false;
|
||||||
switch (inputType)
|
switch (inputType)
|
||||||
|
|
@ -1373,6 +1398,43 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a maxlength attribute to the <paramref name="tagBuilder" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="viewData">A <see cref="ViewDataDictionary"/> instance for the current scope.</param>
|
||||||
|
/// <param name="tagBuilder">A <see cref="TagBuilder"/> instance.</param>
|
||||||
|
/// <param name="modelExplorer">The <see cref="ModelExplorer"/> for the <paramref name="expression"/>.</param>
|
||||||
|
/// <param name="expression">Expression name, relative to the current model.</param>
|
||||||
|
protected virtual void AddMaxLengthAttribute(
|
||||||
|
ViewDataDictionary viewData,
|
||||||
|
TagBuilder tagBuilder,
|
||||||
|
ModelExplorer modelExplorer,
|
||||||
|
string expression)
|
||||||
|
{
|
||||||
|
modelExplorer = modelExplorer ?? ExpressionMetadataProvider.FromStringExpression(
|
||||||
|
expression,
|
||||||
|
viewData,
|
||||||
|
_metadataProvider);
|
||||||
|
|
||||||
|
int? maxLengthValue = null;
|
||||||
|
foreach (var attribute in modelExplorer.Metadata.ValidatorMetadata)
|
||||||
|
{
|
||||||
|
if (attribute is MaxLengthAttribute maxLengthAttribute && (!maxLengthValue.HasValue || maxLengthValue.Value > maxLengthAttribute.Length))
|
||||||
|
{
|
||||||
|
maxLengthValue = maxLengthAttribute.Length;
|
||||||
|
}
|
||||||
|
else if (attribute is StringLengthAttribute stringLengthAttribute && (!maxLengthValue.HasValue || maxLengthValue.Value > stringLengthAttribute.MaximumLength))
|
||||||
|
{
|
||||||
|
maxLengthValue = stringLengthAttribute.MaximumLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxLengthValue.HasValue)
|
||||||
|
{
|
||||||
|
tagBuilder.MergeAttribute("maxlength", maxLengthValue.Value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds validation attributes to the <paramref name="tagBuilder" /> if client validation
|
/// Adds validation attributes to the <paramref name="tagBuilder" /> if client validation
|
||||||
/// is enabled.
|
/// is enabled.
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
values[nameof(MvcViewOptions.SuppressTempDataAttributePrefix)] = true;
|
values[nameof(MvcViewOptions.SuppressTempDataAttributePrefix)] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Version >= CompatibilityVersion.Version_2_2)
|
||||||
|
{
|
||||||
|
values[nameof(MvcViewOptions.AllowRenderingMaxLengthAttribute)] = true;
|
||||||
|
}
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
|
@ -190,6 +191,169 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
Assert.Equal(expected, attribute.Value);
|
Assert.Equal(expected, attribute.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithMaxLength), ModelWithMaxLengthMetadata.MaxLengthAttributeValue)]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithStringLength), ModelWithMaxLengthMetadata.StringLengthAttributeValue)]
|
||||||
|
public void GenerateTextArea_RendersMaxLength(string expression, int expectedValue)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), expression);
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GenerateTextArea(viewContext, modelExplorer, expression, rows: 1, columns: 1, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var attribute = Assert.Single(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
Assert.Equal(expectedValue, Int32.Parse(attribute.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithMaxLength), ModelWithMaxLengthMetadata.MaxLengthAttributeValue)]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithStringLength), ModelWithMaxLengthMetadata.StringLengthAttributeValue)]
|
||||||
|
public void GeneratePassword_RendersMaxLength(string expression, int expectedValue)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), expression);
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GeneratePassword(viewContext, modelExplorer, expression, null, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var attribute = Assert.Single(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
Assert.Equal(expectedValue, Int32.Parse(attribute.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithMaxLength), ModelWithMaxLengthMetadata.MaxLengthAttributeValue)]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithStringLength), ModelWithMaxLengthMetadata.StringLengthAttributeValue)]
|
||||||
|
public void GenerateTextBox_RendersMaxLength(string expression, int expectedValue)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), expression);
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GenerateTextBox(viewContext, modelExplorer, expression, null, null, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var attribute = Assert.Single(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
Assert.Equal(expectedValue, Int32.Parse(attribute.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GenerateTextBox_RendersMaxLength_WithMinimumValueFromBothAttributes()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), nameof(ModelWithMaxLengthMetadata.FieldWithBothAttributes));
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GenerateTextBox(viewContext, modelExplorer, nameof(ModelWithMaxLengthMetadata.FieldWithBothAttributes), null, null, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var attribute = Assert.Single(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
Assert.Equal(Math.Min(ModelWithMaxLengthMetadata.MaxLengthAttributeValue, ModelWithMaxLengthMetadata.StringLengthAttributeValue), Int32.Parse(attribute.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GenerateTextBox_DoesNotRenderMaxLength_WhenNoAttributesPresent()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), nameof(ModelWithMaxLengthMetadata.FieldWithoutAttributes));
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GenerateTextBox(viewContext, modelExplorer, nameof(ModelWithMaxLengthMetadata.FieldWithoutAttributes), null, null, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.DoesNotContain(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithMaxLength), ModelWithMaxLengthMetadata.MaxLengthAttributeValue)]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithStringLength), ModelWithMaxLengthMetadata.StringLengthAttributeValue)]
|
||||||
|
public void GenerateTextBox_SearchType_RendersMaxLength(string expression, int expectedValue)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), expression);
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
{ "type", "search"}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GenerateTextBox(viewContext, modelExplorer, expression, null, null, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var attribute = Assert.Single(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
Assert.Equal(expectedValue, Int32.Parse(attribute.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithMaxLength))]
|
||||||
|
[InlineData(nameof(ModelWithMaxLengthMetadata.FieldWithStringLength))]
|
||||||
|
public void GenerateHidden_DoesNotRenderMaxLength(string expression)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var metadataProvider = new TestModelMetadataProvider();
|
||||||
|
var htmlGenerator = GetGenerator(metadataProvider);
|
||||||
|
var viewContext = GetViewContext<ModelWithMaxLengthMetadata>(model: null, metadataProvider: metadataProvider);
|
||||||
|
var modelMetadata = metadataProvider.GetMetadataForProperty(typeof(ModelWithMaxLengthMetadata), expression);
|
||||||
|
var modelExplorer = new ModelExplorer(metadataProvider, modelMetadata, null);
|
||||||
|
var htmlAttributes = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "name", "testElement" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var tagBuilder = htmlGenerator.GenerateHidden(viewContext, modelExplorer, expression, null, false, htmlAttributes);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.DoesNotContain(tagBuilder.Attributes, a => a.Key == "maxlength");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GenerateValidationMessage_WithNullExpression_Throws()
|
public void GenerateValidationMessage_WithNullExpression_Throws()
|
||||||
{
|
{
|
||||||
|
|
@ -759,7 +923,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
private static IHtmlGenerator GetGenerator(IModelMetadataProvider metadataProvider)
|
private static IHtmlGenerator GetGenerator(IModelMetadataProvider metadataProvider)
|
||||||
{
|
{
|
||||||
var mvcViewOptionsAccessor = new Mock<IOptions<MvcViewOptions>>();
|
var mvcViewOptionsAccessor = new Mock<IOptions<MvcViewOptions>>();
|
||||||
mvcViewOptionsAccessor.SetupGet(accessor => accessor.Value).Returns(new MvcViewOptions());
|
mvcViewOptionsAccessor.SetupGet(accessor => accessor.Value).Returns(new MvcViewOptions() { AllowRenderingMaxLengthAttribute = true });
|
||||||
|
|
||||||
var htmlEncoder = Mock.Of<HtmlEncoder>();
|
var htmlEncoder = Mock.Of<HtmlEncoder>();
|
||||||
var antiforgery = new Mock<IAntiforgery>();
|
var antiforgery = new Mock<IAntiforgery>();
|
||||||
|
|
@ -820,6 +984,24 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
All = -1,
|
All = -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ModelWithMaxLengthMetadata
|
||||||
|
{
|
||||||
|
internal const int MaxLengthAttributeValue = 77;
|
||||||
|
internal const int StringLengthAttributeValue = 7;
|
||||||
|
|
||||||
|
[MaxLength(MaxLengthAttributeValue)]
|
||||||
|
public string FieldWithMaxLength { get; set; }
|
||||||
|
|
||||||
|
[StringLength(StringLengthAttributeValue)]
|
||||||
|
public string FieldWithStringLength { get; set; }
|
||||||
|
|
||||||
|
public string FieldWithoutAttributes { get; set; }
|
||||||
|
|
||||||
|
[MaxLength(MaxLengthAttributeValue)]
|
||||||
|
[StringLength(StringLengthAttributeValue)]
|
||||||
|
public string FieldWithBothAttributes { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
private class Model
|
private class Model
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.Diagnostics;
|
using Microsoft.CodeAnalysis.Diagnostics;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
public class MvcDiagnosticAnalyzerRunner : DiagnosticAnalyzerRunner
|
public class MvcDiagnosticAnalyzerRunner : DiagnosticAnalyzerRunner
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ using System.IO;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure
|
namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
public static class MvcTestSource
|
public static class MvcTestSource
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class AddResponseTypeAttributeCodeFixProviderIntegrationTest
|
public class AddResponseTypeAttributeCodeFixProviderIntegrationTest
|
||||||
{
|
{
|
||||||
|
|
@ -4,10 +4,9 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
public class ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
|
|
@ -65,7 +64,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
private async Task RunTest([CallerMemberName] string testMethod = "")
|
private async Task RunTest([CallerMemberName] string testMethod = "")
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var descriptor = DiagnosticDescriptors.MVC1007_ApiActionsDoNotRequireExplicitModelValidationCheck;
|
var descriptor = ApiDiagnosticDescriptors.API1003_ApiActionsDoNotRequireExplicitModelValidationCheck;
|
||||||
var testSource = MvcTestSource.Read(GetType().Name, testMethod);
|
var testSource = MvcTestSource.Read(GetType().Name, testMethod);
|
||||||
var expectedLocation = testSource.DefaultMarkerLocation;
|
var expectedLocation = testSource.DefaultMarkerLocation;
|
||||||
|
|
||||||
|
|
@ -4,11 +4,10 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest
|
public class ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest
|
||||||
{
|
{
|
||||||
|
|
@ -4,11 +4,10 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class ApiControllerFactsTest
|
public class ApiControllerFactsTest
|
||||||
{
|
{
|
||||||
|
|
@ -5,11 +5,10 @@ using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class ApiConventionAnalyzerIntegrationTest
|
public class ApiConventionAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
|
|
@ -41,55 +40,55 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 404);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 404);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfAsyncMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfAsyncMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 404);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 404);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfAsyncMethodReturningValueTaskWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfAsyncMethodReturningValueTaskWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 200);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 200);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutAnyAttributes()
|
public Task DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutAnyAttributes()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 404);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 404);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutSomeAttributes()
|
public Task DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutSomeAttributes()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 422);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 422);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithConvention_ReturnsUndocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfMethodWithConvention_ReturnsUndocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 400);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 400);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithApiConventionMethod_ReturnsUndocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfMethodWithApiConventionMethod_ReturnsUndocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, 202);
|
=> RunTest(ApiDiagnosticDescriptors.API1000_ActionReturnsUndocumentedStatusCode, 202);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithAttributeReturnsValue_WithoutDocumentation()
|
public Task DiagnosticsAreReturned_IfMethodWithAttributeReturnsValue_WithoutDocumentation()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult);
|
=> RunTest(ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithAttributeAsynchronouslyReturnsValue_WithoutDocumentation()
|
public Task DiagnosticsAreReturned_IfMethodWithAttributeAsynchronouslyReturnsValue_WithoutDocumentation()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult);
|
=> RunTest(ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithAttribute_ReturnsDerivedType()
|
public Task DiagnosticsAreReturned_IfMethodWithAttribute_ReturnsDerivedType()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult);
|
=> RunTest(ApiDiagnosticDescriptors.API1001_ActionReturnsUndocumentedSuccessResult);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotReturnDocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotReturnDocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1006_ActionDoesNotReturnDocumentedStatusCode, 400);
|
=> RunTest(ApiDiagnosticDescriptors.API1002_ActionDoesNotReturnDocumentedStatusCode, 400);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithConvention_DoesNotReturnDocumentedStatusCode()
|
public Task DiagnosticsAreReturned_IfMethodWithConvention_DoesNotReturnDocumentedStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1006_ActionDoesNotReturnDocumentedStatusCode, 404);
|
=> RunTest(ApiDiagnosticDescriptors.API1002_ActionDoesNotReturnDocumentedStatusCode, 404);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public Task DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotDocumentSuccessStatusCode()
|
public Task DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotDocumentSuccessStatusCode()
|
||||||
=> RunTest(DiagnosticDescriptors.MVC1006_ActionDoesNotReturnDocumentedStatusCode, 200);
|
=> RunTest(ApiDiagnosticDescriptors.API1002_ActionDoesNotReturnDocumentedStatusCode, 200);
|
||||||
|
|
||||||
private async Task RunNoDiagnosticsAreReturned([CallerMemberName] string testMethod = "")
|
private async Task RunNoDiagnosticsAreReturned([CallerMemberName] string testMethod = "")
|
||||||
{
|
{
|
||||||
|
|
@ -143,7 +142,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
// 10006 is disabled by default. Explicitly enable it so we can correctly validate no diagnostics
|
// 10006 is disabled by default. Explicitly enable it so we can correctly validate no diagnostics
|
||||||
// are returned scenarios.
|
// are returned scenarios.
|
||||||
var specificDiagnosticOptions = compilationOptions.SpecificDiagnosticOptions.Add(
|
var specificDiagnosticOptions = compilationOptions.SpecificDiagnosticOptions.Add(
|
||||||
DiagnosticDescriptors.MVC1006_ActionDoesNotReturnDocumentedStatusCode.Id,
|
ApiDiagnosticDescriptors.API1002_ActionDoesNotReturnDocumentedStatusCode.Id,
|
||||||
ReportDiagnostic.Info);
|
ReportDiagnostic.Info);
|
||||||
|
|
||||||
return compilationOptions.WithSpecificDiagnosticOptions(specificDiagnosticOptions);
|
return compilationOptions.WithSpecificDiagnosticOptions(specificDiagnosticOptions);
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>
|
||||||
|
<RootNamespace>Microsoft.AspNetCore.Mvc.Api.Analyzers</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\Mvc.Analyzers.Test\Infrastructure\MvcDiagnosticAnalyzerRunner.cs" Link="Infrastructure\MvcDiagnosticAnalyzerRunner.cs" />
|
||||||
|
<Compile Include="..\Mvc.Analyzers.Test\Infrastructure\MvcTestSource.cs" Link="Infrastructure\MvcTestSource.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Mvc\Microsoft.AspNetCore.Mvc.csproj" />
|
||||||
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Mvc.Api.Analyzers\Microsoft.AspNetCore.Mvc.Api.Analyzers.csproj" />
|
||||||
|
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Analyzer.Testing" Version="$(MicrosoftAspNetCoreAnalyzerTestingPackageVersion)" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(MicrosoftAspNetCoreTestingPackageVersion)" />
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
|
|
@ -5,11 +5,10 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class MvcFactsTest
|
public class MvcFactsTest
|
||||||
{
|
{
|
||||||
|
|
@ -5,12 +5,11 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using static Microsoft.AspNetCore.Mvc.Analyzers.SymbolApiConventionMatcher;
|
using static Microsoft.AspNetCore.Mvc.Api.Analyzers.SymbolApiConventionMatcher;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class SymbolApiConventionMatcherTest
|
public class SymbolApiConventionMatcherTest
|
||||||
{
|
{
|
||||||
|
|
@ -6,12 +6,11 @@ using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Analyzer.Testing;
|
using Microsoft.AspNetCore.Analyzer.Testing;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers.Infrastructure;
|
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class SymbolApiResponseMetadataProviderTest
|
public class SymbolApiResponseMetadataProviderTest
|
||||||
{
|
{
|
||||||
|
|
@ -395,7 +394,7 @@ namespace Microsoft.AspNetCore.Mvc.Analyzers
|
||||||
var source = @"
|
var source = @"
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class InspectReturnExpression_ReturnsNull_IfReturnExpressionCannotBeFound : ControllerBase
|
public class InspectReturnExpression_ReturnsNull_IfReturnExpressionCannotBeFound : ControllerBase
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]/[action]")]
|
[Route("[controller]/[action]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class NoDiagnosticsAreReturned_ForApiActionsWithoutModelStateChecks : ControllerBase
|
public class NoDiagnosticsAreReturned_ForApiActionsWithoutModelStateChecks : ControllerBase
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
public class NoDiagnosticsAreReturned_ForNonApiController : ControllerBase
|
public class NoDiagnosticsAreReturned_ForNonApiController : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzerIntegrationTest
|
||||||
{
|
{
|
||||||
public class Home : PageModel
|
public class Home : PageModel
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._INPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._INPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._OUTPUT_
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers.TestFiles.ApiActionsDoNotRequireExplicitModelValidationCheckCodeFixProviderTest._OUTPUT_
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("/api/[controller]")]
|
[Route("/api/[controller]")]
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class ApiConventionAnalyzerTest_IndexModel : PageModel
|
public class ApiConventionAnalyzerTest_IndexModel : PageModel
|
||||||
{
|
{
|
||||||
|
|
@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutAnyAttributes : ControllerBase
|
public class DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutAnyAttributes : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutSomeAttributes : ControllerBase
|
public class DiagnosticsAreReturned_ForActionResultOfTReturningMethodWithoutSomeAttributes : ControllerBase
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers;
|
using Microsoft.AspNetCore.Mvc.Api.Analyzers;
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DiagnosticsAreReturned_ForControllerWithCustomConvention))]
|
[assembly: ApiConventionType(typeof(DiagnosticsAreReturned_ForControllerWithCustomConvention))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_ForControllerWithCustomConventionController : ControllerBase
|
public class DiagnosticsAreReturned_ForControllerWithCustomConventionController : ControllerBase
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfAsyncMethodReturningValueTaskWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfAsyncMethodReturningValueTaskWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfAsyncMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfAsyncMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithApiConventionMethod_ReturnsUndocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithApiConventionMethod_ReturnsUndocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithAttributeAsynchronouslyReturnsValue_WithoutDocumentation : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithAttributeAsynchronouslyReturnsValue_WithoutDocumentation : ControllerBase
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithAttributeReturnsValue_WithoutDocumentation : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithAttributeReturnsValue_WithoutDocumentation : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithAttribute_ReturnsDerivedType : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithAttribute_ReturnsDerivedType : ControllerBase
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithConvention_DoesNotReturnDocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithConvention_DoesNotReturnDocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Analyzers;
|
using Microsoft.AspNetCore.Mvc.Api.Analyzers;
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DiagnosticsAreReturned_IfMethodWithConvention_ReturnsUndocumentedStatusCodeConvention))]
|
[assembly: ApiConventionType(typeof(DiagnosticsAreReturned_IfMethodWithConvention_ReturnsUndocumentedStatusCodeConvention))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithConvention_ReturnsUndocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithConvention_ReturnsUndocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotDocumentSuccessStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotDocumentSuccessStatusCode : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotReturnDocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_DoesNotReturnDocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode : ControllerBase
|
public class DiagnosticsAreReturned_IfMethodWithProducesResponseTypeAttribute_ReturnsUndocumentedStatusCode : ControllerBase
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class NoDiagnosticsAreReturned_ForApiController_IfStatusCodesCannotBeInferred : ControllerBase
|
public class NoDiagnosticsAreReturned_ForApiController_IfStatusCodesCannotBeInferred : ControllerBase
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class NoDiagnosticsAreReturned_ForApiController_WithAllDocumentedStatusCodes : ControllerBase
|
public class NoDiagnosticsAreReturned_ForApiController_WithAllDocumentedStatusCodes : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class NoDiagnosticsAreReturned_ForNonApiController : Controller
|
public class NoDiagnosticsAreReturned_ForNonApiController : Controller
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class Home : PageModel
|
public class Home : PageModel
|
||||||
{
|
{
|
||||||
|
|
@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class NoDiagnosticsAreReturned_ForReturnStatementsInLambdas : ControllerBase
|
public class NoDiagnosticsAreReturned_ForReturnStatementsInLambdas : ControllerBase
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class NoDiagnosticsAreReturned_ForReturnStatementsInLocalFunctions : ControllerBase
|
public class NoDiagnosticsAreReturned_ForReturnStatementsInLocalFunctions : ControllerBase
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public abstract class TestIsControllerActionBase : ControllerBase
|
public abstract class TestIsControllerActionBase : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public interface ITestController { }
|
public interface ITestController { }
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class Base { }
|
public class Base { }
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
[DefaultStatusCode(StatusCodes.Status412PreconditionFailed)]
|
[DefaultStatusCode(StatusCodes.Status412PreconditionFailed)]
|
||||||
public class TestActionResultUsingStatusCodesConstants { }
|
public class TestActionResultUsingStatusCodesConstants { }
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class GetResponseMetadata_ControllerWithoutConvention : ControllerBase
|
public class GetResponseMetadata_ControllerWithoutConvention : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class InspectReturnExpression_ReturnsDefaultResponseMetadata_IfReturnedTypeIsNotActionResult : ControllerBase
|
public class InspectReturnExpression_ReturnsDefaultResponseMetadata_IfReturnedTypeIsNotActionResult : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Microsoft.AspNetCore.Mvc.Analyzers
|
namespace Microsoft.AspNetCore.Mvc.Api.Analyzers
|
||||||
{
|
{
|
||||||
public class InspectReturnExpression_ReturnsStatusCodeFromDefaultStatusCodeAttributeOnActionResult : ControllerBase
|
public class InspectReturnExpression_ReturnsStatusCodeFromDefaultStatusCodeAttributeOnActionResult : ControllerBase
|
||||||
{
|
{
|
||||||
Loading…
Reference in New Issue