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 authored and bricelam committed Jul 12, 2019
1 parent 1dbdc87 commit cda0092
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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,11 +159,30 @@ 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()));
model.FindEntityType("TestNamespace.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("TestNamespace.Entity").GetComment()));
}

private class TestCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
Expand Down

0 comments on commit cda0092

Please sign in to comment.