forked from erikbra/grate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task erikbra#485: Add factory IFoldersConfiguration builder 'Folders'…
… for convenience (erikbra#490) Make it easier to configure custom folder configurations when using grate as a library. Solves erikbra#485
- Loading branch information
Showing
30 changed files
with
272 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace grate.Configuration; | ||
|
||
/// <summary> | ||
/// Factory class for creating <see cref="IFoldersConfiguration"/> instances. | ||
/// </summary> | ||
public static class Folders | ||
{ | ||
/// <summary> | ||
/// The default <see cref="IFoldersConfiguration"/>. | ||
/// </summary> | ||
public static IFoldersConfiguration Default => FoldersConfiguration.Default(); | ||
|
||
/// <summary> | ||
/// An empty <see cref="IFoldersConfiguration"/>. | ||
/// </summary> | ||
public static IFoldersConfiguration Empty => FoldersConfiguration.Empty; | ||
|
||
/// <summary> | ||
/// Folder configuration with the specified folders. | ||
/// </summary> | ||
/// <param name="folders">A list of migration folders</param> | ||
/// <returns>An IFoldersConfiguration with the supplied folders</returns> | ||
public static IFoldersConfiguration Create(params MigrationsFolder [] folders) | ||
=> new FoldersConfiguration(folders); | ||
|
||
/// <summary> | ||
/// Folder configuration with the specified folders. | ||
/// </summary> | ||
/// <param name="folders">A list of migration folders</param> | ||
/// <returns>An IFoldersConfiguration with the supplied folders</returns> | ||
public static IFoldersConfiguration Create(IEnumerable<MigrationsFolder> folders) | ||
=> new FoldersConfiguration(folders); | ||
|
||
/// <summary> | ||
/// Folder configuration with the specified Dictionary of folder names and folders. | ||
/// </summary> | ||
/// <param name="folders">A Dictionary of folder names and migration folders</param> | ||
/// <returns>An IFoldersConfiguration with the supplied folders</returns> | ||
public static IFoldersConfiguration Create(IDictionary<string, MigrationsFolder> folders) | ||
=> new FoldersConfiguration(folders); | ||
|
||
/// <summary> | ||
/// Folder configuration from strings, where each string is a folder configuration, as | ||
/// you can specify on the command line. | ||
/// | ||
/// For convenience, you can specify each folder in a separate string, instead of all in one string, separated by a semicolon. | ||
/// | ||
/// For example: | ||
/// | ||
/// <code> | ||
/// Create("structure=relativePath:myCustomFolder,type:Once,connectionType:Admin", | ||
/// "randomstuff=type:Once;procedures=type:Once;security=type:Once") | ||
/// </code> | ||
/// | ||
/// </summary> | ||
/// <param name="folders">Separate strings with folder configurations</param> | ||
/// <returns>An IFoldersConfiguration with the supplied folders</returns> | ||
public static IFoldersConfiguration Create(params string[] folders) | ||
=> FoldersCommand.Parse(string.Join(";", folders)); | ||
|
||
/// <summary> | ||
/// Folder configuration from strings, where each string is a folder configuration, as | ||
/// you can specify on the command line. | ||
/// | ||
/// You specify multiple folders in one string, separated by a semicolon. | ||
/// | ||
/// For example: "structure=relativePath:myCustomFolder,type:Once,connectionType:Admin;randomstuff=type:Once;procedures=type:Once;security=type:Once" | ||
/// </summary> | ||
/// <param name="folders">A semicolon separated string with all the folder configurations, as specified on the command line</param> | ||
/// <returns>An IFoldersConfiguration with the supplied folders</returns> | ||
public static IFoldersConfiguration Create(string folders) | ||
=> FoldersCommand.Parse(folders); | ||
} |
3 changes: 1 addition & 2 deletions
3
src/grate/Commands/FoldersCommand.cs → ...rate.core/Configuration/FoldersCommand.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
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
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
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
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
115 changes: 115 additions & 0 deletions
115
...ests/Infrastructure/FolderConfiguration/Customized_Folders_Can_Be_Set_Programmatically.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,115 @@ | ||
using System.Collections.Immutable; | ||
using FluentAssertions; | ||
using grate.Configuration; | ||
|
||
namespace Basic_tests.Infrastructure.FolderConfiguration; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class Customized_Folders_Can_Be_Set_Programmatically | ||
{ | ||
[Fact] | ||
public void From_MigrationsFolder_list() | ||
{ | ||
var folders = Folders.Create( | ||
new MigrationsFolder("structure"), | ||
new MigrationsFolder("randomstuff"), | ||
new MigrationsFolder("procedures"), | ||
new MigrationsFolder("security") | ||
); | ||
var items = folders.Values.ToImmutableArray(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
items[0].Should().Be(folders["structure"]); | ||
items[1].Should().Be(folders["randomstuff"]); | ||
items[2].Should().Be(folders["procedures"]); | ||
items[3].Should().Be(folders["security"]); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void From_Enumerable_of_MigrationsFolder() | ||
{ | ||
var folders = Folders.Create(new List<MigrationsFolder> | ||
{ | ||
new("structure"), | ||
new("randomstuff"), | ||
new("procedures"), | ||
new("security")} | ||
); | ||
var items = folders.Values.ToImmutableArray(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
items[0].Should().Be(folders["structure"]); | ||
items[1].Should().Be(folders["randomstuff"]); | ||
items[2].Should().Be(folders["procedures"]); | ||
items[3].Should().Be(folders["security"]); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void From_Dictionary_of_MigrationsFolder() | ||
{ | ||
var folders = Folders.Create(new Dictionary<string, MigrationsFolder> | ||
{ | ||
{"structure", new("str") }, | ||
{"randomstuff", new("rnd") }, | ||
{"procedures", new("procs") }, | ||
{"security", new("sec") } | ||
} | ||
); | ||
var items = folders.Values.ToImmutableArray(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
items[0].Should().Be(folders["structure"]); | ||
items[1].Should().Be(folders["randomstuff"]); | ||
items[2].Should().Be(folders["procedures"]); | ||
items[3].Should().Be(folders["security"]); | ||
}); | ||
} | ||
|
||
|
||
[Fact] | ||
public void From_command_line_argument_style_single_string() | ||
{ | ||
var folders = Folders.Create("nup=tables;sprocs=storedprocedures;views=projections"); | ||
var items = folders.ToImmutableArray(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
items[0].Key.Should().Be("nup"); | ||
items[0].Value!.Path.Should().Be("tables"); | ||
|
||
items[1].Key.Should().Be("sprocs"); | ||
items[1].Value!.Path.Should().Be("storedprocedures"); | ||
|
||
items[2].Key.Should().Be("views"); | ||
items[2].Value!.Path.Should().Be("projections"); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void From_multiple_string_arguments() | ||
{ | ||
var folders = Folders.Create("zup=tables", "sprocs=path:storedprocedures,type:anytime", "views=projections"); | ||
var items = folders.ToImmutableArray(); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
items[0].Key.Should().Be("zup"); | ||
items[0].Value!.Path.Should().Be("tables"); | ||
|
||
items[1].Key.Should().Be("sprocs"); | ||
items[1].Value!.Path.Should().Be("storedprocedures"); | ||
items[1].Value!.Type.Should().Be(MigrationType.AnyTime); | ||
|
||
items[2].Key.Should().Be("views"); | ||
items[2].Value!.Path.Should().Be("projections"); | ||
}); | ||
} | ||
|
||
|
||
|
||
} |
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
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
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
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
Oops, something went wrong.