Ejemplo n.º 1
0
        public async Task CatalogTest_CreatePackageDetails_Minimal()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        // Arrange
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var catalog     = new Catalog(context);
                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var zipFile = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input    = PackageInput.Create(zipFile.FullName);
                            var nupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0/packageA.1.0.0.nupkg");

                            // Act
                            var actual = await CatalogUtility.CreatePackageDetailsAsync(input, catalog.CatalogBaseURI, nupkgUri, context.CommitId, writeFileList : true);

                            var dependencyGroups        = actual["dependencyGroups"] as JArray;
                            var frameworkAssemblyGroups = actual["frameworkAssemblyGroup"] as JArray;
                            var tags = actual["tags"] as JArray;

                            // Assert
                            Assert.EndsWith(".json", actual["@id"].ToString());
                            Assert.Equal(string.Empty, actual["authors"].ToString());
                            Assert.Equal(string.Empty, actual["copyright"].ToString());
                            Assert.Equal(string.Empty, actual["description"].ToString());
                            Assert.Equal(string.Empty, actual["iconUrl"].ToString());
                            Assert.Equal(string.Empty, actual["licenseUrl"].ToString());
                            Assert.Null(actual["minClientVersion"]);
                            Assert.Equal(string.Empty, actual["projectUrl"].ToString());
                            Assert.False(actual["requireLicenseAcceptance"].ToObject <bool>());
                            Assert.Null(actual["title"]);
                            Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString());
                            Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString());
                            Assert.EndsWith(".nupkg", actual["packageContent"].ToString());

                            Assert.Empty(dependencyGroups);
                            Assert.Empty(frameworkAssemblyGroups);
                            Assert.Empty(tags);
                        }
                    }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a package input from a zip file and register it for disposal.
        /// </summary>
        public PackageInput GetPackageInput(FileInfo zipFile, bool isSymbols)
        {
            var reader = new PackageArchiveReader(zipFile.FullName);

            var zip   = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false);
            var input = PackageInput.Create(zipFile.FullName);

            DisposeItems.Add(reader);
            return(input);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a package input from a zip file and register it for disposal.
        /// </summary>
        public PackageInput GetPackageInput(FileInfo zipFile, bool isSymbols)
        {
            var reader = new PackageArchiveReader(zipFile.FullName);

            var zip   = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false);
            var input = new PackageInput(zipFile.FullName, reader.GetIdentity(), isSymbols)
            {
                Zip     = zip,
                Package = reader
            };

            DisposeItems.Add(input);
            DisposeItems.Add(reader);
            return(input);
        }
Ejemplo n.º 4
0
        private void ShowPackageInputsView()
        {
            //Create package inputs.
            packageInputsFlowPanel.Controls.Clear();

            if (!_selectedPackage.Inputs.IsNullOrEmpty())
            {
                foreach (Input input in _selectedPackage.Inputs)
                {
                    PackageInput packageInput = new PackageInput(input);

                    packageInput.Left  = 0;
                    packageInput.Width = packageInputsFlowPanel.ClientSize.Width;
                    packageInputsFlowPanel.Controls.Add(packageInput);
                }
            }

            packageSelectionPanel.Visible = false;
            packageInputsPanel.Visible    = true;
            backButton.Visible            = true;
            nextButton.Text = "&OK";
        }
Ejemplo n.º 5
0
        public async Task CatalogTest_AddPackageAsync_SupportsWritingMultiplePages()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        // Arrange
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled  = true,
                                CatalogPageSize = 1,
                            }
                        };

                        var catalog      = new Catalog(context);
                        var catalogIndex = TemplateUtility.LoadTemplate(
                            "CatalogIndex",
                            DateTimeOffset.UtcNow,
                            fileSystem.BaseURI);
                        await fileSystem.Get("catalog/index.json").Write(
                            JObject.Parse(catalogIndex),
                            log,
                            context.Token);

                        var testPackageA = new TestNupkg("packageA", "1.0.0");
                        var testPackageB = new TestNupkg("packageB", "1.0.0");

                        var zipFileA = testPackageA.Save(packagesFolder.Root);
                        var zipFileB = testPackageB.Save(packagesFolder.Root);
                        using (var zipA = new ZipArchive(File.OpenRead(zipFileA.FullName), ZipArchiveMode.Read, false))
                            using (var zipB = new ZipArchive(File.OpenRead(zipFileB.FullName), ZipArchiveMode.Read, false))
                            {
                                var inputA = new PackageInput(zipFileA.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                                {
                                    NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0/packageA.1.0.0.nupkg"),
                                    Zip      = zipA,
                                    Package  = new PackageArchiveReader(zipA)
                                };

                                var inputB = new PackageInput(zipFileB.FullName, new PackageIdentity("packageB", NuGetVersion.Parse("1.0.0")), false)
                                {
                                    NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageB/1.0.0/packageB.1.0.0.nupkg"),
                                    Zip      = zipB,
                                    Package  = new PackageArchiveReader(zipB)
                                };

                                // Act
                                await catalog.AddPackageAsync(inputA);

                                await catalog.AddPackageAsync(inputB);

                                await fileSystem.Commit(context.Log, context.Token);

                                // Assert
                                Assert.True(
                                    await fileSystem.Get("catalog/page.0.json").Exists(context.Log, context.Token),
                                    "The first catalog page should exist.");
                                Assert.True(
                                    await fileSystem.Get("catalog/page.1.json").Exists(context.Log, context.Token),
                                    "The second catalog page should exist.");
                            }
                    }
        }
Ejemplo n.º 6
0
        public async Task CatalogTest_CreatePackageDetails()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        // Arrange
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var catalog = new Catalog(context);

                        var testPackage = new TestNupkg()
                        {
                            Nuspec = new TestNuspec()
                            {
                                Id                       = "packageA",
                                Version                  = "1.0.0-alpha.1",
                                Authors                  = "authorA, authorB",
                                Copyright                = "Copyright info",
                                Description              = "Package A",
                                IconUrl                  = "http://tempuri.org/icon.png",
                                LicenseUrl               = "http://tempuri.org/license.html",
                                Language                 = "en-us",
                                MinClientVersion         = "3.3.0",
                                DevelopmentDependency    = "true",
                                Owners                   = "ownerA, ownerB",
                                ProjectUrl               = "http://tempuri.org/project.html",
                                ReleaseNotes             = "release 1.0",
                                RequireLicenseAcceptance = "true",
                                Summary                  = "package summary.",
                                Tags                     = "tagA tagB tagC",
                                Title                    = "packageA title",
                                Dependencies             = new List <PackageDependencyGroup>()
                                {
                                    new PackageDependencyGroup(NuGetFramework.AnyFramework, new List <PackageDependency>()
                                    {
                                        new PackageDependency("packageB", VersionRange.Parse("1.0.0"))
                                    }),
                                    new PackageDependencyGroup(NuGetFramework.Parse("net46"), new List <PackageDependency>()),
                                    new PackageDependencyGroup(NuGetFramework.Parse("net45"), new List <PackageDependency>()
                                    {
                                        new PackageDependency("packageAll"),
                                        new PackageDependency("packageExact", VersionRange.Parse("[2.0.0]")),
                                    }),
                                },
                                FrameworkAssemblies = new List <KeyValuePair <string, List <NuGetFramework> > >()
                                {
                                    new KeyValuePair <string, List <NuGetFramework> >("System.IO.Compression", new List <NuGetFramework>()
                                    {
                                        NuGetFramework.Parse("net45"),
                                        NuGetFramework.Parse("win8")
                                    }),
                                    new KeyValuePair <string, List <NuGetFramework> >("System.Threading", new List <NuGetFramework>()
                                    {
                                        NuGetFramework.Parse("net40")
                                    }),
                                    new KeyValuePair <string, List <NuGetFramework> >("System.All", new List <NuGetFramework>()
                                    {
                                    })
                                },
                            }
                        };

                        var zipFile = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0-alpha.1")), false)
                            {
                                NupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0-alpha.1/packageA.1.0.0-alpha.1.nupkg"),
                                Zip      = zip,
                                Package  = new PackageArchiveReader(zip)
                            };

                            // Act
                            var actual = await CatalogUtility.CreatePackageDetailsAsync(input, catalog.CatalogBaseURI, context.CommitId, writeFileList : true);

                            var dependencyGroups        = actual["dependencyGroups"] as JArray;
                            var frameworkAssemblyGroups = actual["frameworkAssemblyGroup"] as JArray;

                            // Assert
                            Assert.EndsWith(".json", actual["@id"].ToString());
                            Assert.Contains("/catalog/data/", actual["@id"].ToString());
                            Assert.Equal(testPackage.Nuspec.Authors, actual["authors"].ToString());
                            Assert.Equal(testPackage.Nuspec.Copyright, actual["copyright"].ToString());
                            Assert.Equal(testPackage.Nuspec.Description, actual["description"].ToString());
                            Assert.Equal(testPackage.Nuspec.IconUrl, actual["iconUrl"].ToString());
                            Assert.Equal(testPackage.Nuspec.LicenseUrl, actual["licenseUrl"].ToString());
                            Assert.Equal(testPackage.Nuspec.MinClientVersion, actual["minClientVersion"].ToString());
                            Assert.Equal(testPackage.Nuspec.ProjectUrl, actual["projectUrl"].ToString());
                            Assert.True(actual["requireLicenseAcceptance"].ToObject <bool>());
                            Assert.Equal(testPackage.Nuspec.Title, actual["title"].ToString());
                            Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString());
                            Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString());
                            Assert.Equal("tagA", ((JArray)actual["tags"])[0].ToString());
                            Assert.Equal("tagB", ((JArray)actual["tags"])[1].ToString());
                            Assert.Equal("tagC", ((JArray)actual["tags"])[2].ToString());
                            Assert.EndsWith(".nupkg", actual["packageContent"].ToString());

                            Assert.Null(dependencyGroups[0]["targetFramework"]);
                            Assert.Equal("packageB", ((JArray)dependencyGroups[0]["dependencies"]).Single()["id"]);
                            Assert.Equal("[1.0.0, )", ((JArray)dependencyGroups[0]["dependencies"]).Single()["range"]);

                            Assert.Equal("net45", dependencyGroups[1]["targetFramework"]);
                            Assert.NotNull(dependencyGroups[1]["dependencies"]);

                            Assert.Equal("net46", dependencyGroups[2]["targetFramework"]);
                            Assert.Null(dependencyGroups[2]["dependencies"]);

                            Assert.Null(frameworkAssemblyGroups[0]["targetFramework"]);
                            Assert.Equal("net40", frameworkAssemblyGroups[1]["targetFramework"]);
                            Assert.Equal("net45", frameworkAssemblyGroups[2]["targetFramework"]);
                            Assert.Equal("win8", frameworkAssemblyGroups[3]["targetFramework"]);

                            Assert.Equal("System.All", ((JArray)frameworkAssemblyGroups[0]["assembly"]).Single());
                            Assert.Equal("System.Threading", ((JArray)frameworkAssemblyGroups[1]["assembly"]).Single());
                            Assert.Equal("System.IO.Compression", ((JArray)frameworkAssemblyGroups[2]["assembly"]).Single());
                            Assert.Equal("System.IO.Compression", ((JArray)frameworkAssemblyGroups[3]["assembly"]).Single());
                        }
                    }
        }
Ejemplo n.º 7
0
        public async Task AddRemove_AddAndRemovePackageAsync()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var zipFile = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                            {
                                Zip     = zip,
                                Package = new PackageArchiveReader(zip)
                            };

                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.0", string.Empty, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                            var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity);

                            var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id);

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            var searchPackages = await search.GetPackagesAsync();

                            var autoCompletePackages = await autoComplete.GetPackageIds();

                            // Assert
                            Assert.True(validateOutput);
                            Assert.Equal(2, catalogEntries.Count);
                            Assert.Equal(0, catalogExistingEntries.Count);
                            Assert.Equal(0, regPackages.Count);
                            Assert.Equal(0, indexPackages.Count);
                            Assert.Equal(0, searchPackages.Count);
                            Assert.Equal(0, autoCompletePackages.Count);

                            Assert.Equal("packageA", catalogLatest.Id);
                            Assert.Equal("1.0.0", catalogLatest.Version.ToIdentityString());
                            Assert.Equal(SleetOperation.Remove, catalogLatest.Operation);
                        }
                    }
        }
Ejemplo n.º 8
0
        public async Task GivenThatIAddAPackageWithTheCatalogDisabledVerifyItSucceeds()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        context.SourceSettings.CatalogEnabled = false;

                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var zipFile = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                            {
                                Zip     = zip,
                                Package = new PackageArchiveReader(zip)
                            };

                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                            var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity);

                            var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id);

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            var searchPackages = await search.GetPackagesAsync();

                            var autoCompletePackages = await autoComplete.GetPackageIds();

                            var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(input.Identity);

                            // Assert
                            validateOutput.Should().BeTrue("the feed is valid");
                            catalogEntries.Should().BeEmpty("the catalog is disabled");
                            catalogExistingEntries.Should().BeEmpty("the catalog is disabled");
                            regPackages.Should().BeEquivalentTo(new[] { input.Identity });
                            indexPackages.Should().BeEquivalentTo(new[] { input.Identity });
                            searchPackages.Should().BeEquivalentTo(new[] { input.Identity });
                            autoCompletePackages.Should().BeEquivalentTo(new[] { input.Identity.Id });

                            catalogLatest.Should().BeNull();
                            catalogEntry["version"].ToString().Should().Be("1.0.0");
                            catalogEntry["sleet:operation"].ToString().Should().Be("add");
                        }
                    }
        }
Ejemplo n.º 9
0
        public async Task Feed_VerifyBaseUriIsAppliedToLocal(string baseUriString)
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log = new TestLogger();

                        var fileSystemRoot = UriUtility.CreateUri(target.Root);
                        var baseUri        = new Uri(baseUriString);

                        var fileSystem = new PhysicalFileSystem(cache, fileSystemRoot, baseUri);
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true,
                                SymbolsEnabled = true
                            }
                        };

                        var testPackage = new TestNupkg("packageA", "1.0.0");
                        var zipFile     = testPackage.Save(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false)
                            {
                                Zip     = zip,
                                Package = new PackageArchiveReader(zip)
                            };

                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                            var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity);

                            var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id);

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            var searchPackages = await search.GetPackagesAsync();

                            var autoCompletePackages = await autoComplete.GetPackageIds();

                            // Assert
                            Assert.True(validateOutput);
                            Assert.Equal(1, catalogEntries.Count);
                            Assert.Equal(1, catalogExistingEntries.Count);
                            Assert.Equal(1, regPackages.Count);
                            Assert.Equal(1, indexPackages.Count);
                            Assert.Equal(1, searchPackages.Count);
                            Assert.Equal(1, autoCompletePackages.Count);

                            // Walk json to check for bad urls
                            await TestUtility.WalkJsonAsync(target.Root, (file, json, toCheck) =>
                            {
                                // Check only URLs found
                                if (toCheck.IndexOf("://") > -1)
                                {
                                    var cleanUriSchema = toCheck.Replace(":///", string.Empty).Replace("://", string.Empty);

                                    var doubleSlash = cleanUriSchema.IndexOf("//") > -1;
                                    Assert.False(doubleSlash, toCheck);
                                }
                            });
                        }
                    }
        }
Ejemplo n.º 10
0
        public async Task PushCommand_GivenADifferentNuspecCasingVerifyPush()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var zipFile = testPackage.Save(packagesFolder.Root);

                        using (var tempZip = new ZipArchive(zipFile.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None), ZipArchiveMode.Update))
                        {
                            var nuspec = tempZip.Entries.Single(e => e.FullName == "packageA.nuspec");

                            using (var ms = new MemoryStream())
                            {
                                using (var nuspecStream = nuspec.Open())
                                {
                                    nuspecStream.CopyTo(ms);
                                }
                                ms.Position = 0;

                                nuspec.Delete();
                                var newEntry = tempZip.CreateEntry("PacKAGEa.NuSpec");
                                ms.CopyTo(newEntry.Open());
                            }
                        }

                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = PackageInput.Create(zipFile.FullName);

                            // Act
                            // run commands
                            await InitCommand.InitAsync(context);

                            await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                            var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                            // read outputs
                            var catalog      = new Catalog(context);
                            var registration = new Registrations(context);
                            var packageIndex = new PackageIndex(context);
                            var search       = new Search(context);
                            var autoComplete = new AutoComplete(context);

                            var catalogEntries = await catalog.GetIndexEntriesAsync();

                            var indexPackages = await packageIndex.GetPackagesAsync();

                            // Assert
                            Assert.True(validateOutput);
                            Assert.Equal(1, catalogEntries.Count);
                            Assert.Equal(1, indexPackages.Count);
                        }
                    }
        }
Ejemplo n.º 11
0
        public async Task AddRemove_AddTwoPackagesOfUniqueIds()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage1 = new TestNupkg("packageA", "1.0.0");
                        var testPackage2 = new TestNupkg("packageB", "1.0.0");

                        var zipFile1 = testPackage1.Save(packagesFolder.Root);
                        var zipFile2 = testPackage2.Save(packagesFolder.Root);
                        using (var zip1 = new ZipArchive(File.OpenRead(zipFile1.FullName), ZipArchiveMode.Read, false))
                            using (var zip2 = new ZipArchive(File.OpenRead(zipFile2.FullName), ZipArchiveMode.Read, false))
                            {
                                var input1 = PackageInput.Create(zipFile1.FullName);
                                var input2 = PackageInput.Create(zipFile2.FullName);

                                var catalog      = new Catalog(context);
                                var registration = new Registrations(context);
                                var packageIndex = new PackageIndex(context);
                                var search       = new Search(context);
                                var autoComplete = new AutoComplete(context);

                                // Act
                                // run commands
                                await InitCommand.InitAsync(context);

                                await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log);

                                await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log);

                                var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                                // read outputs
                                var catalogEntries = await catalog.GetIndexEntriesAsync();

                                var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync();

                                var regPackages = await registration.GetPackagesByIdAsync("packageA");

                                var indexPackages = await packageIndex.GetPackagesAsync();

                                var searchPackages = await search.GetPackagesAsync();

                                var autoCompletePackages = await autoComplete.GetPackageIds();

                                // Assert
                                Assert.True(validateOutput);
                                Assert.Equal(2, catalogEntries.Count);
                                Assert.Equal(2, catalogExistingEntries.Count);
                                Assert.Equal(1, regPackages.Count);
                                Assert.Equal(2, indexPackages.Count);
                                Assert.Equal(2, searchPackages.Count);
                                Assert.Equal(2, autoCompletePackages.Count);
                            }
                    }
        }
Ejemplo n.º 12
0
        public async Task AddRemove_AddTwoPackagesOfUniqueIds()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new SourceSettings()
                        };

                        var testPackage1 = new TestPackageContext()
                        {
                            Nuspec = new TestNuspecContext()
                            {
                                Id      = "packageA",
                                Version = "1.0.0"
                            }
                        };

                        var testPackage2 = new TestPackageContext()
                        {
                            Nuspec = new TestNuspecContext()
                            {
                                Id      = "packageB",
                                Version = "1.0.0"
                            }
                        };

                        var zipFile1 = testPackage1.Create(packagesFolder.Root);
                        var zipFile2 = testPackage2.Create(packagesFolder.Root);
                        using (var zip1 = new ZipArchive(File.OpenRead(zipFile1.FullName), ZipArchiveMode.Read, false))
                            using (var zip2 = new ZipArchive(File.OpenRead(zipFile2.FullName), ZipArchiveMode.Read, false))
                            {
                                var input1 = new PackageInput()
                                {
                                    Identity    = new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")),
                                    Zip         = zip1,
                                    Package     = new PackageArchiveReader(zip1),
                                    PackagePath = zipFile1.FullName
                                };

                                var input2 = new PackageInput()
                                {
                                    Identity    = new PackageIdentity("packageB", NuGetVersion.Parse("1.0.0")),
                                    Zip         = zip2,
                                    Package     = new PackageArchiveReader(zip2),
                                    PackagePath = zipFile2.FullName
                                };

                                var catalog      = new Catalog(context);
                                var registration = new Registrations(context);
                                var packageIndex = new PackageIndex(context);
                                var search       = new Search(context);
                                var autoComplete = new AutoComplete(context);

                                // Act
                                // run commands
                                await InitCommandTestHook.RunCore(context.LocalSettings, context.Source, context.Log);

                                await PushCommandTestHook.RunCore(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, context.Log);

                                await PushCommandTestHook.RunCore(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, context.Log);

                                var validateOutput = await ValidateCommandTestHook.RunCore(context.LocalSettings, context.Source, context.Log);

                                // read outputs
                                var catalogEntries = await catalog.GetIndexEntries();

                                var catalogExistingEntries = await catalog.GetExistingPackagesIndex();

                                var regPackages = await registration.GetPackagesById("packageA");

                                var indexPackages = await packageIndex.GetPackages();

                                var searchPackages = await search.GetPackages();

                                var autoCompletePackages = await autoComplete.GetPackageIds();

                                // Assert
                                Assert.Equal(0, validateOutput);
                                Assert.Equal(2, catalogEntries.Count);
                                Assert.Equal(2, catalogExistingEntries.Count);
                                Assert.Equal(1, regPackages.Count);
                                Assert.Equal(2, indexPackages.Count);
                                Assert.Equal(2, searchPackages.Count);
                                Assert.Equal(2, autoCompletePackages.Count);
                            }
                    }
        }
Ejemplo n.º 13
0
        public void CatalogTest_CreatePackageDetails_Minimal()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        // Arrange
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new SourceSettings()
                        };

                        var catalog = new Catalog(context);

                        var testPackage = new TestPackageContext()
                        {
                            Nuspec = new TestNuspecContext()
                            {
                                Id      = "packageA",
                                Version = "1.0.0"
                            }
                        };

                        var zipFile = testPackage.Create(packagesFolder.Root);
                        using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false))
                        {
                            var input = new PackageInput()
                            {
                                Identity    = new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")),
                                NupkgUri    = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0/packageA.1.0.0.nupkg"),
                                Zip         = zip,
                                Package     = new PackageArchiveReader(zip),
                                PackagePath = zipFile.FullName
                            };

                            // Act
                            var actual = catalog.CreatePackageDetails(input);

                            var dependencyGroups        = actual["dependencyGroups"] as JArray;
                            var frameworkAssemblyGroups = actual["frameworkAssemblyGroup"] as JArray;
                            var tags = actual["tags"] as JArray;

                            // Assert
                            Assert.True(actual["@id"].ToString().EndsWith(".json"));
                            Assert.Equal(string.Empty, actual["authors"].ToString());
                            Assert.Equal(string.Empty, actual["copyright"].ToString());
                            Assert.Equal(string.Empty, actual["description"].ToString());
                            Assert.Equal(string.Empty, actual["iconUrl"].ToString());
                            Assert.Equal(string.Empty, actual["licenseUrl"].ToString());
                            Assert.Null(actual["minClientVersion"]);
                            Assert.Equal(string.Empty, actual["projectUrl"].ToString());
                            Assert.False(actual["requireLicenseAcceptance"].ToObject <bool>());
                            Assert.Null(actual["title"]);
                            Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString());
                            Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString());
                            Assert.True(actual["packageContent"].ToString().EndsWith(".nupkg"));

                            Assert.Equal(0, dependencyGroups.Count);
                            Assert.Equal(0, frameworkAssemblyGroups.Count);
                            Assert.Equal(0, tags.Count);
                        }
                    }
        }