@@ -27,6 +27,37 @@ public class OpenDocumentGeneratorTest(ITestOutputHelper testOutput) : LanguageS
27
27
private readonly HostProject _hostProject1 = new ( "c:/Test1/Test1.csproj" , "c:/Test1/obj" , RazorConfiguration . Default , "TestRootNamespace" ) ;
28
28
private readonly HostProject _hostProject2 = new ( "c:/Test2/Test2.csproj" , "c:/Test2/obj" , RazorConfiguration . Default , "TestRootNamespace" ) ;
29
29
30
+ [ Fact ]
31
+ public async Task DocumentAdded_ProcessesOpenDocument ( )
32
+ {
33
+ // Arrange
34
+ var projectManager = CreateProjectSnapshotManager ( new LspProjectEngineFactoryProvider ( TestRazorLSPOptionsMonitor . Create ( ) ) ) ;
35
+ var listener = new TestDocumentProcessedListener ( ) ;
36
+ using var generator = CreateOpenDocumentGenerator ( projectManager , listener ) ;
37
+
38
+ await projectManager . UpdateAsync ( updater =>
39
+ {
40
+ updater . ProjectAdded ( _hostProject1 ) ;
41
+ updater . ProjectAdded ( _hostProject2 ) ;
42
+ updater . DocumentAdded ( _hostProject1 . Key , _documents [ 0 ] , null ! ) ;
43
+ updater . DocumentOpened ( _hostProject1 . Key , _documents [ 0 ] . FilePath , SourceText . From ( string . Empty ) ) ;
44
+ } ) ;
45
+
46
+ await listener . GetProcessedDocumentAsync ( cancelAfter : TimeSpan . FromSeconds ( 10 ) ) ;
47
+ listener . Reset ( ) ;
48
+
49
+ await projectManager . UpdateAsync ( updater =>
50
+ {
51
+ updater . DocumentRemoved ( _hostProject1 . Key , _documents [ 0 ] ) ;
52
+ updater . DocumentAdded ( _hostProject2 . Key , _documents [ 0 ] , null ! ) ;
53
+ } ) ;
54
+
55
+ // Assert
56
+ var document = await listener . GetProcessedDocumentAsync ( cancelAfter : TimeSpan . FromSeconds ( 10 ) ) ;
57
+ Assert . Equal ( _hostProject2 . Key , document . Project . Key ) ;
58
+ Assert . Equal ( _documents [ 0 ] . FilePath , document . FilePath ) ;
59
+ }
60
+
30
61
[ Fact ]
31
62
public async Task DocumentAdded_IgnoresClosedDocument ( )
32
63
{
@@ -152,7 +183,7 @@ private OpenDocumentGenerator CreateOpenDocumentGenerator(
152
183
153
184
private class TestDocumentProcessedListener : IDocumentProcessedListener
154
185
{
155
- private readonly TaskCompletionSource < IDocumentSnapshot > _tcs ;
186
+ private TaskCompletionSource < IDocumentSnapshot > _tcs ;
156
187
157
188
public TestDocumentProcessedListener ( )
158
189
{
@@ -178,5 +209,10 @@ public void DocumentProcessed(RazorCodeDocument codeDocument, IDocumentSnapshot
178
209
{
179
210
_tcs . SetResult ( document ) ;
180
211
}
212
+
213
+ internal void Reset ( )
214
+ {
215
+ _tcs = new TaskCompletionSource < IDocumentSnapshot > ( ) ;
216
+ }
181
217
}
182
218
}
0 commit comments