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 @@ -4,7 +4,6 @@ namespace {{namespace}}
{
public partial class {{class}} : DbContext
{
{{{> dbconstructor}}}
{{{> dbsets}}}
{{#if entity-type-errors}}
{{#each entity-type-errors}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ namespace {{namespace}}
{
public partial class {{class}} : DbContext
{
{{> dbsets}}
{{{> dbsets}}}
{{#if entity-type-errors}}
{{#each entity-type-errors}}
{{spaces 8}}{{{entity-type-error}}}
{{/each}}

{{/if}}

{{{> dbconstructor}}}

{{{on-configuring}}}
{{{on-model-creating}}}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{spaces 8}}public {{class}}(DbContextOptions<{{class}}> options) : base(options)
{{spaces 8}}{
{{spaces 7}} }
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace {{namespace}}
public partial class {{class}}
{
{{{> constructor}}}
{{> properties}}
{{{> properties}}}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ namespace {{namespace}}
{
public partial class {{class}} : DbContext
{
{{> dbsets}}
{{{> dbsets}}}
{{#if entity-type-errors}}
{{#each entity-type-errors}}
{{spaces 8}}{{{entity-type-error}}}
{{/each}}

{{/if}}

{{{> dbconstructor}}}

{{{on-configuring}}}
{{{on-model-creating}}}
}
Expand Down
8 changes: 8 additions & 0 deletions test/Scaffolding.Handlebars.Tests/ExpectedContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public partial class FakeDbContext : DbContext
public virtual DbSet<Category> Category { get; set; }
public virtual DbSet<Product> Product { get; set; }

public FakeDbContext(DbContextOptions<FakeDbContext> options) : base(options)
{
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
Expand Down Expand Up @@ -76,6 +80,10 @@ public partial class FakeDbContext : DbContext
public virtual DbSet<Category> Category { get; set; }
public virtual DbSet<Product> Product { get; set; }

public FakeDbContext(DbContextOptions<FakeDbContext> options) : base(options)
{
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
Expand Down
6 changes: 4 additions & 2 deletions test/Scaffolding.Handlebars.Tests/ExpectedTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ namespace {{namespace}}
{
public partial class {{class}} : DbContext
{
{{> dbsets}}
{{{> dbsets}}}
{{#if entity-type-errors}}
{{#each entity-type-errors}}
{{spaces 8}}{{{entity-type-error}}}
{{/each}}

{{/if}}

{{{> dbconstructor}}}

{{{on-configuring}}}
{{{on-model-creating}}}
}
Expand All @@ -36,7 +38,7 @@ namespace {{namespace}}
public partial class {{class}}
{
{{{> constructor}}}
{{> properties}}
{{{> properties}}}
}
}
";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class HbsCSharpScaffoldingGeneratorTests

private InputFile ContextClassTemplate { get; }
private InputFile ContextImportsTemplate { get; }
private InputFile ContextCtorTemplate { get; }
private InputFile ContextDbSetsTemplate { get; }
private InputFile EntityClassTemplate { get; }
private InputFile EntityImportsTemplate { get; }
Expand Down Expand Up @@ -61,6 +62,12 @@ public HbsCSharpScaffoldingGeneratorTests(NorthwindDbContextFixture fixture)
File = Constants.Templates.ContextImportsFile,
Contents = File.ReadAllText(Path.Combine(contextPartialTemplatesPath, Constants.Templates.ContextImportsFile))
};
ContextCtorTemplate = new InputFile
{
Directory = contextPartialsVirtualPath,
File = Constants.Templates.ContextCtorFile,
Contents = File.ReadAllText(Path.Combine(contextPartialTemplatesPath, Constants.Templates.ContextCtorFile))
};
ContextDbSetsTemplate = new InputFile
{
Directory = contextPartialsVirtualPath,
Expand Down Expand Up @@ -313,7 +320,7 @@ public void Save_Should_Write_Context_and_Entity_Files()
private IReverseEngineerScaffolder CreateScaffolder(ReverseEngineerOptions options)
{
var fileService = new InMemoryTemplateFileService();
fileService.InputFiles(ContextClassTemplate, ContextImportsTemplate, ContextDbSetsTemplate,
fileService.InputFiles(ContextClassTemplate, ContextImportsTemplate, ContextCtorTemplate, ContextDbSetsTemplate,
EntityClassTemplate, EntityImportsTemplate, EntityCtorTemplate, EntityPropertiesTemplate);

var services = new ServiceCollection()
Expand Down
1 change: 1 addition & 0 deletions test/Scaffolding.Handlebars.Tests/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static class Templates
public const string EntityPropertiesFile = "Properties.hbs";
public const string ContextClassFile = "DbContext.hbs";
public const string ContextImportsFile = "DbImports.hbs";
public const string ContextCtorFile = "DbConstructor.hbs";
public const string ContextDbSetsFile = "DbSets.hbs";
}

Expand Down