33
44using System ;
55using System . Threading . Tasks ;
6+ using Microsoft . AspNetCore . Razor ;
67using Microsoft . AspNetCore . Razor . Language ;
78using Microsoft . AspNetCore . Razor . Test . Common ;
9+ using Microsoft . CodeAnalysis ;
810using Microsoft . CodeAnalysis . ExternalAccess . Razor ;
911using Microsoft . CodeAnalysis . Remote . Razor . ProjectSystem ;
1012using Microsoft . CodeAnalysis . Remote . Razor . Resources ;
@@ -29,7 +31,6 @@ public async Task HoverRequest_ReturnsResults()
2931 var document = CreateProjectAndRazorDocument ( input . Text , RazorFileKind . Component ) ;
3032
3133 // Make sure the source generator has been run while cohosting is off, to simular Roslyn winning the initialization race
32- //var compilation = await document.Project.GetCompilationAsync(DisposalToken);
3334 Assert . Empty ( await document . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
3435
3536 // Now turn the source generator on, to simulate Razor starting up and initializing OOP
@@ -51,6 +52,62 @@ public async Task HoverRequest_ReturnsResults()
5152 Assert . NotNull ( hoverResult ) ;
5253 }
5354
55+ [ Fact ]
56+ public async Task HoverRequest_MultipleProjects_ReturnsResults ( )
57+ {
58+ RazorCohostingOptions . UseRazorCohostServer = false ;
59+
60+ TestCode input = """
61+ <div></div>
62+ @System.DateTi$$me.Now
63+ """ ;
64+ // Specify remoteOnly because our test infrastructure isn't set up to mutate solutions otherwise
65+ var document = CreateProjectAndRazorDocument ( input . Text , remoteOnly : true ) ;
66+
67+ // Now we create another document, in another project
68+ TestCode otherInput = """
69+ @System.DateTi$$me.Now
70+ <div></div>
71+ """ ;
72+ var projectId = ProjectId . CreateNewId ( debugName : TestProjectData . SomeProject . DisplayName ) ;
73+ var documentFilePath = TestProjectData . AnotherProjectComponentFile1 . FilePath ;
74+ var documentId = DocumentId . CreateNewId ( projectId , debugName : documentFilePath ) ;
75+ var otherDocument = AddProjectAndRazorDocument ( document . Project . Solution , TestProjectData . AnotherProject . FilePath , projectId , miscellaneousFile : false , documentId , documentFilePath , otherInput . Text , additionalFiles : null , inGlobalNamespace : false ) ;
76+
77+ // Make sure we have the document from our new fork
78+ document = otherDocument . Project . Solution . GetAdditionalDocument ( document . Id ) . AssumeNotNull ( ) ;
79+
80+ // Make sure the source generator has been run while cohosting is off, to simular Roslyn winning the initialization race
81+ Assert . Empty ( await document . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
82+ Assert . Empty ( await otherDocument . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
83+
84+ // Now turn the source generator on, to simulate Razor starting up and initializing OOP
85+ RazorCohostingOptions . UseRazorCohostServer = true ;
86+
87+ var requestInvoker = new TestHtmlRequestInvoker ( ) ;
88+ var endpoint = new CohostHoverEndpoint ( IncompatibleProjectService , RemoteServiceInvoker , requestInvoker ) ;
89+
90+ // Making this request will cause our solution to be redirected, and project 1 to be a retry project
91+ await MakeHoverRequestAsync ( input , document ) ;
92+
93+ // Making this request will use our redirect solution, but project 2 is not a retry project, so would fail normally
94+ await MakeHoverRequestAsync ( otherInput , otherDocument ) ;
95+
96+ async Task MakeHoverRequestAsync ( TestCode input , TextDocument document )
97+ {
98+ var inputText = await document . GetTextAsync ( DisposalToken ) ;
99+ var linePosition = inputText . GetLinePosition ( input . Position ) ;
100+ var textDocumentPositionParams = new TextDocumentPositionParams
101+ {
102+ Position = LspFactory . CreatePosition ( linePosition ) ,
103+ TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) } ,
104+ } ;
105+
106+ var hoverResult = await endpoint . GetTestAccessor ( ) . HandleRequestAsync ( textDocumentPositionParams , document , DisposalToken ) ;
107+ Assert . NotNull ( hoverResult ) ;
108+ }
109+ }
110+
54111 [ Fact ]
55112 public async Task GetRequiredCodeDocument_SucceedsAndReturnsRetryProject ( )
56113 {
@@ -62,7 +119,6 @@ public async Task GetRequiredCodeDocument_SucceedsAndReturnsRetryProject()
62119 var document = CreateProjectAndRazorDocument ( input . Text , RazorFileKind . Component ) ;
63120
64121 // Make sure the source generator has been run while cohosting is off, to simulate Roslyn winning the initialization race
65- //var compilation = await document.Project.GetCompilationAsync(DisposalToken);
66122 Assert . Empty ( await document . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
67123
68124 // Now turn the source generator on, to simulate Razor starting up and initializing OOP
@@ -89,7 +145,6 @@ public async Task GetSnapshot_ReturnsDifferentSolutionSnapshots()
89145 var document = CreateProjectAndRazorDocument ( input . Text , RazorFileKind . Component ) ;
90146
91147 // Make sure the source generator has been run while cohosting is off, to simular Roslyn winning the initialization race
92- //var compilation = await document.Project.GetCompilationAsync(DisposalToken);
93148 Assert . Empty ( await document . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
94149
95150 var snapshotManager = OOPExportProvider . GetExportedValue < RemoteSnapshotManager > ( ) ;
@@ -119,7 +174,6 @@ public async Task CohostingOff_Throws()
119174 var document = CreateProjectAndRazorDocument ( input . Text , RazorFileKind . Component ) ;
120175
121176 // Make sure the source generator has been run while cohosting is off, to simular Roslyn winning the initialization race
122- //var compilation = await document.Project.GetCompilationAsync(DisposalToken);
123177 Assert . Empty ( await document . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
124178
125179 var snapshotManager = OOPExportProvider . GetExportedValue < RemoteSnapshotManager > ( ) ;
@@ -143,7 +197,6 @@ public async Task ProjectChanges_NotRetryProject()
143197 var document = CreateProjectAndRazorDocument ( input . Text , RazorFileKind . Component ) ;
144198
145199 // Make sure the source generator has been run while cohosting is off, to simular Roslyn winning the initialization race
146- //var compilation = await document.Project.GetCompilationAsync(DisposalToken);
147200 Assert . Empty ( await document . Project . GetSourceGeneratedDocumentsAsync ( DisposalToken ) ) ;
148201
149202 var snapshotManager = OOPExportProvider . GetExportedValue < RemoteSnapshotManager > ( ) ;
0 commit comments