Ejemplo n.º 1
0
        public void ChangeMemberVisibility_ShouldChangeVisibilityOfNode_WhenSpecificNodeIsPassed()
        {
            // Given
            var source = @"
                public void foo() {
                    var a = 10;
                }
            ";

            var underTest = new ChangeMemberVisibilityRunnable
            {
                Visibility = "private"
            };

            var workspace         = new AdhocWorkspace();
            var project           = workspace.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "test", "test-asm", LanguageNames.CSharp));
            var document          = workspace.AddDocument(project.Id, "test-document", SourceText.From(source));
            var documentContext   = new CompilationContext(workspace, document);
            var compilationUnit   = document.GetSyntaxRootAsync().Result as CompilationUnitSyntax;
            var memberDeclaration = compilationUnit.DescendantNodes()
                                    .OfType <MethodDeclarationSyntax>()
                                    .Single(m => m.Identifier.ValueText == "foo");

            // When
            var result = underTest.Run(memberDeclaration, documentContext).ToFullString();

            // Then
            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 2
0
        public void ChangeMemberVisibility_ShouldChangeVisibilityOfNode_WhenSpecificNodeIsPassed()
        {
            // Given
            var source = @"
                public void foo() {
                    var a = 10;
                }
            ";

            var underTest = new ChangeMemberVisibilityRunnable
            {
                Visibility = "private"
            };

            var workspace = new AdhocWorkspace();
            var project = workspace.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "test", "test-asm", LanguageNames.CSharp));
            var document = workspace.AddDocument(project.Id, "test-document", SourceText.From(source));
            var documentContext = new CompilationContext(workspace, document);
            var compilationUnit = document.GetSyntaxRootAsync().Result as CompilationUnitSyntax;
            var memberDeclaration = compilationUnit.DescendantNodes()
                                                   .OfType<MethodDeclarationSyntax>()
                                                   .Single(m => m.Identifier.ValueText == "foo");

            // When
            var result = underTest.Run(memberDeclaration, documentContext).ToFullString();

            // Then
            Assert.That(result, Is.Not.Null);
        }