public void ItShouldReturnCorrectHierarchyWhenPackageHasChildAssemblyOrAnalyzerDependencies()
        {
            // Arrange
            // target definitions
            var mockTarget = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.5",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "net45" },
                { MetadataKeys.TargetFrameworkMoniker, ".Net Framework,Version=v4.5" },
                { MetadataKeys.FrameworkName, ".Net Framework" },
                { MetadataKeys.FrameworkVersion, "4.5" },
                { MetadataKeys.Type, "Target" }
            });

            // package definitions
            var mockPackage = new MockTaskItem(
                itemSpec: "Package3/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "Package3" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Package" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" },
                { PreprocessPackageDependenciesDesignTime.DependenciesMetadata,
                  @"mockChildAssembly1;somepath/mockChildAssembly2;somepath/mockChildAnalyzerAssembly" },
                { MetadataKeys.IsImplicitlyDefined, "True" }
            });

            var mockChildAssembly1 = new MockTaskItem(
                itemSpec: @"mockChildAssembly1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockChildAssembly1" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Assembly" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" }
            });

            var mockChildAssembly2 = new MockTaskItem(
                itemSpec: @"somepath/mockChildAssembly2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockChildAssembly2" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "FrameworkAssembly" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" }
            });

            var mockChildAssemblyNoCompileMetadata = new MockTaskItem(
                itemSpec: @"somepath/mockChildAssemblyNoCompileMetadata",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockChildAssemblyNoCompileMetadata" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Assembly" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" }
            });

            var mockChildAnalyzerAssembly = new MockTaskItem(
                itemSpec: @"somepath/mockChildAnalyzerAssembly",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockChildAnalyzerAssembly" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "AnalyzerAssembly" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" }
            });

            // package dependencies
            var mockPackageDep = new MockTaskItem(
                itemSpec: "Package3/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.IsImplicitlyDefined, "True" }
            });

            var mockChildAssemblyDep1 = new MockTaskItem(
                itemSpec: "mockChildAssembly1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "Package3/1.0.0" },
                { MetadataKeys.FileGroup, PreprocessPackageDependenciesDesignTime.CompileTimeAssemblyMetadata }
            });

            var mockChildAssemblyDep2 = new MockTaskItem(
                itemSpec: @"somepath/mockChildAssembly2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "Package3/1.0.0" },
                { MetadataKeys.FileGroup, PreprocessPackageDependenciesDesignTime.CompileTimeAssemblyMetadata }
            });

            var mockChildAssemblyNoCompileMetadataDep = new MockTaskItem(
                itemSpec: "somepath/mockChildAssemblyNoCompileMetadata",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "Package3/1.0.0" }
            });

            var mockChildAnalyzerAssemblyDep = new MockTaskItem(
                itemSpec: "somepath/mockChildAnalyzerAssembly",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "Package3/1.0.0" }
            });

            var task = new PreprocessPackageDependenciesDesignTime();

            task.TargetDefinitions  = new[] { mockTarget };
            task.PackageDefinitions = new ITaskItem[] {
                mockPackage
            };
            task.FileDefinitions = new ITaskItem[] {
                mockChildAssembly1,
                mockChildAssembly2,
                mockChildAssemblyNoCompileMetadata,
                mockChildAnalyzerAssembly
            };
            task.PackageDependencies = new ITaskItem[] {
                mockPackageDep
            };
            task.FileDependencies = new ITaskItem[] {
                mockChildAssemblyDep1,
                mockChildAssemblyDep2,
                mockChildAssemblyNoCompileMetadataDep,
                mockChildAnalyzerAssemblyDep
            };
            task.PackageReferences = new ITaskItem[] { new MockTaskItem(
                                                           itemSpec: "Package3",
                                                           metadata: new Dictionary <string, string>
                {
                    { MetadataKeys.IsImplicitlyDefined, "True" }
                }) };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.DependenciesDesignTime.Count().Should().Be(5);

            var resultTargets = task.DependenciesDesignTime
                                .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5")).ToArray();

            resultTargets.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Target, mockTarget, resultTargets[0]);

            mockPackage.SetMetadata(MetadataKeys.Path, mockPackage.GetMetadata(MetadataKeys.ResolvedPath));
            var resultPackage = task.DependenciesDesignTime
                                .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/Package3/1.0.0")).ToArray();

            resultPackage.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Package, mockPackage, resultPackage[0]);

            mockChildAssembly1.SetMetadata(MetadataKeys.Path, mockChildAssembly1.GetMetadata(MetadataKeys.ResolvedPath));
            var resultChildAssembly1 = task.DependenciesDesignTime
                                       .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/mockChildAssembly1")).ToArray();

            resultChildAssembly1.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Assembly, mockChildAssembly1, resultChildAssembly1[0]);

            mockChildAssembly2.SetMetadata(MetadataKeys.Path, mockChildAssembly2.GetMetadata(MetadataKeys.ResolvedPath));
            var resultChildAssembly2 = task.DependenciesDesignTime
                                       .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/somepath/mockChildAssembly2")).ToArray();

            resultChildAssembly2.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.FrameworkAssembly, mockChildAssembly2, resultChildAssembly2[0]);

            mockChildAnalyzerAssembly.SetMetadata(MetadataKeys.Path, mockChildAnalyzerAssembly.GetMetadata(MetadataKeys.ResolvedPath));
            var resultChildAnalyzerAssembly = task.DependenciesDesignTime
                                              .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/somepath/mockChildAnalyzerAssembly")).ToArray();

            resultChildAnalyzerAssembly.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.AnalyzerAssembly, mockChildAnalyzerAssembly, resultChildAnalyzerAssembly[0]);
        }
        public void ItShouldNotReturnPackagesWithUnknownTypes()
        {
            // Arrange
            // target definitions
            var mockTarget = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.5",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "net45" },
                { MetadataKeys.TargetFrameworkMoniker, ".Net Framework,Version=v4.5" },
                { MetadataKeys.FrameworkName, ".Net Framework" },
                { MetadataKeys.FrameworkVersion, "4.5" },
                { MetadataKeys.Type, "Target" }
            });

            // package definitions
            var mockPackageNoType = new MockTaskItem(
                itemSpec: "mockPackageNoType/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockPackageNoType" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some path" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockPackageUnknown = new MockTaskItem(
                itemSpec: "mockPackageUnknown/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockPackageUnknown" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "qqqq" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            // package dependencies
            var mockPackageDepNoType = new MockTaskItem(
                itemSpec: "mockPackageNoType/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockPackageDepUnknown = new MockTaskItem(
                itemSpec: "mockPackageUnknown/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var task = new PreprocessPackageDependenciesDesignTime();

            task.TargetDefinitions   = new[] { mockTarget };
            task.PackageDefinitions  = new ITaskItem[] { mockPackageNoType, mockPackageUnknown };
            task.FileDefinitions     = new ITaskItem[] { };
            task.PackageDependencies = new ITaskItem[] { mockPackageDepNoType, mockPackageDepUnknown };
            task.FileDependencies    = new ITaskItem[] { };
            task.PackageReferences   = new ITaskItem[] { };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.DependenciesDesignTime.Count().Should().Be(1);

            var resultTargets = task.DependenciesDesignTime
                                .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5")).ToArray();

            resultTargets.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Target, mockTarget, resultTargets[0]);
        }
        public void ItShouldIgnoreFileDependenciesThatAre_NotAssemblies_And_DontBelongToCompileTimeAssemblyGroup()
        {
            // Arrange
            // target definitions
            var mockTarget = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.5",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "net45" },
                { MetadataKeys.TargetFrameworkMoniker, ".Net Framework,Version=v4.5" },
                { MetadataKeys.FrameworkName, ".Net Framework" },
                { MetadataKeys.FrameworkVersion, "4.5" },
                { MetadataKeys.Type, "Target" }
            });

            // package definitions
            var mockExternalProject = new MockTaskItem(
                itemSpec: "mockExternalProject/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockExternalProject" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some path" },
                { MetadataKeys.Type, "ExternalProject" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockProject = new MockTaskItem(
                itemSpec: "mockProject/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockProject" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Project" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockContent = new MockTaskItem(
                itemSpec: "mockContent/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockContent" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Content" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockPackage = new MockTaskItem(
                itemSpec: "mockPackage/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockAssembly" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Assembly" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockDiagnostic = new MockTaskItem(
                itemSpec: "mockDiagnostic/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockDiagnostic" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Diagnostic" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockWinmd = new MockTaskItem(
                itemSpec: "mockWinmd/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockWinmd" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Winmd" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            var mockReference = new MockTaskItem(
                itemSpec: "mockReference/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "mockReference" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Reference" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "False" }
            });

            // package dependencies
            var mockExternalProjectDep = new MockTaskItem(
                itemSpec: "mockExternalProject/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockProjectDep = new MockTaskItem(
                itemSpec: "mockProject/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockContentDep = new MockTaskItem(
                itemSpec: "mockContent/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockPackageDep = new MockTaskItem(
                itemSpec: "mockPackage/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockDiagnosticDep = new MockTaskItem(
                itemSpec: "mockDiagnostic/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockWinmdDep = new MockTaskItem(
                itemSpec: "mockWinmd/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockReferenceDep = new MockTaskItem(
                itemSpec: "mockReference/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var task = new PreprocessPackageDependenciesDesignTime();

            task.TargetDefinitions  = new[] { mockTarget };
            task.PackageDefinitions = new ITaskItem[] { };
            task.FileDefinitions    = new ITaskItem[] {
                mockExternalProject,
                mockProject,
                mockContent,
                mockPackage,
                mockWinmd,
                mockReference
            };
            task.PackageDependencies = new ITaskItem[] { };
            task.FileDependencies    = new ITaskItem[] {
                mockExternalProjectDep,
                mockProjectDep,
                mockContentDep,
                mockPackageDep,
                mockWinmdDep,
                mockReferenceDep
            };
            task.PackageReferences = new ITaskItem[] { };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.DependenciesDesignTime.Count().Should().Be(1);

            // Target with type
            var resultTargets = task.DependenciesDesignTime
                                .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5")).ToArray();

            resultTargets.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Target, mockTarget, resultTargets[0]);
        }
        public void ItReturnsCorrectHierarchyOfDependenciesThatHaveChildren()
        {
            // Arrange
            // target definitions
            var mockTarget = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.5",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "net45" },
                { MetadataKeys.TargetFrameworkMoniker, ".Net Framework,Version=v4.5" },
                { MetadataKeys.FrameworkName, ".Net Framework" },
                { MetadataKeys.FrameworkVersion, "4.5" },
                { MetadataKeys.Type, "Target" }
            });

            // package definitions
            var mockPackage = new MockTaskItem(
                itemSpec: "Package3/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "Package3" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Package" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" },
                { PreprocessPackageDependenciesDesignTime.DependenciesMetadata, "ChildPackage1/1.0.0;ChildPackage2/2.0.0" },
                { MetadataKeys.IsTopLevelDependency, "True" }
            });

            var mockChildPackage1 = new MockTaskItem(
                itemSpec: "ChildPackage1/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "ChildPackage1" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Package" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" },
                { PreprocessPackageDependenciesDesignTime.DependenciesMetadata, "ChildPackage11/1.0.0" },
                { MetadataKeys.IsTopLevelDependency, "False" }
            });

            var mockChildPackage11 = new MockTaskItem(
                itemSpec: "ChildPackage11/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "ChildPackage11" },
                { MetadataKeys.Version, "1.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Package" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" },
                { MetadataKeys.IsTopLevelDependency, "False" }
            });

            var mockChildPackage2 = new MockTaskItem(
                itemSpec: "ChildPackage2/2.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Name, "ChildPackage2" },
                { MetadataKeys.Version, "2.0.0" },
                { MetadataKeys.Path, "some path" },
                { MetadataKeys.ResolvedPath, "some resolved path" },
                { MetadataKeys.Type, "Package" },
                { PreprocessPackageDependenciesDesignTime.ResolvedMetadata, "True" },
                { MetadataKeys.IsTopLevelDependency, "False" }
            });

            // package dependencies
            var mockPackageDep = new MockTaskItem(
                itemSpec: "Package3/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" }
            });

            var mockChildPackageDep1 = new MockTaskItem(
                itemSpec: "ChildPackage1/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "Package3/1.0.0" }
            });

            var mockChildPackageDep11 = new MockTaskItem(
                itemSpec: "ChildPackage11/1.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "ChildPackage1/1.0.0" }
            });

            var mockChildPackageDep2 = new MockTaskItem(
                itemSpec: "ChildPackage2/2.0.0",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.ParentTarget, ".Net Framework,Version=v4.5" },
                { MetadataKeys.ParentPackage, "Package3/1.0.0" }
            });

            var task = new PreprocessPackageDependenciesDesignTime();

            task.TargetDefinitions  = new[] { mockTarget };
            task.PackageDefinitions = new ITaskItem[] {
                mockPackage,
                mockChildPackage1,
                mockChildPackage11,
                mockChildPackage2
            };
            task.FileDefinitions     = new ITaskItem[] { };
            task.PackageDependencies = new ITaskItem[] {
                mockPackageDep,
                mockChildPackageDep1,
                mockChildPackageDep11,
                mockChildPackageDep2
            };
            task.FileDependencies  = new ITaskItem[] { };
            task.PackageReferences = new ITaskItem[] { };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.DependenciesDesignTime.Count().Should().Be(5);

            var resultTargets = task.DependenciesDesignTime
                                .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5")).ToArray();

            resultTargets.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Target, mockTarget, resultTargets[0]);

            mockPackage.SetMetadata(MetadataKeys.Path, mockPackage.GetMetadata(MetadataKeys.ResolvedPath));
            var resultPackage = task.DependenciesDesignTime
                                .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/Package3/1.0.0")).ToArray();

            resultPackage.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Package, mockPackage, resultPackage[0]);

            mockChildPackage1.SetMetadata(MetadataKeys.Path, mockChildPackage1.GetMetadata(MetadataKeys.ResolvedPath));
            var resultChildPackage1 = task.DependenciesDesignTime
                                      .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/ChildPackage1/1.0.0")).ToArray();

            resultChildPackage1.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Package, mockChildPackage1, resultChildPackage1[0]);

            mockChildPackage11.SetMetadata(MetadataKeys.Path, mockChildPackage11.GetMetadata(MetadataKeys.ResolvedPath));
            var resultChildPackage11 = task.DependenciesDesignTime
                                       .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/ChildPackage11/1.0.0")).ToArray();

            resultChildPackage11.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Package, mockChildPackage11, resultChildPackage11[0]);

            mockChildPackage2.SetMetadata(MetadataKeys.Path, mockChildPackage2.GetMetadata(MetadataKeys.ResolvedPath));
            var resultChildPackage2 = task.DependenciesDesignTime
                                      .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5/ChildPackage2/2.0.0")).ToArray();

            resultChildPackage2.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Package, mockChildPackage2, resultChildPackage2[0]);
        }
        public void ItShouldReturnOnlyValidTargetsWithoutRIDs()
        {
            // Arrange
            // target definitions
            var mockTargetWithType = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.5",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "net45" },
                { MetadataKeys.TargetFrameworkMoniker, ".Net Framework,Version=v4.5" },
                { MetadataKeys.FrameworkName, ".Net Framework" },
                { MetadataKeys.FrameworkVersion, "4.5" },
                { MetadataKeys.Type, "target" }     // lower case just in case
            });

            var mockTargetWithRidToBeSkipped = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.5/win7x86",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "" },
                { MetadataKeys.TargetFrameworkMoniker, "" },
                { MetadataKeys.FrameworkName, "" },
                { MetadataKeys.FrameworkVersion, "" },
                { MetadataKeys.Type, "" }
            });

            var mockTargetWithoutType = new MockTaskItem(
                itemSpec: ".Net Framework,Version=v4.6",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "net46" },
                { MetadataKeys.TargetFrameworkMoniker, ".Net Framework,Version=v4.6" },
                { MetadataKeys.FrameworkName, ".Net Framework" },
                { MetadataKeys.FrameworkVersion, "4.6" },
            });

            var mockTargetWithEmptyItemSpecToBeSkipped = new MockTaskItem(
                itemSpec: "",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.RuntimeIdentifier, "" },
                { MetadataKeys.TargetFrameworkMoniker, "" },
                { MetadataKeys.FrameworkName, "" },
                { MetadataKeys.FrameworkVersion, "" }
            });

            var task = new PreprocessPackageDependenciesDesignTime();

            task.TargetDefinitions = new[] {
                mockTargetWithType,
                mockTargetWithRidToBeSkipped,
                mockTargetWithoutType,
                mockTargetWithEmptyItemSpecToBeSkipped
            };
            task.PackageDefinitions  = new ITaskItem[] { };
            task.FileDefinitions     = new ITaskItem[] { };
            task.PackageDependencies = new ITaskItem[] { };
            task.FileDependencies    = new ITaskItem[] { };
            task.PackageReferences   = new ITaskItem[] { };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.DependenciesDesignTime.Count().Should().Be(1);

            var resultTargetsWithType = task.DependenciesDesignTime
                                        .Where(x => x.ItemSpec.Equals(".Net Framework,Version=v4.5")).ToArray();

            resultTargetsWithType.Length.Should().Be(1);
            VerifyTargetTaskItem(DependencyType.Target, mockTargetWithType, resultTargetsWithType[0]);
        }
        public void ItShouldCombineSdkReferencesWithImplicitPackageReferences()
        {
            // Arrange
            var sdkReference1 = new MockTaskItem(
                itemSpec: "SdkReference1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Version, "2.0.1" }
            });

            var sdkReference2 = new MockTaskItem(
                itemSpec: "SdkReference2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Version, "1.0.1" }
            });

            var packageReference1 = new MockTaskItem(
                itemSpec: "PackageReference1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.SDKPackageItemSpec, "" },
                { MetadataKeys.Name, "PackageReference1" }
            });

            var packageReference2 = new MockTaskItem(
                itemSpec: "PackageReference2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.IsImplicitlyDefined, "aaa" },
                { MetadataKeys.Version, "3.0.1" }
            });

            var packageReference3 = new MockTaskItem(
                itemSpec: "PackageReference3",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.IsImplicitlyDefined, "False" },
                { MetadataKeys.Version, "1.0.1" }
            });
            var defaultImplicitPackage1 = new MockTaskItem(
                itemSpec: "DefaultImplicitPackage1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.SDKPackageItemSpec, "" },
                { MetadataKeys.Name, "DefaultImplicitPackage1" }
            });

            var task = new CollectSDKReferencesDesignTime();

            task.SdkReferences = new[] {
                sdkReference1,
                sdkReference2
            };
            task.PackageReferences = new ITaskItem[] {
                packageReference1,
                packageReference2,
                packageReference3,
                defaultImplicitPackage1
            };
            task.DefaultImplicitPackages = "DefaultImplicitPackage1;SomeOtherImplicitPackage";

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.SDKReferencesDesignTime.Count().Should().Be(4);

            VerifyTaskItem(sdkReference1, task.SDKReferencesDesignTime[0]);
            VerifyTaskItem(sdkReference2, task.SDKReferencesDesignTime[1]);
            VerifyTaskItem(packageReference1, task.SDKReferencesDesignTime[2]);
            VerifyTaskItem(defaultImplicitPackage1, task.SDKReferencesDesignTime[3]);
        }
Exemplo n.º 7
0
        public void ItShouldCombineSdkReferencesWithImplicitPackageReferences()
        {
            // Arrange
            var sdkReference1 = new MockTaskItem(
                itemSpec: "SdkReference1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Version, "2.0.1" }
            });

            var sdkReference2 = new MockTaskItem(
                itemSpec: "SdkReference2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Version, "1.0.1" }
            });

            var packageReference1 = new MockTaskItem(
                itemSpec: "tfm1/PackageReference1/3.0.1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Package" },
                { MetadataKeys.IsTopLevelDependency, "True" },
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.SDKPackageItemSpec, "tfm1/PackageReference1/3.0.1" },
                { MetadataKeys.Name, "PackageReference1" },
                { MetadataKeys.OriginalItemSpec, "PackageReference1" },
                { MetadataKeys.Path, @"x:\folder\subfolder" },
                { MetadataKeys.Version, @"3.0.1" }
            });

            var packageReference1_otherTFM = new MockTaskItem(
                itemSpec: "tfm2/PackageReference1/3.0.1",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Package" },
                { MetadataKeys.IsTopLevelDependency, "True" },
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.SDKPackageItemSpec, "tfm2/PackageReference1/3.0.1" },
                { MetadataKeys.Name, "PackageReference1" },
                { MetadataKeys.OriginalItemSpec, "PackageReference1" },
                { MetadataKeys.Path, @"x:\folder\subfolder\tfm2" }
            });

            var packageReference_Target = new MockTaskItem(
                itemSpec: "packageReference_Target",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Target" },
                { MetadataKeys.IsTopLevelDependency, "True" },
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.Name, "packageReference_Target" }
            });

            var packageReference_Unknown = new MockTaskItem(
                itemSpec: "packageReference_Unknown",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Xxx" },
                { MetadataKeys.IsTopLevelDependency, "True" },
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.Name, "packageReference_Unknown" }
            });

            var packageReference_NotTopLevel = new MockTaskItem(
                itemSpec: "packageReference_NotTopLevel",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Package" },
                { MetadataKeys.IsTopLevelDependency, "False" },
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.Name, "packageReference_NotTopLevel" }
            });

            var packageReference_NotTopLevel2 = new MockTaskItem(
                itemSpec: "packageReference_NotTopLevel2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Package" },
                { MetadataKeys.IsTopLevelDependency, "xxxx" },
                { MetadataKeys.IsImplicitlyDefined, "True" },
                { MetadataKeys.Name, "packageReference_NotTopLevel2" }
            });

            var packageReference_NotImplicit = new MockTaskItem(
                itemSpec: "packageReference_NotImplicit",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Package" },
                { MetadataKeys.IsTopLevelDependency, "True" },
                { MetadataKeys.IsImplicitlyDefined, "False" },
                { MetadataKeys.Name, "packageReference_NotImplicit" }
            });

            var packageReference_NotImplicit2 = new MockTaskItem(
                itemSpec: "packageReference_NotImplicit2",
                metadata: new Dictionary <string, string>
            {
                { MetadataKeys.Type, "Package" },
                { MetadataKeys.IsTopLevelDependency, "True" },
                { MetadataKeys.IsImplicitlyDefined, "Xxxx" },
                { MetadataKeys.Name, "packageReference_NotImplicit2" }
            });

            var task = new CollectResolvedSDKReferencesDesignTime();

            task.ResolvedSdkReferences = new[] {
                sdkReference1,
                sdkReference2
            };
            task.DependenciesDesignTime = new ITaskItem[] {
                packageReference1,
                packageReference1_otherTFM,
                packageReference_Target,
                packageReference_Unknown,
                packageReference_NotTopLevel,
                packageReference_NotTopLevel2,
                packageReference_NotImplicit,
                packageReference_NotImplicit2
            };

            // Act
            var result = task.Execute();

            // Assert
            result.Should().BeTrue();
            task.ResolvedSDKReferencesDesignTime.Count().Should().Be(3);

            VerifyTaskItem(sdkReference1, task.ResolvedSDKReferencesDesignTime[0]);
            VerifyTaskItem(sdkReference2, task.ResolvedSDKReferencesDesignTime[1]);

            var path = packageReference1.GetMetadata(MetadataKeys.Path);

            packageReference1.RemoveMetadata(MetadataKeys.Path);
            packageReference1.SetMetadata(MetadataKeys.SDKRootFolder, path);
            VerifyTaskItem(packageReference1, task.ResolvedSDKReferencesDesignTime[2], "PackageReference1");
        }