WIP: Convert templates from enum to class
This commit is contained in:
parent
1a4035418a
commit
6fec0dc8e9
|
|
@ -1,14 +0,0 @@
|
|||
namespace AspNetCoreSdkTests
|
||||
{
|
||||
public enum Template
|
||||
{
|
||||
Web,
|
||||
Mvc,
|
||||
Razor,
|
||||
Angular,
|
||||
React,
|
||||
ReactRedux,
|
||||
RazorClassLib,
|
||||
WebApi
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using AspNetCoreSdkTests.Util;
|
||||
using AspNetCoreSdkTests.Templates;
|
||||
using AspNetCoreSdkTests.Util;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AspNetCoreSdkTests
|
||||
{
|
||||
|
|
@ -8,37 +8,33 @@ namespace AspNetCoreSdkTests
|
|||
public class TemplateTests
|
||||
{
|
||||
[Test]
|
||||
[TestCaseSource(typeof(TestData), nameof(TestData.AllTemplates))]
|
||||
public void Restore(Template template, NuGetConfig nuGetConfig)
|
||||
public void Restore(
|
||||
[ValueSource(typeof(TemplateData), nameof(TemplateData.All))] Template template,
|
||||
[Values] NuGetConfig nuGetConfig)
|
||||
{
|
||||
IEnumerable<string> objFiles;
|
||||
using (var context = new DotNetContext())
|
||||
{
|
||||
context.New(template, restore: false);
|
||||
context.New(template);
|
||||
context.Restore(nuGetConfig);
|
||||
objFiles = context.GetObjFiles();
|
||||
|
||||
CollectionAssert.AreEquivalent(template.ExpectedObjFilesAfterRestore, context.GetObjFiles());
|
||||
}
|
||||
|
||||
var t = template.ToString().ToLowerInvariant();
|
||||
var expectedObjFiles = new[] {
|
||||
$"{t}.csproj.nuget.cache",
|
||||
$"{t}.csproj.nuget.g.props",
|
||||
$"{t}.csproj.nuget.g.targets",
|
||||
"project.assets.json",
|
||||
};
|
||||
|
||||
CollectionAssert.AreEquivalent(expectedObjFiles, objFiles);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//[TestCaseSource(typeof(TestData), nameof(TestData.AllTemplates))]
|
||||
//public void Build(Template template, NuGetConfig nuGetConfig)
|
||||
//{
|
||||
// using (var context = new DotNetContext())
|
||||
// {
|
||||
// context.New(template, restore: false);
|
||||
// context.Restore(nuGetConfig);
|
||||
// }
|
||||
//}
|
||||
[Test]
|
||||
public void Build(
|
||||
[ValueSource(typeof(TemplateData), nameof(TemplateData.All))] Template template,
|
||||
[Values] NuGetConfig nuGetConfig)
|
||||
{
|
||||
using (var context = new DotNetContext())
|
||||
{
|
||||
context.New(template);
|
||||
context.Restore(nuGetConfig);
|
||||
context.Build();
|
||||
|
||||
CollectionAssert.AreEquivalent(template.ExpectedObjFilesAfterBuild, context.GetObjFiles());
|
||||
CollectionAssert.AreEquivalent(template.ExpectedBinFilesAfterBuild, context.GetBinFiles());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace AspNetCoreSdkTests.Templates
|
||||
{
|
||||
public class ClassLibraryTemplate : Template
|
||||
{
|
||||
public virtual string OutputPath { get; } = Path.Combine("Debug", "netstandard2.0");
|
||||
|
||||
public override string Name => "classlib";
|
||||
|
||||
public override TemplateType Type => TemplateType.ClassLibrary;
|
||||
|
||||
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]
|
||||
{
|
||||
$"{Name}.AssemblyInfo.cs",
|
||||
$"{Name}.AssemblyInfoInputs.cache",
|
||||
$"{Name}.assets.cache",
|
||||
$"{Name}.csproj.CoreCompileInputs.cache",
|
||||
$"{Name}.csproj.FileListAbsolute.txt",
|
||||
$"{Name}.csprojAssemblyReference.cache",
|
||||
$"{Name}.dll",
|
||||
$"{Name}.pdb",
|
||||
}.Select(p => Path.Combine(OutputPath, p)));
|
||||
|
||||
public override IEnumerable<string> ExpectedBinFilesAfterBuild => new[]
|
||||
{
|
||||
$"{Name}.deps.json",
|
||||
$"{Name}.dll",
|
||||
$"{Name}.pdb",
|
||||
}.Select(p => Path.Combine(OutputPath, p));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace AspNetCoreSdkTests.Templates
|
||||
{
|
||||
public class ConsoleApplicationTemplate : ClassLibraryTemplate
|
||||
{
|
||||
public override string OutputPath { get; } = Path.Combine("Debug", "netcoreapp2.1");
|
||||
|
||||
public override string Name => "console";
|
||||
|
||||
public override TemplateType Type => TemplateType.Application;
|
||||
|
||||
public override IEnumerable<string> ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[]
|
||||
{
|
||||
$"{Name}.runtimeconfig.dev.json",
|
||||
$"{Name}.runtimeconfig.json",
|
||||
}.Select(p => Path.Combine(OutputPath, p)));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace AspNetCoreSdkTests.Templates
|
||||
{
|
||||
public abstract class Template
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
public abstract TemplateType Type { get; }
|
||||
|
||||
public virtual IEnumerable<string> ExpectedObjFilesAfterRestore => new[]
|
||||
{
|
||||
$"{Name}.csproj.nuget.cache",
|
||||
$"{Name}.csproj.nuget.g.props",
|
||||
$"{Name}.csproj.nuget.g.targets",
|
||||
"project.assets.json",
|
||||
};
|
||||
|
||||
public virtual IEnumerable<string> ExpectedObjFilesAfterBuild => ExpectedObjFilesAfterRestore;
|
||||
|
||||
public abstract IEnumerable<string> ExpectedBinFilesAfterBuild { get; }
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace AspNetCoreSdkTests.Templates
|
||||
{
|
||||
public static class TemplateData
|
||||
{
|
||||
public static IEnumerable<Template> All { get; } = new Template[]
|
||||
{
|
||||
new ClassLibraryTemplate(),
|
||||
new ConsoleApplicationTemplate(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace AspNetCoreSdkTests.Templates
|
||||
{
|
||||
public enum TemplateType
|
||||
{
|
||||
Application,
|
||||
ClassLibrary
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace AspNetCoreSdkTests.Templates
|
||||
{
|
||||
public class WebTemplate : ConsoleApplicationTemplate
|
||||
{
|
||||
public override string Name => "web";
|
||||
public override TemplateType Type => TemplateType.Application;
|
||||
|
||||
public override IEnumerable<string> ExpectedObjFilesAfterRestore => throw new System.NotImplementedException();
|
||||
|
||||
public override IEnumerable<string> ExpectedObjFilesAfterBuild => throw new System.NotImplementedException();
|
||||
|
||||
public override IEnumerable<string> ExpectedBinFilesAfterBuild => throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace AspNetCoreSdkTests
|
||||
{
|
||||
public static class TestData
|
||||
{
|
||||
public static IEnumerable<TestCaseData> AllTemplates { get; } =
|
||||
from t in Enum.GetValues(typeof(Template)).Cast<Template>()
|
||||
from c in Enum.GetValues(typeof(NuGetConfig)).Cast<NuGetConfig>()
|
||||
let data = new TestCaseData(t, c)
|
||||
select (
|
||||
c == NuGetConfig.NuGetOrg ?
|
||||
data.Ignore("RC1 not yet published to nuget.org") :
|
||||
data);
|
||||
|
||||
// TODO: Add TemplateTypeAttribute to distinguish app templates from classlib templates
|
||||
public static IEnumerable<TestCaseData> ApplicationTemplates { get; } =
|
||||
from d in AllTemplates
|
||||
where ((Template)d.Arguments[0] != Template.RazorClassLib)
|
||||
select d;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using AspNetCoreSdkTests.Templates;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AspNetCoreSdkTests.Util
|
||||
{
|
||||
public class DotNetContext : TempDir
|
||||
{
|
||||
public string New(Template template, bool restore)
|
||||
public string New(Template template)
|
||||
{
|
||||
return DotNet.New(template.ToString().ToLowerInvariant(), Path, restore);
|
||||
return DotNet.New(template.Name, Path);
|
||||
}
|
||||
|
||||
public string Restore(NuGetConfig config)
|
||||
|
|
@ -14,9 +15,19 @@ namespace AspNetCoreSdkTests.Util
|
|||
return DotNet.Restore(Path, config);
|
||||
}
|
||||
|
||||
public string Build()
|
||||
{
|
||||
return DotNet.Build(Path);
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetObjFiles()
|
||||
{
|
||||
return IOUtil.GetFiles(System.IO.Path.Combine(Path, "obj"));
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetBinFiles()
|
||||
{
|
||||
return IOUtil.GetFiles(System.IO.Path.Combine(Path, "bin"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,9 @@ namespace AspNetCoreSdkTests.Util
|
|||
yield return new KeyValuePair<string, string>("NUGET_PACKAGES", Path.Combine(workingDirectory, ".nuget", "packages"));
|
||||
}
|
||||
|
||||
public static string New(string template, string workingDirectory, bool restore)
|
||||
public static string New(string template, string workingDirectory)
|
||||
{
|
||||
var arguments = $"new {template} --name {template} --output ." + (restore ? "" : " --no-restore");
|
||||
return RunDotNet(arguments, workingDirectory, GetEnvironment(workingDirectory));
|
||||
return RunDotNet($"new {template} --name {template} --output . --no-restore", workingDirectory, GetEnvironment(workingDirectory));
|
||||
}
|
||||
|
||||
public static string Restore(string workingDirectory, NuGetConfig config)
|
||||
|
|
@ -28,6 +27,11 @@ namespace AspNetCoreSdkTests.Util
|
|||
return RunDotNet($"restore --no-cache --configfile {configPath}", workingDirectory, GetEnvironment(workingDirectory));
|
||||
}
|
||||
|
||||
public static string Build(string workingDirectory)
|
||||
{
|
||||
return RunDotNet("build --no-restore", workingDirectory, GetEnvironment(workingDirectory));
|
||||
}
|
||||
|
||||
private static string RunDotNet(string arguments, string workingDirectory,
|
||||
IEnumerable<KeyValuePair<string, string>> environment = null, bool throwOnError = true)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue