Ejemplo n.º 1
0
        public void GivenThatTheFeedIsNotInitializedVerifyRecreateFails()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                        using (var outputFolder = new TestFolder())
                        {
                            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()
                            };

                            Func <Task> action = async() => await RecreateCommand.RunAsync(settings, fileSystem, outputFolder, force : false, log : log);

                            action.ShouldThrow <InvalidOperationException>("the feed is not initialized");
                        }
        }
Ejemplo n.º 2
0
        public async Task VerifyRecreateKeepsExternalSearch()
        {
            using (var tmpFolder = new TestFolder())
                using (var packagesFolder = new TestFolder())
                    using (var target = new TestFolder())
                        using (var cache = new LocalCache())
                            using (var outputFolder = new TestFolder())
                            {
                                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()
                                };

                                var success = await InitCommand.RunAsync(settings, fileSystem, log);

                                success &= await FeedSettingsCommand.RunAsync(
                                    settings,
                                    fileSystem,
                                    unsetAll : false,
                                    getAll : false,
                                    getSettings : Array.Empty <string>(),
                                    unsetSettings : Array.Empty <string>(),
                                    setSettings : new string[] { "externalsearch:https://example.org/search/query" },
                                    log : log,
                                    token : context.Token);

                                success &= await RecreateCommand.RunAsync(
                                    settings,
                                    fileSystem,
                                    tmpFolder.RootDirectory.FullName,
                                    false,
                                    context.Log);

                                success.Should().BeTrue();

                                var indexJsonPath = Path.Combine(target.RootDirectory.FullName, "index.json");
                                var entry         = GetSearchEntry(indexJsonPath);
                                var value         = entry["@id"].ToObject <string>();

                                value.Should().Be("https://example.org/search/query");
                            }
        }
Ejemplo n.º 3
0
        public async Task GivenThatTheFeedHasMissingPackagesVerifyRecreateSucceedsWithForce()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var outputFolder = new TestFolder())
                        using (var cache = new LocalCache())
                            using (var cache2 = new LocalCache())
                                using (var cache3 = new LocalCache())
                                {
                                    var log      = new TestLogger();
                                    var settings = new LocalSettings();

                                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                                    await InitCommand.RunAsync(settings, fileSystem, log);

                                    var packageA = new TestNupkg("a", "1.0");
                                    var packageB = new TestNupkg("b", "2.0.0-beta+blah");
                                    packageA.Save(packagesFolder.Root);
                                    packageB.Save(packagesFolder.Root);

                                    await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder }, false, false, log);

                                    var root = new DirectoryInfo(target);
                                    foreach (var file in root.GetFiles("a.1.0.0*", SearchOption.AllDirectories))
                                    {
                                        // Corrupt the feed
                                        file.Delete();
                                    }

                                    // Recreate
                                    var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root));

                                    var success = await RecreateCommand.RunAsync(settings, fileSystem2, outputFolder, force : true, log : log);

                                    success.Should().BeTrue();

                                    var fileSystem3 = new PhysicalFileSystem(cache3, UriUtility.CreateUri(target.Root));

                                    var finalPackages = (await fileSystem3.GetFiles(log, CancellationToken.None))
                                                        .Select(e => Path.GetFileName(e.EntityUri.LocalPath))
                                                        .Where(e => e.EndsWith(".nupkg"))
                                                        .OrderBy(e => e, StringComparer.OrdinalIgnoreCase);

                                    Directory.Exists(outputFolder).Should().BeFalse();

                                    log.GetMessages().Should().Contain("Feed recreation complete.");
                                }
        }
Ejemplo n.º 4
0
        public async Task GivenThatTheFeedHasPackagesVerifyRecreateSucceeds()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var outputFolder = new TestFolder())
                        using (var cache = new LocalCache())
                            using (var cache2 = new LocalCache())
                                using (var cache3 = new LocalCache())
                                {
                                    var log      = new TestLogger();
                                    var settings = new LocalSettings();

                                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                                    await InitCommand.RunAsync(settings, fileSystem, log);

                                    var packageA = new TestNupkg("a", "1.0");
                                    var packageB = new TestNupkg("b", "2.0.0-beta+blah");
                                    packageA.Save(packagesFolder.Root);
                                    packageB.Save(packagesFolder.Root);

                                    await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder }, false, false, log);

                                    // Recreate
                                    var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root));

                                    var success = await RecreateCommand.RunAsync(settings, fileSystem2, outputFolder, false, log);

                                    success.Should().BeTrue();

                                    var fileSystem3 = new PhysicalFileSystem(cache3, UriUtility.CreateUri(target.Root));

                                    var finalPackages = (await fileSystem3.GetFiles(log, CancellationToken.None))
                                                        .Select(e => Path.GetFileName(e.EntityUri.LocalPath))
                                                        .Where(e => e.EndsWith(".nupkg"))
                                                        .OrderBy(e => e, StringComparer.OrdinalIgnoreCase);

                                    Directory.Exists(outputFolder).Should().BeFalse();

                                    finalPackages.ShouldBeEquivalentTo(new string[] { "a.1.0.0.nupkg", "b.2.0.0-beta.nupkg" });
                                }
        }
Ejemplo n.º 5
0
        public async Task GivenThatTheFeedHasNoPackagesVerifyRecreateSucceeds()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var outputFolder = new TestFolder())
                        using (var cache = new LocalCache())
                            using (var cache2 = new LocalCache())
                                using (var cache3 = new LocalCache())
                                {
                                    var log      = new TestLogger();
                                    var settings = new LocalSettings();

                                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                                    await InitCommand.RunAsync(settings, fileSystem, log);

                                    // Recreate
                                    var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root));

                                    var success = await RecreateCommand.RunAsync(settings, fileSystem2, outputFolder, false, log);

                                    success.Should().BeTrue();
                                }
        }