Replace NuGetConfig with NuGetPackageSource
This commit is contained in:
parent
823baabb8f
commit
394adba776
|
|
@ -15,16 +15,4 @@
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Update="NuGetConfig\NuGet.DotNetCore.config">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="NuGetConfig\NuGet.NuGetOrg.config">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="NuGetConfig\NuGet.Empty.config">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Net;
|
||||||
namespace AspNetCoreSdkTests
|
namespace AspNetCoreSdkTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TemplateTests
|
public class FrameworkDependent
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
[TestCaseSource(nameof(RestoreData))]
|
[TestCaseSource(nameof(RestoreData))]
|
||||||
|
|
@ -48,19 +48,19 @@ namespace AspNetCoreSdkTests
|
||||||
|
|
||||||
public static IEnumerable<Template> RestoreData = new[]
|
public static IEnumerable<Template> RestoreData = new[]
|
||||||
{
|
{
|
||||||
Template.GetInstance<ClassLibraryTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<ClassLibraryTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<ConsoleApplicationTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<ConsoleApplicationTemplate>(NuGetPackageSource.None),
|
||||||
|
|
||||||
// Offline restore currently not supported for RazorClassLibrary template (https://github.com/aspnet/Universe/issues/1123)
|
// Offline restore currently not supported for RazorClassLibrary template (https://github.com/aspnet/Universe/issues/1123)
|
||||||
Template.GetInstance<RazorClassLibraryTemplate>(NuGetConfig.NuGetOrg),
|
Template.GetInstance<RazorClassLibraryTemplate>(NuGetPackageSource.NuGetOrg),
|
||||||
|
|
||||||
Template.GetInstance<WebTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<WebTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<RazorTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<RazorTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<MvcTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<MvcTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<AngularTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<AngularTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<ReactTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<ReactTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<ReactReduxTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<ReactReduxTemplate>(NuGetPackageSource.None),
|
||||||
Template.GetInstance<WebApiTemplate>(NuGetConfig.Empty),
|
Template.GetInstance<WebApiTemplate>(NuGetPackageSource.None),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static IEnumerable<Template> BuildData => RestoreData;
|
public static IEnumerable<Template> BuildData => RestoreData;
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
namespace AspNetCoreSdkTests
|
|
||||||
{
|
|
||||||
public enum NuGetConfig
|
|
||||||
{
|
|
||||||
Empty,
|
|
||||||
DotNetCore,
|
|
||||||
NuGetOrg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<packageSources>
|
|
||||||
<add key="DotNetCore" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
|
||||||
</packageSources>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<packageSources>
|
|
||||||
<clear />
|
|
||||||
</packageSources>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<packageSources>
|
|
||||||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
|
||||||
</packageSources>
|
|
||||||
</configuration>
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace AspNetCoreSdkTests
|
||||||
|
{
|
||||||
|
public enum NuGetPackageSource
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
NuGetOrg,
|
||||||
|
EnvironmentVariable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,11 +21,11 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
ServerCertificateCustomValidationCallback = (m, c, ch, p) => true
|
ServerCertificateCustomValidationCallback = (m, c, ch, p) => true
|
||||||
});
|
});
|
||||||
|
|
||||||
private static ConcurrentDictionary<(Type, NuGetConfig), Template> _templates = new ConcurrentDictionary<(Type, NuGetConfig), Template>();
|
private static ConcurrentDictionary<(Type, NuGetPackageSource), Template> _templates = new ConcurrentDictionary<(Type, NuGetPackageSource), Template>();
|
||||||
|
|
||||||
public static T GetInstance<T>(NuGetConfig nuGetConfig) where T : Template, new()
|
public static T GetInstance<T>(NuGetPackageSource nuGetPackageSource) where T : Template, new()
|
||||||
{
|
{
|
||||||
return (T)_templates.GetOrAdd((typeof(T), nuGetConfig), (k) => new T() { NuGetConfig = nuGetConfig });
|
return (T)_templates.GetOrAdd((typeof(T), nuGetPackageSource), (k) => new T() { NuGetPackageSource = nuGetPackageSource });
|
||||||
}
|
}
|
||||||
|
|
||||||
private Lazy<IEnumerable<string>> _objFilesAfterRestore;
|
private Lazy<IEnumerable<string>> _objFilesAfterRestore;
|
||||||
|
|
@ -34,7 +34,7 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
private Lazy<(HttpResponseMessage Http, HttpResponseMessage Https)> _httpResponsesAfterRun;
|
private Lazy<(HttpResponseMessage Http, HttpResponseMessage Https)> _httpResponsesAfterRun;
|
||||||
private Lazy<(HttpResponseMessage Http, HttpResponseMessage Https)> _httpResponsesAfterExec;
|
private Lazy<(HttpResponseMessage Http, HttpResponseMessage Https)> _httpResponsesAfterExec;
|
||||||
|
|
||||||
public NuGetConfig NuGetConfig { get; private set; }
|
public NuGetPackageSource NuGetPackageSource { get; private set; }
|
||||||
|
|
||||||
protected Template()
|
protected Template()
|
||||||
{
|
{
|
||||||
|
|
@ -54,9 +54,9 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
GetHttpResponsesAfterExec, LazyThreadSafetyMode.ExecutionAndPublication);
|
GetHttpResponsesAfterExec, LazyThreadSafetyMode.ExecutionAndPublication);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"{Name},{NuGetConfig}";
|
public override string ToString() => $"{Name},{NuGetPackageSource}";
|
||||||
|
|
||||||
private string TempDir => Path.Combine(AssemblySetUp.TempDir, Name, NuGetConfig.ToString());
|
private string TempDir => Path.Combine(AssemblySetUp.TempDir, Name, NuGetPackageSource.ToString());
|
||||||
|
|
||||||
public abstract string Name { get; }
|
public abstract string Name { get; }
|
||||||
public abstract TemplateType Type { get; }
|
public abstract TemplateType Type { get; }
|
||||||
|
|
@ -89,8 +89,8 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(TempDir);
|
Directory.CreateDirectory(TempDir);
|
||||||
DotNetUtil.New(Name, TempDir);
|
DotNetUtil.New(Name, TempDir);
|
||||||
DotNetUtil.Restore(TempDir, NuGetConfig);
|
DotNetUtil.Restore(TempDir, NuGetPackageSource);
|
||||||
return IOUtil.GetFiles(System.IO.Path.Combine(TempDir, "obj"));
|
return IOUtil.GetFiles(Path.Combine(TempDir, "obj"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private (IEnumerable<string> ObjFiles, IEnumerable<string> BinFiles) GetFilesAfterBuild()
|
private (IEnumerable<string> ObjFiles, IEnumerable<string> BinFiles) GetFilesAfterBuild()
|
||||||
|
|
@ -99,7 +99,7 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
_ = ObjFilesAfterRestore;
|
_ = ObjFilesAfterRestore;
|
||||||
|
|
||||||
DotNetUtil.Build(TempDir);
|
DotNetUtil.Build(TempDir);
|
||||||
return (IOUtil.GetFiles(System.IO.Path.Combine(TempDir, "obj")), IOUtil.GetFiles(System.IO.Path.Combine(TempDir, "bin")));
|
return (IOUtil.GetFiles(Path.Combine(TempDir, "obj")), IOUtil.GetFiles(Path.Combine(TempDir, "bin")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetFilesAfterPublish()
|
private IEnumerable<string> GetFilesAfterPublish()
|
||||||
|
|
@ -108,7 +108,7 @@ namespace AspNetCoreSdkTests.Templates
|
||||||
_ = BinFilesAfterBuild;
|
_ = BinFilesAfterBuild;
|
||||||
|
|
||||||
DotNetUtil.Publish(TempDir);
|
DotNetUtil.Publish(TempDir);
|
||||||
return IOUtil.GetFiles(System.IO.Path.Combine(TempDir, DotNetUtil.PublishOutput));
|
return IOUtil.GetFiles(Path.Combine(TempDir, DotNetUtil.PublishOutput));
|
||||||
}
|
}
|
||||||
|
|
||||||
private (HttpResponseMessage Http, HttpResponseMessage Https) GetHttpResponsesAfterRun()
|
private (HttpResponseMessage Http, HttpResponseMessage Https) GetHttpResponsesAfterRun()
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,15 @@ namespace AspNetCoreSdkTests.Util
|
||||||
{
|
{
|
||||||
internal static class DotNetUtil
|
internal static class DotNetUtil
|
||||||
{
|
{
|
||||||
|
private const string _clearPackageSourcesNuGetConfig =
|
||||||
|
@"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<clear />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
|
";
|
||||||
|
|
||||||
// Bind to dynamic port 0 to avoid port conflicts during parallel tests
|
// Bind to dynamic port 0 to avoid port conflicts during parallel tests
|
||||||
private const string _urls = "--urls http://127.0.0.1:0;https://127.0.0.1:0";
|
private const string _urls = "--urls http://127.0.0.1:0;https://127.0.0.1:0";
|
||||||
|
|
||||||
|
|
@ -22,13 +31,16 @@ namespace AspNetCoreSdkTests.Util
|
||||||
|
|
||||||
public static string New(string template, string workingDirectory)
|
public static string New(string template, string workingDirectory)
|
||||||
{
|
{
|
||||||
|
// Clear all packages sources by default. May be overridden by NuGetPackageSource parameter.
|
||||||
|
File.WriteAllText(Path.Combine(workingDirectory, "NuGet.config"), _clearPackageSourcesNuGetConfig);
|
||||||
|
|
||||||
return RunDotNet($"new {template} --name {template} --output . --no-restore", workingDirectory, GetEnvironment(workingDirectory));
|
return RunDotNet($"new {template} --name {template} --output . --no-restore", workingDirectory, GetEnvironment(workingDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Restore(string workingDirectory, NuGetConfig config)
|
public static string Restore(string workingDirectory, NuGetPackageSource packageSource)
|
||||||
{
|
{
|
||||||
var configPath = Path.GetFullPath(Path.Combine("NuGetConfig", $"NuGet.{config}.config"));
|
var sourceArgument = GetSourceArgument(packageSource);
|
||||||
return RunDotNet($"restore --no-cache --configfile {configPath}", workingDirectory, GetEnvironment(workingDirectory));
|
return RunDotNet($"restore --no-cache{sourceArgument}", workingDirectory, GetEnvironment(workingDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Build(string workingDirectory)
|
public static string Build(string workingDirectory)
|
||||||
|
|
@ -52,6 +64,24 @@ namespace AspNetCoreSdkTests.Util
|
||||||
return RunDotNet($"publish --no-build -o {PublishOutput}", workingDirectory, GetEnvironment(workingDirectory));
|
return RunDotNet($"publish --no-build -o {PublishOutput}", workingDirectory, GetEnvironment(workingDirectory));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetSourceArgument(NuGetPackageSource packageSource)
|
||||||
|
{
|
||||||
|
switch (packageSource)
|
||||||
|
{
|
||||||
|
case NuGetPackageSource.None:
|
||||||
|
return string.Empty;
|
||||||
|
case NuGetPackageSource.NuGetOrg:
|
||||||
|
return " --source https://api.nuget.org/v3/index.json";
|
||||||
|
case NuGetPackageSource.EnvironmentVariable:
|
||||||
|
var env = Environment.GetEnvironmentVariable("NUGET_PACKAGE_SOURCE");
|
||||||
|
return string.IsNullOrEmpty(env) ?
|
||||||
|
throw new InvalidOperationException("Environment variable NUGET_PACKAGE_SOURCE is required but not set") :
|
||||||
|
$" --source env";
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Invalid value", nameof(packageSource));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static string RunDotNet(string arguments, string workingDirectory,
|
private static string RunDotNet(string arguments, string workingDirectory,
|
||||||
IEnumerable<KeyValuePair<string, string>> environment = null, bool throwOnError = true)
|
IEnumerable<KeyValuePair<string, string>> environment = null, bool throwOnError = true)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue