public void PackageReader_NestedReferenceItemsMixed()
        {
            using (var packageFile = TestPackagesCore.GetLibEmptyFolderPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetReferenceItems().ToArray();

                    Assert.Equal(3, groups.Count());

                    Assert.Equal(NuGetFramework.AnyFramework, groups[0].TargetFramework);
                    Assert.Equal(2, groups[0].Items.Count());
                    Assert.Equal("lib/a.dll", groups[0].Items.ToArray()[0]);
                    Assert.Equal("lib/x86/b.dll", groups[0].Items.ToArray()[1]);

                    Assert.Equal(NuGetFramework.Parse("net40"), groups[1].TargetFramework);
                    Assert.Equal(2, groups[1].Items.Count());
                    Assert.Equal("lib/net40/test40.dll", groups[1].Items.ToArray()[0]);
                    Assert.Equal("lib/net40/x86/testx86.dll", groups[1].Items.ToArray()[1]);

                    Assert.Equal(NuGetFramework.Parse("net45"), groups[2].TargetFramework);
                    Assert.Equal(0, groups[2].Items.Count());
                }
            }
        }
        public void PackageReader_SupportedFrameworksForInvalidPortableFrameworkThrows()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackageWithInvalidPortableFrameworkFolderName())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var ex = Assert.Throws <PackagingException>(
                        () => reader.GetSupportedFrameworks());
                    Assert.Equal(
                        "The framework in the folder name of '" +
                        "lib/portable-net+win+wpa+wp+sl+net-cf+netmf+MonoAndroid+MonoTouch+Xamarin.iOS/test.dll" +
                        "' in package 'packageA.2.0.3' could not be parsed.",
                        ex.Message);
                    Assert.NotNull(ex.InnerException);
                    Assert.IsType <ArgumentException>(ex.InnerException);
                    Assert.Equal(
                        "Invalid portable frameworks '" +
                        "net+win+wpa+wp+sl+net-cf+netmf+MonoAndroid+MonoTouch+Xamarin.iOS" +
                        "'. A hyphen may not be in any of the portable framework names.",
                        ex.InnerException.Message);
                }
            }
        }
        public void PackageReader_ReferencesWithoutGroups()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackageWithPre25References())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetReferenceItems().ToArray();

                    Assert.Equal(3, groups.Count());

                    Assert.Equal(NuGetFramework.AnyFramework, groups[0].TargetFramework);
                    Assert.Equal(1, groups[0].Items.Count());
                    Assert.Equal("lib/test.dll", groups[0].Items.Single());

                    Assert.Equal(NuGetFramework.Parse("net40"), groups[1].TargetFramework);
                    Assert.Equal(1, groups[1].Items.Count());
                    Assert.Equal("lib/net40/test.dll", groups[1].Items.Single());

                    Assert.Equal(NuGetFramework.Parse("net451"), groups[2].TargetFramework);
                    Assert.Equal(1, groups[1].Items.Count());
                    Assert.Equal("lib/net451/test.dll", groups[2].Items.Single());
                }
            }
        }
        public void PackageReader_LegacyFolders()
        {
            // Verify legacy folder names such as 40 and 35 parse to frameworks
            using (var packageFile = TestPackagesCore.GetLegacyFolderPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetReferenceItems().ToArray();

                    Assert.Equal(4, groups.Count());

                    Assert.Equal(NuGetFramework.AnyFramework, groups[0].TargetFramework);
                    Assert.Equal("lib/a.dll", groups[0].Items.ToArray()[0]);

                    Assert.Equal(NuGetFramework.Parse("net35"), groups[1].TargetFramework);
                    Assert.Equal("lib/35/b.dll", groups[1].Items.ToArray()[0]);

                    Assert.Equal(NuGetFramework.Parse("net4"), groups[2].TargetFramework);
                    Assert.Equal("lib/40/test40.dll", groups[2].Items.ToArray()[0]);
                    Assert.Equal("lib/40/x86/testx86.dll", groups[2].Items.ToArray()[1]);

                    Assert.Equal(NuGetFramework.Parse("net45"), groups[3].TargetFramework);
                    Assert.Equal("lib/45/a.dll", groups[3].Items.ToArray()[0]);
                }
            }
        }
示例#5
0
            internal static PackageHelperTest Create(TestPackagesCore.TempFile tempFile)
            {
                var testDirectory = TestDirectory.Create();
                var zip           = TestPackagesCore.GetZip(tempFile);
                var reader        = new PackageArchiveReader(zip);

                return(new PackageHelperTest(testDirectory, reader, tempFile));
            }
        public void PackageReader_ContentWithFrameworks()
        {
            using (var packageFile = TestPackagesCore.GetLegacyContentPackageWithFrameworks())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetContentItems().ToArray();

                    Assert.Equal(3, groups.Count());
                }
            }
        }
        public void PackageReader_MinClientVersion(string minClientVersion, string expected)
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackageMinClient(minClientVersion))
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var version = reader.GetMinClientVersion();

                    Assert.Equal(expected, version.ToNormalizedString());
                }
            }
        }
        public void PackageReader_NoReferences()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetReferenceItems().ToArray();

                    Assert.Equal(3, groups.Count());

                    Assert.Equal(4, groups.SelectMany(e => e.Items).Count());
                }
            }
        }
        public void PackageReader_EmptyLibFolder()
        {
            using (var packageFile = TestPackagesCore.GetLibEmptyFolderPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetReferenceItems().ToArray();

                    var emptyGroup = groups.Where(g => g.TargetFramework == NuGetFramework.ParseFolder("net45")).Single();

                    Assert.Equal(0, emptyGroup.Items.Count());
                }
            }
        }
        public void PackageReader_Serviceable()
        {
            // Arrange
            using (var packageFile = TestPackagesCore.GetServiceablePackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    // Act
                    var actual = reader.IsServiceable();

                    // Assert
                    Assert.True(actual);
                }
            }
        }
        public void PackageReader_SupportedFrameworks()
        {
            using (var packageFile = TestPackagesCore.GetLegacyTestPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    string[] frameworks = reader.GetSupportedFrameworks().Select(f => f.DotNetFrameworkName).ToArray();

                    Assert.Equal("Any,Version=v0.0", frameworks[0]);
                    Assert.Equal(".NETFramework,Version=v4.0", frameworks[1]);
                    Assert.Equal(".NETFramework,Version=v4.5", frameworks[2]);
                    Assert.Equal(3, frameworks.Length);
                }
            }
        }
        public void PackageReader_ContentNoFrameworks()
        {
            using (var packageFile = TestPackagesCore.GetLegacyContentPackage())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    var groups = reader.GetContentItems().ToArray();

                    Assert.Equal(1, groups.Count());

                    Assert.Equal(NuGetFramework.AnyFramework, groups.Single().TargetFramework);

                    Assert.Equal(3, groups.Single().Items.Count());
                }
            }
        }
示例#13
0
        public void PathTooLongWarning_PackageWithOutLongPath_NoWarn()
        {
            using (var packageFile = TestPackagesCore.GetPackageCoreReaderTestPackage())
            {
                var zip     = TestPackagesCore.GetZip(packageFile);
                var ruleSet = RuleSet.PackageCreationRuleSet;

                using (var reader = new PackageArchiveReader(zip))
                {
                    var issues = new List <PackagingLogMessage>();

                    foreach (var rule in ruleSet)
                    {
                        issues.AddRange(rule.Validate(reader).OrderBy(p => p.Code.ToString(), StringComparer.CurrentCulture));
                    }

                    Assert.False(issues.Any(p => p.Code == NuGetLogCode.NU5123));
                }
            }
        }
        public void PackageReader_PackageTypes()
        {
            // Arrange
            using (var packageFile = TestPackagesCore.GetPackageWithPackageTypes())
            {
                var zip = TestPackagesCore.GetZip(packageFile);

                using (PackageArchiveReader reader = new PackageArchiveReader(zip))
                {
                    // Act
                    var actual = reader.GetPackageTypes();

                    // Assert
                    Assert.Equal(2, actual.Count);
                    Assert.Equal("foo", actual[0].Name);
                    Assert.Equal(new Version(0, 0), actual[0].Version);
                    Assert.Equal("bar", actual[1].Name);
                    Assert.Equal(new Version(2, 0, 0), actual[1].Version);
                }
            }
        }
        public void PackageReader_RespectReferencesAccordingToDifferentFrameworks()
        {
            // Copy of the InstallPackageRespectReferencesAccordingToDifferentFrameworks functional test

            // Arrange
            using (var path = TestPackagesCore.GetNearestReferenceFilteringPackage())
            {
                using (var zip = TestPackagesCore.GetZip(path.File))
                    using (var reader = new PackageArchiveReader(zip))
                    {
                        // Act
                        var references = reader.GetReferenceItems();
                        var netResult  = NuGetFrameworkUtility.GetNearest <FrameworkSpecificGroup>(references, NuGetFramework.Parse("net45"));
                        var slResult   = NuGetFrameworkUtility.GetNearest <FrameworkSpecificGroup>(references, NuGetFramework.Parse("sl5"));

                        // Assert
                        Assert.Equal(2, netResult.Items.Count());
                        Assert.Equal(1, slResult.Items.Count());
                        Assert.Equal("lib/sl40/a.dll", slResult.Items.First());
                        Assert.Equal("lib/net40/one.dll", netResult.Items.First());
                        Assert.Equal("lib/net40/three.dll", netResult.Items.Skip(1).First());
                    }
            }
        }