public IPackageObject FindPackage(string path, IPackageReference packageRef) { Guard.AgainstNullArgument("packageRef", packageRef); var repository = new LocalPackageRepository(path); var package = packageRef.Version != null ? repository.FindPackage(packageRef.PackageId, new SemanticVersion(packageRef.Version, packageRef.SpecialVersion), true, true) : repository.FindPackage(packageRef.PackageId); return(package == null ? null : new PackageObject(package, packageRef.FrameworkName)); }
/*<summary> * Using Nuget.Core API, we gather all nuget`s packages that specific project depend on them. * </summary> * <returns></returns> */ private static void addDependencies(string projectName, Module module, string localSource, string[] packageConfigPath, string Configuration) { if (packageConfigPath.Length != 0) { var sharedPackages = new LocalPackageRepository(localSource); var packageReferenceFile = new PackageReferenceFile(packageConfigPath[0]); IEnumerable <PackageReference> projectPackages = packageReferenceFile.GetPackageReferences(); foreach (PackageReference package in projectPackages) { var pack = sharedPackages.FindPackage(package.Id, package.Version); using (Stream packageStream = ((NuGet.OptimizedZipPackage)(pack)).GetStream()) { byte[] buf = new byte[packageStream.Length]; int byteread = packageStream.Read(buf, 0, buf.Length); module.Dependencies.Add(new Dependency { type = "nupkg", md5 = MD5CheckSum.GenerateMD5(buf), sha1 = Sha1Reference.GenerateSHA1(buf), scopes = new List <string> { Configuration }, id = pack.Id + ":" + pack.Version }); } } } }
static void OutputGraph(LocalPackageRepository repository, IEnumerable <IPackage> packages, int depth, int maxDepth) { foreach (IPackage package in packages) { Console.WriteLine("{0}{1} v{2}", new string(' ', depth * 3), package.Id, package.Version); IList <IPackage> dependentPackages = new List <IPackage>(); foreach (var dependencySet in package.DependencySets) { foreach (var dependency in dependencySet.Dependencies) { var dependentPackage = repository.FindPackage(dependency.Id, dependency.VersionSpec, true, true); if (dependentPackage != null) { dependentPackages.Add(dependentPackage); } } } if (depth < maxDepth) { OutputGraph(repository, dependentPackages, depth + 1, maxDepth); } } }
private IPackage ReadPackage(string packageName) { var path = Path.Combine(TestRootPath, packageName, "bin/Debug"); var repository = new LocalPackageRepository(path); return(repository.FindPackage(packageName)); }
public void FindPackageReturnsPackagesWithDotInId() { // Arrange var repositoryRoot = CreatePackage("Test", "1.0.0", @"Test.1.0.0.nupkg"); CreatePackage("Test", "1.2.0", @"SubDir\Test.1.0.0.nupkg"); CreatePackage("test.extensions", "1.0", "Test.Extensions.1.0.0.0.nupkg", repositoryRoot); CreatePackage("test.extensions", "1.3.0-alpha", "Test.Extensions.1.3.0-alpha.nupkg", repositoryRoot); var repository = new LocalPackageRepository(repositoryRoot); // Act var result1 = repository.FindPackage("test.extensions", new SemanticVersion("1.0")); var result2 = repository.FindPackage("test.extensions", new SemanticVersion("1.3-alpha")); // Assert AssertPackage("test.extensions", "1.0", result1); AssertPackage("test.extensions", "1.3.0-alpha", result2); }
public void FindPackageReturnsPackageWithVersionedFileNameAtRoot(string id, string version, string packageName) { // Arrange var repositoryRoot = CreatePackage(id, version, packageName); var repository = new LocalPackageRepository(repositoryRoot); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
internal PackageEngine(FileInfo localPackage) : this() { var dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "LocalTemplates")); localPackage.CopyTo(Path.Combine(dir.FullName, localPackage.Name), true); Repository = new LocalPackageRepository(dir.FullName, true); Manager = new PackageManager(Repository, Resolver, FileSystem); Package = Repository.FindPackage(localPackage.Name.Replace(localPackage.Extension, string.Empty), new VersionSpec() { MinVersion = new SemanticVersion(0, 0, 0, 0) }, true, true); }
//================================================================ #region Getting the package from NuGet private InstalledPackage TryGetPackageFromNuGetCache(PackageRequest request, FileSyncer binFileSyncer) { var sw = Stopwatch.StartNew(); // Use cache only if not deploying from source and an exact version is specified: if (request.Source != null) { return(null); } var requestVersionsRange = !string.IsNullOrEmpty(request.VersionsRange) ? VersionUtility.ParseVersionSpec(request.VersionsRange) : new VersionSpec(); if (requestVersionsRange.MinVersion == null || requestVersionsRange.MinVersion.Equals(new SemanticVersion("0.0")) || requestVersionsRange.MinVersion != requestVersionsRange.MaxVersion) { _logger.Trace(() => $"Not looking for {request.ReportIdVersionsRange()} in packages cache because the request does not specify an exact version."); return(null); } // Find the NuGet package: var nugetRepository = new LocalPackageRepository(Paths.PackagesCacheFolder, enableCaching: false); IPackage package = nugetRepository.FindPackage(request.Id, requestVersionsRange, allowPrereleaseVersions: true, allowUnlisted: true); _performanceLogger.Write(sw, () => $"PackageDownloader: {(package == null ? "Did not find" : "Found")} the NuGet package {request.ReportIdVersionsRange()} in cache."); if (package == null) { return(null); } // Copy binary files and resources: string packageSubfolder = nugetRepository.PathResolver.GetPackageDirectory(request.Id, requestVersionsRange.MinVersion); _deployPackagesLogger.Trace(() => $"Reading package from cache '{packageSubfolder}'."); string targetFolder = Path.Combine(Paths.PackagesCacheFolder, packageSubfolder); foreach (var file in FilterCompatibleLibFiles(package.GetFiles())) { binFileSyncer.AddFile(Path.Combine(targetFolder, file.Path), Paths.PluginsFolder, Path.Combine(Paths.PluginsFolder, file.EffectivePath)); } binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Plugins"), Paths.PluginsFolder, recursive: false); // Obsolete bin folder; lib should be used instead. binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Resources"), Paths.ResourcesFolder, SimplifyPackageName(package.Id), recursive: true); return(new InstalledPackage(package.Id, package.Version.ToString(), GetNuGetPackageDependencies(package), targetFolder, request, Paths.PackagesCacheFolder)); }
public void FindPackageReturnsPackageWithUnVersionedFileNameWhenUsingVersionlessPathResolver(string id, string version, string packageName) { // Arrange var repositoryRoot = CreatePackage(id, version, packageName); var fileSystem = new PhysicalFileSystem(repositoryRoot); var pathResolver = new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false); var repository = new LocalPackageRepository(pathResolver, fileSystem); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
private IPackage FindCandidate(string name, SemanticVersion version) { if (version == null) { return(_repository.FindPackagesById(name).FirstOrDefault()); } else if (version.IsSnapshot) { return(_repository.FindPackagesById(name) .OrderByDescending(pk => pk.Version.SpecialVersion, StringComparer.OrdinalIgnoreCase) .FirstOrDefault(pk => pk.Version.EqualsSnapshot(version))); } return(_repository.FindPackage(name, version)); }
static void OutputGraph(LocalPackageRepository repository, IEnumerable <IPackage> packages, int depth) { foreach (IPackage package in packages) { Console.WriteLine("{0}{1} v{2}", new string(' ', depth), package.Id, package.Version); IList <IPackage> dependentPackages = new List <IPackage>(); foreach (var dependency in package.Dependencies) { dependentPackages.Add(repository.FindPackage(dependency.Id, dependency.VersionSpec.ToString())); } OutputGraph(repository, dependentPackages, depth += 3); } }
//================================================================ #region Getting the package from NuGet private InstalledPackage TryGetPackageFromNuGetCache(PackageRequest request, FileSyncer binFileSyncer) { // Use cache only if not deploying from source and an exact version is specified: if (request.Source != null) { return(null); } var requestVersionsRange = !string.IsNullOrEmpty(request.VersionsRange) ? VersionUtility.ParseVersionSpec(request.VersionsRange) : new VersionSpec(); // Default NuGet behavior is to download the smallest version in the given range, so only MinVersion is checked here: if (!SpecifiedMinVersion(requestVersionsRange)) { _logger.Trace(() => $"Not looking for {request.ReportIdVersionsRange()} in packages cache because the request does not specify an exact version."); return(null); } // Find the NuGet package: var nugetRepository = new LocalPackageRepository(_packagesCacheFolder, enableCaching: false); IPackage package = nugetRepository.FindPackage(request.Id, requestVersionsRange, allowPrereleaseVersions: true, allowUnlisted: true); if (package == null) { _logger.Trace(() => $"Did not find NuGet package {request.ReportIdVersionsRange()} in cache."); return(null); } // Copy binary files: string packageSubfolder = nugetRepository.PathResolver.GetPackageDirectory(request.Id, package.Version); _logger.Trace(() => $"Reading package {request.Id} from cache '{packageSubfolder}'."); _logger.Info(() => $"Reading {request.Id} from cache."); string targetFolder = Path.Combine(_packagesCacheFolder, packageSubfolder); foreach (var file in FilterCompatibleLibFiles(package.GetFiles())) { binFileSyncer.AddFile(Path.Combine(targetFolder, file.Path), Paths.PluginsFolder, Path.Combine(Paths.PluginsFolder, file.EffectivePath)); } binFileSyncer.AddFolderContent(Path.Combine(targetFolder, "Plugins"), Paths.PluginsFolder, recursive: false); // Obsolete bin folder; lib should be used instead. return(new InstalledPackage(package.Id, package.Version.ToString(), GetNuGetPackageDependencies(package), targetFolder, request, _packagesCacheFolder)); }
public static IList <Package> Collect(string projectFolder) { string packageReferenceFilePath = Path.Combine(projectFolder, "packages.config"); if (!File.Exists(packageReferenceFilePath)) { return(new List <Package>()); } string solutionFolder = Path.GetFullPath(Path.Combine(projectFolder, @"..\")); string packageRepositoryPath = Path.Combine(solutionFolder, "packages"); var packageReferences = new PackageReferenceFile(packageReferenceFilePath); var packageRepository = new LocalPackageRepository(packageRepositoryPath); var packages = new List <Package>(); foreach (var packageReference in packageReferences.GetPackageReferences()) { string packageId = packageReference.Id; if (ExcludedPackageNames.Any(w => packageId.ToLower().Contains(w.ToLower()))) { continue; } var package = new Package { Name = packageId, Version = packageReference.Version.Version.ToString(), TargetFramework = packageReference?.TargetFramework?.Version?.ToString() }; // Try to get remaining attributes from local package store var nugetPackage = packageRepository.FindPackage(packageId, packageReference.Version); if (nugetPackage != null) { package.Summary = nugetPackage.Summary; package.Description = nugetPackage.Description; package.Authors = String.Join(",", nugetPackage.Authors); package.IconUrl = nugetPackage.IconUrl; package.ProjectUrl = nugetPackage.ProjectUrl; } packages.Add(package); } return(packages); }
public void RunFromGallery() { Directory.CreateDirectory(_targetDirectory); var client = new HttpClient(DeveloperFeed); client.SendingRequest += (sender, e) => { e.Request.Credentials = _credentials; e.Request.PreAuthenticate = true; }; var remoteRepo = new DataServicePackageRepository(client); var targetRepo = new LocalPackageRepository(_targetDirectory); var packages = remoteRepo.GetPackages() .Where(p => p.IsAbsoluteLatestVersion) .ToList(); Parallel.ForEach(packages, new ParallelOptions { MaxDegreeOfParallelism = 4 }, package => { // Some packages are updated without revving the version. We'll only opt not to re-download // a package if an identical version does not exist on disk. var existingPackage = targetRepo.FindPackage(package.Id, package.Version); var dataServicePackage = (DataServicePackage)package; if (existingPackage == null || !existingPackage.GetHash(dataServicePackage.PackageHashAlgorithm).Equals(dataServicePackage.PackageHash, StringComparison.Ordinal)) { Trace.WriteLine(string.Format("{0}: Adding package {1}", DateTime.Now, package.GetFullName())); var packagePath = GetPackagePath(package); using (var input = package.GetStream()) using (var output = File.Create(packagePath)) { input.CopyTo(output); } PurgeOldVersions(targetRepo, package); } }); }
public ReferenceAttacher(Solution solution) { _solution = solution; _repository = new LocalPackageRepository(_solution.PackagesDirectory()); _packages = new Cache <string, IPackage>(name => { try { return(_repository.FindPackage(name)); } catch (Exception) { return(null); } }); _toolsVersionMatch["4.0"] = "net40"; }
private static void ReportDependencyPackage(LocalPackageRepository repository, List <Dependency> dependencies, IPackage package, HashSet <string> packageCollection) { Dependency targetDependency = new Dependency(); dependencies.Add(targetDependency); targetDependency.key = "nuget:" + package.Id; targetDependency.name = package.Id; targetDependency.versions.Add(package.Version.ToString()); //versions = new List<string> { package.Version.ToString() }, //targetDependency.description = package.Description, //homepageUrl = package.ProjectUrl?.AbsoluteUri, //targetDependency.name = projectLibrary.FrameworkName.ToString(); //targetDependency.key = $"netframework:{projectLibrary.FrameworkName.ToString()}"; // We let add duplicate package in our Dependency tree, but won't allow its further children. if (packageCollection.Contains(package.GetFullName())) { return; } packageCollection.Add(package.GetFullName()); foreach (var dependencySet in package.DependencySets) { foreach (var dependency in dependencySet.Dependencies) { IPackage dependentPackage = repository.FindPackage(dependency.Id, dependency.VersionSpec, true, true); if (dependentPackage != null) { ReportDependencyPackage(repository, targetDependency.dependencies, dependentPackage, packageCollection); } } } }
public void FindPackageMatchesExactVersion() { // Arrange string id = "Test"; string version = "1.3.1.0"; string packageName = "Test.1.3.1.nupkg"; var repositoryRoot = CreatePackage(id, version, packageName); CreatePackage(id, "1.3.4", "Test.nupkg", repositoryRoot); // Create dummy files. Attempting to open these packages would throw, so we know we're not opening it. File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.3.2.nupkg"), ""); File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.3.nupkg"), ""); File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.31.nupkg"), ""); var repository = new LocalPackageRepository(repositoryRoot); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
public void FindPackageReturnsPackagesFromNestedDirectories() { // Arrange string id = "Test"; string version = "1.3.1.0"; string packageName = @"SubDir\Test.1.3.1.nupkg"; var repositoryRoot = CreatePackage(id, version, packageName); CreatePackage(id, "1.3.4", "Test.nupkg", repositoryRoot); // Create dummy files. Attempting to open these packages would throw, so we know we're not opening it. File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.3.2.nupkg"), ""); File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.3.nupkg"), ""); File.WriteAllText(Path.Combine(repositoryRoot, "Test.1.31.nupkg"), ""); var repository = new LocalPackageRepository(repositoryRoot); // Act var findPackage = repository.FindPackage(id, new SemanticVersion(version)); // Assert AssertPackage(id, version, findPackage); }
static void OutputGraph(LocalPackageRepository repository, IEnumerable <IPackage> packages, int depth, ECSDependecy basePkg) { foreach (IPackage package in packages) { ECSDependecy dep = new ECSDependecy { versions = new List <string> { package.Version.ToString() }, key = "nuget:" + package.Id, name = package.Id, //package.Title == null ? package.Title : package.Id, description = package.Description, homepageUrl = package.ProjectUrl?.AbsoluteUri, dependencies = new List <ECSDependecy>(), licenses = new List <License> { }, }; dep.licenses.Add(new License { name = "unknown", url = package.LicenseUrl?.AbsoluteUri }); Console.WriteLine("{0}{1} v{2}", new string(' ', depth), package.Id, package.Version); basePkg.dependencies.Add(dep); IList <IPackage> dependentPackages = new List <IPackage>(); foreach (var dependencySet in package.DependencySets) { foreach (var dependency in dependencySet.Dependencies) { dependentPackages.Add(repository.FindPackage(dependency.Id, dependency.VersionSpec, true, true)); } } OutputGraph(repository, dependentPackages, depth + 3, dep); } }
public static ScriptExtensions CompileAssembly(PackageConfiguration configuration, string editorRepositoryPath, bool includeDebugInformation) { var path = Environment.CurrentDirectory; var configurationRoot = ConfigurationHelper.GetConfigurationRoot(configuration); var scriptProjectFile = Path.Combine(path, Path.ChangeExtension(OutputAssemblyName, ProjectExtension)); if (!File.Exists(scriptProjectFile)) { return(new ScriptExtensions(configuration, null)); } var extensionsPath = Path.Combine(path, OutputAssemblyName); if (!Directory.Exists(extensionsPath)) { return(new ScriptExtensions(configuration, null)); } var scriptFiles = Directory.GetFiles(extensionsPath, ScriptExtension, SearchOption.AllDirectories); if (scriptFiles.Length == 0) { return(new ScriptExtensions(configuration, null)); } var assemblyNames = new HashSet <string>(); var assemblyDirectory = Path.GetTempPath() + OutputAssemblyName + "." + Guid.NewGuid().ToString(); var scriptEnvironment = new ScriptExtensions(configuration, assemblyDirectory); var packageRepository = new LocalPackageRepository(editorRepositoryPath); var projectReferences = from id in scriptEnvironment.GetPackageReferences() let package = packageRepository.FindPackage(id) where package != null from assemblyReference in FindAssemblyReferences(packageRepository, package) select assemblyReference; assemblyNames.AddRange(scriptEnvironment.GetAssemblyReferences()); assemblyNames.AddRange(projectReferences); var assemblyFile = Path.Combine(assemblyDirectory, Path.ChangeExtension(OutputAssemblyName, DllExtension)); var assemblyReferences = (from fileName in assemblyNames let assemblyName = Path.GetFileNameWithoutExtension(fileName) let assemblyLocation = ConfigurationHelper.GetAssemblyLocation(configuration, assemblyName) select assemblyLocation == null ? fileName : Path.IsPathRooted(assemblyLocation) ? assemblyLocation : Path.Combine(configurationRoot, assemblyLocation)) .ToArray(); var compilerParameters = new CompilerParameters(assemblyReferences, assemblyFile); compilerParameters.GenerateExecutable = false; compilerParameters.GenerateInMemory = false; compilerParameters.IncludeDebugInformation = includeDebugInformation; if (!includeDebugInformation) { compilerParameters.CompilerOptions = "/optimize"; } using (var codeProvider = new CSharpCodeProvider()) { var results = codeProvider.CompileAssemblyFromFile(compilerParameters, scriptFiles); if (results.Errors.HasErrors) { try { Console.Error.WriteLine("--- Error building script extensions ---"); foreach (var error in results.Errors) { Console.Error.WriteLine(error); } } finally { scriptEnvironment.Dispose(); } return(new ScriptExtensions(configuration, null)); } else { var assemblyName = AssemblyName.GetAssemblyName(assemblyFile); configuration.AssemblyReferences.Add(assemblyName.Name); configuration.AssemblyLocations.Add(assemblyName.Name, ProcessorArchitecture.MSIL, assemblyName.CodeBase); scriptEnvironment.AssemblyName = assemblyName; } return(scriptEnvironment); } }
private static void Do(LocalPackageRepository inputRepository, PackageManager inputManager, IPackage package, string cacheDirectory, IEnumerable <string> references, string outputDirectory) { Console.WriteLine("--- Building {0} ---", package.GetFullName()); var solution = new ProjectCollection(); var logger = new ConsoleLogger(); logger.Verbosity = LoggerVerbosity.Minimal; inputManager.InstallPackage(package, false, false); var packageDirectory = Path.Combine(cacheDirectory, package.Id); var moduleDirectory = Directory.GetDirectories(Path.Combine(packageDirectory, "Content", "Modules"))[0]; var moduleName = Path.GetFileName(moduleDirectory); var project = solution.LoadProject(Path.Combine(moduleDirectory, moduleName + ".csproj")); var candidateDirectories = references .Select(r => Path.Combine(cacheDirectory, r)) .Concat(Directory.EnumerateDirectories(cacheDirectory).Where(d => !Path.GetFileName(d).StartsWith("Orchard."))) .Join(new[] { "net40-full", "net40", "net35", "net20", "net", "" }, l => true, r => true, (l, r) => Path.Combine(l, "lib", r)) .Where(Directory.Exists) .ToList(); foreach (var item in GetReferences(project).ToList()) { var referenceName = GetReferenceName(item); var referenceDirectory = candidateDirectories.FirstOrDefault(d => File.Exists(Path.Combine(d, referenceName + ".dll"))); if (referenceDirectory != null) { Console.WriteLine("Replacing reference {0} with {1}", referenceName, referenceDirectory); ReplaceReference(project, item, referenceName, referenceDirectory); } } var dependencies = new List <ManifestDependency>(); foreach (var item in GetModuleReferences(project).ToList()) { var referencedModuleName = item.GetMetadataValue("Name"); var referencedPackageId = "Orchard.Module." + item.GetMetadataValue("Name"); var referencedPackage = inputRepository.FindPackage(referencedPackageId); Console.WriteLine("Depends on {0}", referencedModuleName); dependencies.Add(new ManifestDependency { Id = referencedPackage.Id, Version = "[" + referencedPackage.Version + "]" }); Do(inputRepository, inputManager, referencedPackage, cacheDirectory, references, outputDirectory); ReplaceReference(project, item, referencedModuleName, Path.Combine(cacheDirectory, referencedPackageId, "Content", "Modules", referencedModuleName, "bin")); } if (!File.Exists(Path.Combine(moduleDirectory, "bin", moduleName + ".dll"))) { if (!project.Build(logger)) { throw new Exception("Failed to build"); } } var rules = new[] { @"bin\" + moduleName + ".dll", @"Module.txt", @"Placement.info", @"Web.config", @"Content\**", @"Scripts\**", @"Recipes\**", @"Styles\**", @"Views\**" }; var manifest = Manifest.Create(package); manifest.Metadata.DependencySets = new List <ManifestDependencySet> { new ManifestDependencySet { Dependencies = dependencies } }; manifest.Files = rules.Select(r => new ManifestFile { Source = @"Content\Modules\" + moduleName + @"\**\" + r, Target = @"Content\Modules\" + moduleName }).ToList(); var builder = new PackageBuilder(); builder.Populate(manifest.Metadata); builder.PopulateFiles(packageDirectory, manifest.Files); Directory.CreateDirectory(outputDirectory); var outputPackgeFileName = Path.Combine(outputDirectory, manifest.Metadata.Id + "." + manifest.Metadata.Version + ".nupkg"); using (var outputPackageFile = File.Create(outputPackgeFileName)) builder.Save(outputPackageFile); }
public void FindPackageMatchesExactVersionIfSideBySideIsEnabled() { // Arrange var fileSystem = new Mock<MockProjectSystem> { CallBase = true }; fileSystem.Setup(c => c.FileExists(It.Is<string>(a => a.Equals(@"A.1.0\A.1.0.nupkg")))).Returns(false); fileSystem.Setup(c => c.FileExists(It.Is<string>(a => a.Equals(@"A.0.8\A.0.8.nupkg")))).Returns(false); fileSystem.Setup(c => c.FileExists(It.Is<string>(a => a.Equals(@"A.1.1\A.1.1.nupkg")))).Returns(true); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem.Object, useSideBySidePaths: true), fileSystem.Object, enableCaching: false); var searchedPaths = new List<string>(); Func<string, IPackage> openPackage = p => { searchedPaths.Add(p); string id = Path.GetFileNameWithoutExtension(p); return PackageUtility.CreatePackage("A", "1.1"); }; // Act and Assert IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); Assert.Null(result); Assert.False(searchedPaths.Any()); result = repository.FindPackage(openPackage, "A", new SemanticVersion("0.8")); Assert.Null(result); Assert.False(searchedPaths.Any()); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.1")); Assert.Equal(@"A.1.1\A.1.1.nupkg", searchedPaths.Single()); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.1"), result.Version); fileSystem.Verify(); }
public void FindPackageMatchesExactVersionIfSideBySideIsDisabled() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(PathFixUtility.FixPath(@"A\A.nupkg")); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: false), fileSystem, enableCaching: false); var searchedPaths = new List<string>(); Func<string, IPackage> openPackage = p => { searchedPaths.Add(p); return PackageUtility.CreatePackage("A", "1.1"); }; // Act and Assert IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); Assert.Null(result); Assert.Equal(PathFixUtility.FixPath(@"A\A.nupkg"), searchedPaths.Single()); searchedPaths.Clear(); result = repository.FindPackage(openPackage, "A", new SemanticVersion("0.8")); Assert.Null(result); Assert.Equal(PathFixUtility.FixPath(@"A\A.nupkg"), searchedPaths.Single()); searchedPaths.Clear(); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.1")); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.1"), result.Version); }
public void FindPackageVerifiesPackageFileExistsOnFileSystemWhenCaching() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"A.1.0.0.nupkg"); var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem, useSideBySidePaths: true), fileSystem, enableCaching: true); var searchedPaths = new List<string>(); Func<string, IPackage> openPackage = p => { searchedPaths.Add(p); return PackageUtility.CreatePackage("A", "1.0"); }; // Act - 1 IPackage result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); // Assert - 1 Assert.NotNull(result); Assert.Equal("A", result.Id); Assert.Equal(new SemanticVersion("1.0"), result.Version); // Act - 2 fileSystem.DeleteFile("A.1.0.0.nupkg"); result = repository.FindPackage(openPackage, "A", new SemanticVersion("1.0")); // Assert - 2 Assert.Null(result); }
public Task <Stream> OpenNupkgStreamAsync(PackageInfo package) { return(Task.FromResult(_repository.FindPackage(package.Id, package.Version).GetStream())); }