mirror of
https://github.com/aphrody-labs/NuGet.Client.git
synced 2026-10-17 20:54:54 +00:00
V3OnlySourceRepositoryProvider. This is really useful to add real functional tests for NuGetPackageManager using xunit Called Update-Package for the entire PackageManagement.sln
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using NuGet.Client;
|
|
using NuGet.Configuration;
|
|
using NuGet.PackageManagement;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.Composition;
|
|
using System.ComponentModel.Composition.Hosting;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace Test.Utility
|
|
{
|
|
public class TestSourceRepositoryUtility
|
|
{
|
|
public TestSourceRepositoryUtility() {}
|
|
|
|
[ImportMany]
|
|
public Lazy<INuGetResourceProvider, INuGetResourceProviderMetadata>[] ResourceProviders;
|
|
|
|
private CompositionContainer Initialize()
|
|
{
|
|
var aggregateCatalog = new AggregateCatalog();
|
|
{
|
|
aggregateCatalog.Catalogs.Add(new DirectoryCatalog(Environment.CurrentDirectory, "*.dll"));
|
|
var container = new CompositionContainer(aggregateCatalog);
|
|
container.ComposeParts(this);
|
|
return container;
|
|
}
|
|
}
|
|
|
|
public static SourceRepositoryProvider CreateV3OnlySourceRepositoryProvider()
|
|
{
|
|
var thisUtility = new TestSourceRepositoryUtility();
|
|
var container = thisUtility.Initialize();
|
|
var packageSourceProvider = new V3OnlyPackageSourceProvider();
|
|
|
|
var sourceRepositoryProvider = new SourceRepositoryProvider(packageSourceProvider, thisUtility.ResourceProviders);
|
|
return sourceRepositoryProvider;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Provider that only returns V3 as a source
|
|
/// </summary>
|
|
class V3OnlyPackageSourceProvider : IPackageSourceProvider
|
|
{
|
|
|
|
public void DisablePackageSource(PackageSource source)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool IsPackageSourceEnabled(PackageSource source)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public IEnumerable<PackageSource> LoadPackageSources()
|
|
{
|
|
return new List<PackageSource>() { new PackageSource("https://az320820.vo.msecnd.net/ver3-preview/index.json", "v3") };
|
|
}
|
|
|
|
public event EventHandler PackageSourcesSaved;
|
|
|
|
public void SavePackageSources(IEnumerable<PackageSource> sources)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
}
|