Add test for ensuring that migration is current (#344)

This commit is contained in:
Hao Kung 2018-03-08 12:12:13 -08:00 committed by GitHub
parent bae1156511
commit d682c971b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View File

@ -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);

View File

@ -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))

View File

@ -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))