Ejemplo n.º 1
0
        public void Unresolved()
        {
            var properties = ImmutableStringDictionary <string> .EmptyOrdinal.Add("myProp", "myVal");

            var dependencyIDs = new[] { "id1", "id2" };

            var flag  = ProjectTreeFlags.Create("MyCustomFlag");
            var model = new PackageAnalyzerAssemblyDependencyModel(
                providerType: "myProvider",
                path: "c:\\myPath",
                originalItemSpec: "myOriginalItemSpec",
                name: "myPath",
                flags: flag,
                resolved: false,
                properties: properties,
                dependenciesIDs: dependencyIDs);

            Assert.Equal("myProvider", model.ProviderType);
            Assert.Equal("c:\\myPath", model.Path);
            Assert.Equal("myPath", model.Name);
            Assert.Equal("myOriginalItemSpec", model.OriginalItemSpec);
            Assert.Equal("myPath", model.Caption);
            Assert.Null(model.SchemaName);
            Assert.False(model.TopLevel);
            Assert.True(model.Visible);
            Assert.False(model.Resolved);
            Assert.False(model.Implicit);
            Assert.Equal(properties, model.Properties);
            Assert.Equal(Dependency.UnresolvedReferenceNodePriority, model.Priority);
            Assert.Equal(KnownMonikers.CodeInformation, model.Icon);
            Assert.Equal(KnownMonikers.CodeInformation, model.ExpandedIcon);
            Assert.Equal(ManagedImageMonikers.CodeInformationWarning, model.UnresolvedIcon);
            Assert.Equal(ManagedImageMonikers.CodeInformationWarning, model.UnresolvedExpandedIcon);
            AssertEx.CollectionLength(model.DependencyIDs, 2);
            Assert.True(model.Flags.Contains(flag));
        }
Ejemplo n.º 2
0
        public void Resolved()
        {
            var properties = ImmutableStringDictionary <string> .EmptyOrdinal.Add("myProp", "myVal");

            var dependencyIDs = new[] { "id1", "id2" };

            var model = new PackageAnalyzerAssemblyDependencyModel(
                path: "c:\\myPath",
                originalItemSpec: "myOriginalItemSpec",
                name: "myPath",
                isResolved: true,
                properties: properties,
                dependenciesIDs: dependencyIDs);

            Assert.Equal(PackageRuleHandler.ProviderTypeString, model.ProviderType);
            Assert.Equal("c:\\myPath", model.Path);
            Assert.Equal("myPath", model.Name);
            Assert.Equal("myOriginalItemSpec", model.OriginalItemSpec);
            Assert.Equal("myPath", model.Caption);
            Assert.Null(model.SchemaName);
            Assert.False(model.TopLevel);
            Assert.True(model.Visible);
            Assert.True(model.Resolved);
            Assert.False(model.Implicit);
            Assert.Equal(properties, model.Properties);
            Assert.Equal(Dependency.PackageAssemblyNodePriority, model.Priority);
            Assert.Equal(KnownMonikers.CodeInformation, model.Icon);
            Assert.Equal(KnownMonikers.CodeInformation, model.ExpandedIcon);
            Assert.Equal(ManagedImageMonikers.CodeInformationWarning, model.UnresolvedIcon);
            Assert.Equal(ManagedImageMonikers.CodeInformationWarning, model.UnresolvedExpandedIcon);
            AssertEx.CollectionLength(model.DependencyIDs, 2);
            Assert.Equal(
                DependencyTreeFlags.NuGetDependency +
                DependencyTreeFlags.GenericResolvedDependencyFlags,
                model.Flags);
        }
        private IDependencyModel GetDependencyModel(
            string itemSpec,
            bool resolved,
            IImmutableDictionary <string, string> properties,
            IProjectChangeDescription projectChange,
            HashSet <string> unresolvedChanges,
            ITargetFramework targetFramework)
        {
            PackageDependencyMetadata metadata;
            bool isTopLevel = true;
            bool isTarget   = false;

            if (resolved)
            {
                metadata   = new PackageDependencyMetadata(itemSpec, properties);
                isTopLevel = metadata.IsImplicitlyDefined ||
                             (metadata.DependencyType == DependencyType.Package &&
                              unresolvedChanges != null &&
                              unresolvedChanges.Contains(metadata.Name));
                isTarget = metadata.IsTarget;
                ITargetFramework packageTargetFramework = TargetFrameworkProvider.GetTargetFramework(metadata.Target);
                if (!(packageTargetFramework?.Equals(targetFramework) == true))
                {
                    return(null);
                }
            }
            else
            {
                metadata = CreateUnresolvedMetadata(itemSpec, properties);
            }

            if (isTarget)
            {
                return(null);
            }

            string originalItemSpec = itemSpec;

            if (resolved && isTopLevel)
            {
                originalItemSpec = metadata.Name;
            }

            IDependencyModel dependencyModel = null;

            switch (metadata.DependencyType)
            {
            case DependencyType.Package:
                dependencyModel = new PackageDependencyModel(
                    ProviderType,
                    itemSpec,
                    originalItemSpec,
                    metadata.Name,
                    DependencyTreeFlags.NuGetSubTreeNodeFlags,
                    metadata.Version,
                    resolved,
                    metadata.IsImplicitlyDefined,
                    isTopLevel,
                    !metadata.IsImplicitlyDefined /*visible*/,
                    properties,
                    metadata.DependenciesItemSpecs);
                break;

            case DependencyType.Assembly:
            case DependencyType.FrameworkAssembly:
                dependencyModel = new PackageAssemblyDependencyModel(
                    ProviderType,
                    itemSpec,
                    originalItemSpec,
                    metadata.Name,
                    DependencyTreeFlags.NuGetSubTreeNodeFlags,
                    resolved,
                    properties,
                    metadata.DependenciesItemSpecs);
                break;

            case DependencyType.AnalyzerAssembly:
                dependencyModel = new PackageAnalyzerAssemblyDependencyModel(
                    ProviderType,
                    itemSpec,
                    originalItemSpec,
                    metadata.Name,
                    DependencyTreeFlags.NuGetSubTreeNodeFlags,
                    resolved,
                    properties,
                    metadata.DependenciesItemSpecs);
                break;

            case DependencyType.Diagnostic:
                dependencyModel = new DiagnosticDependencyModel(
                    ProviderType,
                    itemSpec,
                    metadata.Severity,
                    metadata.DiagnosticCode,
                    metadata.Name,
                    DependencyTreeFlags.NuGetSubTreeNodeFlags,
                    isVisible: true,
                    properties: properties);
                break;

            default:
                dependencyModel = new PackageUnknownDependencyModel(
                    ProviderType,
                    itemSpec,
                    originalItemSpec,
                    metadata.Name,
                    DependencyTreeFlags.NuGetSubTreeNodeFlags,
                    resolved,
                    properties,
                    metadata.DependenciesItemSpecs);
                break;
            }

            return(dependencyModel);
        }