Add RazorClassLibraryTemplate

This commit is contained in:
Mike Harder 2018-04-27 12:02:17 -07:00
parent 4681618075
commit 6db0dc7db0
11 changed files with 236 additions and 27 deletions

View File

@ -8,9 +8,8 @@ namespace AspNetCoreSdkTests
public class TemplateTests
{
[Test]
public void Restore(
[ValueSource(typeof(TemplateData), nameof(TemplateData.All))] Template template,
[Values] NuGetConfig nuGetConfig)
[TestCaseSource(typeof(TemplateData), nameof(TemplateData.Current))]
public void Restore(Template template, NuGetConfig nuGetConfig)
{
using (var context = new DotNetContext())
{
@ -22,9 +21,8 @@ namespace AspNetCoreSdkTests
}
[Test]
public void Build(
[ValueSource(typeof(TemplateData), nameof(TemplateData.All))] Template template,
[Values] NuGetConfig nuGetConfig)
[TestCaseSource(typeof(TemplateData), nameof(TemplateData.Current))]
public void Build(Template template, NuGetConfig nuGetConfig)
{
using (var context = new DotNetContext())
{

View File

@ -6,10 +6,14 @@ namespace AspNetCoreSdkTests.Templates
{
public class ClassLibraryTemplate : Template
{
public virtual string OutputPath { get; } = Path.Combine("Debug", "netstandard2.0");
public static ClassLibraryTemplate Instance { get; } = new ClassLibraryTemplate();
protected ClassLibraryTemplate() { }
public override string Name => "classlib";
public virtual string OutputPath { get; } = Path.Combine("Debug", "netstandard2.0");
public override TemplateType Type => TemplateType.ClassLibrary;
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]

View File

@ -7,10 +7,14 @@ namespace AspNetCoreSdkTests.Templates
{
public class ConsoleApplicationTemplate : ClassLibraryTemplate
{
public override string OutputPath { get; } = Path.Combine("Debug", "netcoreapp2.1");
public new static ConsoleApplicationTemplate Instance { get; } = new ConsoleApplicationTemplate();
protected ConsoleApplicationTemplate() { }
public override string Name => "console";
public override string OutputPath { get; } = Path.Combine("Debug", "netcoreapp2.1");
public override TemplateType Type => TemplateType.Application;
public override IEnumerable<string> ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[]

View File

@ -4,8 +4,12 @@ using System.Linq;
namespace AspNetCoreSdkTests.Templates
{
public class MvcTemplate : RazorBaseTemplate
public class MvcTemplate : RazorApplicationBaseTemplate
{
public new static MvcTemplate Instance { get; } = new MvcTemplate();
protected MvcTemplate() { }
public override string Name => "mvc";
protected override string RazorPath => "Views";

View File

@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AspNetCoreSdkTests.Templates
{
public abstract class RazorApplicationBaseTemplate : RazorBaseTemplate
{
protected abstract string RazorPath { get; }
public override string OutputPath { get; } = Path.Combine("Debug", "netcoreapp2.1");
public override TemplateType Type => TemplateType.Application;
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]
{
Path.Combine("Razor", RazorPath, "_ViewImports.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "_ViewStart.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "Shared", "_CookieConsentPartial.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "Shared", "_Layout.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "Shared", "_ValidationScriptsPartial.g.cshtml.cs"),
}.Select(p => Path.Combine(OutputPath, p)));
public override IEnumerable<string> ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[]
{
$"{Name}.runtimeconfig.dev.json",
$"{Name}.runtimeconfig.json",
}.Select(p => Path.Combine(OutputPath, p)));
}
}

View File

@ -4,23 +4,19 @@ using System.Linq;
namespace AspNetCoreSdkTests.Templates
{
public abstract class RazorBaseTemplate : WebTemplate
public abstract class RazorBaseTemplate : ClassLibraryTemplate
{
protected abstract string RazorPath { get; }
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]
{
$"{Name}.RazorAssemblyInfo.cache",
$"{Name}.RazorAssemblyInfo.cs",
$"{Name}.RazorCoreGenerate.cache",
$"{Name}.RazorTargetAssemblyInfo.cache",
$"{Name}.RazorTargetAssemblyInfo.cs",
$"{Name}.TagHelpers.input.cache",
$"{Name}.TagHelpers.output.cache",
$"{Name}.Views.dll",
$"{Name}.Views.pdb",
Path.Combine("Razor", RazorPath, "_ViewImports.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "_ViewStart.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "Shared", "_CookieConsentPartial.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "Shared", "_Layout.g.cshtml.cs"),
Path.Combine("Razor", RazorPath, "Shared", "_ValidationScriptsPartial.g.cshtml.cs"),
}.Select(p => Path.Combine(OutputPath, p)));
public override IEnumerable<string> ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[]

View File

@ -0,0 +1,141 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AspNetCoreSdkTests.Templates
{
public class RazorClassLibraryTemplate : RazorBaseTemplate
{
public new static RazorClassLibraryTemplate Instance { get; } = new RazorClassLibraryTemplate();
protected RazorClassLibraryTemplate() { }
public override string Name => "razorclasslib";
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]
{
Path.Combine("Razor", "Areas", "MyFeature", "Pages", "Page1.g.cshtml.cs"),
}.Select(p => Path.Combine(OutputPath, p)));
// We set PreserveCompilationContext=true for all project types in the Razor.Sdk. This results in an refs directory to be created
// in the build output directory which is undesirable. We should consider setting PreserveCompilationContext=true only if the
// app's an executable.
// https://github.com/aspnet/Razor/issues/2308
public override IEnumerable<string> ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[]
{
Path.Combine("refs", "Microsoft.Win32.Primitives.dll"),
Path.Combine("refs", "mscorlib.dll"),
Path.Combine("refs", "netstandard.dll"),
Path.Combine("refs", "System.AppContext.dll"),
Path.Combine("refs", "System.Collections.Concurrent.dll"),
Path.Combine("refs", "System.Collections.dll"),
Path.Combine("refs", "System.Collections.NonGeneric.dll"),
Path.Combine("refs", "System.Collections.Specialized.dll"),
Path.Combine("refs", "System.ComponentModel.Composition.dll"),
Path.Combine("refs", "System.ComponentModel.dll"),
Path.Combine("refs", "System.ComponentModel.EventBasedAsync.dll"),
Path.Combine("refs", "System.ComponentModel.Primitives.dll"),
Path.Combine("refs", "System.ComponentModel.TypeConverter.dll"),
Path.Combine("refs", "System.Console.dll"),
Path.Combine("refs", "System.Core.dll"),
Path.Combine("refs", "System.Data.Common.dll"),
Path.Combine("refs", "System.Data.dll"),
Path.Combine("refs", "System.Diagnostics.Contracts.dll"),
Path.Combine("refs", "System.Diagnostics.Debug.dll"),
Path.Combine("refs", "System.Diagnostics.FileVersionInfo.dll"),
Path.Combine("refs", "System.Diagnostics.Process.dll"),
Path.Combine("refs", "System.Diagnostics.StackTrace.dll"),
Path.Combine("refs", "System.Diagnostics.TextWriterTraceListener.dll"),
Path.Combine("refs", "System.Diagnostics.Tools.dll"),
Path.Combine("refs", "System.Diagnostics.TraceSource.dll"),
Path.Combine("refs", "System.Diagnostics.Tracing.dll"),
Path.Combine("refs", "System.dll"),
Path.Combine("refs", "System.Drawing.dll"),
Path.Combine("refs", "System.Drawing.Primitives.dll"),
Path.Combine("refs", "System.Dynamic.Runtime.dll"),
Path.Combine("refs", "System.Globalization.Calendars.dll"),
Path.Combine("refs", "System.Globalization.dll"),
Path.Combine("refs", "System.Globalization.Extensions.dll"),
Path.Combine("refs", "System.IO.Compression.dll"),
Path.Combine("refs", "System.IO.Compression.FileSystem.dll"),
Path.Combine("refs", "System.IO.Compression.ZipFile.dll"),
Path.Combine("refs", "System.IO.dll"),
Path.Combine("refs", "System.IO.FileSystem.dll"),
Path.Combine("refs", "System.IO.FileSystem.DriveInfo.dll"),
Path.Combine("refs", "System.IO.FileSystem.Primitives.dll"),
Path.Combine("refs", "System.IO.FileSystem.Watcher.dll"),
Path.Combine("refs", "System.IO.IsolatedStorage.dll"),
Path.Combine("refs", "System.IO.MemoryMappedFiles.dll"),
Path.Combine("refs", "System.IO.Pipes.dll"),
Path.Combine("refs", "System.IO.UnmanagedMemoryStream.dll"),
Path.Combine("refs", "System.Linq.dll"),
Path.Combine("refs", "System.Linq.Expressions.dll"),
Path.Combine("refs", "System.Linq.Parallel.dll"),
Path.Combine("refs", "System.Linq.Queryable.dll"),
Path.Combine("refs", "System.Net.dll"),
Path.Combine("refs", "System.Net.Http.dll"),
Path.Combine("refs", "System.Net.NameResolution.dll"),
Path.Combine("refs", "System.Net.NetworkInformation.dll"),
Path.Combine("refs", "System.Net.Ping.dll"),
Path.Combine("refs", "System.Net.Primitives.dll"),
Path.Combine("refs", "System.Net.Requests.dll"),
Path.Combine("refs", "System.Net.Security.dll"),
Path.Combine("refs", "System.Net.Sockets.dll"),
Path.Combine("refs", "System.Net.WebHeaderCollection.dll"),
Path.Combine("refs", "System.Net.WebSockets.Client.dll"),
Path.Combine("refs", "System.Net.WebSockets.dll"),
Path.Combine("refs", "System.Numerics.dll"),
Path.Combine("refs", "System.ObjectModel.dll"),
Path.Combine("refs", "System.Reflection.dll"),
Path.Combine("refs", "System.Reflection.Extensions.dll"),
Path.Combine("refs", "System.Reflection.Primitives.dll"),
Path.Combine("refs", "System.Resources.Reader.dll"),
Path.Combine("refs", "System.Resources.ResourceManager.dll"),
Path.Combine("refs", "System.Resources.Writer.dll"),
Path.Combine("refs", "System.Runtime.CompilerServices.VisualC.dll"),
Path.Combine("refs", "System.Runtime.dll"),
Path.Combine("refs", "System.Runtime.Extensions.dll"),
Path.Combine("refs", "System.Runtime.Handles.dll"),
Path.Combine("refs", "System.Runtime.InteropServices.dll"),
Path.Combine("refs", "System.Runtime.InteropServices.RuntimeInformation.dll"),
Path.Combine("refs", "System.Runtime.Numerics.dll"),
Path.Combine("refs", "System.Runtime.Serialization.dll"),
Path.Combine("refs", "System.Runtime.Serialization.Formatters.dll"),
Path.Combine("refs", "System.Runtime.Serialization.Json.dll"),
Path.Combine("refs", "System.Runtime.Serialization.Primitives.dll"),
Path.Combine("refs", "System.Runtime.Serialization.Xml.dll"),
Path.Combine("refs", "System.Security.Claims.dll"),
Path.Combine("refs", "System.Security.Cryptography.Algorithms.dll"),
Path.Combine("refs", "System.Security.Cryptography.Csp.dll"),
Path.Combine("refs", "System.Security.Cryptography.Encoding.dll"),
Path.Combine("refs", "System.Security.Cryptography.Primitives.dll"),
Path.Combine("refs", "System.Security.Cryptography.X509Certificates.dll"),
Path.Combine("refs", "System.Security.Principal.dll"),
Path.Combine("refs", "System.Security.SecureString.dll"),
Path.Combine("refs", "System.ServiceModel.Web.dll"),
Path.Combine("refs", "System.Text.Encoding.dll"),
Path.Combine("refs", "System.Text.Encoding.Extensions.dll"),
Path.Combine("refs", "System.Text.RegularExpressions.dll"),
Path.Combine("refs", "System.Threading.dll"),
Path.Combine("refs", "System.Threading.Overlapped.dll"),
Path.Combine("refs", "System.Threading.Tasks.dll"),
Path.Combine("refs", "System.Threading.Tasks.Parallel.dll"),
Path.Combine("refs", "System.Threading.Thread.dll"),
Path.Combine("refs", "System.Threading.ThreadPool.dll"),
Path.Combine("refs", "System.Threading.Timer.dll"),
Path.Combine("refs", "System.Transactions.dll"),
Path.Combine("refs", "System.ValueTuple.dll"),
Path.Combine("refs", "System.Web.dll"),
Path.Combine("refs", "System.Windows.dll"),
Path.Combine("refs", "System.Xml.dll"),
Path.Combine("refs", "System.Xml.Linq.dll"),
Path.Combine("refs", "System.Xml.ReaderWriter.dll"),
Path.Combine("refs", "System.Xml.Serialization.dll"),
Path.Combine("refs", "System.Xml.XDocument.dll"),
Path.Combine("refs", "System.Xml.XmlDocument.dll"),
Path.Combine("refs", "System.Xml.XmlSerializer.dll"),
Path.Combine("refs", "System.Xml.XPath.dll"),
Path.Combine("refs", "System.Xml.XPath.XDocument.dll"),
}.Select(p => Path.Combine(OutputPath, p)));
}
}

View File

@ -4,8 +4,12 @@ using System.Linq;
namespace AspNetCoreSdkTests.Templates
{
public class RazorTemplate : RazorBaseTemplate
public class RazorTemplate : RazorApplicationBaseTemplate
{
public new static RazorTemplate Instance { get; } = new RazorTemplate();
protected RazorTemplate() { }
public override string Name => "razor";
protected override string RazorPath => "Pages";

View File

@ -1,17 +1,37 @@
using System.Collections.Generic;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AspNetCoreSdkTests.Templates
{
public static class TemplateData
{
public static IEnumerable<Template> All { get; } = new Template[]
private static IEnumerable<Template> Templates { get; } = new Template[]
{
new ClassLibraryTemplate(),
new ConsoleApplicationTemplate(),
new WebTemplate(),
new RazorTemplate(),
new MvcTemplate(),
new WebApiTemplate(),
ClassLibraryTemplate.Instance,
ConsoleApplicationTemplate.Instance,
WebTemplate.Instance,
RazorTemplate.Instance,
MvcTemplate.Instance,
WebApiTemplate.Instance,
RazorClassLibraryTemplate.Instance,
};
private static IEnumerable<NuGetConfig> NuGetConfigs { get; } = Enum.GetValues(typeof(NuGetConfig)).Cast<NuGetConfig>();
private static IEnumerable<TestCaseData> All { get; } =
from t in Templates
from c in NuGetConfigs
select new TestCaseData(t, c);
private static IEnumerable<TestCaseData> IgnoreRazorClassLibEmpty { get; } =
from d in All
select (
((Template)d.Arguments[0] == RazorClassLibraryTemplate.Instance && (NuGetConfig)d.Arguments[1] == NuGetConfig.Empty) ?
d.Ignore("https://github.com/aspnet/Universe/issues/1123") :
d);
public static IEnumerable<TestCaseData> Current => IgnoreRazorClassLibEmpty;
}
}

View File

@ -2,6 +2,10 @@
{
public class WebApiTemplate : WebTemplate
{
public new static WebApiTemplate Instance { get; } = new WebApiTemplate();
protected WebApiTemplate() { }
public override string Name => "webapi";
}
}

View File

@ -6,6 +6,10 @@ namespace AspNetCoreSdkTests.Templates
{
public class WebTemplate : ConsoleApplicationTemplate
{
public new static WebTemplate Instance { get; } = new WebTemplate();
protected WebTemplate() { }
public override string Name => "web";
public override IEnumerable<string> ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[]