public async Task Handle_ExtractCodeBlockWithUsing() { // Arrange var documentPath = "c:/Test.razor"; var documentUri = new Uri(documentPath); var contents = $"@page \"/test\"\n@using System.Diagnostics{Environment.NewLine}@code {{ private var x = 1; }}"; var codeDocument = CreateCodeDocument(contents); var resolver = new ExtractToCodeBehindCodeActionResolver(Dispatcher, CreateDocumentResolver(documentPath, codeDocument), FilePathNormalizer); var actionParams = new ExtractToCodeBehindCodeActionParams { Uri = documentUri, RemoveStart = contents.IndexOf("@code", StringComparison.Ordinal), ExtractStart = contents.IndexOf("{", StringComparison.Ordinal), ExtractEnd = contents.IndexOf("}", StringComparison.Ordinal), RemoveEnd = contents.IndexOf("}", StringComparison.Ordinal), }; var data = JObject.FromObject(actionParams); // Act var workspaceEdit = await resolver.ResolveAsync(data, default); // Assert Assert.NotNull(workspaceEdit); Assert.NotNull(workspaceEdit.DocumentChanges); Assert.Equal(3, workspaceEdit.DocumentChanges !.Count()); var documentChanges = workspaceEdit.DocumentChanges !.ToArray(); var createFileChange = documentChanges[0]; Assert.True(createFileChange.IsCreateFile); var editCodeDocumentChange = documentChanges[1]; Assert.NotNull(editCodeDocumentChange.TextDocumentEdit); var editCodeDocumentEdit = editCodeDocumentChange.TextDocumentEdit !.Edits.First(); Assert.True(editCodeDocumentEdit.Range.Start.TryGetAbsoluteIndex(codeDocument.GetSourceText(), _logger, out var removeStart)); Assert.Equal(actionParams.RemoveStart, removeStart); Assert.True(editCodeDocumentEdit.Range.End.TryGetAbsoluteIndex(codeDocument.GetSourceText(), _logger, out var removeEnd)); Assert.Equal(actionParams.RemoveEnd, removeEnd); var editCodeBehindChange = documentChanges[2]; Assert.NotNull(editCodeBehindChange.TextDocumentEdit); var editCodeBehindEdit = editCodeBehindChange.TextDocumentEdit !.Edits.First(); Assert.Contains("using System.Diagnostics", editCodeBehindEdit.NewText, StringComparison.Ordinal); Assert.Contains("public partial class Test", editCodeBehindEdit.NewText, StringComparison.Ordinal); Assert.Contains("private var x = 1", editCodeBehindEdit.NewText, StringComparison.Ordinal); Assert.Contains("namespace test.Pages", editCodeBehindEdit.NewText, StringComparison.Ordinal); }