1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+
4+ using System . Net . Http ;
5+ using System . Text . Json . Nodes ;
6+
7+ namespace Microsoft . AspNetCore . OpenApi . SourceGenerators . Tests ;
8+
9+ [ UsesVerify ]
10+ public class XmlCommentDocumentationIdTests
11+ {
12+ [ Fact ]
13+ public async Task CanMergeXmlCommentsWithDifferentDocumentationIdFormats ( )
14+ {
15+ // This test verifies that XML comments from referenced assemblies (without return type suffix)
16+ // are properly merged with in-memory symbols (with return type suffix)
17+ var source = """
18+ using System;
19+ using System.Threading.Tasks;
20+ using Microsoft.AspNetCore.Builder;
21+ using Microsoft.Extensions.DependencyInjection;
22+ using ReferencedLibrary;
23+
24+ var builder = WebApplication.CreateBuilder();
25+
26+ builder.Services.AddOpenApi();
27+
28+ var app = builder.Build();
29+
30+ app.MapPost("/test-method", ReferencedLibrary.TestApi.TestMethod);
31+
32+ app.Run();
33+ """ ;
34+
35+ var referencedLibrarySource = """
36+ using System;
37+ using System.Threading.Tasks;
38+
39+ namespace ReferencedLibrary;
40+
41+ public static class TestApi
42+ {
43+ /// <summary>
44+ /// This method should have its XML comment merged properly.
45+ /// </summary>
46+ /// <param name="id">The identifier for the test.</param>
47+ /// <returns>A task representing the asynchronous operation.</returns>
48+ public static Task TestMethod(int id)
49+ {
50+ return Task.CompletedTask;
51+ }
52+ }
53+ """ ;
54+
55+ var references = new Dictionary < string , List < string > >
56+ {
57+ { "ReferencedLibrary" , [ referencedLibrarySource ] }
58+ } ;
59+
60+ var generator = new XmlCommentGenerator ( ) ;
61+ await SnapshotTestHelper . Verify ( source , generator , references , out var compilation , out var additionalAssemblies ) ;
62+ await SnapshotTestHelper . VerifyOpenApi ( compilation , additionalAssemblies , document =>
63+ {
64+ var path = document . Paths [ "/test-method" ] . Operations [ HttpMethod . Post ] ;
65+
66+ // Verify that the XML comment from the referenced library was properly merged
67+ // This would fail before the fix because the documentation IDs didn't match
68+ Assert . NotNull ( path . Summary ) ;
69+ Assert . Equal ( "This method should have its XML comment merged properly." , path . Summary ) ;
70+
71+ // Verify the parameter comment is also available
72+ Assert . NotNull ( path . Parameters ) ;
73+ Assert . Single ( path . Parameters ) ;
74+ Assert . Equal ( "The identifier for the test." , path . Parameters [ 0 ] . Description ) ;
75+ } ) ;
76+ }
77+
78+ [ Theory ]
79+ [ InlineData ( "M:Sample.MyMethod(System.Int32)~System.Threading.Tasks.Task" , "M:Sample.MyMethod(System.Int32)" ) ]
80+ [ InlineData ( "M:Sample.MyMethod(System.Int32)" , "M:Sample.MyMethod(System.Int32)" ) ]
81+ [ InlineData ( "M:Sample.op_Implicit(System.Int32)~Sample.MyClass" , "M:Sample.op_Implicit(System.Int32)~Sample.MyClass" ) ]
82+ [ InlineData ( "M:Sample.op_Explicit(System.Int32)~Sample.MyClass" , "M:Sample.op_Explicit(System.Int32)~Sample.MyClass" ) ]
83+ [ InlineData ( "T:Sample.MyClass" , "T:Sample.MyClass" ) ]
84+ [ InlineData ( "P:Sample.MyClass.MyProperty" , "P:Sample.MyClass.MyProperty" ) ]
85+ public void NormalizeDocId_ReturnsExpectedResult ( string input , string expected )
86+ {
87+ var result = XmlCommentGenerator . NormalizeDocId ( input ) ;
88+ Assert . Equal ( expected , result ) ;
89+ }
90+ }
0 commit comments