Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@
"language": "C#",
"type": "solution"
},
"sourceName": "MyApp",
"preferNameDirectory": true,
"defaultName": "MyApp",
"symbols": {
"safeName": {
"type": "generated",
"generator": "regex",
"dataType": "string",
"replaces": "MyApp",
"fileRename": "MyApp",
"parameters": {
"source": "name",
"steps": [
{
"regex": "[^A-Za-z0-9_.]",
"replacement": "_"
},
{
"regex": "(^|\\.)([0-9])",
"replacement": "$1_$2"
}
]
}
},
"userSecretsId": {
"type": "generated",
"generator": "guid",
Expand All @@ -38,6 +57,10 @@
{
"regex": "[^A-Za-z0-9_]",
"replacement": "_"
},
{
"regex": "^([0-9])",
"replacement": "_$1"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MyApp.Api.Features.Widgets;
/// </remarks>
internal sealed class WidgetConfiguration : IEntityTypeConfiguration<Widget>
{
public void Configure(EntityTypeBuilder<Widget> builder)
void IEntityTypeConfiguration<Widget>.Configure(EntityTypeBuilder<Widget> builder)
{
ArgumentNullException.ThrowIfNull(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace MyApp.Api.Infrastructure;
/// </summary>
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
/// <summary>Gets the widgets. Only aggregate roots get a set of their own.</summary>
public DbSet<Widget> Widgets => Set<Widget>();

// Conventions, not model creation. Property discovery skips types it does not recognise, so an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace MyApp.Api.Infrastructure;
/// </remarks>
internal sealed class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
AppDbContext IDesignTimeDbContextFactory<AppDbContext>.CreateDbContext(string[] args)
{
DbContextOptionsBuilder<AppDbContext> builder = new();
builder.UseNpgsql("Host=design-time;Database=designtime;Username=none;Password=none");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@
"language": "C#",
"type": "solution"
},
"sourceName": "MyApp",
"preferNameDirectory": true,
"defaultName": "MyApp",
"symbols": {
"safeName": {
"type": "generated",
"generator": "regex",
"dataType": "string",
"replaces": "MyApp",
"fileRename": "MyApp",
"parameters": {
"source": "name",
"steps": [
{
"regex": "[^A-Za-z0-9_.]",
"replacement": "_"
},
{
"regex": "(^|\\.)([0-9])",
"replacement": "$1_$2"
}
]
}
},
"userSecretsId": {
"type": "generated",
"generator": "guid",
Expand All @@ -38,6 +57,10 @@
{
"regex": "[^A-Za-z0-9_]",
"replacement": "_"
},
{
"regex": "^([0-9])",
"replacement": "_$1"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace MyApp.Worker.Features.Widgets;
/// </remarks>
internal sealed class WidgetConfiguration : IEntityTypeConfiguration<Widget>
{
public void Configure(EntityTypeBuilder<Widget> builder)
void IEntityTypeConfiguration<Widget>.Configure(EntityTypeBuilder<Widget> builder)
{
ArgumentNullException.ThrowIfNull(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace MyApp.Worker.Infrastructure;
/// </summary>
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
/// <summary>Gets the widgets. Only aggregate roots get a set of their own.</summary>
public DbSet<Widget> Widgets => Set<Widget>();

// Conventions, not model creation. Property discovery skips types it does not recognise, so an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace MyApp.Worker.Infrastructure;
/// </remarks>
internal sealed class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
AppDbContext IDesignTimeDbContextFactory<AppDbContext>.CreateDbContext(string[] args)
{
DbContextOptionsBuilder<AppDbContext> builder = new();
builder.UseNpgsql("Host=design-time;Database=designtime;Username=none;Password=none");
Expand Down
18 changes: 14 additions & 4 deletions tests/Loom.Templates.Tests/TemplateManifestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task The_Manifest_Is_Valid_Json_With_The_Members_Dotnet_New_Require
{
JsonElement manifest = await ReadManifestAsync(template);

foreach (string member in (string[])["identity", "name", "shortName", "sourceName"])
foreach (string member in (string[])["identity", "name", "shortName"])
{
await Assert.That(manifest.TryGetProperty(member, out JsonElement value) &&
value.ValueKind is JsonValueKind.String &&
Expand All @@ -53,12 +53,22 @@ public async Task The_Short_Name_Matches_The_Directory(string template)

[Test]
[MethodDataSource(nameof(Templates))]
public async Task The_Source_Name_Occurs_In_The_Content_It_Renames(string template)
public async Task Exactly_One_Symbol_Renames_Files(string template)
{
JsonElement manifest = await ReadManifestAsync(template);
string sourceName = manifest.GetProperty("sourceName").GetString()!;

await Assert.That(await OccurrencesAsync(template, sourceName)).IsGreaterThan(0);
string[] renamers =
[
.. manifest.GetProperty("symbols").EnumerateObject()
.Where(symbol => symbol.Value.TryGetProperty("fileRename", out _))
.Select(symbol => symbol.Name),
];

// The token is renamed and replaced by one symbol rather than by sourceName, so that paths and
// file contents get the same sanitised value. A name like "My-App" is a valid directory and an
// invalid identifier; two mechanisms would disagree about which to write where.
await Assert.That(renamers.Length).IsEqualTo(1);
await Assert.That(manifest.TryGetProperty("sourceName", out _)).IsFalse();
}

[Test]
Expand Down
Loading