From 43db13f223b08d30a187d32b92a5cad60e136af0 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Mon, 17 Apr 2023 16:43:58 +0200 Subject: [PATCH] Cleanups and fix tests --- .../src/Binding/CascadingModelBinder.cs | 4 ++-- .../src/Binding/ModelBindingContext.cs | 6 +++--- .../Components/src/PublicAPI.Unshipped.txt | 7 ++++--- src/Components/Components/src/RouteView.cs | 2 +- .../test/RenderTreeDiffBuilderTest.cs | 18 +++++++++--------- .../Components/test/RouteViewTest.cs | 2 +- .../src/RazorComponentEndpointHost.cs | 2 +- src/Components/Web/src/Forms/EditForm.cs | 4 ++-- src/Components/Web/src/PublicAPI.Unshipped.txt | 2 ++ src/Components/Web/test/Forms/EditFormTest.cs | 4 ++-- 10 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Components/Components/src/Binding/CascadingModelBinder.cs b/src/Components/Components/src/Binding/CascadingModelBinder.cs index a386f53363ca..8aa340acbf73 100644 --- a/src/Components/Components/src/Binding/CascadingModelBinder.cs +++ b/src/Components/Components/src/Binding/CascadingModelBinder.cs @@ -23,7 +23,7 @@ public class CascadingModelBinder : IComponent /// /// The binding context name. /// - [Parameter] public string BindingId { get; set; } = default!; + [Parameter] public string BindingContextId { get; set; } = default!; /// /// Specifies the content to be rendered inside this . @@ -49,7 +49,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters) } var name = string.IsNullOrEmpty(ParentContext?.Name) ? Name : $"{ParentContext.Name}.{Name}"; - var bindingId = !string.IsNullOrEmpty(name) ? null : BindingId; + var bindingId = !string.IsNullOrEmpty(name) ? null : BindingContextId; _bindingContext = new ModelBindingContext(name, bindingId); _handle.Render(builder => diff --git a/src/Components/Components/src/Binding/ModelBindingContext.cs b/src/Components/Components/src/Binding/ModelBindingContext.cs index e4a0146aaaed..080762ec40fe 100644 --- a/src/Components/Components/src/Binding/ModelBindingContext.cs +++ b/src/Components/Components/src/Binding/ModelBindingContext.cs @@ -23,7 +23,7 @@ public class ModelBindingContext // Nested named binder // Name = <>.<> // FormAction = ?handler=<>.<> - public ModelBindingContext(string name, string? bindingId = null) + internal ModelBindingContext(string name, string? bindingId = null) { // We are initializing the root context, that can be a "named" root context, or the default context. // A named root context only provides a name, and that acts as the BindingId @@ -35,7 +35,7 @@ public ModelBindingContext(string name, string? bindingId = null) } Name = name; - BindingId = bindingId ?? name; + BindingContextId = bindingId ?? name; } /// @@ -46,5 +46,5 @@ public ModelBindingContext(string name, string? bindingId = null) /// /// The computed identifier used to determine what parts of the app can bind data. /// - public string BindingId { get; } + public string BindingContextId { get; } } diff --git a/src/Components/Components/src/PublicAPI.Unshipped.txt b/src/Components/Components/src/PublicAPI.Unshipped.txt index 76c08dad5091..3211e60d1491 100644 --- a/src/Components/Components/src/PublicAPI.Unshipped.txt +++ b/src/Components/Components/src/PublicAPI.Unshipped.txt @@ -1,10 +1,12 @@ #nullable enable Microsoft.AspNetCore.Components.Binding.ModelBindingContext -Microsoft.AspNetCore.Components.Binding.ModelBindingContext.ModelBindingContext(string! name) -> void +Microsoft.AspNetCore.Components.Binding.ModelBindingContext.BindingContextId.get -> string! Microsoft.AspNetCore.Components.Binding.ModelBindingContext.Name.get -> string! Microsoft.AspNetCore.Components.CascadingModelBinder +Microsoft.AspNetCore.Components.CascadingModelBinder.BindingContextId.get -> string! +Microsoft.AspNetCore.Components.CascadingModelBinder.BindingContextId.set -> void Microsoft.AspNetCore.Components.CascadingModelBinder.CascadingModelBinder() -> void -Microsoft.AspNetCore.Components.CascadingModelBinder.ChildContent.get -> Microsoft.AspNetCore.Components.RenderFragment! +Microsoft.AspNetCore.Components.CascadingModelBinder.ChildContent.get -> Microsoft.AspNetCore.Components.RenderFragment! Microsoft.AspNetCore.Components.CascadingModelBinder.ChildContent.set -> void Microsoft.AspNetCore.Components.CascadingModelBinder.Name.get -> string! Microsoft.AspNetCore.Components.CascadingModelBinder.Name.set -> void @@ -13,7 +15,6 @@ Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager. Microsoft.AspNetCore.Components.RenderHandle.DispatchExceptionAsync(System.Exception! exception) -> System.Threading.Tasks.Task! *REMOVED*Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string! relativeUri) -> System.Uri! Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string? relativeUri) -> System.Uri! -Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParameter(int sequence, string! name, Microsoft.AspNetCore.Components.RenderFragment? value) -> void Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.SetEventHandlerName(string! eventHandlerName) -> void Microsoft.AspNetCore.Components.Routing.IScrollToLocationHash Microsoft.AspNetCore.Components.Routing.IScrollToLocationHash.RefreshScrollPositionForHash(string! locationAbsolute) -> System.Threading.Tasks.Task! diff --git a/src/Components/Components/src/RouteView.cs b/src/Components/Components/src/RouteView.cs index 025a832b5643..c6daa21c6458 100644 --- a/src/Components/Components/src/RouteView.cs +++ b/src/Components/Components/src/RouteView.cs @@ -88,7 +88,7 @@ private void RenderPageWithParameters(RenderTreeBuilder builder) builder.OpenComponent(0); builder.AddComponentParameter(1, nameof(CascadingModelBinder.Name), ""); - builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingId), bindingId); + builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingContextId), bindingId); builder.AddComponentParameter(3, nameof(CascadingModelBinder.ChildContent), (RenderFragment)RenderPageWithContext); builder.CloseComponent(); diff --git a/src/Components/Components/test/RenderTreeDiffBuilderTest.cs b/src/Components/Components/test/RenderTreeDiffBuilderTest.cs index 57303b776fb6..8c92db2141f4 100644 --- a/src/Components/Components/test/RenderTreeDiffBuilderTest.cs +++ b/src/Components/Components/test/RenderTreeDiffBuilderTest.cs @@ -816,7 +816,7 @@ public void RecognizesComponentTypeChangesAtSameSequenceNumber() using var batchBuilder = new RenderBatchBuilder(); // Act - var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, newTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); + var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), newTree.GetFrames(), newTree.GetNamedEvents()); // Assert: We're going to dispose the old component and render the new one Assert.Equal(new[] { 0 }, batchBuilder.ComponentDisposalQueue); @@ -1627,7 +1627,7 @@ public void RetainsChildComponentsForExistingFrames() using var batchBuilder = new RenderBatchBuilder(); using var renderTreeBuilder = new RenderTreeBuilder(); - RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTreeBuilder.GetFrames(), renderTreeBuilder.GetNamedEvents()); + RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); var originalFakeComponentInstance = oldTree.GetFrames().Array[2].Component; var originalFakeComponent2Instance = oldTree.GetFrames().Array[3].Component; @@ -1713,7 +1713,7 @@ public void SetsUpdatedParametersOnChildComponents() using var batchBuilder = new RenderBatchBuilder(); using var renderTree = new RenderTreeBuilder(); - RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTree.GetFrames(), renderTree.GetNamedEvents()); + RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); var originalComponentInstance = (FakeComponent)oldTree.GetFrames().Array[0].Component; // Act @@ -1763,7 +1763,7 @@ public void SkipsUpdatingParametersOnChildComponentsIfAllAreDefinitelyImmutableA using var batchBuilder = new RenderBatchBuilder(); using var renderTreeBuilder = new RenderTreeBuilder(); - RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTreeBuilder.GetFrames(), renderTreeBuilder.GetNamedEvents()); + RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); var originalComponentInstance = (CaptureSetParametersComponent)oldTree.GetFrames().Array[0].Component; Assert.Equal(1, originalComponentInstance.SetParametersCallCount); @@ -1793,7 +1793,7 @@ public void AlwaysRegardsRenderFragmentAsPossiblyChanged() using var batchBuilder = new RenderBatchBuilder(); using var renderTreeBuilder = new RenderTreeBuilder(); - RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), renderTreeBuilder.GetNamedEvents()); + RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); var componentInstance = (CaptureSetParametersComponent)oldTree.GetFrames().Array[0].Component; Assert.Equal(1, componentInstance.SetParametersCallCount); @@ -1819,13 +1819,13 @@ public void QueuesRemovedChildComponentsForDisposal() using var batchBuilder = new RenderBatchBuilder(); using var renderTree = new RenderTreeBuilder(); - RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTree.GetFrames(), renderTree.GetNamedEvents()); + RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); // Act/Assert // Note that we track NonDisposableComponent was disposed even though it's not IDisposable, // because it's up to the upstream renderer to decide what "disposing" a component means Assert.Empty(batchBuilder.ComponentDisposalQueue); - RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, newTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents()); + RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), newTree.GetFrames(), newTree.GetNamedEvents()); Assert.Equal(new[] { 0, 1 }, batchBuilder.ComponentDisposalQueue); } @@ -2238,14 +2238,14 @@ private RenderBatch GetRenderedBatch(RenderTreeBuilder from, RenderTreeBuilder t var emptyFrames = renderTreeBuilder.GetFrames(); var oldFrames = from.GetFrames(); - RenderTreeDiffBuilder.ComputeDiff(renderer, initializeBatchBuilder, 0, oldFrames, emptyFrames, null); + RenderTreeDiffBuilder.ComputeDiff(renderer, initializeBatchBuilder, 0, emptyFrames, oldFrames, from.GetNamedEvents()); } batchBuilder?.Dispose(); // This gets disposed as part of the test type's Dispose batchBuilder = new RenderBatchBuilder(); - var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, to.GetFrames(), from.GetFrames(), from.GetNamedEvents()); + var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, from.GetFrames(), to.GetFrames(), to.GetNamedEvents()); batchBuilder.UpdatedComponentDiffs.Append(diff); return batchBuilder.ToBatch(); } diff --git a/src/Components/Components/test/RouteViewTest.cs b/src/Components/Components/test/RouteViewTest.cs index 7f89d70a6864..2f00c61c0c86 100644 --- a/src/Components/Components/test/RouteViewTest.cs +++ b/src/Components/Components/test/RouteViewTest.cs @@ -79,7 +79,7 @@ public void RendersPageInsideLayoutView() frame => AssertFrame.Region(frame, subtreeLength: 5), frame => AssertFrame.Component(frame, sequence: 0, subtreeLength: 4), frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.Name), "", sequence: 1), - frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.BindingId), "jan", sequence: 2), + frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.BindingContextId), "jan", sequence: 2), frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.ChildContent), typeof(RenderFragment), sequence: 3), frame => AssertFrame.Text(frame, "Layout ends here", sequence: 2)); diff --git a/src/Components/Endpoints/src/RazorComponentEndpointHost.cs b/src/Components/Endpoints/src/RazorComponentEndpointHost.cs index 626a93847e8f..064941afc074 100644 --- a/src/Components/Endpoints/src/RazorComponentEndpointHost.cs +++ b/src/Components/Endpoints/src/RazorComponentEndpointHost.cs @@ -39,7 +39,7 @@ private void BuildRenderTree(RenderTreeBuilder builder) builder.OpenComponent(0); builder.AddComponentParameter(1, nameof(LayoutView.Layout), pageLayoutType); - builder.AddComponentParameter(2, nameof(LayoutView.ChildContent), RenderPageWithParameters); + builder.AddComponentParameter(2, nameof(LayoutView.ChildContent), (RenderFragment)RenderPageWithParameters); builder.CloseComponent(); } diff --git a/src/Components/Web/src/Forms/EditForm.cs b/src/Components/Web/src/Forms/EditForm.cs index f17093344d3b..f35109188313 100644 --- a/src/Components/Web/src/Forms/EditForm.cs +++ b/src/Components/Web/src/Forms/EditForm.cs @@ -90,7 +90,7 @@ public EditContext? EditContext /// The name attribute on the form element will default to /// the unless an explicit name is provided. /// - [Parameter] public string FormHandlerName { get; set; } + [Parameter] public string? FormHandlerName { get; set; } /// protected override void OnParametersSet() @@ -165,7 +165,7 @@ void RenderFormContents(RenderTreeBuilder builder, ModelBindingContext? bindingC builder.AddAttribute(4, "onsubmit", _handleSubmitDelegate); if (bindingContext != null) { - builder.SetEventHandlerName(bindingContext.BindingId); + builder.SetEventHandlerName(bindingContext.BindingContextId); } builder.OpenComponent>(5); builder.AddComponentParameter(6, "IsFixed", true); diff --git a/src/Components/Web/src/PublicAPI.Unshipped.txt b/src/Components/Web/src/PublicAPI.Unshipped.txt index 614e93d5e3bd..f7de8f26da50 100644 --- a/src/Components/Web/src/PublicAPI.Unshipped.txt +++ b/src/Components/Web/src/PublicAPI.Unshipped.txt @@ -2,6 +2,8 @@ *REMOVED*override Microsoft.AspNetCore.Components.Forms.InputFile.OnInitialized() -> void Microsoft.AspNetCore.Components.Forms.EditForm.BindingContext.get -> Microsoft.AspNetCore.Components.Binding.ModelBindingContext? Microsoft.AspNetCore.Components.Forms.EditForm.BindingContext.set -> void +Microsoft.AspNetCore.Components.Forms.EditForm.FormHandlerName.get -> string? +Microsoft.AspNetCore.Components.Forms.EditForm.FormHandlerName.set -> void Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.BeginRenderingComponent(System.Type! componentType, Microsoft.AspNetCore.Components.ParameterView initialParameters) -> Microsoft.AspNetCore.Components.Web.HtmlRendering.HtmlRootComponent Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.StaticHtmlRenderer(System.IServiceProvider! serviceProvider, Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> void diff --git a/src/Components/Web/test/Forms/EditFormTest.cs b/src/Components/Web/test/Forms/EditFormTest.cs index 57cea8ccadb5..0aa095665e7b 100644 --- a/src/Components/Web/test/Forms/EditFormTest.cs +++ b/src/Components/Web/test/Forms/EditFormTest.cs @@ -398,8 +398,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) { builder.OpenComponent(0); builder.AddComponentParameter(1, nameof(CascadingModelBinder.Name), BindingContext.Name); - builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingId), BindingContext.BindingId); - builder.AddComponentParameter(3, nameof(CascadingModelBinder.ChildContent), (_) => RenderForm); + builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingContextId), BindingContext.BindingContextId); + builder.AddComponentParameter(3, nameof(CascadingModelBinder.ChildContent), (RenderFragment)((_) => RenderForm)); builder.CloseComponent(); } else