示例#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_NodeDoesNotExistAnyMore()
        {
            // Arrange
            var projectPath  = @"c:\myproject\project.csproj";
            var nodeIdString = @"file:///[MyProvider;MyNodeItemSpec]";
            var nodeJson     = @"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec""
    }
}";
            var existingNode = IDependencyNodeFactory.FromJson(nodeJson);
            var inputNode    = IGraphContextFactory.CreateNode(projectPath, nodeIdString, existingNode);

            var mockGraphContext = IGraphContextFactory.Implement(CancellationToken.None,
                                                                  new HashSet <GraphNode>()
            {
                inputNode
            },
                                                                  GraphContextDirection.Contains);

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

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

            // Act (if something is wrong, there would be exception since we did not provide more mocks)
            await provider.BeginGetGraphDataAsync(mockGraphContext);
        }
示例#3
0
        public async Task DependenciesGraphProvider_GetChildrenAsync_InvalidNodeData_NoId(
            bool canceledToken, string projectPath, string nodeJson)
        {
            // Arrange
            var nodeIdString = @"";
            var tcs          = new CancellationTokenSource();

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

            var existingNode = IDependencyNodeFactory.FromJson(nodeJson);
            var inputNode    = IGraphContextFactory.CreateNode(projectPath, nodeIdString, existingNode);

            var mockGraphContext = IGraphContextFactory.Implement(tcs.Token,
                                                                  new HashSet <GraphNode>()
            {
                inputNode
            },
                                                                  GraphContextDirection.Contains);

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

            // Act (if something is wrong, there would be exception since we did not provide more mocks)
            await provider.BeginGetGraphDataAsync(mockGraphContext);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
0
        public void NuGetDependenciesSubTreeProvider_GetDependencyNode_WhenNodeIsNotInSnapshotReturnNull()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

            var nodeJson     = @"
{
    ""Id"": {
        ""ProviderType"": ""NuGetDependency"",
        ""ItemSpec"": ""tfm1/PackageToRemove/1.0.0"",
        ""ItemType"": ""PackageReference""
    }
}";
            var existingNode = IDependencyNodeFactory.FromJson(nodeJson);

            var resultNode = provider.GetDependencyNode(existingNode.Id);

            Assert.Null(resultNode);
        }
示例#8
0
        public void NuGetDependenciesSubTreeProvider_GetDependencyNode_WhenNodeIsInCacheJustReturn()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

            var nodeJson     = @"
{
    ""Id"": {
        ""ProviderType"": ""NuGetDependency"",
        ""ItemSpec"": ""tfm1/PackageToRemove/1.0.0"",
        ""ItemType"": ""PackageReference""
    }
}";
            var existingNode = IDependencyNodeFactory.FromJson(nodeJson);

            provider.SetCurrentSnapshotNodesCache(new[] { existingNode });

            var resultNode = provider.GetDependencyNode(existingNode.Id);

            Assert.Equal(existingNode, resultNode);
        }
示例#9
0
        public async Task DependenciesGraphProvider_TrackChangesAsync_InvalidNodeData(
            string projectPath, bool existingNodeSpecified, bool updatedNodeProvided)
        {
            var nodeIdString = @"file:///[MyProvider;MyNodeItemSpec]";
            var inputNode    = IGraphContextFactory.CreateNode(projectPath, nodeIdString);

            var existingNode      = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec""
    }
}");
            var existingChildNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpecExisting""
    }
}");

            var existingRefreshedNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec""
    }
}");
            var newChildNode          = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpecNew""
    }
}");

            existingNode.Children.Add(existingChildNode);
            existingRefreshedNode.AddChild(newChildNode);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

            if (updatedNodeProvided)
            {
                mockProvider.AddTestDependencyNodes(new[] { existingRefreshedNode });
            }

            if (existingNodeSpecified)
            {
                inputNode.SetValue(DependenciesGraphSchema.DependencyNodeProperty, existingNode);
            }

            inputNode.SetValue(DependenciesGraphSchema.ProviderProperty, mockProvider);

            var outputNodes      = new HashSet <GraphNode>();
            var mockGraphContext = IGraphContextFactory.ImplementTrackChanges(inputNode, outputNodes);

            var updatedProjectContext =
                IDependenciesGraphProjectContextProviderFactory.ImplementProjectContext(projectPath);

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

            provider.AddExpandedGraphContext(mockGraphContext);

            // Act
            await provider.TrackChangesAsync(updatedProjectContext);

            // Assert
            Assert.Equal(0, outputNodes.Count);
        }
示例#10
0
        public async Task DependenciesGraphProvider_TrackChangesAsync_WithContextProject()
        {
            var projectPath        = @"c:\myproject\project.csproj";
            var contextProjectPath = @"c:\mycontextproject\project.csproj";
            var nodeIdString       = @"file:///[MyProvider;MyNodeItemSpec]";
            var inputNode          = IGraphContextFactory.CreateNode(projectPath, nodeIdString);

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

            existingNode.Id.ContextProject = contextProjectPath;
            var existingChildNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpecExisting""
    }
}");

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

            existingRefreshedNode.Id.ContextProject = contextProjectPath;

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

            existingNode.Children.Add(existingChildNode);
            existingRefreshedNode.AddChild(newChildNode);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

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

            inputNode.SetValue(DependenciesGraphSchema.DependencyNodeProperty, existingNode);
            inputNode.SetValue(DependenciesGraphSchema.ProviderProperty, mockProvider);

            var outputNodes      = new HashSet <GraphNode>();
            var mockGraphContext = IGraphContextFactory.ImplementTrackChanges(inputNode, outputNodes);

            var updatedProjectContext =
                IDependenciesGraphProjectContextProviderFactory.ImplementProjectContext(contextProjectPath);

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

            provider.AddExpandedGraphContext(mockGraphContext);

            // Act
            await provider.TrackChangesAsync(updatedProjectContext);

            // Assert
            Assert.Equal(1, outputNodes.Count);
            var outputNode       = outputNodes.First();
            var outputDependency = outputNode.GetValue <IDependencyNode>(DependenciesGraphSchema.DependencyNodeProperty);

            Assert.Equal(newChildNode.Id, outputDependency.Id);
            var childProjectPath = outputNode.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.Assembly);

            Assert.Equal(contextProjectPath.Replace('\\', '/'), childProjectPath.AbsolutePath);
        }
        public async Task SdkDependenciesSubTreeProvider_SearchAsync()
        {
            // Arrange
            const string packageItemSpec = "MyPackage1";

            var existingNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec1""
    },
    ""Properties"": {
        ""SDKPackageItemSpec"": ""MyPackage1""
    }
}");

            var existingNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec2""
    },
    ""Properties"": {
    }
}");

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

            var searchResultNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec2""
    },
    ""Properties"": {
        ""SDKPackageItemSpec"": ""SomeUnknownPackage""
    }
}");

            var searchResults = new[] { searchResultNode1, searchResultNode2 };

            var nugetPackagesDataProvider =
                INuGetPackagesDataProviderFactory.ImplementSearchAsync(packageItemSpec, "xxx", searchResults);

            var provider = new TestableSdkDependenciesSubTreeProvider(nugetPackagesDataProvider);

            // Successful scenario
            // Act
            var resultNodes = await provider.SearchAsync(existingNode1, "xxx");

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

            // node does not have proprty SDKPackageItemSpecProperty
            // Act
            resultNodes = await provider.SearchAsync(existingNode2, "xxx");

            // Assert
            Assert.Null(resultNodes);
        }
示例#12
0
        public void DependenciesSubTreeProviderBase_ProcessDependenciesChanges_WhenAnyChangesFalse_ShouldSkip()
        {
            var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{
    ""ProjectChanges"": {
        ""rulenameResolved"": {
            ""After"": {
                ""Items"": {
                    ""item21"": {
                        ""OriginalItemSpec"":""item1""
                    },
                    ""item22"": {
                        ""OriginalItemSpec"":""item2""
                    },
                    ""itemWithoutOriginalItemSpec"": {
                    }
                },
                ""RuleName"":""rulenameResolved""
            },
            ""Before"": {
                ""Items"": {
                    ""resolvedItemTobeRemoved"": {
                        ""OriginalItemSpec"":""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem""
                    }
                },
                ""RuleName"":""rulenameResolved""
            },
            ""Difference"": {
                ""AddedItems"": [ ""item21"", ""item22"", ""itemWithoutOriginalItemSpec"", ""itemWithoutPropertiesInAfter"" ],
                ""ChangedItems"": [ ],
                ""RemovedItems"": [ ""resolvedItemTobeRemoved"" ],
                ""AnyChanges"": ""false""
            },
        },
        ""rulenameUnresolved"": {
            ""After"": {
                ""Items"": {
                    ""item1"": {
                    },
                    ""item2"": {
                    },
                    ""item3"": {
                    },
                    ""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"": {
                    }
                },
                ""RuleName"":""rulenameUnresolved""
            },
            ""Difference"": {
                ""AddedItems"": [ ""item1"", ""item2"", ""item3"" ],
                ""ChangedItems"": [ ],
                ""RemovedItems"": [ ""item4"", ""itemNotInRootNode"", ""itemWithoutPropertiesInAfter"" ],
                ""AnyChanges"": ""false""
            },
        }
    }
}");
            var rootNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");

            var item4Node = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""item4"",
        ""ItemType"": ""myUnresolvedItemType""
    }
}");

            var resolvedItemTobeRemovedNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""resolvedItemTobeRemoved"",
        ""ItemType"": ""myUnresolvedItemType""
    }
}");

            rootNode.AddChild(item4Node);
            rootNode.AddChild(resolvedItemTobeRemovedNode);

            var catalogs = IProjectCatalogSnapshotFactory.ImplementRulesWithItemTypes(
                new Dictionary <string, string>
            {
                { "rulenameResolved", "myResolvedItemType" },
                { "rulenameUnresolved", "myUnresolvedItemType" }
            });

            var provider = new TestableDependenciesSubTreeProviderBase();

            // set itemTypes to process
            provider.SetResolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameResolved"));
            provider.SetUnresolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameUnresolved"));
            provider.SetRootNode(rootNode);

            // Act
            var resultChanges = provider.TestProcessDependenciesChanges(projectSubscriptionUpdate, catalogs);

            // Assert
            Assert.NotNull(resultChanges);
            Assert.Equal(0, resultChanges.AddedNodes.Count);
            Assert.Equal(0, resultChanges.RemovedNodes.Count);
        }
示例#13
0
        public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_RemoveDependency()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

            var snapshotJson = @"
{
    ""NodesCache"": [ 
        {
            ""Id"": {
                ""ProviderType"": ""NuGetDependency"",
                ""ItemSpec"": ""tfm1/Package2/1.0.0"",
                ""ItemType"": ""PackageReference""
            },
        },
        {
            ""Id"": {
                ""ProviderType"": ""NuGetDependency"",
                ""ItemSpec"": ""tfm1/PackageChild1/1.0.0"",
                ""ItemType"": ""PackageReference""
            }
        },
        {
            ""Id"": {
                ""ProviderType"": ""NuGetDependency"",
                ""ItemSpec"": ""tfm1/PackageToStayInCache/1.0.0"",
                ""ItemType"": ""PackageReference""
            }
        }
    ],
    ""DependenciesWorld"": [
        {
            ""ItemSpec"": ""tfm1/Package2/1.0.0"",
            ""Properties"": {
                ""Name"": ""Package2"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Package"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": ""Package3/2.0.0;NotExistentPackage/2.0.0;Assembly1/1.0.0;FrameworkAssembly1/4.0.0;SomeUnknown/1.0.0""
            }
        }
    ]
}";

            var childNodeInCache = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""NuGetDependency"",
        ""ItemSpec"": ""tfm1/PackageChild1/1.0.0"",
        ""ItemType"": ""PackageReference""
    }
}");

            var itemSpec = "tfm1/Package2/1.0.0";

            provider.LoadSnapshotFromJson(snapshotJson);
            provider.AddChildToNodeInCache(itemSpec, childNodeInCache);

            // Add a dependency
            var sampleDependencyProperties = new Dictionary <string, string>
            {
                { "Name", "Package2" },
                { "Version", "3.0.0" }
            }.ToImmutableDictionary();

            // Act
            provider.RemoveDependencyFromSnapshot(itemSpec);

            // Assert
            // check node and it's children were removed form cache
            var cacheNodes = provider.GetCurrentSnapshotNodesCache();

            Assert.Equal(1, cacheNodes.Count());
            Assert.Equal("tfm1/PackageToStayInCache/1.0.0", cacheNodes.First());
        }
示例#14
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());
        }
示例#15
0
        public void ProjectDependenciesSubTreeProvider_GetDependencyNode()
        {
            // Arrange
            var projectPath = @"c:\myproject\project.csproj";

            // our provider under test nodes
            var myRootNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""ProviderUnderTest"",
        ""ItemSpec"": ""RootNodeUnderTest""
    }
}");

            var myTopNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""ProviderUnderTest"",
        ""ItemSpec"": ""MyTopNodeItemSpec1""
    }
}");

            var myDependencyNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""ProviderUnderTest"",
        ""ItemSpec"": ""MyDependencyNodeItemSpec1""
    }
}");

            myDependencyNode1.Id.ContextProject = "c:\\myproject\\project.csproj";

            myTopNode1.AddChild(myDependencyNode1);
            myRootNode.AddChild(myTopNode1);

            // other provider nodes
            var otherProviderRootNode = 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);
            otherProviderRootNode.AddChild(topNode1);
            otherProviderRootNode.AddChild(topNode2);
            otherProviderRootNode.AddChild(topNode3);

            var mockProvider = new IProjectDependenciesSubTreeProviderMock();

            mockProvider.RootNode = otherProviderRootNode;
            mockProvider.AddTestDependencyNodes(new[] { topNode1, topNode2, topNode3 });
            var mockProjectContextProvider = IDependenciesGraphProjectContextProviderFactory.Implement(
                projectPath, subTreeProviders: new[] { mockProvider });

            var provider = new TestableProjectDependenciesSubTreeProvider(unconfiguredProject: null,
                                                                          projectContextProvider: mockProjectContextProvider);

            provider.SetRootNode(myRootNode);

            // Act
            var resultNode = provider.GetDependencyNode(myDependencyNode1.Id);

            // Assert
            Assert.Equal(resultNode.Id, myDependencyNode1.Id);
            Assert.Equal(3, resultNode.Children.Count);
        }
        public void SdkDependenciesSubTreeProvider_GetDependencyNode()
        {
            // Arrange
            const string packageItemSpec = "MyPackage1";

            var rootNode      = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");
            var existingNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec1""
    },
    ""Properties"": {
        ""SDKPackageItemSpec"": ""MyPackage1""
    }
}");

            var existingNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyNodeItemSpec2""
    },
    ""Properties"": {
    }
}");

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

            var childNode2 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyChildNodeItemSpec2""
    },
    ""Properties"": {
        ""SDKPackageItemSpec"": ""SomeUnknownPackage""
    }
}");

            rootNode.AddChild(existingNode1);
            rootNode.AddChild(existingNode2);

            var childrenToAdd = new[] { childNode1, childNode2 };

            var nugetPackagesDataProvider =
                INuGetPackagesDataProviderFactory.ImplementUpdateNodeChildren(packageItemSpec, existingNode1, childrenToAdd);

            var provider = new TestableSdkDependenciesSubTreeProvider(nugetPackagesDataProvider);

            provider.SetRootNode(rootNode);

            // Successful scenario
            // Act
            var resultNode = provider.GetDependencyNode(existingNode1.Id);

            // Assert
            Assert.Equal(2, existingNode1.Children.Count);

            // node does not exist in root
            // Act
            resultNode = provider.GetDependencyNode(childNode1.Id);
            // Assert
            Assert.Null(resultNode);

            // node does not have proprty SDKPackageItemSpecProperty
            // Act
            resultNode = provider.GetDependencyNode(existingNode2.Id);
            // Assert
            Assert.Equal(existingNode2, resultNode);
        }
示例#17
0
        public async Task NuGetDependenciesSubTreeProvider_SearchAsync()
        {
            var provider = new TestableNuGetDependenciesSubTreeProvider();

            var snapshotJson = @"
{
    ""NodesCache"": [],
    ""DependenciesWorld"": [
        {
            ""ItemSpec"": ""tfm1/Package2/1.0.0"",
            ""Properties"": {
                ""Name"": ""Package2"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Package"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": ""Package3/2.0.0;NotExistentPackage/2.0.0;Assembly1/1.0.0;FrameworkAssembly1/4.0.0;SomeUnknown/1.0.0""
            }
        },
        {
            ""ItemSpec"": ""tfm1/Package3/2.0.0"",
            ""Properties"": {
                ""Name"": ""Package3"",
                ""Version"": ""2.0.0"",
                ""Type"": ""Package"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        },
        {
            ""ItemSpec"": ""tfm1/Assembly1/1.0.0"",
            ""Properties"": {
                ""Name"": ""Assembly1"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Assembly"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        },
        {
            ""ItemSpec"": ""tfm1/FrameworkAssembly1/4.0.0"",
            ""Properties"": {
                ""Name"": ""FrameworkAssembly1"",
                ""Version"": ""4.0.0"",
                ""Type"": ""FrameworkAssembly"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        },
        {
            ""ItemSpec"": ""tfm1/SomeUnknown/1.0.0"",
            ""Properties"": {
                ""Name"": ""SomeUnknown"",
                ""Version"": ""1.0.0"",
                ""Type"": ""Xxxx"",
                ""Path"": ""SomePath"",
                ""Resolved"": ""true"",
                ""Dependencies"": """"
            }
        }
    ]
}";

            provider.LoadSnapshotFromJson(snapshotJson);

            var rootNodeNode  = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""NuGetDependency"",
        ""ItemSpec"": ""tfm1/Package2/1.0.0"",
        ""ItemType"": ""PackageReference""
    }
}");
            var searchResults = await provider.SearchAsync(rootNodeNode, "ass");

            Assert.NotNull(searchResults);
            Assert.Equal(2, searchResults.Count());

            var searchResultsArray = searchResults.ToArray();

            Assert.True(searchResultsArray[0] is PackageAssemblyDependencyNode);
            Assert.Equal("Assembly1", searchResultsArray[0].Caption);
            Assert.False(string.IsNullOrEmpty(searchResultsArray[0].Id.UniqueToken));

            Assert.True(searchResultsArray[1] is PackageAssemblyDependencyNode);
            Assert.Equal("FrameworkAssembly1", searchResultsArray[1].Caption);
            Assert.False(string.IsNullOrEmpty(searchResultsArray[1].Id.UniqueToken));
        }
示例#18
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));
        }
示例#19
0
        public void DependenciesSubTreeProviderBase_ProcessDependenciesChanges()
        {
            var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(@"{
    ""ProjectChanges"": {
        ""rulenameResolved"": {
            ""After"": {
                ""Items"": {
                    ""item21"": {
                        ""OriginalItemSpec"":""item1""
                    },
                    ""item22"": {
                        ""OriginalItemSpec"":""item2""
                    },
                    ""itemWithoutOriginalItemSpec"": {
                    },
                    ""unresolvedItemTobeRemoved"": {
                        ""OriginalItemSpec"":""unresolvedItemTobeRemoved""
                    },
                },
                ""RuleName"":""rulenameResolved""
            },
            ""Before"": {
                ""Items"": {
                    ""resolvedItemTobeRemoved"": {
                        ""OriginalItemSpec"":""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem""
                    },
                    ""resolvedItemTobeRemovedWithNonExistentOriginalItemSpec"": {
                        ""OriginalItemSpec"":""nonExistentUnresolvedOriginalItemSpec""
                    },
                },
                ""RuleName"":""rulenameResolved""
            },
            ""Difference"": {
                ""AddedItems"": [ ""item21"", ""item22"", ""itemWithoutOriginalItemSpec"", ""itemWithoutPropertiesInAfter"", 
                                  ""unresolvedItemTobeRemoved"" ],
                ""ChangedItems"": [ ],
                ""RemovedItems"": [ ""resolvedItemTobeRemoved"", ""resolvedItemTobeRemovedWithNonExistentOriginalItemSpec"" ],
                ""AnyChanges"": ""true""
            },
        },
        ""rulenameUnresolved"": {
            ""After"": {
                ""Items"": {
                    ""item1"": {
                    },
                    ""item2"": {
                    },
                    ""item3"": {
                    },
                    ""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"": {
                    },
                    ""unresolvedItemTobeRemoved"": {
                    }
                },
                ""RuleName"":""rulenameUnresolved""
            },
            ""Difference"": {
                ""AddedItems"": [ ""item1"", ""item2"", ""item3"" ],
                ""ChangedItems"": [ ],
                ""RemovedItems"": [ ""item4"", ""itemNotInRootNode"", ""itemWithoutPropertiesInAfter"" ],
                ""AnyChanges"": ""true""
            },
        },
        ""rulenameUnknown"": {
            ""After"": {
                ""Items"": {
                    ""shouldNotApper"": {
                    }
                },
                ""RuleName"":""rulenameUnknown""
            },
            ""Difference"": {
                ""AddedItems"": [ ""shouldNotApper"" ],
                ""ChangedItems"": [ ],
                ""RemovedItems"": [ ],
                ""AnyChanges"": ""true""
            },
        }
    }
}");
            var rootNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");

            var item4Node = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""item4"",
        ""ItemType"": ""myUnresolvedItemType""
    }
}");

            var resolvedItemTobeRemovedNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""unresolvedItemTobeAddedInsteadOfRemovedResolvedItem"",
        ""ItemType"": ""myUnresolvedItemType""
    }
}");

            var unresolvedItemTobeRemovedNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""unresolvedItemTobeRemoved"",
        ""ItemType"": ""myUnresolvedItemType""
    }
}");

            var unresolvedItemTobeRemovedNodeWithNonExistentOriginalItemSpecNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""resolvedItemTobeRemovedWithNonExistentOriginalItemSpec"",
        ""ItemType"": ""myUnresolvedItemType""
    }
}");

            rootNode.AddChild(item4Node);
            rootNode.AddChild(resolvedItemTobeRemovedNode);
            rootNode.AddChild(unresolvedItemTobeRemovedNode);
            rootNode.AddChild(unresolvedItemTobeRemovedNodeWithNonExistentOriginalItemSpecNode);

            var catalogs = IProjectCatalogSnapshotFactory.ImplementRulesWithItemTypes(
                new Dictionary <string, string>
            {
                { "rulenameResolved", "myResolvedItemType" },
                { "rulenameUnresolved", "myUnresolvedItemType" },
                { "unresolvedItemTobeRemoved", "myUnresolvedItemType" },
                { "unresolvedItemTobeAddedInsteadOfRemovedResolvedItem", "myUnresolvedItemType" }
            });

            var provider = new TestableDependenciesSubTreeProviderBase();

            // set itemTypes to process
            provider.SetResolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameResolved"));
            provider.SetUnresolvedReferenceRuleNames(ImmutableHashSet <string> .Empty.Add("rulenameUnresolved"));
            provider.SetRootNode(rootNode);

            // Act
            var resultChanges = provider.TestProcessDependenciesChanges(projectSubscriptionUpdate, catalogs);

            // Assert
            Assert.NotNull(resultChanges);
            Assert.Equal(5, resultChanges.AddedNodes.Count);

            var addedNodesArray = resultChanges.AddedNodes.ToArray();

            // unresolved items added first
            Assert.False(addedNodesArray[0].Properties.ContainsKey("OriginalItemSpec"));
            Assert.False(addedNodesArray[0].Resolved);
            Assert.Equal("item3", addedNodesArray[0].Caption);

            Assert.False(addedNodesArray[1].Properties.ContainsKey("OriginalItemSpec"));
            Assert.False(addedNodesArray[1].Resolved);
            Assert.Equal("unresolvedItemTobeAddedInsteadOfRemovedResolvedItem", addedNodesArray[1].Caption);

            Assert.True(addedNodesArray[2].Properties.ContainsKey("OriginalItemSpec"));
            Assert.True(addedNodesArray[2].Resolved);
            Assert.Equal("item1", addedNodesArray[2].Caption);
            Assert.True(addedNodesArray[3].Properties.ContainsKey("OriginalItemSpec"));
            Assert.True(addedNodesArray[3].Resolved);
            Assert.Equal("item2", addedNodesArray[3].Caption);

            Assert.True(addedNodesArray[4].Properties.ContainsKey("OriginalItemSpec"));
            Assert.True(addedNodesArray[4].Resolved);
            Assert.Equal("unresolvedItemTobeRemoved", addedNodesArray[4].Caption);

            Assert.Equal(4, resultChanges.RemovedNodes.Count);

            var removedNodesArray = resultChanges.RemovedNodes.ToArray();

            Assert.Equal(item4Node.Id, removedNodesArray[0].Id);
            Assert.Equal(resolvedItemTobeRemovedNode.Id, removedNodesArray[1].Id);
            Assert.Equal(unresolvedItemTobeRemovedNodeWithNonExistentOriginalItemSpecNode.Id, removedNodesArray[2].Id);
            Assert.Equal(unresolvedItemTobeRemovedNode.Id, removedNodesArray[3].Id);
        }
示例#20
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));
        }
示例#21
0
        public void DependenciesSubTreeProviderBase_ProcessDuplicatedNodes()
        {
            // Arrange
            var rootNode = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""MyRootNode""
    }
}");
            var topNode1 = IDependencyNodeFactory.FromJson(@"
{
    ""Id"": {
        ""ProviderType"": ""MyProvider"",
        ""ItemSpec"": ""TopNodeItemSpec1""
    }
}");

            topNode1.SetProperties(caption: "Caption1");

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

            topNode2.SetProperties(caption: "Caption2");

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

            topNode3.SetProperties(caption: "Caption3");

            topNode2.SetProperties(caption: topNode2.Alias);
            rootNode.AddChild(topNode1);
            rootNode.AddChild(topNode2);
            rootNode.AddChild(topNode3);

            var dependenciesChange = DependenciesChangeFactory.FromJson(@"
{
    ""AddedNodes"": [
        {
            ""Id"": {
                ""ProviderType"": ""MyProvider"",
                ""ItemSpec"": ""TopNodeItemSpec1"",
                ""ItemType"": ""OtherItemType""
            }
        },
        {
            ""Id"": {
                ""ProviderType"": ""MyProvider"",
                ""ItemSpec"": ""TopNodeItemSpec2"",
                ""ItemType"": ""OtherItemType""
            }
        }
    ],    
    ""UpdatedNodes"": [ ],
    ""RemovedNodes"": [ ]
}");
            var addedNodesArray    = dependenciesChange.AddedNodes.ToArray();

            addedNodesArray[0].SetProperties(caption: "Caption1");
            addedNodesArray[1].SetProperties(caption: "Caption2");

            var provider = new TestableDependenciesSubTreeProviderBase();

            provider.SetRootNode(rootNode);

            // Act
            provider.TestProcessDuplicatedNodes(dependenciesChange);

            // Assert
            Assert.Equal(1, dependenciesChange.UpdatedNodes.Count);
            Assert.Equal(topNode1.Alias, topNode1.Caption);
            Assert.Equal(5, provider.RootNode.Children.Count);
            var childrenArray = provider.RootNode.Children.ToArray();

            Assert.Equal(childrenArray[3].Alias, childrenArray[3].Caption);
            Assert.Equal(childrenArray[4].Alias, childrenArray[4].Caption);
        }
示例#22
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));
        }