@@ -96,6 +96,33 @@ public Task SetParametersAsync(ParameterView parameters)
9696 => throw new NotImplementedException ( ) ;
9797 }
9898
99+ public static IEnumerable < object [ ] > ComponentKeyTestData ( )
100+ {
101+ yield return new object [ ] { "test-string-key" , "test-string-key" } ;
102+ yield return new object [ ] { 42 , "42" } ;
103+ yield return new object [ ] { Guid . Parse ( "12345678-1234-1234-1234-123456789012" ) , "12345678-1234-1234-1234-123456789012" } ;
104+ yield return new object [ ] { 123.45 , "123.45" } ;
105+ yield return new object [ ] { new DateTime ( 2023 , 12 , 25 , 10 , 30 , 0 , DateTimeKind . Utc ) , "12/25/2023 10:30:00" } ;
106+ yield return new object [ ] { null , string . Empty } ;
107+ yield return new object [ ] { new object ( ) , string . Empty } ;
108+ }
109+
110+ [ Theory ]
111+ [ MemberData ( nameof ( ComponentKeyTestData ) ) ]
112+ public void GetComponentMarkerKey_WorksWithVariousKeyTypes ( object componentKey , string expectedFormattedKey )
113+ {
114+ // Arrange
115+ var httpContext = new DefaultHttpContext ( ) ;
116+ var boundary = new SSRRenderModeBoundary ( httpContext , typeof ( TestComponent ) , new InteractiveServerRenderMode ( ) ) ;
117+
118+ // Act
119+ var markerKey = boundary . GetComponentMarkerKey ( 1 , componentKey ) ;
120+
121+ // Assert
122+ Assert . Equal ( expectedFormattedKey , markerKey . FormattedComponentKey ) ;
123+ Assert . NotEmpty ( markerKey . LocationHash ) ;
124+ }
125+
99126 class ServerRenderModeSubclass : InteractiveServerRenderMode { }
100127 class WebAssemblyRenderModeSubclass : InteractiveWebAssemblyRenderMode { }
101128 class AutoRenderModeSubclass : InteractiveAutoRenderMode { }
0 commit comments