public void TestSourceRepoPackageSourcesChanged() { // Arrange var localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var localPackageSource = new PackageSource(localAppDataPath); var oldPackageSources = new List<PackageSource>() { localPackageSource }; var packageSourceProvider = new TestPackageSourceProvider(oldPackageSources); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(packageSourceProvider); // Act var oldEffectivePackageSources = sourceRepositoryProvider.GetRepositories().ToList(); // Assert Assert.Equal(1, oldEffectivePackageSources.Count); Assert.Equal(localAppDataPath, oldEffectivePackageSources[0].PackageSource.Source); // Main Act var newPackageSources = new List<PackageSource>() { TestSourceRepositoryUtility.V3PackageSource, localPackageSource }; packageSourceProvider.SavePackageSources(newPackageSources); var newEffectivePackageSources = sourceRepositoryProvider.GetRepositories().ToList(); // Main Assert Assert.Equal(2, newEffectivePackageSources.Count); Assert.Equal(TestSourceRepositoryUtility.V3PackageSource.Source, newEffectivePackageSources[0].PackageSource.Source); Assert.Equal(localAppDataPath, newEffectivePackageSources[1].PackageSource.Source); }
void CreateAction ( string packageId = "Test", string version = "2.1") { project = new FakeDotNetProject (@"d:\projects\MyProject\MyProject.csproj"); solutionManager = new FakeSolutionManager (); nugetProject = new FakeNuGetProject (project); solutionManager.NuGetProjects[project] = nugetProject; var repositoryProvider = solutionManager.SourceRepositoryProvider; var source = new PackageSource ("http://test.com"); repositoryProvider.AddRepository (source); primaryRepositories = repositoryProvider.Repositories; action = new TestableReinstallNuGetPackageAction ( project, solutionManager); packageManagementEvents = action.PackageManagementEvents; fileRemover = action.FileRemover; action.PackageId = packageId; action.Version = new NuGetVersion (version); uninstallPackageManager = action.UninstallAction.PackageManager; installPackageManager = action.InstallAction.PackageManager; }
public virtual IPackageRepository CreateRepository(PackageSource packageSource) { if (packageSource == null) { throw new ArgumentNullException("packageSource"); } if (packageSource.IsAggregate) { throw new NotSupportedException(); } Uri uri = new Uri(packageSource.Source); if (uri.IsFile) { return new LocalPackageRepository(uri.LocalPath); } try { uri = _httpClient.GetRedirectedUri(uri); } catch (Exception exception) { throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.UnavailablePackageSource, packageSource), exception); } // Make sure we get resolve any fwlinks before creating the repository return new DataServicePackageRepository(uri, _httpClient); }
void CreateAction ( string packageId = "Test", string version = "2.1") { project = new FakeDotNetProject (@"d:\projects\MyProject\MyProject.csproj"); solutionManager = new FakeSolutionManager (); nugetProject = new FakeNuGetProject (project); solutionManager.NuGetProjects[project] = nugetProject; var metadataResourceProvider = new FakePackageMetadataResourceProvider (); packageMetadataResource = metadataResourceProvider.PackageMetadataResource; var source = new PackageSource ("http://test.com"); var providers = new INuGetResourceProvider[] { metadataResourceProvider }; var sourceRepository = new SourceRepository (source, providers); primaryRepositories = new [] { sourceRepository }.ToList (); action = new TestableInstallNuGetPackageAction ( primaryRepositories, solutionManager, project); packageManager = action.PackageManager; packageManagementEvents = action.PackageManagementEvents; fileRemover = action.FileRemover; action.PackageId = packageId; action.Version = new NuGetVersion (version); }
public override async Task<Resource> Create(PackageSource source) { try { object repo = null; string host = "TestHost"; // Check if the source is already present in the cache. if (!packageSourceCache.TryGetValue(source.Url, out repo)) { // if it's not in cache, then check if it is V2. if (await V2Utilities.IsV2(source)) { // Get a IPackageRepo object and add it to the cache. repo = V2Utilities.GetV2SourceRepository(source, host); packageSourceCache.Add(source.Url, repo); } else { // if it's not V2, returns null return null; } } // Create a resource and return it. var resource = new V2Resource((IPackageRepository)repo, host); return resource; } catch (Exception) { // *TODOs:Do tracing and throw apppropriate exception here. return null; } }
private static PackageSource CreateV3PreviewSource() { var source = new PackageSource( Strings.VsSourceRepositoryManager_V3SourceName, NuGetConstants.V3FeedUrl); return source; }
private HttpMessageHandler TryGetCredentialAndProxy(PackageSource packageSource) { Uri uri = new Uri(packageSource.Source); var proxy = ProxyCache.Instance.GetProxy(uri); var credential = CredentialStore.Instance.GetCredentials(uri); if (proxy != null && proxy.Credentials == null) { proxy.Credentials = CredentialCache.DefaultCredentials; } if (credential == null && !String.IsNullOrEmpty(packageSource.UserName) && !String.IsNullOrEmpty(packageSource.Password)) { var cache = new CredentialCache(); foreach (var scheme in _authenticationSchemes) { cache.Add(uri, scheme, new NetworkCredential(packageSource.UserName, packageSource.Password)); } credential = cache; } if (proxy == null && credential == null) return null; else { if(proxy != null) ProxyCache.Instance.Add(proxy); if (credential != null) CredentialStore.Instance.Add(uri, credential); return new WebRequestHandler() { Proxy = proxy, Credentials = credential }; } }
public static bool TryLoad(string uriOrPath, out PackageSource packageSource) { try { Uri path; if (!Uri.TryCreate(uriOrPath, UriKind.RelativeOrAbsolute, out path)) { packageSource = null; return false; } var resolvedPath = path.IsAbsoluteUri ? path.LocalPath : uriOrPath; if (File.Exists(resolvedPath)) { packageSource = PackageSource.FromJson(File.OpenRead(resolvedPath), uriOrPath); return true; } } catch (Exception e) { // TODO: proper logging if (Environment.IsDebug) { Console.Error.WriteLine($"Unable to load local file index '{uriOrPath}'"); Console.Error.WriteLine(e); } } packageSource = null; return false; }
public static async Task<bool> IsV2(PackageSource source) { var url = new Uri(source.Url); // If the url is a directory, then it's a V2 source if (url.IsFile || url.IsUnc) { return !File.Exists(url.LocalPath); } using (var client = new Data.DataClient()) { var result = await client.GetFile(url); if (result == null) { return false; } var raw = result.Value<string>("raw"); if (raw != null && raw.IndexOf("Packages", StringComparison.OrdinalIgnoreCase) != -1) { return true; } return false; } }
void CreateAction () { project = new FakeDotNetProject (@"d:\projects\MyProject\MyProject.csproj"); solutionManager = new FakeSolutionManager (); nugetProject = new FakeNuGetProject (project); solutionManager.NuGetProjects[project] = nugetProject; var metadataResourceProvider = new FakePackageMetadataResourceProvider (); packageMetadataResource = metadataResourceProvider.PackageMetadataResource; var source = new PackageSource ("http://test.com"); var providers = new INuGetResourceProvider[] { metadataResourceProvider }; var sourceRepository = new SourceRepository (source, providers); primaryRepositories = new [] { sourceRepository }.ToList (); solutionManager.SourceRepositoryProvider.Repositories.AddRange (primaryRepositories); action = new TestableUpdateAllNuGetPackagesInProjectAction ( solutionManager, project); packageManager = action.PackageManager; packageManagementEvents = action.PackageManagementEvents; fileRemover = action.FileRemover; restoreManager = action.RestoreManager; }
public RemoteV2FindPackageByIdResourcce(PackageSource packageSource) { _baseUri = packageSource.Source.EndsWith("/") ? packageSource.Source : (packageSource.Source + "/"); _httpSource = new HttpSource(new Uri(_baseUri), packageSource.UserName, packageSource.Password); PackageSource = packageSource; }
public void AddFromExtension(ISourceRepositoryProvider provider, string extensionId) { string path = GetExtensionRepositoryPath(extensionId, null, _errorHandler); PackageSource source = new PackageSource(path); _repositories.Add(provider.CreateRepository(source)); }
public void AddFromRegistry(string keyName) { string path = GetRegistryRepositoryPath(keyName, null, _errorHandler); PackageSource source = new PackageSource(path); _repositories.Add(_provider.CreateRepository(source)); }
public IPackageRepository CreateRepository(PackageSource packageSource) { IPackageRepository repository = GetExistingRepository(packageSource); if (repository != null) { return repository; } return CreateNewCachedRepository(packageSource); }
public RegisteredPackageSource(PackageSource packageSource) { Source = packageSource.Source; Name = packageSource.Name; IsEnabled = packageSource.IsEnabled; UserName = packageSource.UserName; Password = packageSource.Password; }
FakePackageRepository AddRegisteredPackageRepository(string packageSourceUrl, string packageSourceName) { var packageSource = new PackageSource(packageSourceUrl, packageSourceName); AddRegisteredPackageSource(packageSource); FakePackageRepository fakeRepository = new FakePackageRepository(); fakeMainCache.FakePackageRepositories.Add(packageSource.Source, fakeRepository); return fakeRepository; }
public void DisablePackageSource(PackageSource source) { var sourceInUse = _sources.Find(p => p.Equals(source)); if (sourceInUse != null) { sourceInUse.IsEnabled = false; } }
void CreateCacheUsingPackageSources() { nuGetPackageSource = new PackageSource("http://nuget.org", "NuGet"); fakePackageRepositoryFactory = new FakePackageRepositoryFactory(); RegisteredPackageSources packageSources = packageSourcesHelper.Options.PackageSources; IList<RecentPackageInfo> recentPackages = packageSourcesHelper.Options.RecentPackages; cache = new PackageRepositoryCache(fakePackageRepositoryFactory, packageSources, recentPackages); }
IPackageRepository GetExistingRepository(PackageSource packageSource) { IPackageRepository repository = null; if (repositories.TryGetValue(packageSource, out repository)) { return repository; } return null; }
static string ConvertToString (PackageSource source) { if (source != null) { return String.Format ("[PackageSource] Name='{0}', Source='{1}'", source.Name, source.Source); } return "[PackageSource] == Null"; }
void AddTwoPackageSourcesToRegisteredSources() { var expectedPackageSources = new PackageSource[] { new PackageSource("http://first.com", "First"), new PackageSource("http://second.com", "Second") }; AddPackageSourcesToRegisteredSources(expectedPackageSources); registeredPackageRepositories.HasMultiplePackageSources = true; }
void AddTwoPackageSourcesToRegisteredSources() { var expectedPackageSources = new PackageSource[] { new PackageSource("http://first.com", "First"), new PackageSource("http://second.com", "Second") }; AddPackageSourcesToRegisteredSources(expectedPackageSources); packageManagementService.HasMultiplePackageSources = true; }
public void CreateRepository_PackageSourceSpecified_PackageSourcePassedToCache() { CreateRegisteredPackageRepositories(); var source = new PackageSource("Test"); IPackageRepository repository = registeredRepositories.CreateRepository(source); string actualSource = fakeRepositoryCache.FirstPackageSourcePassedToCreateRepository; Assert.AreEqual("Test", actualSource); }
void ReadActivePackageSource() { IList<KeyValuePair<string, string>> packageSources = settings.GetValues(ActivePackageSourceSectionName); activePackageSource = PackageSourceConverter.ConvertFromFirstKeyValuePair(packageSources); if (IsActivePackageSourceAggregatePackageSource()) { activePackageSource.IsAggregate = true; } }
public void DisablePackageSource(PackageSource source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } _settingsManager.SetValue(DisabledPackageSourcesSectionName, source.Name, "true"); }
public RegisteredPackageSourceSettings( ISettings settings, IPackageSourceProvider packageSourceProvider, PackageSource defaultPackageSource) { this.settings = settings; this.packageSourceProvider = packageSourceProvider; this.defaultPackageSource = defaultPackageSource; ReadActivePackageSource(); }
PackageSource AddTwoPackageSourcesToRegisteredSourcesWithFirstOneDisabled() { var expectedPackageSources = new PackageSource[] { new PackageSource("http://first.com", "First") { IsEnabled = false }, new PackageSource("http://second.com", "Second") { IsEnabled = true } }; AddPackageSourcesToRegisteredSources(expectedPackageSources); registeredPackageRepositories.HasMultiplePackageSources = true; return expectedPackageSources[0]; }
public void ActivePackageSource_ActivePackageSourceChanged_RegisteredPackageSourcesActivePackageSourceIsUpdated() { CreateHost(); var expectedPackageSource = new PackageSource("Test"); host.ActivePackageSource = expectedPackageSource; PackageSource actualPackageSource = fakeRegisteredPackageRepositories.ActivePackageSource; Assert.AreEqual(expectedPackageSource, actualPackageSource); }
public void ActivePackageSource_ConsoleHostCreated_ReturnsRegisteredPackageSourcesActivePackageSource() { CreateHost(); var expectedPackageSource = new PackageSource("Test"); fakeRegisteredPackageRepositories.ActivePackageSource = expectedPackageSource; PackageSource actualPackageSource = host.ActivePackageSource; Assert.AreEqual(expectedPackageSource, actualPackageSource); }
public IPackageRepository CreateRepository(PackageSource packageSource) { if (packageSource.IsAggregate) { // Never cache the aggregate return new AggregateRepository(_packageSourceProvider.GetPackageSources() .Where(source => !source.IsAggregate) .Select(GetPackageRepository)); } return GetPackageRepository(packageSource); }