Пример #1
0
            public void BuildPackageFile(string repositoryUrl, string expectedOwner, string expectedRepositoryName, string expectedGithubRepositoryUrl)
            {
                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest =>
                {
                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = repositoryUrl,
                        Type = "git"
                    };
                }));

                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, repositoryUrl);

                packageFile.IsNuspecRewritten = true;

                Assert.That(packageFile, Is.Not.Null);
                Assert.That(packageFile.Filename, Is.EqualTo("test.1.0.0.nupkg"));
                Assert.That(packageFile.Filename, Is.EqualTo("test.1.0.0.nupkg"));
                Assert.That(packageFile.FilenameAbsolutePath, Is.EqualTo(packageBuilderContext.NupkgFilename));

                if (expectedGithubRepositoryUrl == null)
                {
                    Assert.Null(packageFile.Owner);
                    Assert.Null(packageFile.RepositoryName);
                    Assert.That(packageFile.RepositoryUrl, Is.Null);
                    return;
                }

                Assert.That(packageFile.Owner, Is.EqualTo(expectedOwner));
                Assert.That(packageFile.RepositoryName, Is.EqualTo(expectedRepositoryName));
                Assert.That(packageFile.RepositoryUrl, Is.Not.Null);
                Assert.That(packageFile.RepositoryUrl, Is.EqualTo(expectedGithubRepositoryUrl));
            }
Пример #2
0
            public void RewriteNuspec(string repositoryUrl, string expectedRepositoryUrl)
            {
                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(
                                                                                manifest =>
                {
                    manifest.Metadata.Repository = null;
                }));
                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, repositoryUrl);

                NuGetUtilities.RewriteNupkg(packageFile, NuGetVersion.Parse("2.0.0"));

                using var rewrittenNupkgPackageReader = new PackageArchiveReader(File.OpenRead(packageFile.FilenameAbsolutePath));

                var rewrittenNupkgPackageIdentity    = rewrittenNupkgPackageReader.GetIdentity();
                var rewrittenNupkgRepositoryMetadata = rewrittenNupkgPackageReader.NuspecReader.GetRepositoryMetadata();

                Assert.That(rewrittenNupkgPackageIdentity, Is.Not.Null);
                Assert.That(rewrittenNupkgPackageIdentity.Id, Is.EqualTo("test"));
                Assert.That(rewrittenNupkgPackageIdentity.Version, Is.EqualTo(NuGetVersion.Parse("2.0.0")));
                Assert.That(rewrittenNupkgRepositoryMetadata, Is.Not.Null);
                Assert.That(rewrittenNupkgRepositoryMetadata.Url, Is.EqualTo(expectedRepositoryUrl));
                Assert.That(rewrittenNupkgRepositoryMetadata.Type, Is.EqualTo("git"));
            }
Пример #3
0
            public void RewriteNuspec_Overwrites_Existing_Repository_Url()
            {
                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(
                                                                                manifest =>
                {
                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = "https://google.com",
                        Type = "google"
                    };
                }));
                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, "https://github.com/owner/repo");

                NuGetUtilities.RewriteNupkg(packageFile, NuGetVersion.Parse("2.0.0"));

                using var rewrittenNupkgPackageReader = new PackageArchiveReader(File.OpenRead(packageFile.FilenameAbsolutePath));

                var rewrittenNupkgPackageIdentity    = rewrittenNupkgPackageReader.GetIdentity();
                var rewrittenNupkgRepositoryMetadata = rewrittenNupkgPackageReader.NuspecReader.GetRepositoryMetadata();

                Assert.That(rewrittenNupkgPackageIdentity, Is.Not.Null);
                Assert.That(rewrittenNupkgPackageIdentity.Id, Is.EqualTo("test"));
                Assert.That(rewrittenNupkgPackageIdentity.Version, Is.EqualTo(NuGetVersion.Parse("2.0.0")));
                Assert.That(rewrittenNupkgRepositoryMetadata, Is.Not.Null);
                Assert.That(rewrittenNupkgRepositoryMetadata.Url, Is.EqualTo("https://github.com/owner/repo"));
                Assert.That(rewrittenNupkgRepositoryMetadata.Type, Is.EqualTo("git"));
            }
Пример #4
0
            public void ShouldRewriteNupkg_Ignores_RepositoryType(string repositoryType)
            {
                const string currentRepositoryUrl = "https://github.com/jcansdale/gpr";

                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest =>
                {
                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = currentRepositoryUrl,
                        Type = repositoryType
                    };
                }));

                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, currentRepositoryUrl);

                Assert.That(NuGetUtilities.ShouldRewriteNupkg(packageFile), Is.EqualTo(false));
            }
Пример #5
0
            public void ReadNupkgManifest()
            {
                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest =>
                {
                    manifest.Metadata.Version    = new NuGetVersion("1.0.0");
                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = "https://github.com/jcansdale/gpr",
                        Type = "git"
                    };
                }));

                packageBuilderContext.Build();

                var manifest = NuGetUtilities.ReadNupkgManifest(packageBuilderContext.NupkgFilename);

                Assert.That(manifest, Is.Not.Null);
                Assert.That(manifest.Metadata.Version, Is.EqualTo(packageBuilderContext.NuspecContext.Manifest.Metadata.Version));
                Assert.That(manifest.Metadata.Repository, Is.Not.Null);
                Assert.That(manifest.Metadata.Repository.Url, Is.EqualTo(packageBuilderContext.NuspecContext.Manifest.Metadata.Repository.Url));
            }
Пример #6
0
            public void BuildOwnerAndRepositoryFromUrlFromNupkg(string repositoryUrl, string expectedOwner, string expectedRepositoryName, string expectedGithubRepositoryUrl)
            {
                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest =>
                {
                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = repositoryUrl,
                        Type = "git"
                    };
                }));

                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, null);

                Assert.True(NuGetUtilities.BuildOwnerAndRepositoryFromUrlFromNupkg(packageFile));

                Assert.That(packageFile.Owner, Is.EqualTo(expectedOwner));
                Assert.That(packageFile.RepositoryName, Is.EqualTo(expectedRepositoryName));
                Assert.That(packageFile.RepositoryUrl, Is.EqualTo(expectedGithubRepositoryUrl));
            }
Пример #7
0
            public void ShouldRewriteNupkg_Version(string currentVersion, string updatedVersion, bool shouldUpdateVersion)
            {
                const string repositoryUrl = "https://github.com/jcansdale/gpr";

                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest =>
                {
                    manifest.Metadata.Version    = new NuGetVersion(currentVersion);
                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = repositoryUrl,
                        Type = "git"
                    };
                }));

                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, repositoryUrl);

                Assert.That(
                    NuGetUtilities.ShouldRewriteNupkg(packageFile,
                                                      NuGetVersion.Parse(updatedVersion)), Is.EqualTo(shouldUpdateVersion));
            }
Пример #8
0
            public void ShouldRewriteNupkg_RepositoryUrl(string currentRepositoryUrl, string updatedRepositoryUrl, bool shouldUpdateRepositoryUrl)
            {
                using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest =>
                {
                    if (currentRepositoryUrl == null)
                    {
                        manifest.Metadata.Repository = null;
                        return;
                    }

                    manifest.Metadata.Repository = new RepositoryMetadata
                    {
                        Url  = currentRepositoryUrl,
                        Type = "git"
                    };
                }));

                packageBuilderContext.Build();

                var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, updatedRepositoryUrl);

                Assert.That(NuGetUtilities.ShouldRewriteNupkg(packageFile), Is.EqualTo(shouldUpdateRepositoryUrl));
            }