コード例 #1
0
        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)));
        }
コード例 #2
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());
        }
コード例 #3
0
        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"));
        }
コード例 #4
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"));
        }
コード例 #5
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));
        }
コード例 #6
0
        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));
        }