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, name: dependencyMetadata.Name, 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); }
public void PackageAnalyzerAssemblyDependencyNode_Constructor(bool resolved) { // Arrange var expectedIcon = resolved ? KnownMonikers.CodeInformation : KnownMonikers.ReferenceWarning; var defaultFlags = (resolved ? DependencyNode.ResolvedDependencyFlags : DependencyNode.UnresolvedDependencyFlags) .Add(ProjectTreeFlags.Common.ResolvedReference); var priority = resolved ? DependencyNode.PackageAssemblyNodePriority : DependencyNode.UnresolvedReferenceNodePriority; var caption = "MyCaption"; 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 PackageAnalyzerAssemblyDependencyNode(id, caption, myFlags, properties, resolved: resolved); // Assert Assert.Equal(expectedIcon, node.Icon); Assert.Equal(resolved, node.Resolved); Assert.Equal(priority, node.Priority); Assert.Equal(caption, node.Caption); Assert.Equal(caption, node.Name); 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))); }