Add test for ensuring that migration is current (#344)
This commit is contained in:
parent
bae1156511
commit
d682c971b7
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
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)
|
protected void AssertDirectoryExists(string path, bool shouldExist)
|
||||||
{
|
{
|
||||||
var fullPath = Path.Combine(TemplateOutputDir, path);
|
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)
|
protected void AssertFileExists(string path, bool shouldExist)
|
||||||
{
|
{
|
||||||
var fullPath = Path.Combine(TemplateOutputDir, path);
|
var fullPath = Path.Combine(TemplateOutputDir, path);
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,10 @@ namespace Templates.Test
|
||||||
Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
||||||
Assert.Contains("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents);
|
Assert.Contains("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents);
|
||||||
|
|
||||||
|
RunDotNetEfCreateMigration("mvc");
|
||||||
|
|
||||||
|
AssertEmptyMigration("mvc");
|
||||||
|
|
||||||
foreach (var publish in new[] { false, true })
|
foreach (var publish in new[] { false, true })
|
||||||
{
|
{
|
||||||
using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))
|
using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ namespace Templates.Test
|
||||||
Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
Assert.Contains("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
||||||
Assert.Contains("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents);
|
Assert.Contains("Microsoft.EntityFrameworkCore.Tools.DotNet", projectFileContents);
|
||||||
|
|
||||||
|
RunDotNetEfCreateMigration("razorpages");
|
||||||
|
|
||||||
|
AssertEmptyMigration("razorpages");
|
||||||
|
|
||||||
foreach (var publish in new[] { false, true })
|
foreach (var publish in new[] { false, true })
|
||||||
{
|
{
|
||||||
using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))
|
using (var aspNetProcess = StartAspNetProcess(targetFrameworkOverride, publish))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue