Skip to content

Commit be35c27

Browse files
Copilotjaviercn
andcommitted
Convert individual component key tests to xUnit Theory
Co-authored-by: javiercn <[email protected]>
1 parent 486f500 commit be35c27

File tree

1 file changed

+13
-97
lines changed

1 file changed

+13
-97
lines changed

src/Components/Endpoints/test/SSRRenderModeBoundaryTest.cs

Lines changed: 13 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -96,114 +96,30 @@ public Task SetParametersAsync(ParameterView parameters)
9696
=> throw new NotImplementedException();
9797
}
9898

99-
[Fact]
100-
public void GetComponentMarkerKey_WorksWithStringKey()
101-
{
102-
// Arrange
103-
var httpContext = new DefaultHttpContext();
104-
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
105-
var stringKey = "test-string-key";
106-
107-
// Act
108-
var markerKey = boundary.GetComponentMarkerKey(1, stringKey);
109-
110-
// Assert
111-
Assert.Equal(stringKey, markerKey.FormattedComponentKey);
112-
Assert.NotEmpty(markerKey.LocationHash);
113-
}
114-
115-
[Fact]
116-
public void GetComponentMarkerKey_WorksWithIntKey()
117-
{
118-
// Arrange
119-
var httpContext = new DefaultHttpContext();
120-
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
121-
var intKey = 42;
122-
123-
// Act
124-
var markerKey = boundary.GetComponentMarkerKey(1, intKey);
125-
126-
// Assert
127-
Assert.Equal("42", markerKey.FormattedComponentKey);
128-
Assert.NotEmpty(markerKey.LocationHash);
129-
}
130-
131-
[Fact]
132-
public void GetComponentMarkerKey_WorksWithGuidKey()
133-
{
134-
// Arrange
135-
var httpContext = new DefaultHttpContext();
136-
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
137-
var guidKey = Guid.Parse("12345678-1234-1234-1234-123456789012");
138-
139-
// Act
140-
var markerKey = boundary.GetComponentMarkerKey(1, guidKey);
141-
142-
// Assert
143-
Assert.Equal("12345678-1234-1234-1234-123456789012", markerKey.FormattedComponentKey);
144-
Assert.NotEmpty(markerKey.LocationHash);
145-
}
146-
147-
[Fact]
148-
public void GetComponentMarkerKey_WorksWithDoubleKey()
99+
public static IEnumerable<object[]> ComponentKeyTestData()
149100
{
150-
// Arrange
151-
var httpContext = new DefaultHttpContext();
152-
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
153-
var doubleKey = 123.45;
154-
155-
// Act
156-
var markerKey = boundary.GetComponentMarkerKey(1, doubleKey);
157-
158-
// Assert
159-
Assert.Equal("123.45", markerKey.FormattedComponentKey);
160-
Assert.NotEmpty(markerKey.LocationHash);
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 };
161108
}
162109

163-
[Fact]
164-
public void GetComponentMarkerKey_WorksWithDateTimeKey()
165-
{
166-
// Arrange
167-
var httpContext = new DefaultHttpContext();
168-
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
169-
var dateTimeKey = new DateTime(2023, 12, 25, 10, 30, 0, DateTimeKind.Utc);
170-
171-
// Act
172-
var markerKey = boundary.GetComponentMarkerKey(1, dateTimeKey);
173-
174-
// Assert
175-
Assert.Equal("12/25/2023 10:30:00", markerKey.FormattedComponentKey);
176-
Assert.NotEmpty(markerKey.LocationHash);
177-
}
178-
179-
[Fact]
180-
public void GetComponentMarkerKey_WorksWithNullKey()
181-
{
182-
// Arrange
183-
var httpContext = new DefaultHttpContext();
184-
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
185-
186-
// Act
187-
var markerKey = boundary.GetComponentMarkerKey(1, null);
188-
189-
// Assert
190-
Assert.Equal(string.Empty, markerKey.FormattedComponentKey);
191-
Assert.NotEmpty(markerKey.LocationHash);
192-
}
193-
194-
[Fact]
195-
public void GetComponentMarkerKey_WorksWithNonFormattableKey()
110+
[Theory]
111+
[MemberData(nameof(ComponentKeyTestData))]
112+
public void GetComponentMarkerKey_WorksWithVariousKeyTypes(object componentKey, string expectedFormattedKey)
196113
{
197114
// Arrange
198115
var httpContext = new DefaultHttpContext();
199116
var boundary = new SSRRenderModeBoundary(httpContext, typeof(TestComponent), new InteractiveServerRenderMode());
200-
var nonFormattableKey = new object();
201117

202118
// Act
203-
var markerKey = boundary.GetComponentMarkerKey(1, nonFormattableKey);
119+
var markerKey = boundary.GetComponentMarkerKey(1, componentKey);
204120

205121
// Assert
206-
Assert.Equal(string.Empty, markerKey.FormattedComponentKey);
122+
Assert.Equal(expectedFormattedKey, markerKey.FormattedComponentKey);
207123
Assert.NotEmpty(markerKey.LocationHash);
208124
}
209125

0 commit comments

Comments
 (0)