From 3c62c5d1dc7c9c995ecd3984ac7bc672ac97a9b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 18 Jul 2025 18:31:02 +0000 Subject: [PATCH 1/3] Initial plan From 486f5009549de842102f96f823398844f7ad7acb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 18 Jul 2025 18:47:30 +0000 Subject: [PATCH 2/3] Fix GenerateMarkerKey to handle string keys and add comprehensive tests Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --- .../src/Rendering/SSRRenderModeBoundary.cs | 7 +- .../test/SSRRenderModeBoundaryTest.cs | 111 ++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs b/src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs index 5c931c61b6f5..e9930ea24991 100644 --- a/src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs +++ b/src/Components/Endpoints/src/Rendering/SSRRenderModeBoundary.cs @@ -212,7 +212,12 @@ private ComponentMarkerKey GenerateMarkerKey(int sequence, object? componentKey) var sequenceString = sequence.ToString(CultureInfo.InvariantCulture); var locationHash = $"{componentTypeNameHash}:{sequenceString}"; - var formattedComponentKey = (componentKey as IFormattable)?.ToString(null, CultureInfo.InvariantCulture) ?? string.Empty; + var formattedComponentKey = componentKey switch + { + string str => str, + IFormattable formattable => formattable.ToString(null, CultureInfo.InvariantCulture), + _ => string.Empty + }; return new() { diff --git a/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs b/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs index a5db11e45c06..0c0ea5537127 100644 --- a/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs +++ b/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs @@ -96,6 +96,117 @@ public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } + [Fact] + public void GetComponentMarkerKey_WorksWithStringKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + var stringKey = "test-string-key"; + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, stringKey); + + // Assert + Assert.Equal(stringKey, markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + + [Fact] + public void GetComponentMarkerKey_WorksWithIntKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + var intKey = 42; + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, intKey); + + // Assert + Assert.Equal("42", markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + + [Fact] + public void GetComponentMarkerKey_WorksWithGuidKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + var guidKey = Guid.Parse("12345678-1234-1234-1234-123456789012"); + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, guidKey); + + // Assert + Assert.Equal("12345678-1234-1234-1234-123456789012", markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + + [Fact] + public void GetComponentMarkerKey_WorksWithDoubleKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + var doubleKey = 123.45; + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, doubleKey); + + // Assert + Assert.Equal("123.45", markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + + [Fact] + public void GetComponentMarkerKey_WorksWithDateTimeKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + var dateTimeKey = new DateTime(2023, 12, 25, 10, 30, 0, DateTimeKind.Utc); + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, dateTimeKey); + + // Assert + Assert.Equal("12/25/2023 10:30:00", markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + + [Fact] + public void GetComponentMarkerKey_WorksWithNullKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, null); + + // Assert + Assert.Equal(string.Empty, markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + + [Fact] + public void GetComponentMarkerKey_WorksWithNonFormattableKey() + { + // Arrange + var httpContext = new DefaultHttpContext(); + var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); + var nonFormattableKey = new object(); + + // Act + var markerKey = boundary.GetComponentMarkerKey(1, nonFormattableKey); + + // Assert + Assert.Equal(string.Empty, markerKey.FormattedComponentKey); + Assert.NotEmpty(markerKey.LocationHash); + } + class ServerRenderModeSubclass : InteractiveServerRenderMode { } class WebAssemblyRenderModeSubclass : InteractiveWebAssemblyRenderMode { } class AutoRenderModeSubclass : InteractiveAutoRenderMode { } From be35c271e21ede9748f2ac9e76f0e22aaf39e14d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 18 Jul 2025 18:56:35 +0000 Subject: [PATCH 3/3] Convert individual component key tests to xUnit Theory Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --- .../test/SSRRenderModeBoundaryTest.cs | 110 +++--------------- 1 file changed, 13 insertions(+), 97 deletions(-) diff --git a/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs b/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs index 0c0ea5537127..f521373db15f 100644 --- a/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs +++ b/src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs @@ -96,114 +96,30 @@ public Task SetParametersAsync(ParameterView parameters) => throw new NotImplementedException(); } - [Fact] - public void GetComponentMarkerKey_WorksWithStringKey() - { - // Arrange - var httpContext = new DefaultHttpContext(); - var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - var stringKey = "test-string-key"; - - // Act - var markerKey = boundary.GetComponentMarkerKey(1, stringKey); - - // Assert - Assert.Equal(stringKey, markerKey.FormattedComponentKey); - Assert.NotEmpty(markerKey.LocationHash); - } - - [Fact] - public void GetComponentMarkerKey_WorksWithIntKey() - { - // Arrange - var httpContext = new DefaultHttpContext(); - var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - var intKey = 42; - - // Act - var markerKey = boundary.GetComponentMarkerKey(1, intKey); - - // Assert - Assert.Equal("42", markerKey.FormattedComponentKey); - Assert.NotEmpty(markerKey.LocationHash); - } - - [Fact] - public void GetComponentMarkerKey_WorksWithGuidKey() - { - // Arrange - var httpContext = new DefaultHttpContext(); - var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - var guidKey = Guid.Parse("12345678-1234-1234-1234-123456789012"); - - // Act - var markerKey = boundary.GetComponentMarkerKey(1, guidKey); - - // Assert - Assert.Equal("12345678-1234-1234-1234-123456789012", markerKey.FormattedComponentKey); - Assert.NotEmpty(markerKey.LocationHash); - } - - [Fact] - public void GetComponentMarkerKey_WorksWithDoubleKey() + public static IEnumerable ComponentKeyTestData() { - // Arrange - var httpContext = new DefaultHttpContext(); - var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - var doubleKey = 123.45; - - // Act - var markerKey = boundary.GetComponentMarkerKey(1, doubleKey); - - // Assert - Assert.Equal("123.45", markerKey.FormattedComponentKey); - Assert.NotEmpty(markerKey.LocationHash); + yield return new object[] { "test-string-key", "test-string-key" }; + yield return new object[] { 42, "42" }; + yield return new object[] { Guid.Parse("12345678-1234-1234-1234-123456789012"), "12345678-1234-1234-1234-123456789012" }; + yield return new object[] { 123.45, "123.45" }; + yield return new object[] { new DateTime(2023, 12, 25, 10, 30, 0, DateTimeKind.Utc), "12/25/2023 10:30:00" }; + yield return new object[] { null, string.Empty }; + yield return new object[] { new object(), string.Empty }; } - [Fact] - public void GetComponentMarkerKey_WorksWithDateTimeKey() - { - // Arrange - var httpContext = new DefaultHttpContext(); - var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - var dateTimeKey = new DateTime(2023, 12, 25, 10, 30, 0, DateTimeKind.Utc); - - // Act - var markerKey = boundary.GetComponentMarkerKey(1, dateTimeKey); - - // Assert - Assert.Equal("12/25/2023 10:30:00", markerKey.FormattedComponentKey); - Assert.NotEmpty(markerKey.LocationHash); - } - - [Fact] - public void GetComponentMarkerKey_WorksWithNullKey() - { - // Arrange - var httpContext = new DefaultHttpContext(); - var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - - // Act - var markerKey = boundary.GetComponentMarkerKey(1, null); - - // Assert - Assert.Equal(string.Empty, markerKey.FormattedComponentKey); - Assert.NotEmpty(markerKey.LocationHash); - } - - [Fact] - public void GetComponentMarkerKey_WorksWithNonFormattableKey() + [Theory] + [MemberData(nameof(ComponentKeyTestData))] + public void GetComponentMarkerKey_WorksWithVariousKeyTypes(object componentKey, string expectedFormattedKey) { // Arrange var httpContext = new DefaultHttpContext(); var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode()); - var nonFormattableKey = new object(); // Act - var markerKey = boundary.GetComponentMarkerKey(1, nonFormattableKey); + var markerKey = boundary.GetComponentMarkerKey(1, componentKey); // Assert - Assert.Equal(string.Empty, markerKey.FormattedComponentKey); + Assert.Equal(expectedFormattedKey, markerKey.FormattedComponentKey); Assert.NotEmpty(markerKey.LocationHash); }