Ejemplo n.º 1
0
        public void DontCrash_VB_2()
        {
            var code             = @"
Public Class Class1
    Public Custom Event Event2 As EventHandler
        AddHandler(ByVal value As EventHandler)
        End AddHandler
        RemoveHandler(ByVal value As EventHandler)
        End RemoveHandler
        RaiseEvent(ByVal sender As Object, ByVal e As EventArgs)
            e
    End Event

End Class
";
            var document         = CreateDocument(code, LanguageNames.VisualBasic);
            var semanticModel    = document.GetSemanticModelAsync().Result;
            var root             = document.GetSyntaxRootAsync().Result;
            var accessor         = root.DescendantNodes().OfType <VisualBasic.Syntax.AccessorBlockSyntax>().Last();
            var factory          = new SemanticModelWorkspaceServiceFactory();
            var provider         = WorkspaceService.GetProvider(document.Project.Solution.Workspace);
            var service          = (ISemanticModelService)factory.CreateService(provider);
            var newSemanticModel = service.GetSemanticModelForNodeAsync(document, accessor, CancellationToken.None).Result;

            Assert.NotNull(newSemanticModel);
            var newDocument = CreateDocument(code, LanguageNames.VisualBasic);
            var newRoot     = newDocument.GetSyntaxRootAsync().Result;
            var newAccessor = newRoot.DescendantNodes().OfType <VisualBasic.Syntax.AccessorBlockSyntax>().Last();

            root             = root.ReplaceNode(accessor, newAccessor);
            document         = document.WithSyntaxRoot(root);
            accessor         = root.DescendantNodes().OfType <VisualBasic.Syntax.AccessorBlockSyntax>().Last();
            newSemanticModel = service.GetSemanticModelForNodeAsync(document, accessor, CancellationToken.None).Result;
            Assert.NotNull(newSemanticModel);
            var cleanDocument = CodeCleaner.CleanupAsync(document).Result;

            Assert.Equal(document, cleanDocument);
        }
Ejemplo n.º 2
0
 public TestWorkspace(IWorkspaceServiceProvider workspaceServiceProvider = null)
     : base(workspaceServiceProvider ?? WorkspaceService.GetProvider(new CustomWorkspace()))
 {
 }