Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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));
        }