Skip to content

Commit d087641

Browse files
Test updates
1 parent 2d9d92e commit d087641

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.EventDispatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void UpdateNamedEvents(in RenderBatch renderBatch)
7777
// We could allow multiple events with the same name, since they are all tracked separately. However
7878
// this is most likely a mistake on the developer's part so we will consider it an error.
7979
var existingEntry = _namedSubmitEventsByScopeQualifiedName[scopeQualifiedName];
80-
throw new InvalidOperationException($"There is more than one named event with the name '{scopeQualifiedName}'. Ensure named events have unique names. The following components both use this name:"
80+
throw new InvalidOperationException($"There is more than one named event with the name '{scopeQualifiedName}'. Ensure named events have unique names, or are in scopes with distinct names. The following components both use this name:"
8181
+ $"\n - {GenerateComponentPath(existingEntry.ComponentId)}"
8282
+ $"\n - {GenerateComponentPath(addedEntry.ComponentId)}");
8383
}

src/Components/Endpoints/test/EndpointHtmlRendererTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.Components.Endpoints.Forms;
88
using Microsoft.AspNetCore.Components.Endpoints.Tests.TestComponents;
99
using Microsoft.AspNetCore.Components.Forms;
10+
using Microsoft.AspNetCore.Components.Forms.Mapping;
1011
using Microsoft.AspNetCore.Components.Infrastructure;
1112
using Microsoft.AspNetCore.Components.Rendering;
1213
using Microsoft.AspNetCore.Components.Test.Helpers;
@@ -821,7 +822,7 @@ public async Task CanRender_AsyncComponent()
821822
public void Duplicate_NamedEventHandlers_AcrossComponents_Throws()
822823
{
823824
// Arrange
824-
var expectedError = @"There is more than one named event with the name 'default'. Ensure named events have unique names. The following components both use this name:
825+
var expectedError = @"There is more than one named event with the name 'default'. Ensure named events have unique names, or are in scopes with distinct names. The following components both use this name:
825826
- TestComponent > NamedEventHandlerComponent
826827
- TestComponent > OtherNamedEventHandlerComponent";
827828

@@ -1228,6 +1229,7 @@ private static ServiceCollection CreateDefaultServiceCollection()
12281229
services.AddSingleton<ComponentStatePersistenceManager>();
12291230
services.AddSingleton<PersistentComponentState>(sp => sp.GetRequiredService<ComponentStatePersistenceManager>().State);
12301231
services.AddSingleton<AntiforgeryStateProvider, EndpointAntiforgeryStateProvider>();
1232+
services.AddSingleton<ICascadingValueSupplier>(_ => new SupplyParameterFromFormValueProvider(null, ""));
12311233

12321234
return services;
12331235
}

src/Components/Web/test/Forms/EditFormTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public async Task AddSSRContentWhenMappingContextPresent()
155155

156156
// Assigns name to the submit event
157157
frame => AssertFrame.Attribute(frame, "onsubmit"),
158-
frame => AssertFrame.NamedEvent(frame, "onsubmit", "mapping-context-name.my-form"),
158+
frame => AssertFrame.NamedEvent(frame, "onsubmit", "my-form"),
159159

160160
frame => AssertFrame.Region(frame, 4),
161161

@@ -273,7 +273,7 @@ void RenderForm(RenderTreeBuilder builder)
273273

274274
private class TestFormValueModelBinder : IFormValueMapper
275275
{
276-
public bool CanMap(Type valueType, string formName = null) => false;
276+
public bool CanMap(Type valueType, string mappingScopeName, string formName) => false;
277277
public void Map(FormValueMappingContext context) { }
278278
}
279279
}

src/Components/Web/test/Forms/Mapping/FormMappingScopeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
146146

147147
private class TestFormValueMapper : IFormValueMapper
148148
{
149-
public bool CanMap(Type valueType, string formName = null) => false;
149+
public bool CanMap(Type valueType, string mappingScopeName, string formName) => false;
150150
public void Map(FormValueMappingContext context) { }
151151
}
152152
}

src/Components/Web/test/Forms/Mapping/SupplyParameterFromFormTest.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public async Task FindCascadingParameters_HandlesSupplyParameterFromFormValues()
2929
}
3030

3131
[Fact]
32-
public async Task FindCascadingParameters_HandlesSupplyParameterFromFormValues_WithName()
32+
public async Task FindCascadingParameters_HandlesSupplyParameterFromFormValues_WithMappingScopeName()
3333
{
3434
// Arrange
3535
var renderer = CreateRendererWithFormValueModelBinder();
3636
var formMappingScope = new FormMappingScope
3737
{
3838
Name = "scope-name",
39-
FormValueModelBinder = new TestFormModelValueBinder("scope-name.handler-name"),
39+
FormValueModelBinder = new TestFormModelValueBinder("[scope-name]handler-name"),
4040
ChildContent = modelBindingContext => builder =>
4141
{
4242
builder.OpenComponent<FormParametersComponentWithName>(0);
@@ -78,12 +78,21 @@ class FormParametersComponentWithName : TestComponentBase
7878
[SupplyParameterFromForm(Handler = "handler-name")] public string FormParameter { get; set; }
7979
}
8080

81-
class TestFormModelValueBinder(string FormName = "") : IFormValueMapper
81+
class TestFormModelValueBinder(string IncomingScopeQualifiedFormName = "") : IFormValueMapper
8282
{
8383
public void Map(FormValueMappingContext context) { }
8484

85-
public bool CanMap(Type valueType, string formName = null)
86-
=> formName is null || formName == FormName;
85+
public bool CanMap(Type valueType, string mappingScopeName, string formName)
86+
{
87+
if (string.IsNullOrEmpty(mappingScopeName))
88+
{
89+
return IncomingScopeQualifiedFormName == (formName ?? string.Empty);
90+
}
91+
else
92+
{
93+
return IncomingScopeQualifiedFormName == $"[{mappingScopeName}]{formName ?? string.Empty}";
94+
}
95+
}
8796
}
8897

8998
class TestComponentBase : IComponent

src/Components/Web/test/HtmlRendering/HtmlRendererTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ await htmlRenderer.Dispatcher.InvokeAsync(async () =>
10791079
var result = await htmlRenderer.RenderComponentAsync<TestComponent>();
10801080

10811081
// Assert
1082-
Assert.Equal("<form><input type=\"hidden\" name=\"handler\" value=\"myscope.somename\" /></form>", result.ToHtmlString());
1082+
Assert.Equal("<form><input type=\"hidden\" name=\"handler\" value=\"[myscope]somename\" /></form>", result.ToHtmlString());
10831083
});
10841084
}
10851085

@@ -1262,7 +1262,7 @@ HtmlRenderer GetHtmlRenderer(IServiceProvider serviceProvider = null)
12621262

12631263
class TestFormValueMapper : IFormValueMapper
12641264
{
1265-
public bool CanMap(Type valueType, string formName = null)
1265+
public bool CanMap(Type valueType, string mappingScopeName, string formName)
12661266
=> throw new NotImplementedException();
12671267

12681268
public void Map(FormValueMappingContext context)

0 commit comments

Comments
 (0)