public async Task Handle_CreateComponent() { // Arrange var documentPath = "c:/Test.razor"; var documentUri = new Uri(documentPath); var contents = $"@page \"/test\""; var codeDocument = CreateCodeDocument(contents); var resolver = new CreateComponentCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument)); var actionParams = new CreateComponentCodeActionParams { Uri = documentUri, Path = "c:/Another.razor", }; var data = JObject.FromObject(actionParams); // Act var workspaceEdit = await resolver.ResolveAsync(data, default); // Assert Assert.NotNull(workspaceEdit); Assert.NotNull(workspaceEdit.DocumentChanges); Assert.Single(workspaceEdit.DocumentChanges); var documentChanges = workspaceEdit.DocumentChanges.ToArray(); var createFileChange = documentChanges[0]; Assert.True(createFileChange.IsCreateFile); }
public async Task Handle_CreateComponentWithNamespace() { // Arrange var documentPath = "c:/Test.razor"; var documentUri = new Uri(documentPath); var contents = $"@page \"/test\"{Environment.NewLine}@namespace Another.Namespace"; var codeDocument = CreateCodeDocument(contents); var resolver = new CreateComponentCodeActionResolver(new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument)); var actionParams = new CreateComponentCodeActionParams { Uri = documentUri, Path = "c:/Another.razor", }; var data = JObject.FromObject(actionParams); // Act var workspaceEdit = await resolver.ResolveAsync(data, default); // Assert Assert.NotNull(workspaceEdit); Assert.NotNull(workspaceEdit.DocumentChanges); Assert.Equal(2, workspaceEdit.DocumentChanges.Count()); var documentChanges = workspaceEdit.DocumentChanges.ToArray(); var createFileChange = documentChanges[0]; Assert.True(createFileChange.IsCreateFile); var editNewComponentChange = documentChanges[1]; var editNewComponentEdit = editNewComponentChange.TextDocumentEdit.Edits.First(); Assert.Contains("@namespace Another.Namespace", editNewComponentEdit.NewText, StringComparison.Ordinal); }