diff --git a/test/Templates.Test/Helpers/TemplateTestBase.cs b/test/Templates.Test/Helpers/TemplateTestBase.cs index b2d82c1434..b42eba6ae3 100644 --- a/test/Templates.Test/Helpers/TemplateTestBase.cs +++ b/test/Templates.Test/Helpers/TemplateTestBase.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Linq; using System.Reflection; using System.Threading; using Microsoft.Extensions.CommandLineUtils; @@ -79,6 +80,18 @@ namespace Templates.Test } } + protected void RunDotNetEfCreateMigration(string migrationName) + { + var args = $"ef migrations add {migrationName}"; + + // Only run one instance of 'dotnet new' at once, as a workaround for + // https://github.com/aspnet/templating/issues/63 + lock (DotNetNewLock) + { + ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), args).WaitForExit(assertSuccess: true); + } + } + protected void AssertDirectoryExists(string path, bool shouldExist) { var fullPath = Path.Combine(TemplateOutputDir, path); @@ -94,6 +107,26 @@ namespace Templates.Test } } + protected void AssertEmptyMigration(string migration) + { + var fullPath = Path.Combine(TemplateOutputDir, "Data/Migrations"); + var file = Directory.EnumerateFiles(fullPath).Where(f => f.EndsWith($"{migration}.cs")).FirstOrDefault(); + + Assert.NotNull(file); + var contents = File.ReadAllText(file); + + var emptyMigration = @"protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + }"; + Assert.Contains(emptyMigration, contents); + } + protected void AssertFileExists(string path, bool shouldExist) { var fullPath = Path.Combine(TemplateOutputDir, path); diff --git a/test/Templates.Test/MvcTemplateTest.cs b/test/Templates.Test/MvcTemplateTest.cs index a9d9771014..e670d38414 100644 --- a/test/Templates.Test/MvcTemplateTest.cs +++ b/test/Templates.Test/MvcTemplateTest.cs @@ -86,6 +86,10 @@ namespace Templates.Test Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents); Assert.Contains("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents); + RunDotNetEfCreateMigration("mvc"); + + AssertEmptyMigration("mvc"); + foreach (var publish in new[] { false, true }) { using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish)) diff --git a/test/Templates.Test/RazorPagesTemplateTest.cs b/test/Templates.Test/RazorPagesTemplateTest.cs index 949e86a3f5..c7cf898356 100644 --- a/test/Templates.Test/RazorPagesTemplateTest.cs +++ b/test/Templates.Test/RazorPagesTemplateTest.cs @@ -75,6 +75,10 @@ namespace Templates.Test Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents); Assert.Contains("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents); + RunDotNetEfCreateMigration("razorpages"); + + AssertEmptyMigration("razorpages"); + foreach (var publish in new[] { false, true }) { using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))