Пример #1
0
        public async Task DependenciesGraphProvider_CheckChildrenAsync_TopLevelNodeWithoutId_ShouldGetProviderFromParent()
        {
            var projectPath         = @"c:\myproject\project.csproj";
            var parentNodeIdString  = @"file:///[MyProvider;;;]";
            var nodeFilePath        = @"c:/myproject/MyNodeItemSpec";
            var mockVsHierarchyItem = IVsHierarchyItemFactory.ImplementProperties(
                text: "MyNodeItemSpec",
                parentCanonicalName: parentNodeIdString);
            var inputNode = IGraphContextFactory.CreateNode(projectPath,
                                                            nodeFilePath,
                                                            hierarchyItem: mockVsHierarchyItem);
            var rootNode          = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");
            var existingNode      = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec""
    }
}");
            var existingChildNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec""
    }   
}");

            rootNode.AddChild(existingNode);
            existingNode.Children.Add(existingChildNode);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

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

            var mockProjectContextProvider = IDependenciesGraphProjectContextProviderFactory.Implement(projectPath, mockProvider);
            var mockGraphContext           = IGraphContextFactory.ImplementContainsChildren(inputNode);

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

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.True(inputNode.GetValue <bool>(DgmlNodeProperties.ContainsChildren));
            Assert.NotNull(inputNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty));
            Assert.Equal(existingNode, inputNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty));
            Assert.True(inputNode.GetValue(DependenciesGraphSchema.ProviderProperty) is IProjectDependenciesSubTreeProviderMock);
        }
Пример #2
0
        public async Task DependenciesGraphProvider_CheckChildrenAsync_HasChildrenFalse()
        {
            var projectPath  = @"c:\myproject\project.csproj";
            var nodeIdString = @"file:///[MyProvider;MyNodeItemSpec]";

            var mockVsHierarchyItem = IVsHierarchyItemFactory.ImplementProperties(text: "MyNodeItemSpec");
            var inputNode           = IGraphContextFactory.CreateNode(projectPath,
                                                                      nodeIdString,
                                                                      hierarchyItem: mockVsHierarchyItem);
            var rootNode     = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");
            var existingNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec""
    }
}");

            rootNode.AddChild(existingNode);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

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

            var mockProjectContextProvider = IDependenciesGraphProjectContextProviderFactory.Implement(projectPath, mockProvider);

            var mockGraphContext = IGraphContextFactory.Implement(CancellationToken.None,
                                                                  new HashSet <GraphNode>()
            {
                inputNode
            },
                                                                  GraphContextDirection.Self,
                                                                  new List <GraphProperty> {
                DgmlNodeProperties.ContainsChildren
            });

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

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.False(inputNode.GetValue <bool>(DgmlNodeProperties.ContainsChildren));
            Assert.NotNull(inputNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty));
            Assert.Equal(existingNode, inputNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty));
            Assert.True(inputNode.GetValue(DependenciesGraphSchema.ProviderProperty) is IProjectDependenciesSubTreeProviderMock);
        }
Пример #3
0
        public async Task DependenciesGraphProvider_GetChildrenAsync_WhenPreFilledFolderNode_ShouldNotRefresh()
        {
            // Arrange
            var projectPath   = @"c:\myproject\project.csproj";
            var nodeIdString  = @"file:///[MyProvider;MyNodeItemSpec]";
            var nodeJson      = @"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec""
    }
}";
            var childNodeJson = @"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec""
    }
}";

            var existingNode      = IDependencyNodeFactory.FromJson(nodeJson, DependencyNode.PreFilledFolderNode);
            var existingChildNode = IDependencyNodeFactory.FromJson(childNodeJson, DependencyNode.PreFilledFolderNode);

            existingNode.Children.Add(existingChildNode);

            var inputNode   = IGraphContextFactory.CreateNode(projectPath, nodeIdString, existingNode);
            var outputNodes = new HashSet <GraphNode>();

            var mockGraphContext = IGraphContextFactory.ImplementGetChildrenAsync(inputNode,
                                                                                  trackChanges: true,
                                                                                  outputNodes: outputNodes);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();
            var mockProjectContextProvider =
                IDependenciesGraphProjectContextProviderFactory.Implement(projectPath, mockProvider);

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

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.Equal(1, outputNodes.Count);
            var childGraphNode = outputNodes.First();

            Assert.Equal(existingChildNode,
                         childGraphNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty));
            Assert.True(childGraphNode.GetValue <bool>(DgmlNodeProperties.ContainsChildren));
            Assert.True(childGraphNode.GetValue(
                            DependenciesGraphSchema.ProviderProperty) is IProjectDependenciesSubTreeProviderMock);
            Assert.Equal(1, childGraphNode.IncomingLinkCount);
        }
Пример #4
0
        public async Task DependenciesGraphProvider_CheckChildrenAsync_InvalidNodeData(
            bool canceledToken, string projectPath, string nodeIdString, bool invalidProvider)
        {
            var inputNode = IGraphContextFactory.CreateNode(projectPath, nodeIdString);

            var tcs = new CancellationTokenSource();

            if (canceledToken)
            {
                tcs.Cancel();
            }

            var mockGraphContext = IGraphContextFactory.Implement(tcs.Token,
                                                                  new HashSet <GraphNode>()
            {
                inputNode
            },
                                                                  GraphContextDirection.Self,
                                                                  new List <GraphProperty> {
                DgmlNodeProperties.ContainsChildren
            });
            IProjectDependenciesSubTreeProviderMock mockProvider = invalidProvider
                    ? null
                    : new IProjectDependenciesSubTreeProviderMock();
            var mockProjectContextProvider =
                IDependenciesGraphProjectContextProviderFactory.Implement(projectPath, mockProvider);

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

            // Act
            await provider.BeginGetGraphDataAsync(mockGraphContext);

            // Assert
            Assert.False(inputNode.GetValue <bool>(DgmlNodeProperties.ContainsChildren));
            Assert.Null(inputNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty));
            if (invalidProvider)
            {
                Assert.Null(inputNode.GetValue(DependenciesGraphSchema.ProviderProperty));
            }
        }