From 6db0dc7db0960cedba4e48c2554a5bbe22bb6e86 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 27 Apr 2018 12:02:17 -0700 Subject: [PATCH] Add RazorClassLibraryTemplate --- AspNetCoreSdkTests/TemplateTests.cs | 10 +- .../Templates/ClassLibraryTemplate.cs | 6 +- .../Templates/ConsoleApplicationTemplate.cs | 6 +- AspNetCoreSdkTests/Templates/MvcTemplate.cs | 6 +- .../Templates/RazorApplicationBaseTemplate.cs | 30 ++++ .../Templates/RazorBaseTemplate.cs | 14 +- .../Templates/RazorClassLibraryTemplate.cs | 141 ++++++++++++++++++ AspNetCoreSdkTests/Templates/RazorTemplate.cs | 6 +- AspNetCoreSdkTests/Templates/TemplateData.cs | 36 ++++- .../Templates/WebApiTemplate.cs | 4 + AspNetCoreSdkTests/Templates/WebTemplate.cs | 4 + 11 files changed, 236 insertions(+), 27 deletions(-) create mode 100644 AspNetCoreSdkTests/Templates/RazorApplicationBaseTemplate.cs create mode 100644 AspNetCoreSdkTests/Templates/RazorClassLibraryTemplate.cs diff --git a/AspNetCoreSdkTests/TemplateTests.cs b/AspNetCoreSdkTests/TemplateTests.cs index f8dd59c466..f67f58001d 100644 --- a/AspNetCoreSdkTests/TemplateTests.cs +++ b/AspNetCoreSdkTests/TemplateTests.cs @@ -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()) { diff --git a/AspNetCoreSdkTests/Templates/ClassLibraryTemplate.cs b/AspNetCoreSdkTests/Templates/ClassLibraryTemplate.cs index 3a64557f74..70f968defd 100644 --- a/AspNetCoreSdkTests/Templates/ClassLibraryTemplate.cs +++ b/AspNetCoreSdkTests/Templates/ClassLibraryTemplate.cs @@ -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 ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[] diff --git a/AspNetCoreSdkTests/Templates/ConsoleApplicationTemplate.cs b/AspNetCoreSdkTests/Templates/ConsoleApplicationTemplate.cs index 0f4a489f26..46c6110a92 100644 --- a/AspNetCoreSdkTests/Templates/ConsoleApplicationTemplate.cs +++ b/AspNetCoreSdkTests/Templates/ConsoleApplicationTemplate.cs @@ -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 ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[] diff --git a/AspNetCoreSdkTests/Templates/MvcTemplate.cs b/AspNetCoreSdkTests/Templates/MvcTemplate.cs index 13bdcc24bc..a32e522940 100644 --- a/AspNetCoreSdkTests/Templates/MvcTemplate.cs +++ b/AspNetCoreSdkTests/Templates/MvcTemplate.cs @@ -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"; diff --git a/AspNetCoreSdkTests/Templates/RazorApplicationBaseTemplate.cs b/AspNetCoreSdkTests/Templates/RazorApplicationBaseTemplate.cs new file mode 100644 index 0000000000..7526c0a0f3 --- /dev/null +++ b/AspNetCoreSdkTests/Templates/RazorApplicationBaseTemplate.cs @@ -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 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 ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[] + { + $"{Name}.runtimeconfig.dev.json", + $"{Name}.runtimeconfig.json", + }.Select(p => Path.Combine(OutputPath, p))); + } +} diff --git a/AspNetCoreSdkTests/Templates/RazorBaseTemplate.cs b/AspNetCoreSdkTests/Templates/RazorBaseTemplate.cs index 416eb9150d..e5de3449c1 100644 --- a/AspNetCoreSdkTests/Templates/RazorBaseTemplate.cs +++ b/AspNetCoreSdkTests/Templates/RazorBaseTemplate.cs @@ -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 ExpectedObjFilesAfterBuild => Enumerable.Concat(base.ExpectedObjFilesAfterBuild, new[] + public override IEnumerable 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 ExpectedBinFilesAfterBuild => Enumerable.Concat(base.ExpectedBinFilesAfterBuild, new[] diff --git a/AspNetCoreSdkTests/Templates/RazorClassLibraryTemplate.cs b/AspNetCoreSdkTests/Templates/RazorClassLibraryTemplate.cs new file mode 100644 index 0000000000..b252e38ffb --- /dev/null +++ b/AspNetCoreSdkTests/Templates/RazorClassLibraryTemplate.cs @@ -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 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 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))); + } +} diff --git a/AspNetCoreSdkTests/Templates/RazorTemplate.cs b/AspNetCoreSdkTests/Templates/RazorTemplate.cs index 48b4814379..bc50de40dc 100644 --- a/AspNetCoreSdkTests/Templates/RazorTemplate.cs +++ b/AspNetCoreSdkTests/Templates/RazorTemplate.cs @@ -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"; diff --git a/AspNetCoreSdkTests/Templates/TemplateData.cs b/AspNetCoreSdkTests/Templates/TemplateData.cs index c3c4df456e..b2ef37b804 100644 --- a/AspNetCoreSdkTests/Templates/TemplateData.cs +++ b/AspNetCoreSdkTests/Templates/TemplateData.cs @@ -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