Skip to content

Commit 6045c08

Browse files
Ryan Nowakrynowak
Ryan Nowak
authored andcommitted
Blazor API Review: Built-in components
Fixes: #12548 Renaming properties to drop 'Content' as a suffix. We haven't been consistent in using this, and we're removing it instead of adding it elsewhere.
1 parent bef01f3 commit 6045c08

File tree

11 files changed

+55
-56
lines changed

11 files changed

+55
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Router AppAssembly="typeof(Program).Assembly">
2-
<NotFoundContent>
2+
<NotFound>
33
<p>Sorry, there's nothing at this address.</p>
4-
</NotFoundContent>
4+
</NotFound>
55
</Router>

Diff for: src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ public partial class PageDisplay : Microsoft.AspNetCore.Components.IComponent
306306
{
307307
public PageDisplay() { }
308308
[Microsoft.AspNetCore.Components.ParameterAttribute]
309-
public Microsoft.AspNetCore.Components.RenderFragment AuthorizingContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
309+
public Microsoft.AspNetCore.Components.RenderFragment Authorizing { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
310310
[Microsoft.AspNetCore.Components.ParameterAttribute]
311-
public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.AuthenticationState> NotAuthorizedContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
311+
public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.AuthenticationState> NotAuthorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
312312
[Microsoft.AspNetCore.Components.ParameterAttribute]
313313
public System.Type Page { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
314314
[Microsoft.AspNetCore.Components.ParameterAttribute]
@@ -643,11 +643,11 @@ public Router() { }
643643
[Microsoft.AspNetCore.Components.ParameterAttribute]
644644
public System.Reflection.Assembly AppAssembly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
645645
[Microsoft.AspNetCore.Components.ParameterAttribute]
646-
public Microsoft.AspNetCore.Components.RenderFragment AuthorizingContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
646+
public Microsoft.AspNetCore.Components.RenderFragment Authorizing { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
647647
[Microsoft.AspNetCore.Components.ParameterAttribute]
648-
public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.AuthenticationState> NotAuthorizedContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
648+
public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.AuthenticationState> NotAuthorized { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
649649
[Microsoft.AspNetCore.Components.ParameterAttribute]
650-
public Microsoft.AspNetCore.Components.RenderFragment NotFoundContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
650+
public Microsoft.AspNetCore.Components.RenderFragment NotFound { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
651651
public void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { }
652652
public void Dispose() { }
653653
System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleAfterRender.OnAfterRenderAsync() { throw null; }

Diff for: src/Components/Components/src/Auth/AuthorizeViewCore.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
5858
}
5959
else if (isAuthorized)
6060
{
61-
var authorizedContent = Authorized ?? ChildContent;
62-
builder.AddContent(1, authorizedContent?.Invoke(currentAuthenticationState));
61+
var authorized = Authorized ?? ChildContent;
62+
builder.AddContent(1, authorized?.Invoke(currentAuthenticationState));
6363
}
6464
else
6565
{

Diff for: src/Components/Components/src/PageDisplay.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public class PageDisplay : IComponent
3636
/// The content that will be displayed if the user is not authorized.
3737
/// </summary>
3838
[Parameter]
39-
public RenderFragment<AuthenticationState> NotAuthorizedContent { get; set; }
39+
public RenderFragment<AuthenticationState> NotAuthorized { get; set; }
4040

4141
/// <summary>
4242
/// The content that will be displayed while asynchronous authorization is in progress.
4343
/// </summary>
4444
[Parameter]
45-
public RenderFragment AuthorizingContent { get; set; }
45+
public RenderFragment Authorizing { get; set; }
4646

4747
/// <inheritdoc />
4848
public void Attach(RenderHandle renderHandle)
@@ -109,14 +109,14 @@ private RenderFragment WrapInAuthorizeViewCore(RenderFragment pageFragment)
109109
}
110110

111111
// Some authorization data exists, so we do need to wrap the fragment
112-
RenderFragment<AuthenticationState> authorizedContent = context => pageFragment;
112+
RenderFragment<AuthenticationState> authorized = context => pageFragment;
113113
return builder =>
114114
{
115115
builder.OpenComponent<AuthorizeViewWithSuppliedData>(0);
116116
builder.AddAttribute(1, nameof(AuthorizeViewWithSuppliedData.AuthorizeDataParam), authorizeData);
117-
builder.AddAttribute(2, nameof(AuthorizeViewWithSuppliedData.Authorized), authorizedContent);
118-
builder.AddAttribute(3, nameof(AuthorizeViewWithSuppliedData.NotAuthorized), NotAuthorizedContent ?? DefaultNotAuthorizedContent);
119-
builder.AddAttribute(4, nameof(AuthorizeViewWithSuppliedData.Authorizing), AuthorizingContent);
117+
builder.AddAttribute(2, nameof(AuthorizeViewWithSuppliedData.Authorized), authorized);
118+
builder.AddAttribute(3, nameof(AuthorizeViewWithSuppliedData.NotAuthorized), NotAuthorized ?? DefaultNotAuthorized);
119+
builder.AddAttribute(4, nameof(AuthorizeViewWithSuppliedData.Authorizing), Authorizing);
120120
builder.CloseComponent();
121121
};
122122
}
@@ -133,7 +133,7 @@ private class AuthorizeViewWithSuppliedData : AuthorizeViewCore
133133

134134
// There has to be some default content. If we render blank by default, developers
135135
// will find it hard to guess why their UI isn't appearing.
136-
private static RenderFragment DefaultNotAuthorizedContent(AuthenticationState authenticationState)
136+
private static RenderFragment DefaultNotAuthorized(AuthenticationState authenticationState)
137137
=> builder => builder.AddContent(0, "Not authorized");
138138
}
139139
}

Diff for: src/Components/Components/src/Routing/Router.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public class Router : IComponent, IHandleAfterRender, IDisposable
4141
/// <summary>
4242
/// Gets or sets the type of the component that should be used as a fallback when no match is found for the requested route.
4343
/// </summary>
44-
[Parameter] public RenderFragment NotFoundContent { get; set; }
44+
[Parameter] public RenderFragment NotFound { get; set; }
4545

4646
/// <summary>
4747
/// The content that will be displayed if the user is not authorized.
4848
/// </summary>
49-
[Parameter] public RenderFragment<AuthenticationState> NotAuthorizedContent { get; set; }
49+
[Parameter] public RenderFragment<AuthenticationState> NotAuthorized { get; set; }
5050

5151
/// <summary>
5252
/// The content that will be displayed while asynchronous authorization is in progress.
5353
/// </summary>
54-
[Parameter] public RenderFragment AuthorizingContent { get; set; }
54+
[Parameter] public RenderFragment Authorizing { get; set; }
5555

5656
private RouteTable Routes { get; set; }
5757

@@ -94,8 +94,8 @@ protected virtual void Render(RenderTreeBuilder builder, Type handler, IDictiona
9494
builder.OpenComponent(0, typeof(PageDisplay));
9595
builder.AddAttribute(1, nameof(PageDisplay.Page), handler);
9696
builder.AddAttribute(2, nameof(PageDisplay.PageParameters), parameters);
97-
builder.AddAttribute(3, nameof(PageDisplay.NotAuthorizedContent), NotAuthorizedContent);
98-
builder.AddAttribute(4, nameof(PageDisplay.AuthorizingContent), AuthorizingContent);
97+
builder.AddAttribute(3, nameof(PageDisplay.NotAuthorized), NotAuthorized);
98+
builder.AddAttribute(4, nameof(PageDisplay.Authorizing), Authorizing);
9999
builder.CloseComponent();
100100
}
101101

@@ -120,14 +120,14 @@ private void Refresh(bool isNavigationIntercepted)
120120
}
121121
else
122122
{
123-
if (!isNavigationIntercepted && NotFoundContent != null)
123+
if (!isNavigationIntercepted && NotFound != null)
124124
{
125-
Log.DisplayingNotFoundContent(_logger, locationPath, _baseUri);
125+
Log.DisplayingNotFound(_logger, locationPath, _baseUri);
126126

127127
// We did not find a Component that matches the route.
128-
// Only show the NotFoundContent if the application developer programatically got us here i.e we did not
128+
// Only show the NotFound if the application developer programatically got us here i.e we did not
129129
// intercept the navigation. In all other cases, force a browser navigation since this could be non-Blazor content.
130-
_renderHandle.Render(NotFoundContent);
130+
_renderHandle.Render(NotFound);
131131
}
132132
else
133133
{
@@ -159,18 +159,18 @@ Task IHandleAfterRender.OnAfterRenderAsync()
159159

160160
private static class Log
161161
{
162-
private static readonly Action<ILogger, string, string, Exception> _displayingNotFoundContent =
163-
LoggerMessage.Define<string, string>(LogLevel.Debug, new EventId(1, "DisplayingNotFoundContent"), $"Displaying {nameof(NotFoundContent)} because path '{{Path}}' with base URI '{{BaseUri}}' does not match any component route");
162+
private static readonly Action<ILogger, string, string, Exception> _displayingNotFound =
163+
LoggerMessage.Define<string, string>(LogLevel.Debug, new EventId(1, "DisplayingNotFound"), $"Displaying {nameof(NotFound)} because path '{{Path}}' with base URI '{{BaseUri}}' does not match any component route");
164164

165165
private static readonly Action<ILogger, Type, string, string, Exception> _navigatingToComponent =
166166
LoggerMessage.Define<Type, string, string>(LogLevel.Debug, new EventId(2, "NavigatingToComponent"), "Navigating to component {ComponentType} in response to path '{Path}' with base URI '{BaseUri}'");
167167

168168
private static readonly Action<ILogger, string, string, string, Exception> _navigatingToExternalUri =
169169
LoggerMessage.Define<string, string, string>(LogLevel.Debug, new EventId(3, "NavigatingToExternalUri"), "Navigating to non-component URI '{ExternalUri}' in response to path '{Path}' with base URI '{BaseUri}'");
170170

171-
internal static void DisplayingNotFoundContent(ILogger logger, string path, string baseUri)
171+
internal static void DisplayingNotFound(ILogger logger, string path, string baseUri)
172172
{
173-
_displayingNotFoundContent(logger, path, baseUri, null);
173+
_displayingNotFound(logger, path, baseUri, null);
174174
}
175175

176176
internal static void NavigatingToComponent(ILogger logger, Type componentType, string path, string baseUri)

Diff for: src/Components/Components/test/Auth/AuthorizeViewTest.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ public void RendersNothingIfNotAuthorized()
5353
}
5454

5555
[Fact]
56-
public void RendersNotAuthorizedContentIfNotAuthorized()
56+
public void RendersNotAuthorizedIfNotAuthorized()
5757
{
5858
// Arrange
5959
var authorizationService = new TestAuthorizationService();
6060
var renderer = CreateTestRenderer(authorizationService);
6161
var rootComponent = WrapInAuthorizeView(
62-
notAuthorizedContent:
62+
notAuthorized:
6363
context => builder => builder.AddContent(0, $"You are not authorized, even though we know you are {context.User.Identity.Name}"));
6464
rootComponent.AuthenticationState = CreateAuthenticationState("Nellie");
6565

@@ -88,7 +88,7 @@ public void RendersNotAuthorizedContentIfNotAuthorized()
8888
}
8989

9090
[Fact]
91-
public void RendersNothingIfAuthorizedButNoChildContentOrAuthorizedContentProvided()
91+
public void RendersNothingIfAuthorizedButNoChildContentOrAuthorizedProvided()
9292
{
9393
// Arrange
9494
var authorizationService = new TestAuthorizationService();
@@ -152,14 +152,14 @@ public void RendersChildContentIfAuthorized()
152152
}
153153

154154
[Fact]
155-
public void RendersAuthorizedContentIfAuthorized()
155+
public void RendersAuthorizedIfAuthorized()
156156
{
157157
// Arrange
158158
var authorizationService = new TestAuthorizationService();
159159
authorizationService.NextResult = AuthorizationResult.Success();
160160
var renderer = CreateTestRenderer(authorizationService);
161161
var rootComponent = WrapInAuthorizeView(
162-
authorizedContent: context => builder =>
162+
authorized: context => builder =>
163163
builder.AddContent(0, $"You are authenticated as {context.User.Identity.Name}"));
164164
rootComponent.AuthenticationState = CreateAuthenticationState("Nellie");
165165

@@ -235,13 +235,13 @@ public void RespondsToChangeInAuthorizationState()
235235
}
236236

237237
[Fact]
238-
public void ThrowsIfBothChildContentAndAuthorizedContentProvided()
238+
public void ThrowsIfBothChildContentAndAuthorizedProvided()
239239
{
240240
// Arrange
241241
var authorizationService = new TestAuthorizationService();
242242
var renderer = CreateTestRenderer(authorizationService);
243243
var rootComponent = WrapInAuthorizeView(
244-
authorizedContent: context => builder => { },
244+
authorized: context => builder => { },
245245
childContent: context => builder => { });
246246

247247
// Act/Assert
@@ -260,7 +260,7 @@ public void RendersNothingUntilAuthorizationCompleted()
260260
var renderer = CreateTestRenderer(authorizationService);
261261
renderer.OnUpdateDisplayComplete = () => { @event.Set(); };
262262
var rootComponent = WrapInAuthorizeView(
263-
notAuthorizedContent:
263+
notAuthorized:
264264
context => builder => builder.AddContent(0, "You are not authorized"));
265265
var authTcs = new TaskCompletionSource<AuthenticationState>();
266266
rootComponent.AuthenticationState = authTcs.Task;
@@ -293,7 +293,7 @@ public void RendersNothingUntilAuthorizationCompleted()
293293
}
294294

295295
[Fact]
296-
public void RendersAuthorizingContentUntilAuthorizationCompleted()
296+
public void RendersAuthorizingUntilAuthorizationCompleted()
297297
{
298298
// Arrange
299299
var @event = new ManualResetEventSlim();
@@ -302,8 +302,8 @@ public void RendersAuthorizingContentUntilAuthorizationCompleted()
302302
var renderer = CreateTestRenderer(authorizationService);
303303
renderer.OnUpdateDisplayComplete = () => { @event.Set(); };
304304
var rootComponent = WrapInAuthorizeView(
305-
authorizingContent: builder => builder.AddContent(0, "Auth pending..."),
306-
authorizedContent: context => builder => builder.AddContent(0, $"Hello, {context.User.Identity.Name}!"));
305+
authorizing: builder => builder.AddContent(0, "Auth pending..."),
306+
authorized: context => builder => builder.AddContent(0, $"Hello, {context.User.Identity.Name}!"));
307307
var authTcs = new TaskCompletionSource<AuthenticationState>();
308308
rootComponent.AuthenticationState = authTcs.Task;
309309

@@ -447,9 +447,9 @@ public void RejectsNonemptyScheme()
447447

448448
private static TestAuthStateProviderComponent WrapInAuthorizeView(
449449
RenderFragment<AuthenticationState> childContent = null,
450-
RenderFragment<AuthenticationState> authorizedContent = null,
451-
RenderFragment<AuthenticationState> notAuthorizedContent = null,
452-
RenderFragment authorizingContent = null,
450+
RenderFragment<AuthenticationState> authorized = null,
451+
RenderFragment<AuthenticationState> notAuthorized = null,
452+
RenderFragment authorizing = null,
453453
string policy = null,
454454
string roles = null,
455455
object resource = null)
@@ -458,9 +458,9 @@ private static TestAuthStateProviderComponent WrapInAuthorizeView(
458458
{
459459
builder.OpenComponent<AuthorizeView>(0);
460460
builder.AddAttribute(1, nameof(AuthorizeView.ChildContent), childContent);
461-
builder.AddAttribute(2, nameof(AuthorizeView.Authorized), authorizedContent);
462-
builder.AddAttribute(3, nameof(AuthorizeView.NotAuthorized), notAuthorizedContent);
463-
builder.AddAttribute(4, nameof(AuthorizeView.Authorizing), authorizingContent);
461+
builder.AddAttribute(2, nameof(AuthorizeView.Authorized), authorized);
462+
builder.AddAttribute(3, nameof(AuthorizeView.NotAuthorized), notAuthorized);
463+
builder.AddAttribute(4, nameof(AuthorizeView.Authorizing), authorizing);
464464
builder.AddAttribute(5, nameof(AuthorizeView.Policy), policy);
465465
builder.AddAttribute(6, nameof(AuthorizeView.Roles), roles);
466466
builder.AddAttribute(7, nameof(AuthorizeView.Resource), resource);

Diff for: src/Components/test/testassets/BasicTestApp/AuthTest/AuthRouter.razor

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
<CascadingAuthenticationState>
1212
<Router AppAssembly=typeof(BasicTestApp.Program).Assembly>
13-
<AuthorizingContent>Authorizing...</AuthorizingContent>
14-
<NotAuthorizedContent>
13+
<Authorizing>Authorizing...</Authorizing>
14+
<NotAuthorized>
1515
<div id="auth-failure">
1616
Sorry, @(context.User.Identity.Name ?? "anonymous"), you're not authorized.
1717
</div>
18-
</NotAuthorizedContent>
18+
</NotAuthorized>
1919
</Router>
2020
</CascadingAuthenticationState>
2121

Diff for: src/Components/test/testassets/BasicTestApp/Index.razor

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
<option value="BasicTestApp.RenderFragmentToggler">Render fragment renderer</option>
5959
<option value="BasicTestApp.ReorderingFocusComponent">Reordering focus retention</option>
6060
<option value="BasicTestApp.RouterTest.TestRouter">Router</option>
61-
<option value="BasicTestApp.RouterTest.TestRouterWithoutNotFoundContent">Router without NotFoundContent</option>
6261
<option value="BasicTestApp.RouterTest.UriHelperComponent">UriHelper Test</option>
6362
<option value="BasicTestApp.SvgComponent">SVG</option>
6463
<option value="BasicTestApp.SvgWithChildComponent">SVG with child component</option>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@using Microsoft.AspNetCore.Components.Routing
22
<Router AppAssembly=typeof(BasicTestApp.Program).Assembly>
3-
<NotFoundContent>
3+
<NotFound>
44
<div id="test-info">Oops, that component wasn't found!</div>
5-
</NotFoundContent>
5+
</NotFound>
66
</Router>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@using Microsoft.AspNetCore.Components.Routing
22
Router component
33
<Router AppAssembly="System.Reflection.Assembly.GetAssembly(typeof(RouterContainer))">
4-
<NotFoundContent>
4+
<NotFound>
55
<p>Route not found</p>
6-
</NotFoundContent>
6+
</NotFound>
77
</Router>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<CascadingAuthenticationState>
22
<Router AppAssembly="typeof(Startup).Assembly">
3-
<NotFoundContent>
3+
<NotFound>
44
<p>Sorry, there's nothing at this address.</p>
5-
</NotFoundContent>
5+
</NotFound>
66
</Router>
77
</CascadingAuthenticationState>

0 commit comments

Comments
 (0)