Skip to content

Commit 26cc4aa

Browse files
committed
Add new test to fully represent the real world case
This was mostly covered by other tests, but they used the project snapshot manager directly.
1 parent 4e7a407 commit 26cc4aa

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorProjectServiceTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,44 @@ await _projectService.UpdateProjectAsync(
182182
Assert.Empty(miscProject.DocumentFilePaths);
183183
}
184184

185+
[Fact]
186+
public async Task UpdateProject_MovesDocumentsFromMisc_ViaService()
187+
{
188+
// Arrange
189+
const string DocumentFilePath = "C:/path/to/file.cshtml";
190+
const string ProjectFilePath = "C:/path/to/project.csproj";
191+
const string IntermediateOutputPath = "C:/path/to/obj";
192+
const string RootNamespace = "TestRootNamespace";
193+
194+
var ownerProjectKey = await _projectService.AddProjectAsync(
195+
ProjectFilePath, IntermediateOutputPath, RazorConfiguration.Default, RootNamespace, displayName: null, DisposalToken);
196+
197+
await _projectService.AddDocumentToMiscProjectAsync(DocumentFilePath, DisposalToken);
198+
199+
var miscProject = await _snapshotResolver.GetMiscellaneousProjectAsync(DisposalToken);
200+
201+
var project = _projectManager.GetLoadedProject(ownerProjectKey);
202+
203+
var addedDocument = new DocumentSnapshotHandle(DocumentFilePath, DocumentFilePath, FileKinds.Legacy);
204+
205+
// Act
206+
await _projectService.UpdateProjectAsync(
207+
project.Key,
208+
project.Configuration,
209+
project.RootNamespace,
210+
project.DisplayName,
211+
ProjectWorkspaceState.Default,
212+
[addedDocument],
213+
DisposalToken);
214+
215+
// Assert
216+
project = _projectManager.GetLoadedProject(ownerProjectKey);
217+
var projectFilePaths = project.DocumentFilePaths.OrderBy(path => path);
218+
Assert.Equal(projectFilePaths, [addedDocument.FilePath]);
219+
miscProject = _projectManager.GetLoadedProject(miscProject.Key);
220+
Assert.Empty(miscProject.DocumentFilePaths);
221+
}
222+
185223
[Fact]
186224
public async Task UpdateProject_MovesExistingDocumentToMisc()
187225
{

0 commit comments

Comments
 (0)