Exemplo n.º 1
0
        internal static Project ApplyOperation(this Project project, CodeActionOperation operation)
        {
            var workspace = project.Solution.Workspace;

            operation.Apply(workspace, CancellationToken.None);
            return(workspace.CurrentSolution.GetProject(project.Id) !);
        }
Exemplo n.º 2
0
        public static void TestAssertingEndText(
            string sampleClassCode,
            TextSpan refactoringSiteTextSpan,
            Action <string> assertion,
            int refactoringNumber = 0)
        {
            TestAsertingRefactorings(
                sampleClassCode,
                refactoringSiteTextSpan,
                (workspace, document, proposedCodeRefactorings) =>
            {
                CodeAction refactoring        = proposedCodeRefactorings.ElementAt(refactoringNumber);
                CodeActionOperation operation = refactoring
                                                .GetOperationsAsync(CancellationToken.None)
                                                .Result
                                                .Single();

                operation.Apply(workspace, CancellationToken.None);

                Document newDocument = workspace.CurrentSolution.GetDocument(document.Id);

                SourceText newText = newDocument.GetTextAsync(CancellationToken.None).Result;

                string text = newText.ToString();

                assertion(text);
            });
        }
Exemplo n.º 3
0
        private static void VerifyOperationText([NotNull] CodeActionOperation operation, [NotNull] string expectedCode,
                                                [NotNull] Document document)
        {
            Workspace workspace = document.Project.Solution.Workspace;

            operation.Apply(workspace, CancellationToken.None);

            Document newDocument = workspace.CurrentSolution.GetDocument(document.Id);

            SourceText sourceText = newDocument.GetTextAsync().Result;
            string     text       = sourceText.ToString();

            text.Should().Be(expectedCode);
        }
Exemplo n.º 4
0
        private async Task CodeActionAsync(CodeAction codeAction, Document document, string expectedCode)
        {
            ImmutableArray <CodeActionOperation> operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;

            Assert.Single(operations);

            CodeActionOperation operation = operations.First();
            Workspace           workspace = document.Project.Solution.Workspace;

            operation.Apply(workspace, CancellationToken.None);

            Document newDocument = workspace.CurrentSolution.GetDocument(document.Id);

            SourceText sourceText = await newDocument.GetTextAsync(CancellationToken.None).ConfigureAwait(false);

            string text = sourceText.ToString();

            Assert.Equal(expectedCode, text);
        }
        public static void CodeAction([NotNull] CodeAction codeAction, [NotNull] Document document,
                                      [NotNull] string expectedCode)
        {
            Guard.NotNull(codeAction, nameof(codeAction));
            Guard.NotNull(document, nameof(document));
            Guard.NotNull(expectedCode, nameof(expectedCode));

            ImmutableArray <CodeActionOperation> operations =
                codeAction.GetOperationsAsync(CancellationToken.None).Result;

            operations.Should().HaveCount(1);

            CodeActionOperation operation = operations.Single();
            Workspace           workspace = document.Project.Solution.Workspace;

            operation.Apply(workspace, CancellationToken.None);

            Document newDocument = workspace.CurrentSolution.GetDocument(document.Id);

            SourceText sourceText = newDocument.GetTextAsync().Result;
            string     text       = sourceText.ToString();

            text.Should().Be(expectedCode);
        }
 public void Apply(object workspace, CancellationToken cancellationToken)
 {
     _inner.Apply(workspace as Microsoft.CodeAnalysis.Workspace, cancellationToken);
 }