public void NuGetDependenciesSubTreeProvider_ProcessDependenciesChanges_EmptyTreeAndBothResolvedAndUnresolvedAreProvided( string projectSubscriptionUpdateJson, string existingTopLevelNodesJson, string existingDependenciesChanges) { // Arrange var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(projectSubscriptionUpdateJson); var mockRootNode = IDependencyNodeFactory.Implement(existingTopLevelNodesJson); var provider = new TestableNuGetDependenciesSubTreeProvider(); provider.SetRootNode(mockRootNode); // Act var resultDependenciesChange = provider.TestDependenciesChanged(projectSubscriptionUpdate, catalogs: null); // Assert // check that DependenciesChange returned is as expected var expectedResult = DependenciesChangeFactory.FromJson(existingDependenciesChanges); Assert.True(DependenciesChangeFactory.AreEqual(expectedResult, resultDependenciesChange)); // Check if all added items were added to Snapshot var currentSnapshot = provider.GetCurrentSnapshotDependenciesWorld(); foreach (var addedNode in expectedResult.AddedNodes) { if (addedNode.Id.ItemSpec.Contains("/")) { // if it is a resolved package Assert.True(currentSnapshot.Any(x => x.Equals(addedNode.Id.ItemSpec, StringComparison.OrdinalIgnoreCase))); } } }
public void NuGetDependenciesSubTreeProvider_ResolvedReferenceRuleNames() { var provider = new TestableNuGetDependenciesSubTreeProvider(); Assert.Equal(1, provider.GetResolvedReferenceRuleNames().Count()); Assert.Equal("ResolvedPackageReference", provider.GetResolvedReferenceRuleNames().First()); }
public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_UpdateDependency() { var provider = new TestableNuGetDependenciesSubTreeProvider(); var snapshotJson = @" { ""NodesCache"": [ { ""Id"": { ""ProviderType"": ""NuGetDependency"", ""ItemSpec"": ""tfm1/Package2/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"" } } ] }"; provider.LoadSnapshotFromJson(snapshotJson); // Add a dependency var sampleDependencyProperties = new Dictionary <string, string> { { "Name", "Package2" }, { "Version", "3.0.0" } }.ToImmutableDictionary(); var itemsSpec = "tfm1/Package2/1.0.0"; // Act provider.UpdateDependencyInSnapshot(itemsSpec, sampleDependencyProperties); // Assert // check node was updated var resultVersion = provider.GetCurrentSnapshotDependencyProperty( itemsSpec, "Version"); Assert.Equal("3.0.0", resultVersion); // check node was removed form cache Assert.False(provider.GetCurrentSnapshotNodesCache().Any(x => x.Equals(itemsSpec))); }
public void NuGetDependenciesSubTreeProvider_CreateRootNode() { var provider = new TestableNuGetDependenciesSubTreeProvider(); var rootNode = provider.TestCreateRootNode(); Assert.True(rootNode is SubTreeRootDependencyNode); Assert.True(rootNode.Flags.Contains(NuGetDependenciesSubTreeProvider.NuGetSubTreeRootNodeFlags)); Assert.Equal("NuGet", rootNode.Caption); Assert.Equal(KnownMonikers.PackageReference, rootNode.Icon); Assert.Equal(NuGetDependenciesSubTreeProvider.ProviderTypeString, rootNode.Id.ProviderType); }
public void NuGetDependenciesSubTreeProvider_Icons() { var provider = new TestableNuGetDependenciesSubTreeProvider(); Assert.Equal(5, provider.Icons.Count()); var iconsArray = provider.Icons.ToArray(); Assert.Equal(KnownMonikers.PackageReference, iconsArray[0]); Assert.Equal(KnownMonikers.Reference, iconsArray[1]); Assert.Equal(KnownMonikers.ReferenceWarning, iconsArray[2]); Assert.Equal(KnownMonikers.QuestionMark, iconsArray[3]); Assert.Equal(KnownMonikers.Library, iconsArray[4]); }
public void NuGetDependenciesSubTreeProvider_ProcessDuplicatedNodes_VerifyDoesNoChanges() { var existingTopLevelNodesJson = @" { ""Nodes"": [ { ""Id"": { ""ProviderType"": ""NuGetDependency"", ""ItemSpec"": ""tfm1/Package1/1.0.0"", ""ItemType"": ""PackageReference"" } }, { ""Id"": { ""ProviderType"": ""NuGetDependency"", ""ItemSpec"": ""tfm1/Package2/2.0.0"", ""ItemType"": ""PackageReference"" } } ] }"; var mockRootNode = IDependencyNodeFactory.Implement(existingTopLevelNodesJson); var provider = new TestableNuGetDependenciesSubTreeProvider(); provider.SetRootNode(mockRootNode); var expectedDependenciesChanges = @" { ""AddedNodes"": [ { ""Id"": { ""ProviderType"": ""NuGetDependency"", ""ItemSpec"": ""tfm1/package1/1.0.0"", ""ItemType"": ""PackageReference"" } } ], ""UpdatedNodes"": [ ], ""RemovedNodes"": [ ] }"; var dependenciesChanges = DependenciesChangeFactory.FromJson(expectedDependenciesChanges); var expectedChanges = DependenciesChangeFactory.FromJson(expectedDependenciesChanges); // Act provider.TestProcessDuplicatedNodes(dependenciesChanges); Assert.True(DependenciesChangeFactory.AreEqual(expectedChanges, dependenciesChanges)); }
public void NuGetDependenciesSubTreeProvider_ProcessDependenciesChanges( string projectSubscriptionUpdateJson, string existingTopLevelNodesJson, string packageToTestVersionUpdate, string existingDependenciesChanges) { // Arrange var projectSubscriptionUpdate = IProjectSubscriptionUpdateFactory.FromJson(projectSubscriptionUpdateJson); var mockRootNode = IDependencyNodeFactory.Implement(existingTopLevelNodesJson); var provider = new TestableNuGetDependenciesSubTreeProvider(); provider.SetRootNode(mockRootNode); // Act var resultDependenciesChange = provider.TestDependenciesChanged(projectSubscriptionUpdate, catalogs: null); // Assert // Check that for updated/changed nodes, properties were updated var propertyToCheck = "Version"; var itemsProperties = projectSubscriptionUpdate.ProjectChanges.Values .Where(y => y.Difference.AnyChanges && y.Difference.ChangedItems.Any(x => x.Equals(packageToTestVersionUpdate))) .Select(x => x.After.Items) .FirstOrDefault(); var expectedPropertyValue = itemsProperties[packageToTestVersionUpdate][propertyToCheck]; var properties = provider.GetDependencyProperties(packageToTestVersionUpdate); Assert.Equal(expectedPropertyValue, properties[propertyToCheck]); // check that DependenciesChange returned is as expected var expectedResult = DependenciesChangeFactory.FromJson(existingDependenciesChanges); Assert.True(DependenciesChangeFactory.AreEqual(expectedResult, resultDependenciesChange)); // Check if all added items were added to Snapshot var currentSnapshot = provider.GetCurrentSnapshotDependenciesWorld(); foreach (var addedNode in expectedResult.AddedNodes) { if (addedNode.Id.ItemSpec.Contains("/")) { // if it is a resolved package Assert.True(currentSnapshot.Any(x => x.Equals(addedNode.Id.ItemSpec, StringComparison.OrdinalIgnoreCase))); } } }
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); }
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); }
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()); }
public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_GetUniqueTopLevelDependencies() { var provider = new TestableNuGetDependenciesSubTreeProvider(); var snapshotJson = @" { ""NodesCache"": [ ], ""DependenciesWorld"": [ { ""ItemSpec"": ""tfm1"", ""Properties"": { ""Name"": ""tfm1"", ""Type"": ""Target"", ""Dependencies"": ""Package3/2.0.0;Package2/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/Package2/1.0.0"", ""Properties"": { ""Name"": ""Package2"", ""Version"": ""1.0.0"", ""Type"": ""Package"", ""Path"": ""SomePath"", ""Resolved"": ""true"", ""Dependencies"": """" } }, { ""ItemSpec"": ""tfm2"", ""Properties"": { ""Name"": ""tfm2"", ""Type"": ""Target"", ""Dependencies"": ""Package1/1.0.0"" } }, { ""ItemSpec"": ""tfm2/Package1/1.0.0"", ""Properties"": { ""Name"": ""Package1"", ""Version"": ""1.0.0"", ""Type"": ""Package"", ""Path"": ""SomePath"", ""Resolved"": ""true"", ""Dependencies"": """" } }, { ""ItemSpec"": ""tfm2/Package2/1.0.0"", ""Properties"": { ""Name"": ""Package2"", ""Version"": ""1.0.0"", ""Type"": ""Package"", ""Path"": ""SomePath"", ""Resolved"": ""true"", ""Dependencies"": """" } } ] }"; provider.LoadSnapshotFromJson(snapshotJson); var topLevelDependencies = provider.GetUniqueTopLevelDependencies(); Assert.Equal(3, topLevelDependencies.Count); Assert.True(topLevelDependencies.Contains("tfm1/Package3/2.0.0")); Assert.True(topLevelDependencies.Contains("tfm1/Package2/1.0.0")); Assert.True(topLevelDependencies.Contains("tfm2/Package1/1.0.0")); }
public void NuGetDependenciesSubTreeProvider_DependenciesSnapshot_AddDependency() { 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); // Add a dependency var sampleDependencyProperties = new Dictionary <string, string> { { "Name", "Package2" }, { "Version", "3.0.0" } }.ToImmutableDictionary(); provider.AddDependencyToSnapshot("tfm1/Package4/1.0.0", sampleDependencyProperties); var currentSnapshotDependencies = provider.GetCurrentSnapshotDependenciesWorld(); Assert.True(currentSnapshotDependencies.Contains("tfm1/Package4/1.0.0")); // Add a target provider.AddDependencyToSnapshot("tfm1", sampleDependencyProperties); var currentSnapshotTargets = provider.GetCurrentSnapshotTargets(); Assert.True(currentSnapshotTargets.Contains("tfm1")); }
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)); }
public void NuGetDependenciesSubTreeProvider_GetDependencyNode_VerifyAllNodeTypesAreCreated() { var provider = new TestableNuGetDependenciesSubTreeProvider(); var snapshotJson = @" { ""NodesCache"": [ { ""Id"": { ""ProviderType"": ""NuGetDependency"", ""ItemSpec"": ""tfm1/Package1/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;AnalyzerAssembly1/4.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/AnalyzerAssembly1/4.0.0"", ""Properties"": { ""Name"": ""AnalyzerAssembly1"", ""Version"": ""4.0.0"", ""Type"": ""AnalyzerAssembly"", ""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 id = DependencyNodeId.FromString(@"file:///[MyProviderType;tfm1/Package2/1.0.0]"); var resultNode = provider.GetDependencyNode(id); Assert.NotNull(resultNode); Assert.Equal(5, resultNode.Children.Count); var childrenArray = resultNode.Children.ToArray(); Assert.True(childrenArray[0] is PackageDependencyNode); Assert.Equal("Package3 (2.0.0)", childrenArray[0].Caption); Assert.False(string.IsNullOrEmpty(childrenArray[0].Id.UniqueToken)); Assert.True(childrenArray[1] is PackageAssemblyDependencyNode); Assert.Equal("Assembly1", childrenArray[1].Caption); Assert.False(string.IsNullOrEmpty(childrenArray[1].Id.UniqueToken)); Assert.True(childrenArray[2] is PackageUnknownDependencyNode); Assert.Equal("SomeUnknown", childrenArray[2].Caption); Assert.False(string.IsNullOrEmpty(childrenArray[2].Id.UniqueToken)); // Analyzers Assert.Equal("AnalyzerAssembly1", childrenArray[3].Caption); Assert.True(childrenArray[3] is PackageAnalyzerAssemblyDependencyNode); // Framework assemblies Assert.True(childrenArray[4] is PackageFrameworkAssembliesDependencyNode); Assert.False(string.IsNullOrEmpty(childrenArray[4].Id.UniqueToken)); Assert.True(childrenArray[4].Children.First() is PackageAssemblyDependencyNode); Assert.Equal("FrameworkAssembly1", childrenArray[4].Children.First().Caption); Assert.False(string.IsNullOrEmpty(childrenArray[4].Children.First().Id.UniqueToken)); Assert.True(provider.GetCurrentSnapshotNodesCache().Contains(id.ItemSpec)); }
public void NuGetDependenciesSubTreeProvider_UnresolvedReferenceRuleNames() { var provider = new TestableNuGetDependenciesSubTreeProvider(); Assert.Equal(1, provider.GetUnresolvedReferenceRuleNames().Count()); }