@@ -58,6 +58,9 @@ public void AddSignalRSwaggerUi_DefaultOptions()
5858 Assert . AreEqual ( 0 , options . Headers . Count ) ;
5959 Assert . IsTrue ( options . SyntaxHighlight ) ;
6060 Assert . AreEqual ( - 1 , options . DefaultModelsExpandDepth ) ;
61+ Assert . AreEqual ( DocExpansion . List , options . DocExpansion ) ;
62+ Assert . IsFalse ( options . SortTagsAlphabetically ) ;
63+ Assert . IsFalse ( options . SortOperationsAlphabetically ) ;
6164 }
6265
6366 /// <summary>
@@ -117,6 +120,60 @@ public void AddSignalRSwaggerUi_CustomDefaultModelsExpandDepth()
117120 Assert . AreEqual ( 2 , options . DefaultModelsExpandDepth ) ;
118121 }
119122
123+ /// <summary>
124+ /// Verifies that DocExpansion can be configured via DI.
125+ /// </summary>
126+ [ TestMethod ]
127+ public void AddSignalRSwaggerUi_CustomDocExpansion ( )
128+ {
129+ var services = new ServiceCollection ( ) ;
130+ services . AddSignalRSwaggerUi ( o =>
131+ {
132+ o . DocExpansion = DocExpansion . None ;
133+ } ) ;
134+
135+ using var provider = services . BuildServiceProvider ( ) ;
136+ var options = provider . GetRequiredService < IOptions < SignalRSwaggerUiOptions > > ( ) . Value ;
137+
138+ Assert . AreEqual ( DocExpansion . None , options . DocExpansion ) ;
139+ }
140+
141+ /// <summary>
142+ /// Verifies that SortTagsAlphabetically can be configured via DI.
143+ /// </summary>
144+ [ TestMethod ]
145+ public void AddSignalRSwaggerUi_SortTagsAlphabetically ( )
146+ {
147+ var services = new ServiceCollection ( ) ;
148+ services . AddSignalRSwaggerUi ( o =>
149+ {
150+ o . SortTagsAlphabetically = true ;
151+ } ) ;
152+
153+ using var provider = services . BuildServiceProvider ( ) ;
154+ var options = provider . GetRequiredService < IOptions < SignalRSwaggerUiOptions > > ( ) . Value ;
155+
156+ Assert . IsTrue ( options . SortTagsAlphabetically ) ;
157+ }
158+
159+ /// <summary>
160+ /// Verifies that SortOperationsAlphabetically can be configured via DI.
161+ /// </summary>
162+ [ TestMethod ]
163+ public void AddSignalRSwaggerUi_SortOperationsAlphabetically ( )
164+ {
165+ var services = new ServiceCollection ( ) ;
166+ services . AddSignalRSwaggerUi ( o =>
167+ {
168+ o . SortOperationsAlphabetically = true ;
169+ } ) ;
170+
171+ using var provider = services . BuildServiceProvider ( ) ;
172+ var options = provider . GetRequiredService < IOptions < SignalRSwaggerUiOptions > > ( ) . Value ;
173+
174+ Assert . IsTrue ( options . SortOperationsAlphabetically ) ;
175+ }
176+
120177 /// <summary>
121178 /// Verifies embedded signalr.min.js resource is served.
122179 /// </summary>
@@ -284,6 +341,102 @@ public async Task SwaggerUi_CustomDefaultModelsExpandDepthApplied()
284341 Assert . IsTrue ( content . Contains ( "defaultModelsExpandDepth" ) , "Config should include defaultModelsExpandDepth" ) ;
285342 }
286343
344+ /// <summary>
345+ /// Verifies that DocExpansion defaults to "list" in the SwaggerUI configObject.
346+ /// </summary>
347+ /// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
348+ [ TestMethod ]
349+ public async Task SwaggerUi_DocExpansionDefaultIsList ( )
350+ {
351+ using var host = await CreateTestHost ( ) ;
352+ using var client = host . GetTestClient ( ) ;
353+
354+ using var response = await client . GetAsync ( "/signalr-swagger/index.js" ) ;
355+ var content = await response . Content . ReadAsStringAsync ( ) ;
356+
357+ Assert . IsTrue ( content . Contains ( "\" docExpansion\" :\" list\" " ) , "Default DocExpansion should be list" ) ;
358+ }
359+
360+ /// <summary>
361+ /// Verifies that DocExpansion.None is applied to the SwaggerUI configObject.
362+ /// </summary>
363+ /// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
364+ [ TestMethod ]
365+ public async Task SwaggerUi_DocExpansionNoneApplied ( )
366+ {
367+ using var host = await CreateTestHost ( o => o . DocExpansion = DocExpansion . None ) ;
368+ using var client = host . GetTestClient ( ) ;
369+
370+ using var response = await client . GetAsync ( "/signalr-swagger/index.js" ) ;
371+ var content = await response . Content . ReadAsStringAsync ( ) ;
372+
373+ Assert . IsTrue ( content . Contains ( "\" docExpansion\" :\" none\" " ) , "DocExpansion should be none" ) ;
374+ }
375+
376+ /// <summary>
377+ /// Verifies that tagsSorter is not present by default.
378+ /// </summary>
379+ /// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
380+ [ TestMethod ]
381+ public async Task SwaggerUi_TagsSorterNotPresentByDefault ( )
382+ {
383+ using var host = await CreateTestHost ( ) ;
384+ using var client = host . GetTestClient ( ) ;
385+
386+ using var response = await client . GetAsync ( "/signalr-swagger/index.js" ) ;
387+ var content = await response . Content . ReadAsStringAsync ( ) ;
388+
389+ Assert . IsFalse ( content . Contains ( "tagsSorter" ) , "tagsSorter should not be present by default" ) ;
390+ }
391+
392+ /// <summary>
393+ /// Verifies that tagsSorter is set to "alpha" when SortTagsAlphabetically is true.
394+ /// </summary>
395+ /// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
396+ [ TestMethod ]
397+ public async Task SwaggerUi_SortTagsAlphabeticallyApplied ( )
398+ {
399+ using var host = await CreateTestHost ( o => o . SortTagsAlphabetically = true ) ;
400+ using var client = host . GetTestClient ( ) ;
401+
402+ using var response = await client . GetAsync ( "/signalr-swagger/index.js" ) ;
403+ var content = await response . Content . ReadAsStringAsync ( ) ;
404+
405+ Assert . IsTrue ( content . Contains ( "\" tagsSorter\" :\" alpha\" " ) , "tagsSorter should be alpha when enabled" ) ;
406+ }
407+
408+ /// <summary>
409+ /// Verifies that operationsSorter is not present by default.
410+ /// </summary>
411+ /// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
412+ [ TestMethod ]
413+ public async Task SwaggerUi_OperationsSorterNotPresentByDefault ( )
414+ {
415+ using var host = await CreateTestHost ( ) ;
416+ using var client = host . GetTestClient ( ) ;
417+
418+ using var response = await client . GetAsync ( "/signalr-swagger/index.js" ) ;
419+ var content = await response . Content . ReadAsStringAsync ( ) ;
420+
421+ Assert . IsFalse ( content . Contains ( "operationsSorter" ) , "operationsSorter should not be present by default" ) ;
422+ }
423+
424+ /// <summary>
425+ /// Verifies that operationsSorter is set to "alpha" when SortOperationsAlphabetically is true.
426+ /// </summary>
427+ /// <returns>A <see cref="Task"/> representing the asynchronous test.</returns>
428+ [ TestMethod ]
429+ public async Task SwaggerUi_SortOperationsAlphabeticallyApplied ( )
430+ {
431+ using var host = await CreateTestHost ( o => o . SortOperationsAlphabetically = true ) ;
432+ using var client = host . GetTestClient ( ) ;
433+
434+ using var response = await client . GetAsync ( "/signalr-swagger/index.js" ) ;
435+ var content = await response . Content . ReadAsStringAsync ( ) ;
436+
437+ Assert . IsTrue ( content . Contains ( "\" operationsSorter\" :\" alpha\" " ) , "operationsSorter should be alpha when enabled" ) ;
438+ }
439+
287440 /// <summary>
288441 /// Verifies that the document includes hubPath in x-signalr extension.
289442 /// </summary>
0 commit comments