コード例 #1
0
        public void SharedProjectDependencyNode_Constructor(bool resolved)
        {
            // Arrange
            var expectedIcon = resolved
                ? KnownMonikers.SharedProject
                : KnownMonikers.ReferenceWarning;
            var priority = 3;
            var id       = DependencyNodeId.FromString(
                "file:///[MyProviderType;c:\\MyItemSpec.dll;MyItemType;MyUniqueToken]");
            var properties = new Dictionary <string, string>().ToImmutableDictionary();

            // Act
            var node = new SharedProjectDependencyNode(id,
                                                       ProjectTreeFlags.Empty,
                                                       priority,
                                                       properties,
                                                       resolved: resolved);

            // Assert
            Assert.Equal(expectedIcon, node.Icon);
            Assert.Equal(resolved, node.Resolved);
            Assert.Equal("MyItemSpec", node.Caption);

            // Just to double-check that these properties are still set as sexpected
            Assert.Equal(priority, node.Priority);
            Assert.Equal(properties, node.Properties);
            Assert.Equal(node.Icon, node.ExpandedIcon);
        }
        /// <summary>
        /// Updates the shared project import nodes that are shown under the 'Dependencies/Projects' node.
        /// </summary>
        /// <param name="sharedFolders">Snapshot of shared folders.</param>
        /// <param name="dependenciesChange"></param>
        /// <returns></returns>
        protected override void ProcessSharedProjectImportNodes(IProjectSharedFoldersSnapshot sharedFolders,
                                                                DependenciesChange dependenciesChange)
        {
            Requires.NotNull(sharedFolders, nameof(sharedFolders));
            Requires.NotNull(dependenciesChange, nameof(dependenciesChange));

            var sharedFolderProjectPaths = sharedFolders.Value.Select(sf => sf.ProjectPath);
            var rootNodeChildren         = RootNode.Children;
            var currentSharedImportNodes = rootNodeChildren
                                           .Where(x => x.Flags.Contains(ProjectTreeFlags.Common.SharedProjectImportReference));
            var currentSharedImportNodePaths = currentSharedImportNodes.Select(x => x.Id.ItemSpec);

            // process added nodes
            IEnumerable <string> addedSharedImportPaths = sharedFolderProjectPaths.Except(currentSharedImportNodePaths);
            var itemType = ResolvedProjectReference.PrimaryDataSourceItemType;

            foreach (string addedSharedImportPath in addedSharedImportPaths)
            {
                rootNodeChildren = RootNode.Children;
                var node = rootNodeChildren.FindNode(addedSharedImportPath, itemType);
                if (node == null)
                {
                    var sharedFlags = ProjectTreeFlags.Create(ProjectTreeFlags.Common.SharedProjectImportReference);

                    var id = new DependencyNodeId(ProviderType,
                                                  addedSharedImportPath,
                                                  itemType);
                    node = new SharedProjectDependencyNode(id, flags: sharedFlags);
                    dependenciesChange.AddedNodes.Add(node);
                }
            }

            // process removed nodes
            var removedSharedImportPaths = currentSharedImportNodePaths.Except(sharedFolderProjectPaths);

            foreach (string removedSharedImportPath in removedSharedImportPaths)
            {
                var existingImportNode = currentSharedImportNodes
                                         .Where(node => PathHelper.IsSamePath(node.Id.ItemSpec, removedSharedImportPath))
                                         .FirstOrDefault();

                if (existingImportNode != null)
                {
                    dependenciesChange.RemovedNodes.Add(existingImportNode);
                }
            }
        }