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); }
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); }
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); }
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)); } }