@@ -26,16 +26,15 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.Diagnostics;
26
26
27
27
public class RazorDiagnosticsPublisherTest : LanguageServerTestBase
28
28
{
29
- private static readonly RazorDiagnostic [ ] s_emptyRazorDiagnostics = Array . Empty < RazorDiagnostic > ( ) ;
30
-
31
- private static readonly RazorDiagnostic [ ] s_singleRazorDiagnostic = new RazorDiagnostic [ ]
32
- {
29
+ private static readonly RazorDiagnostic [ ] s_emptyRazorDiagnostics = [ ] ;
30
+ private static readonly RazorDiagnostic [ ] s_singleRazorDiagnostic =
31
+ [
33
32
RazorDiagnosticFactory . CreateDirective_BlockDirectiveCannotBeImported ( "test" )
34
- } ;
33
+ ] ;
35
34
36
- private static readonly Diagnostic [ ] s_emptyCSharpDiagnostics = Array . Empty < Diagnostic > ( ) ;
37
- private static readonly Diagnostic [ ] s_singleCSharpDiagnostic = new Diagnostic [ ]
38
- {
35
+ private static readonly Diagnostic [ ] s_emptyCSharpDiagnostics = [ ] ;
36
+ private static readonly Diagnostic [ ] s_singleCSharpDiagnostic =
37
+ [
39
38
new Diagnostic ( )
40
39
{
41
40
Code = "TestCode" ,
@@ -47,7 +46,7 @@ public class RazorDiagnosticsPublisherTest : LanguageServerTestBase
47
46
End = new Position ( 0 , 1 )
48
47
}
49
48
}
50
- } ;
49
+ ] ;
51
50
52
51
private readonly ProjectSnapshotManager _projectManager ;
53
52
private readonly IDocumentSnapshot _closedDocument ;
@@ -83,7 +82,7 @@ public RazorDiagnosticsPublisherTest(ITestOutputHelper testOutput)
83
82
}
84
83
85
84
[ Fact ]
86
- public void DocumentProcessed_NewWorkQueued_RestartsTimer ( )
85
+ public async Task DocumentProcessed_NewWorkQueued_RestartsTimer ( )
87
86
{
88
87
// Arrange
89
88
Assert . NotNull ( _openedDocument . FilePath ) ;
@@ -110,19 +109,21 @@ public void DocumentProcessed_NewWorkQueued_RestartsTimer()
110
109
var documentContextFactory = new TestDocumentContextFactory ( _openedDocument . FilePath , codeDocument ) ;
111
110
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
112
111
113
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServerDocument , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory )
112
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServerDocument , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory )
114
113
{
115
114
BlockBackgroundWorkCompleting = new ManualResetEventSlim ( initialState : true ) ,
116
115
NotifyBackgroundWorkCompleting = new ManualResetEventSlim ( initialState : false ) ,
117
116
} ;
118
117
119
118
publisher . Initialize ( _projectManager ) ;
120
- publisher . DocumentProcessed ( _testCodeDocument , processedOpenDocument ) ;
119
+ await RunOnDispatcherThreadAsync ( ( ) =>
120
+ publisher . DocumentProcessed ( _testCodeDocument , processedOpenDocument ) ) ;
121
121
Assert . True ( publisher . NotifyBackgroundWorkCompleting . Wait ( TimeSpan . FromSeconds ( 2 ) ) ) ;
122
122
publisher . NotifyBackgroundWorkCompleting . Reset ( ) ;
123
123
124
124
// Act
125
- publisher . DocumentProcessed ( _testCodeDocument , processedOpenDocument ) ;
125
+ await RunOnDispatcherThreadAsync ( ( ) =>
126
+ publisher . DocumentProcessed ( _testCodeDocument , processedOpenDocument ) ) ;
126
127
publisher . BlockBackgroundWorkCompleting . Set ( ) ;
127
128
128
129
// Assert
@@ -206,7 +207,7 @@ public async Task PublishDiagnosticsAsync_NewDocumentDiagnosticsGetPublished(boo
206
207
var documentMappingService = new RazorDocumentMappingService ( filePathService , documentContextFactory , LoggerFactory ) ;
207
208
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( documentMappingService , LoggerFactory ) ;
208
209
209
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
210
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
210
211
publisher . Initialize ( _projectManager ) ;
211
212
212
213
// Act
@@ -257,7 +258,7 @@ public async Task PublishDiagnosticsAsync_NewRazorDiagnosticsGetPublished()
257
258
var documentContextFactory = new TestDocumentContextFactory ( _openedDocument . FilePath , codeDocument ) ;
258
259
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
259
260
260
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
261
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
261
262
publisher . PublishedRazorDiagnostics [ processedOpenDocument . FilePath ] = s_emptyRazorDiagnostics ;
262
263
publisher . Initialize ( _projectManager ) ;
263
264
@@ -315,7 +316,7 @@ public async Task PublishDiagnosticsAsync_NewCSharpDiagnosticsGetPublished()
315
316
var documentContextFactory = new TestDocumentContextFactory ( _openedDocument . FilePath , codeDocument ) ;
316
317
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
317
318
318
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
319
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
319
320
publisher . Initialize ( _projectManager ) ;
320
321
await publisher . PublishDiagnosticsAsync ( processedOpenDocument ) ;
321
322
arranging = false ;
@@ -352,7 +353,7 @@ public async Task PublishDiagnosticsAsync_NoopsIfRazorDiagnosticsAreSameAsPrevio
352
353
var documentMappingService = new RazorDocumentMappingService ( filePathService , documentContextFactory , LoggerFactory ) ;
353
354
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( documentMappingService , LoggerFactory ) ;
354
355
355
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
356
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
356
357
publisher . PublishedRazorDiagnostics [ processedOpenDocument . FilePath ] = s_singleRazorDiagnostic ;
357
358
publisher . Initialize ( _projectManager ) ;
358
359
@@ -403,7 +404,7 @@ public async Task PublishDiagnosticsAsync_NoopsIfCSharpDiagnosticsAreSameAsPrevi
403
404
var documentContextFactory = new TestDocumentContextFactory ( _openedDocument . FilePath , codeDocument ) ;
404
405
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
405
406
406
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
407
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
407
408
publisher . Initialize ( _projectManager ) ;
408
409
await publisher . PublishDiagnosticsAsync ( processedOpenDocument ) ;
409
410
arranging = false ;
@@ -433,7 +434,7 @@ public void ClearClosedDocuments_ClearsDiagnosticsForClosedDocument()
433
434
var documentContextFactory = new TestDocumentContextFactory ( ) ;
434
435
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
435
436
436
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
437
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
437
438
Assert . NotNull ( _closedDocument . FilePath ) ;
438
439
publisher . PublishedRazorDiagnostics [ _closedDocument . FilePath ] = s_singleRazorDiagnostic ;
439
440
publisher . PublishedCSharpDiagnostics [ _closedDocument . FilePath ] = s_singleCSharpDiagnostic ;
@@ -454,7 +455,7 @@ public void ClearClosedDocuments_NoopsIfDocumentIsStillOpen()
454
455
var documentContextFactory = new TestDocumentContextFactory ( ) ;
455
456
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
456
457
457
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
458
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
458
459
Assert . NotNull ( _openedDocument . FilePath ) ;
459
460
publisher . PublishedRazorDiagnostics [ _openedDocument . FilePath ] = s_singleRazorDiagnostic ;
460
461
publisher . PublishedCSharpDiagnostics [ _openedDocument . FilePath ] = s_singleCSharpDiagnostic ;
@@ -472,7 +473,7 @@ public void ClearClosedDocuments_NoopsIfDocumentIsClosedButNoDiagnostics()
472
473
var documentContextFactory = new TestDocumentContextFactory ( ) ;
473
474
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
474
475
475
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
476
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
476
477
Assert . NotNull ( _closedDocument . FilePath ) ;
477
478
publisher . PublishedRazorDiagnostics [ _closedDocument . FilePath ] = s_emptyRazorDiagnostics ;
478
479
publisher . PublishedCSharpDiagnostics [ _closedDocument . FilePath ] = s_emptyCSharpDiagnostics ;
@@ -490,7 +491,7 @@ public void ClearClosedDocuments_RestartsTimerIfDocumentsStillOpen()
490
491
var documentContextFactory = new TestDocumentContextFactory ( ) ;
491
492
var translateDiagnosticsService = new RazorTranslateDiagnosticsService ( Mock . Of < IRazorDocumentMappingService > ( MockBehavior . Strict ) , LoggerFactory ) ;
492
493
493
- using var publisher = new TestRazorDiagnosticsPublisher ( LegacyDispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
494
+ using var publisher = new TestRazorDiagnosticsPublisher ( Dispatcher , languageServer . Object , TestLanguageServerFeatureOptions . Instance , translateDiagnosticsService , documentContextFactory , LoggerFactory ) ;
494
495
Assert . NotNull ( _closedDocument . FilePath ) ;
495
496
Assert . NotNull ( _openedDocument . FilePath ) ;
496
497
publisher . PublishedRazorDiagnostics [ _closedDocument . FilePath ] = s_emptyRazorDiagnostics ;
0 commit comments