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"); }
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(); }
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))); }
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>"); } }
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"); } }
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('\\', '/')); }
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(); }
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); }
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); }
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")); }
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); } }
private static string GetPackageLocation(string connectionString, LibraryId id) { return(Path.Combine(connectionString, FolderPackages, id.SourceCode.ToLowerInvariant(), id.Name.ToLowerInvariant(), id.Version.ToLowerInvariant())); }
internal string GetPackageLocation(LibraryId id) => GetPackageLocation(Location, id);
public Task WriteLibraryFileAsync(LibraryId id, string fileName, byte[] content, CancellationToken token) { return(_packages.WriteFileAsync(id, fileName, content, token)); }
public Task <Stream> OpenLibraryFileReadAsync(LibraryId id, string fileName, CancellationToken token) { return(_packages.OpenFileReadAsync(id, fileName, token)); }
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); }
public async Task RemoveUnknownLibrary() { var id = new LibraryId("nuget.org", "some name", "version"); await _sut.RemoveLibraryAsync(id, CancellationToken.None); }
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)); } }