Esempio n. 1
0
        private IDependencyNode CreateDependencyNode(DependencyMetadata dependencyMetadata,
                                                     DependencyNodeId id = null,
                                                     bool topLevel       = true)
        {
            if (id == null)
            {
                var uniqueToken = topLevel ? null : Guid.NewGuid().ToString();
                id = new DependencyNodeId(ProviderType,
                                          dependencyMetadata.ItemSpec,
                                          ResolvedPackageReference.PrimaryDataSourceItemType,
                                          uniqueToken);
            }

            // here based on DependencyType we create a corresponding node
            IDependencyNode dependencyNode = null;

            switch (dependencyMetadata.DependencyType)
            {
            case DependencyType.Package:
                dependencyNode = new PackageDependencyNode(
                    id,
                    caption: dependencyMetadata.FriendlyName,
                    flags: NuGetSubTreeNodeFlags,
                    properties: dependencyMetadata.Properties,
                    resolved: dependencyMetadata.Resolved);
                break;

            case DependencyType.Assembly:
            case DependencyType.FrameworkAssembly:
                dependencyNode = new PackageAssemblyDependencyNode(
                    id,
                    caption: dependencyMetadata.Name,
                    flags: NuGetSubTreeNodeFlags,
                    properties: dependencyMetadata.Properties,
                    resolved: dependencyMetadata.Resolved);
                break;

            case DependencyType.AnalyzerAssembly:
                dependencyNode = new PackageAnalyzerAssemblyDependencyNode(
                    id,
                    caption: dependencyMetadata.Name,
                    flags: NuGetSubTreeNodeFlags,
                    properties: dependencyMetadata.Properties,
                    resolved: dependencyMetadata.Resolved);
                break;

            default:
                dependencyNode = new PackageUnknownDependencyNode(
                    id,
                    caption: dependencyMetadata.Name,
                    flags: NuGetSubTreeNodeFlags,
                    properties: dependencyMetadata.Properties,
                    resolved: dependencyMetadata.Resolved);
                break;
            }

            return(dependencyNode);
        }
Esempio n. 2
0
        public void PackageDependencyNode_Constructor(bool resolved)
        {
            // Arrange
            var expectedIcon = resolved
                ? KnownMonikers.PackageReference
                : KnownMonikers.ReferenceWarning;

            var defaultFlags = (resolved
                ? DependencyNode.GenericResolvedDependencyFlags
                : DependencyNode.GenericUnresolvedDependencyFlags);

            var priority = resolved
                            ? DependencyNode.PackageNodePriority
                            : DependencyNode.UnresolvedReferenceNodePriority;

            var name    = "MyName";
            var caption = "MyCaption (xxx)";
            var id      = DependencyNodeId.FromString(
                "file:///[MyProviderType;c:\\MyItemSpec.dll;MyItemType;MyUniqueToken]");
            var properties = new Dictionary <string, string>().ToImmutableDictionary();
            var myFlags    = ProjectTreeFlags.Create("MyFlag");

            // Act
            var node = new PackageDependencyNode(id,
                                                 name,
                                                 caption,
                                                 myFlags,
                                                 properties,
                                                 resolved: resolved);

            // Assert
            Assert.Equal(expectedIcon, node.Icon);
            Assert.Equal(resolved, node.Resolved);
            Assert.Equal(priority, node.Priority);
            Assert.Equal(name, node.Name);
            Assert.Equal(caption, node.Caption);
            Assert.Equal(node.Alias, node.Caption);
            Assert.Equal(properties, node.Properties);
            Assert.Equal(node.Icon, node.ExpandedIcon);
            Assert.True(node.Flags.Contains(defaultFlags.Union(myFlags)));
        }