示例#1
0
        public async Task GivenThatIRemoveAPackageWithTheCatalogDisabledVerifyItSucceeds()
        {
            // 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 testPackage1 = new TestNupkg("packageA", "1.0.1");
                        var testPackage2 = new TestNupkg("packageA", "1.0.2");
                        var testPackage3 = new TestNupkg("packageA", "1.0.3");

                        var zipFile1 = testPackage1.Save(packagesFolder.Root);
                        var zipFile2 = testPackage2.Save(packagesFolder.Root);
                        var zipFile3 = testPackage3.Save(packagesFolder.Root);

                        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);

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

                        await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.3", "", false, context.Log);

                        await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.1", "", 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();

                        var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(new PackageIdentity("packageA", NuGetVersion.Parse("1.0.2")));

                        // 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[] { new PackageIdentity("packageA", NuGetVersion.Parse("1.0.2")) });
                        indexPackages.Should().BeEquivalentTo(new[] { new PackageIdentity("packageA", NuGetVersion.Parse("1.0.2")) });
                        searchPackages.Should().BeEquivalentTo(new[] { new PackageIdentity("packageA", NuGetVersion.Parse("1.0.2")) });
                        autoCompletePackages.Should().BeEquivalentTo(new[] { "packageA" });
                        catalogEntry["version"].ToString().Should().Be("1.0.2");
                        catalogEntry["sleet:operation"].ToString().Should().Be("add");
                    }
        }