Exemplo n.º 1
0
        public async Task WriteReadLibraryIndexJson()
        {
            var id    = new LibraryId("nuget.org", "Newtonsoft.Json", "12.0.2");
            var model = new LibraryIndexJson
            {
                License =
                {
                    Code   = "MIT",
                    Status = "HasToBeApproved"
                }
            };

            await _storage.Object.WriteLibraryIndexJsonAsync(id, model, CancellationToken.None);

            var actual = await _storage.Object.ReadLibraryIndexJsonAsync <LibraryIndexJson>(id, CancellationToken.None);

            using (var stream = await _storage.Object.OpenLibraryFileReadAsync(id, StorageExtensions.IndexFileName, CancellationToken.None))
            {
                Console.WriteLine(new StreamReader(stream).ReadToEnd());
            }

            actual.ShouldNotBeNull();
            actual.License.Code.ShouldBe("MIT");
            actual.License.Status.ShouldBe("HasToBeApproved");
        }
Exemplo n.º 2
0
        public async Task OpenLibraryFileReadNotExists()
        {
            var id = new LibraryId("nuget.org", "Newtonsoft.Json", "12.0.2");

            var actual = await _sut.OpenLibraryFileReadAsync(id, "package1.nuspec", CancellationToken.None);

            actual.ShouldBeNull();
        }
Exemplo n.º 3
0
        public async Task RemoveLibrary()
        {
            var id = new LibraryId("nuget.org", "Newtonsoft.Json", "12.0.2");

            DirectoryAssert.Exists(_sut.GetPackageLocation(id));

            await _sut.RemoveLibraryAsync(id, CancellationToken.None);

            DirectoryAssert.DoesNotExist(Path.GetDirectoryName(_sut.GetPackageLocation(id)));
        }
Exemplo n.º 4
0
        public async Task OpenLibraryFileRead()
        {
            var id = new LibraryId("nuget.org", "Newtonsoft.Json", "12.0.2");

            var actual = await _sut.OpenLibraryFileReadAsync(id, "package.nuspec", CancellationToken.None);

            actual.ShouldNotBeNull();
            using (actual)
            {
                var text = new StreamReader(actual).ReadToEnd();
                text.ShouldContain("<id>Newtonsoft.Json</id>");
            }
        }
Exemplo n.º 5
0
        public async Task WriteReadLibraryFileExisting()
        {
            var id = new LibraryId("nuget.org", "Newtonsoft.Json", "12.0.2");

            await _sut.WriteLibraryFileAsync(id, "package.nuspec", "some text".AsBytes(), CancellationToken.None);

            var actual = await _sut.OpenLibraryFileReadAsync(id, "package.nuspec", CancellationToken.None);

            actual.ShouldNotBeNull();
            using (actual)
            {
                new StreamReader(actual).ReadToEnd().ShouldBe("some text");
            }
        }
Exemplo n.º 6
0
        public string GetPackageLocalHRef(LibraryId id, LibraryId?relativeTo = null)
        {
            var connectionString = string.Empty;

            if (relativeTo != null)
            {
                var depth = relativeTo.Value.Name.Count(i => i == '/');
                connectionString = string.Join(string.Empty, Enumerable.Repeat(@".." + Path.DirectorySeparatorChar, depth + 4));
            }

            var href = GetPackageLocation(connectionString, id);

            return(href.Replace('\\', '/'));
        }
Exemplo n.º 7
0
        public async Task LibraryFileExists()
        {
            var id = new LibraryId("nuget.org", "Newtonsoft.Json", "12.0.2");

            var actual = await _storage.Object.LibraryFileExistsAsync(id, StorageExtensions.IndexFileName, CancellationToken.None);

            actual.ShouldBeFalse();

            await _storage.Object.WriteLibraryFileAsync(id, StorageExtensions.IndexFileName, Array.Empty <byte>(), CancellationToken.None);

            actual = await _storage.Object.LibraryFileExistsAsync(id, StorageExtensions.IndexFileName, CancellationToken.None);

            actual.ShouldBeTrue();
        }
Exemplo n.º 8
0
        public static async Task WriteLibraryReadMeAsync(this IStorage storage, LibraryId id, object context, CancellationToken token)
        {
            storage.AssertNotNull(nameof(storage));
            context.AssertNotNull(nameof(context));

            var templateFileName = LibraryReadMeTemplateFileName.FormatWith(id.SourceCode.ToLowerInvariant());
            var template         = await GetOrCreateConfigurationTemplateAsync(
                storage,
                templateFileName,
                () => DotLiquidTemplate.GetLibraryReadMeTemplate(id.SourceCode),
                token);

            var readMe = DotLiquidTemplate.Render(template, context);
            await storage.WriteLibraryFileAsync(id, ReadMeFileName, readMe, token);
        }
Exemplo n.º 9
0
        public Task RemoveLibraryAsync(LibraryId id, CancellationToken token)
        {
            var location = GetPackageLocation(id);

            if (!Directory.Exists(location))
            {
                return(Task.CompletedTask);
            }

            Directory.Delete(location, true);

            var parent = Path.GetDirectoryName(location);

            if (Directory.GetDirectories(parent).Length == 0)
            {
                Directory.Delete(parent, true);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 10
0
        public void GetLicenseLocalHRef(string licenseCode, string librarySourceCode, string libraryName, string libraryVersion)
        {
            var       currentLocation = _location.Location;
            LibraryId?relativeTo      = null;

            if (librarySourceCode != null)
            {
                relativeTo      = new LibraryId(librarySourceCode, libraryName, libraryVersion);
                currentLocation = Path.Combine(currentLocation, "packages", librarySourceCode, libraryName, libraryVersion);
            }

            DirectoryAssert.Exists(currentLocation);

            var actual = _sut.GetLicenseLocalHRef(licenseCode, relativeTo);

            Console.WriteLine(actual);

            actual.ShouldBe(actual.ToLowerInvariant());

            var licenseLocation = Path.Combine(currentLocation, actual);

            DirectoryAssert.Exists(licenseLocation);
            FileAssert.Exists(Path.Combine(licenseLocation, "index.json"));
        }
Exemplo n.º 11
0
        public static async ValueTask <bool> LibraryFileExistsAsync(this IStorage storage, LibraryId id, string fileName, CancellationToken token)
        {
            storage.AssertNotNull(nameof(storage));
            fileName.AssertNotNull(nameof(fileName));

            var content = await storage.OpenLibraryFileReadAsync(id, fileName, token);

            using (content)
            {
                return(content != null);
            }
        }
Exemplo n.º 12
0
 private static string GetPackageLocation(string connectionString, LibraryId id)
 {
     return(Path.Combine(connectionString, FolderPackages, id.SourceCode.ToLowerInvariant(), id.Name.ToLowerInvariant(), id.Version.ToLowerInvariant()));
 }
Exemplo n.º 13
0
 internal string GetPackageLocation(LibraryId id) => GetPackageLocation(Location, id);
Exemplo n.º 14
0
 public Task WriteLibraryFileAsync(LibraryId id, string fileName, byte[] content, CancellationToken token)
 {
     return(_packages.WriteFileAsync(id, fileName, content, token));
 }
Exemplo n.º 15
0
 public Task <Stream> OpenLibraryFileReadAsync(LibraryId id, string fileName, CancellationToken token)
 {
     return(_packages.OpenFileReadAsync(id, fileName, token));
 }
Exemplo n.º 16
0
        public static async Task WriteLibraryIndexJsonAsync <TModel>(this IStorage storage, LibraryId id, TModel model, CancellationToken token)
        {
            storage.AssertNotNull(nameof(storage));
            model.AssertNotNull(nameof(model));

            var content = JsonSerialize(model);
            await storage.WriteLibraryFileAsync(id, IndexFileName, content, token);
        }
Exemplo n.º 17
0
        public async Task RemoveUnknownLibrary()
        {
            var id = new LibraryId("nuget.org", "some name", "version");

            await _sut.RemoveLibraryAsync(id, CancellationToken.None);
        }
Exemplo n.º 18
0
        public static async Task <TModel> ReadLibraryIndexJsonAsync <TModel>(this IStorage storage, LibraryId id, CancellationToken token)
        {
            storage.AssertNotNull(nameof(storage));

            var content = await storage.OpenLibraryFileReadAsync(id, IndexFileName, token);

            using (content)
            {
                return(JsonDeserialize <TModel>(content));
            }
        }