@@ -158,6 +158,44 @@ await RunOnDispatcherThreadAsync(() =>
158
158
Assert . True ( serializationSuccessful ) ;
159
159
}
160
160
161
+ [ Fact ]
162
+ public async Task ProjectManager_Changed_DocumentOpened_InitializedProject_NoFile_Active_Publishes ( )
163
+ {
164
+ // Arrange
165
+ var serializationSuccessful = false ;
166
+ var hostProject = new HostProject ( @"C:\path\to\project.csproj" , @"C:\path\to\obj" , RazorConfiguration . Default , rootNamespace : "TestRootNamespace" ) ;
167
+ var hostDocument = new HostDocument ( @"C:\path\to\file.razor" , "file.razor" ) ;
168
+ _projectSnapshotManager . ProjectAdded ( hostProject ) ;
169
+ _projectSnapshotManager . ProjectWorkspaceStateChanged ( hostProject . Key , ProjectWorkspaceState . Default ) ;
170
+ _projectSnapshotManager . DocumentAdded ( hostProject . Key , hostDocument , new EmptyTextLoader ( hostDocument . FilePath ) ) ;
171
+ var projectSnapshot = _projectSnapshotManager . GetProjects ( ) [ 0 ] ;
172
+ var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.bin" ;
173
+ _projectConfigurationFilePathStore . Set ( projectSnapshot . Key , expectedConfigurationFilePath ) ;
174
+ var publisher = new TestRazorProjectInfoPublisher (
175
+ _projectConfigurationFilePathStore ,
176
+ onSerializeToFile : ( snapshot , configurationFilePath ) =>
177
+ {
178
+ Assert . Equal ( expectedConfigurationFilePath , configurationFilePath ) ;
179
+ serializationSuccessful = true ;
180
+ } ,
181
+ configurationFileExists : false )
182
+ {
183
+ EnqueueDelay = 10 ,
184
+ _active = true
185
+ } ;
186
+ publisher . Initialize ( _projectSnapshotManager ) ;
187
+
188
+ // Act
189
+ await RunOnDispatcherThreadAsync ( ( ) =>
190
+ {
191
+ _projectSnapshotManager . DocumentOpened ( hostProject . Key , hostDocument . FilePath , SourceText . From ( string . Empty ) ) ;
192
+ } ) ;
193
+
194
+ // Assert
195
+ Assert . Empty ( publisher . DeferredPublishTasks ) ;
196
+ Assert . True ( serializationSuccessful ) ;
197
+ }
198
+
161
199
[ Theory ]
162
200
[ InlineData ( ProjectChangeKind . DocumentAdded ) ]
163
201
[ InlineData ( ProjectChangeKind . DocumentRemoved ) ]
@@ -586,6 +624,7 @@ private class TestRazorProjectInfoPublisher : RazorProjectInfoPublisher
586
624
587
625
private readonly bool _shouldSerialize ;
588
626
private readonly bool _useRealShouldSerialize ;
627
+ private readonly bool _configurationFileExists ;
589
628
590
629
static TestRazorProjectInfoPublisher ( )
591
630
{
@@ -598,17 +637,19 @@ public TestRazorProjectInfoPublisher(
598
637
ProjectConfigurationFilePathStore projectStatePublishFilePathStore ,
599
638
Action < IProjectSnapshot , string > onSerializeToFile = null ,
600
639
bool shouldSerialize = true ,
601
- bool useRealShouldSerialize = false )
640
+ bool useRealShouldSerialize = false ,
641
+ bool configurationFileExists = true )
602
642
: base ( s_lspEditorFeatureDetector . Object , projectStatePublishFilePathStore , TestRazorLogger . Instance )
603
643
{
604
644
_onSerializeToFile = onSerializeToFile ?? ( ( _1 , _2 ) => throw new XunitException ( "SerializeToFile should not have been called." ) ) ;
605
645
_shouldSerialize = shouldSerialize ;
606
646
_useRealShouldSerialize = useRealShouldSerialize ;
647
+ _configurationFileExists = configurationFileExists ;
607
648
}
608
649
609
650
protected override bool FileExists ( string file )
610
651
{
611
- return true ;
652
+ return _configurationFileExists ;
612
653
}
613
654
614
655
protected override void SerializeToFile ( IProjectSnapshot projectSnapshot , string configurationFilePath ) => _onSerializeToFile ? . Invoke ( projectSnapshot , configurationFilePath ) ;
0 commit comments