Skip to content

Commit

Permalink
add entityType comment
Browse files Browse the repository at this point in the history
Add test and fix test
  • Loading branch information
ErikEJ committed Jul 12, 2019
1 parent 1dbdc87 commit 93d6298
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ private void GenerateEntityType(IEntityType entityType, bool useDataAnnotations)
var annotations = entityType.GetAnnotations().ToList();
RemoveAnnotation(ref annotations, CoreAnnotationNames.ConstructorBinding);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.TableName);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Comment);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Schema);
RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.DbSetName);

Expand Down Expand Up @@ -388,6 +389,13 @@ private void GenerateEntityType(IEntityType entityType, bool useDataAnnotations)

lines.AddRange(GenerateAnnotations(annotations.Except(annotationsToRemove)));

if (entityType.GetComment() != null)
{
lines.Add(
$".{nameof(RelationalPropertyBuilderExtensions.HasComment)}" +
$"({_code.Literal(entityType.GetComment())})");
}

AppendMultiLineFluentApi(entityType, lines);

foreach (var index in entityType.GetIndexes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,32 @@ public void Comments_use_fluent_api()
}),
new ModelCodeGenerationOptions(),
code => Assert.Contains(
".HasColumn(\"An int property\")",
".HasComment(\"An int property\")",
code.ContextFile.Code),
model => Assert.Equal(
"An int property",
model.FindEntityType("Entity").GetProperty("Property").GetComment()));
}

[Fact]
public void Entity_comments_use_fluent_api()
{
Test(
modelBuilder => modelBuilder.Entity(
"Entity",
x =>
{
x.HasComment("An entity comment");
}),
new ModelCodeGenerationOptions(),
code => Assert.Contains(
".HasComment(\"An entity comment\")",
code.ContextFile.Code),
model => Assert.Equal(
"An entity comment",
model.FindEntityType("Entity").GetComment()));
}

private class TestCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
public override MethodCallCodeFragment GenerateProviderOptions()
Expand Down

0 comments on commit 93d6298

Please sign in to comment.