Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from nick5454/develop
Added List migrations functionality
- Loading branch information
Showing
7 changed files
with
323 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Cake.DotNetCoreEf.UnitTests/Fixtures/Migration/DotNetCoreEfMigrationListerFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Cake.DotNetCoreEf.Migration; | ||
|
||
namespace Cake.DotNetCoreEf.Tests.Fixtures.Migration | ||
{ | ||
internal sealed class DotNetCoreEfMigrationListerFixture : DotNetCoreEfFixture<DotNetCoreEfMigrationListerSettings> | ||
{ | ||
public string Project { get; set; } | ||
|
||
public string Arguments { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetCoreEfMigrationLister(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Script(Project, Arguments, Settings); | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/Cake.DotNetCoreEf.UnitTests/Unit/Migration/DotNetCoreEfMigrationScriptListerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using Cake.DotNetCoreEf.Tests.Fixtures.Migration; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.DotNetCoreEf.Tests.Unit.Migration | ||
{ | ||
public sealed class DotNetCoreEfMigrationScriptListerTests | ||
{ | ||
|
||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreEfMigrationListerFixture(); | ||
fixture.Project = "./src/"; | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertExtensions.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreEfMigrationListerFixture(); | ||
fixture.Project = "./src/"; | ||
fixture.GivenProcessCannotStart(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertExtensions.IsCakeException(result, ".NET Core CLI: Process was not started."); | ||
} | ||
|
||
// Removed. Process returns json | ||
//[Fact] | ||
//public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code() | ||
//{ | ||
// // Given | ||
// var fixture = new DotNetCoreEfMigrationScriptListerFixture(); | ||
// fixture.Project = "./src/"; | ||
// fixture.GivenProcessExitsWithCode(1); | ||
|
||
// // When | ||
// var result = Record.Exception(() => fixture.Run()); | ||
|
||
// // Then | ||
// AssertExtensions.IsCakeException(result, ".NET Core CLI: Process returned an error (exit code 1)."); | ||
//} | ||
|
||
[Fact] | ||
public void Should_Add_Mandatory_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreEfMigrationListerFixture(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("ef migrations list --no-build --json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Path_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreEfMigrationListerFixture(); | ||
fixture.Project = "./tools/tool/"; | ||
fixture.Arguments = "--args=\"value\""; | ||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("ef migrations list --no-build --json --args=\"value\"", result.Args); | ||
Assert.Equal("/Working/tools/tool", result.Process.WorkingDirectory.FullPath); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Settings() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreEfMigrationListerFixture(); | ||
fixture.Settings.StartupProject = "./src/MyMvcProject"; | ||
fixture.Settings.Project = "./src/MyDataProject"; | ||
fixture.Settings.Configuration = "release"; | ||
fixture.Settings.PrefixOutput = true; | ||
fixture.Settings.NoBuild = true; | ||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("ef migrations list --project \"./src/MyDataProject\" --startup-project \"./src/MyMvcProject\" --prefix-output --no-build --json", result.Args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28010.2041 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.DotNetCoreEf", "Cake.DotNetCoreEf\Cake.DotNetCoreEf.csproj", "{EF4D86EB-7401-4E38-A02B-AB4884DCB168}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{77CAC347-B714-4AD6-9932-328C59DC9B2B}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\.appveyor.yml = ..\.appveyor.yml | ||
..\build.ps1 = ..\build.ps1 | ||
..\nuspec\Cake.DotNetCoreEf.nuspec = ..\nuspec\Cake.DotNetCoreEf.nuspec | ||
..\LICENSE = ..\LICENSE | ||
..\README.md = ..\README.md | ||
..\recipe.cake = ..\recipe.cake | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.DotNetCoreEf.UnitTests", "Cake.DotNetCoreEf.UnitTests\Cake.DotNetCoreEf.UnitTests.csproj", "{8C502FAA-A13C-4051-9716-1C41A4596BED}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {732C4874-8EF7-42F1-82E0-DFF23CD78A46} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28010.2041 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.DotNetCoreEf", "Cake.DotNetCoreEf\Cake.DotNetCoreEf.csproj", "{EF4D86EB-7401-4E38-A02B-AB4884DCB168}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{77CAC347-B714-4AD6-9932-328C59DC9B2B}" | ||
ProjectSection(SolutionItems) = preProject | ||
..\.appveyor.yml = ..\.appveyor.yml | ||
..\build.ps1 = ..\build.ps1 | ||
..\nuspec\Cake.DotNetCoreEf.nuspec = ..\nuspec\Cake.DotNetCoreEf.nuspec | ||
..\LICENSE = ..\LICENSE | ||
..\README.md = ..\README.md | ||
..\recipe.cake = ..\recipe.cake | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.DotNetCoreEf.UnitTests", "Cake.DotNetCoreEf.UnitTests\Cake.DotNetCoreEf.UnitTests.csproj", "{8C502FAA-A13C-4051-9716-1C41A4596BED}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EF4D86EB-7401-4E38-A02B-AB4884DCB168}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8C502FAA-A13C-4051-9716-1C41A4596BED}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {732C4874-8EF7-42F1-82E0-DFF23CD78A46} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Cake.DotNetCoreEf/Migration/DotNetCoreEfMigrationLister.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
|
||
namespace Cake.DotNetCoreEf.Migration | ||
{ | ||
/// <summary> | ||
/// Support for script migrations using .NET Core cli tooling | ||
/// </summary> | ||
public class DotNetCoreEfMigrationLister : DotNetCoreEfTool<DotNetCoreEfMigrationListerSettings> | ||
{ | ||
private readonly ICakeEnvironment _environment; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DotNetCoreEfMigrationScriptLister" />. | ||
/// </summary> | ||
/// <param name="fileSystem">The file system.</param> | ||
/// <param name="environment">The environment.</param> | ||
/// <param name="processRunner">The process runner.</param> | ||
/// <param name="tools">The tool locator.</param> | ||
public DotNetCoreEfMigrationLister( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IProcessRunner processRunner, | ||
IToolLocator tools) | ||
: base(fileSystem, environment, processRunner, tools) | ||
{ | ||
this._environment = environment; | ||
} | ||
|
||
/// <summary> | ||
/// Script migrations for the project using the specified path with arguments and settings. | ||
/// </summary> | ||
/// <param name="project">The target project path.</param> | ||
/// <param name="arguments">The arguments.</param> | ||
/// <param name="settings">The settings.</param> | ||
public string Script(string project, ProcessArgumentBuilder arguments, DotNetCoreEfMigrationListerSettings settings) | ||
{ | ||
if (settings == null) | ||
{ | ||
throw new ArgumentNullException(nameof(settings)); | ||
} | ||
|
||
var result = RunProcess(settings, GetArguments(project, arguments, settings)).GetStandardOutput(); | ||
|
||
return result?.FirstOrDefault(); | ||
} | ||
|
||
private ProcessArgumentBuilder GetArguments(string project, ProcessArgumentBuilder arguments, DotNetCoreEfMigrationListerSettings settings) | ||
{ | ||
ProcessArgumentBuilder builder = new ProcessArgumentBuilder(); | ||
ProcessArgumentBuilder builderArguments = CreateArgumentBuilder(settings); | ||
|
||
builder.Append("ef"); | ||
builder.Append("migrations"); | ||
builder.Append("list"); | ||
|
||
settings.SetProject(project); | ||
|
||
if (!string.IsNullOrWhiteSpace(settings.Project)) | ||
{ | ||
builder.Append("--project"); | ||
builder.AppendQuoted(settings.Project); | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(settings.StartupProject)) | ||
{ | ||
builder.Append("--startup-project"); | ||
builder.AppendQuoted(settings.StartupProject); | ||
} | ||
|
||
if (settings.PrefixOutput) | ||
{ | ||
builder.Append("--prefix-output"); | ||
} | ||
|
||
if (settings.NoBuild) | ||
{ | ||
builder.Append("--no-build"); | ||
} | ||
|
||
// return json output | ||
builder.Append("--json"); | ||
|
||
// Arguments | ||
if (!arguments.IsNullOrEmpty()) | ||
{ | ||
arguments.CopyTo(builder); | ||
} | ||
|
||
return builder; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Cake.DotNetCoreEf/Migration/DotNetCoreEfMigrationListerSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Cake.DotNetCoreEf.Migration | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetCoreEfMigrationScriptLister"/>. | ||
/// </summary> | ||
public class DotNetCoreEfMigrationListerSettings : DotNetCoreEfSettings | ||
{ | ||
/// <summary> | ||
/// Prefix characters in output. | ||
/// </summary> | ||
public bool PrefixOutput { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to not to build the project before publishing. | ||
/// This makes build faster, but requires build to be done before publish is executed. | ||
/// </summary> | ||
public bool NoBuild { get; set; } = true; | ||
} | ||
} |