Modify ViewComponent_CannotFindComponent error message (#6263)
This commit is contained in:
parent
5eabae55cb
commit
b758a86a38
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
=> string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_SyncMethod_ShouldReturnValue"), p0, p1);
|
=> string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_SyncMethod_ShouldReturnValue"), p0, p1);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A view component named '{0}' could not be found.
|
/// A view component named '{0}' could not be found. A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated with '{1}' or have a class name ending with the '{2}' suffix. A view component must not be decorated with '{3}'.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string ViewComponent_CannotFindComponent
|
internal static string ViewComponent_CannotFindComponent
|
||||||
{
|
{
|
||||||
|
|
@ -75,10 +75,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A view component named '{0}' could not be found.
|
/// A view component named '{0}' could not be found. A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated with '{1}' or have a class name ending with the '{2}' suffix. A view component must not be decorated with '{3}'.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string FormatViewComponent_CannotFindComponent(object p0)
|
internal static string FormatViewComponent_CannotFindComponent(object p0, object p1, object p2, object p3)
|
||||||
=> string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_CannotFindComponent"), p0);
|
=> string.Format(CultureInfo.CurrentCulture, GetString("ViewComponent_CannotFindComponent"), p0, p1, p2, p3);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An invoker could not be created for the view component '{0}'.
|
/// An invoker could not be created for the view component '{0}'.
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@
|
||||||
<value>Method '{0}' of view component '{1}' should be declared to return a value.</value>
|
<value>Method '{0}' of view component '{1}' should be declared to return a value.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ViewComponent_CannotFindComponent" xml:space="preserve">
|
<data name="ViewComponent_CannotFindComponent" xml:space="preserve">
|
||||||
<value>A view component named '{0}' could not be found.</value>
|
<value>A view component named '{0}' could not be found. A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated with '{1}' or have a class name ending with the '{2}' suffix. A view component must not be decorated with '{3}'.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ViewComponent_IViewComponentFactory_ReturnedNull" xml:space="preserve">
|
<data name="ViewComponent_IViewComponentFactory_ReturnedNull" xml:space="preserve">
|
||||||
<value>An invoker could not be created for the view component '{0}'.</value>
|
<value>An invoker could not be created for the view component '{0}'.</value>
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
||||||
var descriptor = _selector.SelectComponent(name);
|
var descriptor = _selector.SelectComponent(name);
|
||||||
if (descriptor == null)
|
if (descriptor == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(Resources.FormatViewComponent_CannotFindComponent(name));
|
throw new InvalidOperationException(Resources.FormatViewComponent_CannotFindComponent(
|
||||||
|
name,
|
||||||
|
nameof(ViewComponentAttribute),
|
||||||
|
ViewComponentConventions.ViewComponentSuffix,
|
||||||
|
nameof(NonViewComponentAttribute)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return InvokeCoreAsync(descriptor, arguments);
|
return InvokeCoreAsync(descriptor, arguments);
|
||||||
|
|
@ -129,7 +133,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidOperationException(Resources.FormatViewComponent_CannotFindComponent(
|
throw new InvalidOperationException(Resources.FormatViewComponent_CannotFindComponent(
|
||||||
componentType.FullName));
|
componentType.FullName,
|
||||||
|
nameof(ViewComponentAttribute),
|
||||||
|
ViewComponentConventions.ViewComponentSuffix,
|
||||||
|
nameof(NonViewComponentAttribute)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal for testing
|
// Internal for testing
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewComponents
|
||||||
{
|
{
|
||||||
public static class ViewComponentConventions
|
public static class ViewComponentConventions
|
||||||
{
|
{
|
||||||
private const string ViewComponentSuffix = "ViewComponent";
|
public static readonly string ViewComponentSuffix = "ViewComponent";
|
||||||
|
|
||||||
public static string GetComponentName(TypeInfo componentType)
|
public static string GetComponentName(TypeInfo componentType)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,10 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public async Task ExecuteResultAsync_Throws_IfViewComponentCouldNotBeFound_ByName()
|
public async Task ExecuteResultAsync_Throws_IfViewComponentCouldNotBeFound_ByName()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = "A view component named 'Text' could not be found.";
|
var expected = "A view component named 'Text' could not be found. A view component must be " +
|
||||||
|
"a public non-abstract class, not contain any generic parameters, and either be decorated " +
|
||||||
|
"with 'ViewComponentAttribute' or have a class name ending with the 'ViewComponent' suffix. " +
|
||||||
|
"A view component must not be decorated with 'NonViewComponentAttribute'.";
|
||||||
|
|
||||||
var actionContext = CreateActionContext();
|
var actionContext = CreateActionContext();
|
||||||
|
|
||||||
|
|
@ -125,7 +128,10 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public async Task ExecuteResultAsync_Throws_IfViewComponentCouldNotBeFound_ByType()
|
public async Task ExecuteResultAsync_Throws_IfViewComponentCouldNotBeFound_ByType()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = $"A view component named '{typeof(TextViewComponent).FullName}' could not be found.";
|
var expected = $"A view component named '{typeof(TextViewComponent).FullName}' could not be found. " +
|
||||||
|
"A view component must be a public non-abstract class, not contain any generic parameters, and either be decorated " +
|
||||||
|
"with 'ViewComponentAttribute' or have a class name ending with the 'ViewComponent' suffix. " +
|
||||||
|
"A view component must not be decorated with 'NonViewComponentAttribute'.";
|
||||||
|
|
||||||
var actionContext = CreateActionContext();
|
var actionContext = CreateActionContext();
|
||||||
var services = CreateServices(diagnosticListener: null, context: actionContext.HttpContext);
|
var services = CreateServices(diagnosticListener: null, context: actionContext.HttpContext);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue