コード例 #1
0
        public async Task DependenciesGraphProvider_GetChildrenAsync()
        {
            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);
            var existingChildNode = IDependencyNodeFactory.FromJson(childNodeJson);

            existingNode.Children.Add(existingChildNode);

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

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

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

            var mockProjectContextProvider = IDependenciesGraphProjectContextProviderFactory.Implement(projectPath, mockProvider);
            var mockGraphContext           = IGraphContextFactory.ImplementGetChildrenAsync(inputNode,
                                                                                            trackChanges: true,
                                                                                            outputNodes: outputNodes);

            var provider = new TestableDependenciesGraphProvider(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.False(childGraphNode.GetValue <bool>(DgmlNodeProperties.ContainsChildren));
            var childProjectPath = childGraphNode.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.Assembly);

            Assert.Equal(projectPath.Replace('\\', '/'), childProjectPath.AbsolutePath);
            var childSubTreeProvider = childGraphNode.GetValue(DependenciesGraphSchema.ProviderProperty);

            Assert.True(childSubTreeProvider is IProjectDependenciesSubTreeProviderMock);
            Assert.Equal("MyDefaultTestProvider", ((IProjectDependenciesSubTreeProviderMock)childSubTreeProvider).ProviderTestType);
            Assert.Equal(1, childGraphNode.IncomingLinkCount);
            Assert.Equal(1, provider.GetRegisteredSubTreeProviders().Count());
        }
コード例 #2
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);
        }
コード例 #3
0
        public async Task DependenciesGraphProvider_GetChildrenAsync_NoNodeAttachedToInputNode_ShouldDiscoverItAgain()
        {
            var projectPath       = @"c:\myproject\project.csproj";
            var nodeIdString      = @"file:///[MyProvider;MyNodeItemSpec]";
            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 mockVsHierarchyItem = IVsHierarchyItemFactory.ImplementProperties(text: "MyNodeItemSpec");
            var inputNode           = IGraphContextFactory.CreateNode(projectPath,
                                                                      nodeIdString,
                                                                      hierarchyItem: mockVsHierarchyItem);
            var outputNodes = new HashSet <GraphNode>();

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

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

            var mockProjectContextProvider = IDependenciesGraphProjectContextProviderFactory.Implement(projectPath, mockProvider);
            var mockGraphContext           = IGraphContextFactory.ImplementGetChildrenAsync(inputNode,
                                                                                            trackChanges: true,
                                                                                            outputNodes: outputNodes);

            var provider = new TestableDependenciesGraphProvider(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.False(childGraphNode.GetValue <bool>(DgmlNodeProperties.ContainsChildren));
            Assert.True(childGraphNode.GetValue(DependenciesGraphSchema.ProviderProperty) is IProjectDependenciesSubTreeProviderMock);
            Assert.Equal(1, childGraphNode.IncomingLinkCount);
            Assert.Equal(1, provider.GetRegisteredSubTreeProviders().Count());
        }