@@ -38,25 +38,8 @@ public async Task DiagnosticsRequest_UpdatesUri()
3838 var document = Workspace . CurrentSolution . GetAdditionalDocument ( _documentId ) . AssumeNotNull ( ) ;
3939
4040 var htmlDocumentUri = new Uri ( "file://File.razor.html" , UriKind . Absolute ) ;
41-
42- var htmlTextSnapshot = new StringTextSnapshot ( "" ) ;
43- var htmlTextBuffer = new TestTextBuffer ( htmlTextSnapshot ) ;
44- var checksum = await document . GetChecksumAsync ( DisposalToken ) ;
45- var requestInvoker = new TestLSPRequestInvoker ( ( VSInternalMethods . DocumentPullDiagnosticName , null ) ) ;
46- var lspDocumentManager = new TestDocumentManager ( ) ;
47- var htmlVirtualDocument = new HtmlVirtualDocumentSnapshot ( htmlDocumentUri , htmlTextBuffer . CurrentSnapshot , hostDocumentSyncVersion : 1 , state : checksum ) ;
48- var documentSnapshot = new TestLSPDocumentSnapshot ( document . CreateUri ( ) , version : ( int ) ( htmlVirtualDocument . HostDocumentSyncVersion ! . Value + 1 ) , htmlVirtualDocument ) ;
49- lspDocumentManager . AddDocument ( documentSnapshot . Uri , documentSnapshot ) ;
50-
51- var publisher = new TestHtmlDocumentPublisher ( ) ;
52- var remoteServiceInvoker = new RemoteServiceInvoker ( ) ;
53- var htmlDocumentSynchronizer = new HtmlDocumentSynchronizer ( remoteServiceInvoker , publisher , LoggerFactory ) ;
54- var invoker = new HtmlRequestInvoker ( requestInvoker , lspDocumentManager , htmlDocumentSynchronizer , NoOpTelemetryReporter . Instance , LoggerFactory ) ;
55-
56- var validated = false ;
57- requestInvoker . RequestAction = request =>
41+ var requestValidator = ( object request ) =>
5842 {
59- validated = true ;
6043 var diagnosticParams = Assert . IsType < VSInternalDiagnosticParams > ( request ) ;
6144 Assert . Equal ( htmlDocumentUri , diagnosticParams . TextDocument ! . DocumentUri . GetRequiredParsedUri ( ) ) ;
6245 } ;
@@ -66,15 +49,9 @@ public async Task DiagnosticsRequest_UpdatesUri()
6649 TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) }
6750 } ;
6851
69- _ = await invoker . MakeHtmlLspRequestAsync < VSInternalDiagnosticParams , object > (
70- document ,
71- VSInternalMethods . DocumentPullDiagnosticName ,
72- diagnosticRequest ,
73- DisposalToken ) ;
52+ await MakeHtmlRequestAsync ( document , htmlDocumentUri , requestValidator , VSInternalMethods . DocumentPullDiagnosticName , diagnosticRequest ) ;
7453
7554 Assert . Equal ( document . CreateDocumentUri ( ) , diagnosticRequest . TextDocument ! . DocumentUri ) ;
76-
77- Assert . True ( validated ) ;
7855 }
7956
8057 [ Fact ]
@@ -83,11 +60,29 @@ public async Task ITextDocumentParamsRequest_UpdatesUri()
8360 var document = Workspace . CurrentSolution . GetAdditionalDocument ( _documentId ) . AssumeNotNull ( ) ;
8461
8562 var htmlDocumentUri = new Uri ( "file://File.razor.html" , UriKind . Absolute ) ;
63+ var requestValidator = ( object request ) =>
64+ {
65+ var hoverParams = Assert . IsAssignableFrom < ITextDocumentParams > ( request ) ;
66+ Assert . Equal ( htmlDocumentUri , hoverParams . TextDocument ! . DocumentUri . GetRequiredParsedUri ( ) ) ;
67+ } ;
68+
69+ var hoverRequest = new HoverParams
70+ {
71+ TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) }
72+ } ;
73+
74+ await MakeHtmlRequestAsync ( document , htmlDocumentUri , requestValidator , Methods . TextDocumentHoverName , hoverRequest ) ;
75+
76+ Assert . Equal ( document . CreateDocumentUri ( ) , hoverRequest . TextDocument ! . DocumentUri ) ;
77+ }
8678
79+ private async Task MakeHtmlRequestAsync < TRequest > ( TextDocument document , Uri htmlDocumentUri , Action < object > requestValidator , string method , TRequest request )
80+ where TRequest : notnull
81+ {
8782 var htmlTextSnapshot = new StringTextSnapshot ( "" ) ;
8883 var htmlTextBuffer = new TestTextBuffer ( htmlTextSnapshot ) ;
8984 var checksum = await document . GetChecksumAsync ( DisposalToken ) ;
90- var requestInvoker = new TestLSPRequestInvoker ( ( Methods . TextDocumentHoverName , null ) ) ;
85+ var requestInvoker = new TestLSPRequestInvoker ( ( method , null ) ) ;
9186 var lspDocumentManager = new TestDocumentManager ( ) ;
9287 var htmlVirtualDocument = new HtmlVirtualDocumentSnapshot ( htmlDocumentUri , htmlTextBuffer . CurrentSnapshot , hostDocumentSyncVersion : 1 , state : checksum ) ;
9388 var documentSnapshot = new TestLSPDocumentSnapshot ( document . CreateUri ( ) , version : ( int ) ( htmlVirtualDocument . HostDocumentSyncVersion ! . Value + 1 ) , htmlVirtualDocument ) ;
@@ -99,26 +94,18 @@ public async Task ITextDocumentParamsRequest_UpdatesUri()
9994 var invoker = new HtmlRequestInvoker ( requestInvoker , lspDocumentManager , htmlDocumentSynchronizer , NoOpTelemetryReporter . Instance , LoggerFactory ) ;
10095
10196 var validated = false ;
102- requestInvoker . RequestAction = request =>
97+ requestInvoker . RequestAction = r =>
10398 {
10499 validated = true ;
105- var diagnosticParams = Assert . IsAssignableFrom < ITextDocumentParams > ( request ) ;
106- Assert . Equal ( htmlDocumentUri , diagnosticParams . TextDocument ! . DocumentUri . GetRequiredParsedUri ( ) ) ;
100+ requestValidator ( r ) ;
107101 } ;
108102
109- var diagnosticRequest = new HoverParams
110- {
111- TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) }
112- } ;
113-
114- _ = await invoker . MakeHtmlLspRequestAsync < HoverParams , object > (
103+ _ = await invoker . MakeHtmlLspRequestAsync < TRequest , object > (
115104 document ,
116- Methods . TextDocumentHoverName ,
117- diagnosticRequest ,
105+ method ,
106+ request ,
118107 DisposalToken ) ;
119108
120- Assert . Equal ( document . CreateDocumentUri ( ) , diagnosticRequest . TextDocument ! . DocumentUri ) ;
121-
122109 Assert . True ( validated ) ;
123110 }
124111
0 commit comments