public override async Task <IList <UnitTestLocation> > GatherUnitTests(IUnitTestMarkers[] unitTestMarkers, CancellationToken token) { var analysisDocument = DocumentContext.AnalysisDocument; if (analysisDocument == null) { return(emptyList); } var semanticModel = await analysisDocument.GetSemanticModelAsync(token); if (semanticModel == null) { return(emptyList); } if (!HasMethodMarkerAttribute(semanticModel, unitTestMarkers)) { return(emptyList); } var visitor = new NUnitVisitor(semanticModel, unitTestMarkers, token); try { visitor.Visit(semanticModel.SyntaxTree.GetRoot(token)); } catch (OperationCanceledException) { throw; }catch (Exception ex) { LoggingService.LogError("Exception while analyzing ast for unit tests.", ex); return(emptyList); } return(visitor.FoundTests); }
public override Task <IList <UnitTestLocation> > GatherUnitTests(IUnitTestMarkers[] unitTestMarkers, CancellationToken token) { var parsedDocument = DocumentContext.ParsedDocument; if (parsedDocument == null) { return(Task.FromResult(emptyList)); } var semanticModel = parsedDocument.GetAst <SemanticModel> (); if (semanticModel == null) { return(Task.FromResult(emptyList)); } var visitor = new NUnitVisitor(semanticModel, unitTestMarkers, token); try { visitor.Visit(semanticModel.SyntaxTree.GetRoot(token)); } catch (OperationCanceledException) { throw; }catch (Exception ex) { LoggingService.LogError("Exception while analyzing ast for unit tests.", ex); return(Task.FromResult(emptyList)); } return(Task.FromResult(visitor.FoundTests)); }
internal IList <UnitTestLocation> GatherUnitTests() { var resolver = document.GetSharedResolver(); if (resolver == null || resolver.Result == null) { return(null); } var parsedDocument = document.ParsedDocument; if (parsedDocument == null) { return(null); } var syntaxTree = parsedDocument.GetAst <SyntaxTree> (); if (syntaxTree == null) { return(null); } var visitor = new NUnitVisitor(resolver.Result); try { visitor.VisitSyntaxTree(syntaxTree); } catch (Exception ex) { LoggingService.LogError("Exception while analyzing ast for unit tests.", ex); return(null); } return(visitor.FoundTests); }
public override IList<UnitTestLocation> GatherUnitTests () { var resolver = document.GetSharedResolver (); if (resolver == null || resolver.Result == null) return null; var parsedDocument = document.ParsedDocument; if (parsedDocument == null) return null; var syntaxTree = parsedDocument.GetAst<SyntaxTree> (); if (syntaxTree == null) return null; var visitor = new NUnitVisitor (resolver.Result); try { visitor.VisitSyntaxTree (syntaxTree); } catch (Exception ex) { LoggingService.LogError ("Exception while analyzing ast for unit tests.", ex); return null; } return visitor.FoundTests; }
public override Task<IList<UnitTestLocation>> GatherUnitTests (CancellationToken token) { var parsedDocument = DocumentContext.ParsedDocument; if (parsedDocument == null) return Task.FromResult (emptyList); var semanticModel = parsedDocument.GetAst<SemanticModel> (); if (semanticModel == null) return Task.FromResult (emptyList); var visitor = new NUnitVisitor (semanticModel, token); try { visitor.Visit (semanticModel.SyntaxTree.GetRoot (token)); } catch (OperationCanceledException) { throw; }catch (Exception ex) { LoggingService.LogError ("Exception while analyzing ast for unit tests.", ex); return Task.FromResult (emptyList); } return Task.FromResult (visitor.FoundTests); }
void HandleDocumentParsed (object sender, EventArgs e) { if (!AnalysisOptions.EnableUnitTestEditorIntegration) return; src.Cancel (); src = new CancellationTokenSource (); var token = src.Token; ThreadPool.QueueUserWorkItem (delegate { var resolver = document.GetSharedResolver (); if (resolver == null || resolver.Result == null) return; var visitor = new NUnitVisitor (resolver.Result); try { visitor.VisitSyntaxTree (document.ParsedDocument.GetAst<SyntaxTree> ()); } catch (Exception ex) { LoggingService.LogError ("Exception while analyzing ast for unit tests.", ex); return; } if (token.IsCancellationRequested) return; Application.Invoke (delegate { if (document.Editor.Parent.ActionMargin.IsVisible ^ (visitor.FoundTests.Count > 0)) document.Editor.Parent.QueueDraw (); document.Editor.Parent.ActionMargin.IsVisible = visitor.FoundTests.Count > 0; foreach (var oldMarker in currentMarker) document.Editor.Document.RemoveMarker (oldMarker); foreach (var foundTest in visitor.FoundTests) { if (token.IsCancellationRequested) return; var unitTestMarker = new UnitTestMarker (foundTest, document); currentMarker.Add (unitTestMarker); document.Editor.Document.AddMarker (foundTest.LineNumber, unitTestMarker); } }); }); }
void HandleDocumentParsed(object sender, EventArgs e) { if (!AnalysisOptions.EnableUnitTestEditorIntegration) { return; } src.Cancel(); src = new CancellationTokenSource(); var token = src.Token; ThreadPool.QueueUserWorkItem(delegate { var resolver = document.GetSharedResolver(); if (resolver == null || resolver.Result == null) { return; } var visitor = new NUnitVisitor(resolver.Result); try { visitor.VisitSyntaxTree(document.ParsedDocument.GetAst <SyntaxTree> ()); } catch (Exception ex) { LoggingService.LogError("Exception while analyzing ast for unit tests.", ex); return; } if (token.IsCancellationRequested) { return; } Application.Invoke(delegate { var editor = document.Editor; if (editor == null) { return; } var textEditor = editor.Parent; if (textEditor == null) { return; } var actionMargin = textEditor.ActionMargin; if (actionMargin == null) { return; } if (actionMargin.IsVisible ^ (visitor.FoundTests.Count > 0)) { textEditor.QueueDraw(); } actionMargin.IsVisible = visitor.FoundTests.Count > 0; foreach (var oldMarker in currentMarker) { editor.Document.RemoveMarker(oldMarker); } foreach (var foundTest in visitor.FoundTests) { if (token.IsCancellationRequested) { return; } var unitTestMarker = new UnitTestMarker(foundTest, document); currentMarker.Add(unitTestMarker); editor.Document.AddMarker(foundTest.LineNumber, unitTestMarker); } }); }); }
public UnitTestMarker(NUnitVisitor.UnitTest unitTest, MonoDevelop.Ide.Gui.Document doc) { this.unitTest = unitTest; this.doc = doc; }