Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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));
            }
        }