public void GetsSupportedFrameworksFromFiles() { var package = new FastZipPackage(); package.Files = new[] {new FastZipPackageFile(package, "lib/net35/Neato.dll")}; Assert.That(package.GetSupportedFrameworks(), Is.EquivalentTo(new[] { FrameworkNet35 })); }
public Stream OpenPackageSourceFile(IPackageName package, string relativePath) { relativePath = relativePath.Replace('/', Path.DirectorySeparatorChar); // Try to return the source file from its uncompressed location var parts = new[] { package.Id, package.Version.ToString(), "src", relativePath }; var stream = OpenFile(Path.Combine(parts)); if (stream != null) { return(stream); } // If the file wasn't found uncompressed look for it in symbol package zip file var packagePath = GetNupkgPath(package); if (!File.Exists(packagePath)) { return(null); } var srcPath = Path.Combine("src", relativePath); var packageFile = FastZipPackage.Open(packagePath, new byte[0]); var file = packageFile.GetFiles().SingleOrDefault(f => f.Path.Equals(srcPath, StringComparison.InvariantCultureIgnoreCase)); return(file != null ? new PackageDisposingStream(packageFile, file.GetStream()) : null); }
public void GetsSupportedFrameworksFromFiles() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net35/Neato.dll") }; Assert.That(package.GetSupportedFrameworks(), Is.EquivalentTo(new[] { FrameworkNet35 })); }
public void FiltersNull() { var package = new FastZipPackage { FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new FrameworkName[] { null }) } }; Assert.That(package.GetSupportedFrameworks(), Is.Empty); }
public void FiltersUnsupportedFramework() { var package = new FastZipPackage { FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] { VersionUtility.UnsupportedFrameworkName }) } }; Assert.That(package.GetSupportedFrameworks(), Is.Empty); }
public void GetsSupportedFrameworksFromMetadata() { var package = new FastZipPackage { FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] { FrameworkNet40 }) } }; Assert.That(package.GetSupportedFrameworks(), Is.EquivalentTo(new[] { FrameworkNet40 })); }
public void GetsSupportedFrameworksFromMetadata() { var package = new FastZipPackage { FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] {FrameworkNet40}) } }; Assert.That(package.GetSupportedFrameworks(), Is.EquivalentTo(new[] {FrameworkNet40})); }
public void Combines() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net35/Neato.dll"), }; package.FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] {FrameworkNet40}) }; Assert.That(package.GetSupportedFrameworks().ToArray(), Is.EquivalentTo(new[] { FrameworkNet35, FrameworkNet40 })); }
public void Combines() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net35/Neato.dll"), }; package.FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] { FrameworkNet40 }) }; Assert.That(package.GetSupportedFrameworks().ToArray(), Is.EquivalentTo(new[] { FrameworkNet35, FrameworkNet40 })); }
public void Distinct() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net40/Neato.dll") }; package.FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] { FrameworkNet40 }) }; Assert.That(package.GetSupportedFrameworks().ToArray(), Is.EqualTo(new[] { FrameworkNet40 })); }
public void ComputesOnlyOnce() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net35/Neato.dll"), }; package.FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] {FrameworkNet40}) }; var first = package.GetSupportedFrameworks(); Assert.That(package.GetSupportedFrameworks(), Is.SameAs(first), "Should only compute supported frameworks once."); }
public void ComputesOnlyOnce() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net35/Neato.dll"), }; package.FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] { FrameworkNet40 }) }; var first = package.GetSupportedFrameworks(); Assert.That(package.GetSupportedFrameworks(), Is.SameAs(first), "Should only compute supported frameworks once."); }
public Stream OpenPackageSourceFile(IPackageName package, string relativePath) { relativePath = relativePath.Replace('/', Path.DirectorySeparatorChar); var packagePath = GetNupkgPath(package); if (!File.Exists(packagePath)) { return(null); } var srcPath = Path.Combine("src", relativePath); var packageFile = FastZipPackage.Open(packagePath, new byte[0]); var file = packageFile.GetFiles().SingleOrDefault(f => f.Path.Equals(srcPath, StringComparison.InvariantCultureIgnoreCase)); return(file != null ? new PackageDisposingStream(packageFile, file.GetStream()) : null); }
public dynamic Execute(dynamic parameters, INancyModule module) { var file = module.Request.Files.FirstOrDefault(); string feedName = parameters.feed; if (file == null) { var response = module.Response.AsText("Must provide package with valid id and version."); response.StatusCode = HttpStatusCode.BadRequest; return(response); } int feedId; IFeed feed; using (ITransaction transaction = Store.BeginTransaction()) { feed = transaction.Query <IFeed>().Where("Name = @feedName").Parameter("feedName", feedName).First(); if (feed == null) { var response = module.Response.AsText("Feed does not exist."); response.StatusCode = HttpStatusCode.BadRequest; return(response); } feedId = feed.Id; } if (RequiresApiKeyCheck(feed)) { if (!IsValidNuGetApiKey(module, feed)) { if (module.Request.Headers["Authorization"].FirstOrDefault() != null) { module.RequiresAuthentication(); } else { var response = module.Response.AsText("Invalid API key."); response.StatusCode = HttpStatusCode.Forbidden; return(response); } } } string temporaryFilePath; using (var stream = _fileSystem.CreateTemporaryFile(".nupkg", out temporaryFilePath)) { file.Value.CopyTo(stream); } try { IPackage package = FastZipPackage.Open(temporaryFilePath, new CryptoHashProvider()); if (string.IsNullOrWhiteSpace(package.Id) || package.Version == null) { var response = module.Response.AsText("Must provide package with valid id and version."); response.StatusCode = HttpStatusCode.BadRequest; return(response); } IInternalPackageRepository packageRepository = _packageRepositoryFactory.Create(feedId); var existingPackage = packageRepository.GetPackage(package.Id, package.Version); if (existingPackage != null) { var response = module.Response.AsText("A package with the same ID and version already exists. Overwriting packages is not enabled on this feed."); response.StatusCode = HttpStatusCode.Conflict; return(response); } IInternalPackage latestAbsoluteVersionPackage; IInternalPackage latestVersionPackage; GetCurrentLatestVersionPackages(feedId, package.Id, packageRepository, out latestAbsoluteVersionPackage, out latestVersionPackage); bool isUploadedPackageAbsoluteLatestVersion = true; bool isUploadedPackageLatestVersion = true; if (latestAbsoluteVersionPackage != null) { if (package.Version.CompareTo(latestAbsoluteVersionPackage.GetSemanticVersion()) <= 0) { isUploadedPackageAbsoluteLatestVersion = false; } } if (latestVersionPackage != null) { if (package.Version.CompareTo(latestVersionPackage.GetSemanticVersion()) <= 0) { isUploadedPackageLatestVersion = false; } else { if (!package.IsReleaseVersion()) { isUploadedPackageLatestVersion = false; } } } else { if (!package.IsReleaseVersion()) { isUploadedPackageLatestVersion = false; } } if (isUploadedPackageAbsoluteLatestVersion && latestAbsoluteVersionPackage != null) { latestAbsoluteVersionPackage.IsAbsoluteLatestVersion = false; using (ITransaction transaction = Store.BeginTransaction()) { transaction.Update(latestAbsoluteVersionPackage); transaction.Commit(); } } if (isUploadedPackageLatestVersion && latestVersionPackage != null) { latestVersionPackage.IsLatestVersion = false; using (ITransaction transaction = Store.BeginTransaction()) { transaction.Update(latestVersionPackage); transaction.Commit(); } } packageRepository.AddPackage(package, isUploadedPackageAbsoluteLatestVersion, isUploadedPackageLatestVersion); } finally { if (File.Exists(temporaryFilePath)) { _fileSystem.DeleteFile(temporaryFilePath); } } return(new Response { StatusCode = HttpStatusCode.Created }); }
public void Distinct() { var package = new FastZipPackage(); package.Files = new[] { new FastZipPackageFile(package, "lib/net40/Neato.dll") }; package.FrameworkAssemblies = new[] { new FrameworkAssemblyReference("Neato", new[] {FrameworkNet40}) }; Assert.That(package.GetSupportedFrameworks().ToArray(), Is.EqualTo(new[] { FrameworkNet40 })); }