Ejemplo n.º 1
0
        public async Task DependenciesGraphProvider_SearchAsync()
        {
            // Arrange
            var searchString = "1.0";
            var projectPath  = @"c:\myproject\project.csproj";
            var rootNode     = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");

            var topNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec""
    }
}");
            var topNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec/1.0.0""
    }
}");

            var topNode3 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec3/1.0.0""
    }
}");

            var childNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec1.0""
    }
}");

            var childNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec/1.0.0""
    }
}");

            var childNode3 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec""
    }
}");

            topNode1.Children.Add(childNode1);
            topNode2.Children.Add(childNode3);
            topNode2.Children.Add(childNode2);
            rootNode.AddChild(topNode1);
            rootNode.AddChild(topNode2);
            rootNode.AddChild(topNode3);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

            mockProvider.RootNode = rootNode;
            mockProvider.AddTestDependencyNodes(new[] { topNode1, topNode2, topNode3 });
            mockProvider.AddSearchResults(new[] { topNode1, topNode2, topNode3 });

            var mockProjectContextProvider =
                IDependenciesGraphProjectContextProviderFactory.Implement(
                    projectPath, subTreeProviders: new[] { mockProvider });

            var outputNodes      = new HashSet <GraphNode>();
            var mockGraphContext = IGraphContextFactory.ImplementSearchAsync(searchString,
                                                                             outputNodes: outputNodes);

            var provider = new TestableDependenciesGraphProvider(mockProjectContextProvider,
                                                                 Mock.Of <SVsServiceProvider>(),
                                                                 new IProjectThreadingServiceMock().JoinableTaskContext);

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.Equal(5, outputNodes.Count);

            var outputArray = outputNodes.ToArray();

            // check if top level nodes got CodeNodeCategories.ProjectItem to make sure
            // graph matched them back with IVsHierarchy nodes
            Assert.True(outputArray[0].HasCategory(CodeNodeCategories.ProjectItem));
            Assert.Equal(1, outputArray[0].OutgoingLinkCount);
            Assert.True(outputArray[2].HasCategory(CodeNodeCategories.ProjectItem));
            Assert.Equal(2, outputArray[2].OutgoingLinkCount);

            Assert.False(outputArray[1].HasCategory(CodeNodeCategories.ProjectItem));
            Assert.False(outputArray[3].HasCategory(CodeNodeCategories.ProjectItem));
            Assert.False(outputArray[4].HasCategory(CodeNodeCategories.ProjectItem));
        }
Ejemplo n.º 2
0
        public async Task DependenciesGraphProvider_SearchAsync_TopLevel_GenericNode_WithNormalItemSpec()
        {
            // Arrange
            var searchString = "1.0";
            var projectPath  = @"c:\myproject\project.csproj";
            var rootNode     = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");

            var topNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec""
    }
}", DependencyNode.GenericDependencyFlags);

            ((DependencyNode)topNode1).Name = "TopNodeName";
            var childNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec1.0""
    }
}");

            topNode1.Children.Add(childNode1);
            rootNode.AddChild(topNode1);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

            mockProvider.RootNode = rootNode;
            mockProvider.AddTestDependencyNodes(new[] { topNode1 });
            mockProvider.AddSearchResults(new[] { topNode1 });

            var mockProjectContextProvider =
                IDependenciesGraphProjectContextProviderFactory.Implement(
                    projectPath, subTreeProviders: new[] { mockProvider });

            var outputNodes      = new HashSet <GraphNode>();
            var mockGraphContext = IGraphContextFactory.ImplementSearchAsync(searchString,
                                                                             outputNodes: outputNodes);

            var provider = new TestableDependenciesGraphProvider(mockProjectContextProvider,
                                                                 Mock.Of <SVsServiceProvider>(),
                                                                 new IProjectThreadingServiceMock().JoinableTaskContext);

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.Equal(2, outputNodes.Count);

            var outputArray = outputNodes.ToArray();

            // check if top level nodes got CodeNodeCategories.ProjectItem to make sure
            // graph matched them back with IVsHierarchy nodes
            Assert.True(outputArray[0].HasCategory(CodeNodeCategories.ProjectItem));
            Assert.Equal(1, outputArray[0].OutgoingLinkCount);
            Assert.Equal(@"c:/myproject/mytopnodeitemspec", outputArray[0].Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File).AbsolutePath);
            Assert.False(outputArray[1].HasCategory(CodeNodeCategories.ProjectItem));
        }
Ejemplo n.º 3
0
        public async Task DependenciesGraphProvider_SearchAsync()
        {
            // Arrange
            var searchString = "1.0";
            var projectPath  = @"c:\myproject\project.csproj";
            var rootNode     = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");

            var topNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec""
    }
}");
            var topNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec/1.0.0""
    }
}");

            var topNode3 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyTopNodeItemSpec3/1.0.0""
    }
}");

            var childNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec1.0""
    }
}");

            var childNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec/1.0.0""
    }
}");

            var childNode3 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec""
    }
}");

            topNode1.AddChild(childNode1);
            topNode2.AddChild(childNode3);
            topNode2.AddChild(childNode2);
            rootNode.AddChild(topNode1);
            rootNode.AddChild(topNode2);
            rootNode.AddChild(topNode3);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock
            {
                RootNode = rootNode
            };

            mockProvider.AddTestDependencyNodes(new[] { topNode1, topNode2, topNode3 });
            mockProvider.AddSearchResults(new[] { topNode1, topNode2, topNode3 });

            var mockProjectContextProvider =
                IDependenciesGraphProjectContextProviderFactory.Implement(
                    projectPath, subTreeProviders: new[] { mockProvider });

            var outputNodes      = new HashSet <GraphNode>();
            var mockGraphContext = IGraphContextFactory.ImplementSearchAsync(searchString,
                                                                             outputNodes: outputNodes);

            var provider = new TestableDependenciesGraphProvider(mockProjectContextProvider,
                                                                 Mock.Of <SVsServiceProvider>(),
                                                                 new IProjectThreadingServiceMock().JoinableTaskContext);

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.Equal(4, outputNodes.Count);

            var topNode1Result = GetNodeById(projectPath, outputNodes, topNode1.Id);

            Assert.True(topNode1Result.HasCategory(CodeNodeCategories.ProjectItem));
            Assert.Equal(1, topNode1Result.OutgoingLinkCount);

            var topNode2Result = GetNodeById(projectPath, outputNodes, topNode2.Id);

            Assert.Equal(1, topNode2Result.OutgoingLinkCount);
            Assert.True(topNode2Result.HasCategory(CodeNodeCategories.ProjectItem));

            var childNode1Result = GetNodeById(projectPath, outputNodes, childNode1.Id);

            Assert.Equal(0, childNode1Result.OutgoingLinkCount);
            Assert.False(childNode1Result.HasCategory(CodeNodeCategories.ProjectItem));

            var childNode2Result = GetNodeById(projectPath, outputNodes, childNode2.Id);

            Assert.Equal(0, childNode2Result.OutgoingLinkCount);
            Assert.False(childNode2Result.HasCategory(CodeNodeCategories.ProjectItem));
        }