public IList<Diagnostic> GetDocumentDiagnostics(Document document = null)
 {
     document = document ?? this.Workspace.CurrentSolution.GetDocument(_hostDocument.Id);
     var analyzer = new RenameTrackingDiagnosticAnalyzer();
     return DiagnosticProviderTestUtilities.GetDocumentDiagnostics(analyzer, document, document.GetSyntaxRootAsync(CancellationToken.None).Result.FullSpan).ToList();
 }
 public async Task<IList<Diagnostic>> GetDocumentDiagnosticsAsync(Document document = null)
 {
     document = document ?? this.Workspace.CurrentSolution.GetDocument(_hostDocument.Id);
     var analyzer = new RenameTrackingDiagnosticAnalyzer();
     return (await DiagnosticProviderTestUtilities.GetDocumentDiagnosticsAsync(analyzer, document,
         (await document.GetSyntaxRootAsync()).FullSpan)).ToList();
 }
        public void AssertTag(string expectedFromName, string expectedToName, bool invokeAction = false, int actionIndex = 0)
        {
            WaitForAsyncOperations();

            var tags = _tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(_view.TextBuffer.CurrentSnapshot, new Span(0, _view.TextBuffer.CurrentSnapshot.Length))));

            // There should only ever be one tag
            Assert.Equal(1, tags.Count());

            var tag = tags.Single();

            var document = this.Workspace.CurrentSolution.GetDocument(_hostDocument.Id);

            var analyzer = new RenameTrackingDiagnosticAnalyzer();
            var diagnostics = DiagnosticProviderTestUtilities.GetDocumentDiagnostics(analyzer, document, tag.Span.Span.ToTextSpan()).ToList();

            // There should be a single rename tracking diagnostic
            Assert.Equal(1, diagnostics.Count);
            Assert.Equal(RenameTrackingDiagnosticAnalyzer.DiagnosticId, diagnostics[0].Id);

            var actions = new List<CodeAction>();
            var context = new CodeFixContext(document, diagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
            _codeFixProvider.RegisterCodeFixesAsync(context).Wait();

            // There should be two actions
            Assert.Equal(2, actions.Count);

            Assert.Equal(string.Format("Rename '{0}' to '{1}'", expectedFromName, expectedToName), actions[0].Title);
            Assert.Equal(string.Format("Rename '{0}' to '{1}' with preview...", expectedFromName, expectedToName), actions[1].Title);

            if (invokeAction)
            {
                var operations = actions[actionIndex]
                    .GetOperationsAsync(CancellationToken.None)
                    .WaitAndGetResult(CancellationToken.None)
                    .ToArray();

                Assert.Equal(1, operations.Length);

                operations[0].Apply(this.Workspace, CancellationToken.None);
            }
        }