Skip to content

Commit

Permalink
add entityType comment
Browse files Browse the repository at this point in the history
Add test and fix test
Fix wrong class name
Add missing test
  • Loading branch information
ErikEJ authored and bricelam committed Jul 18, 2019
1 parent 4e4fe65 commit 1c675ca
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 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(RelationalEntityTypeBuilderExtensions.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
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ public void Unmapped_column_is_ignored()
}

[Fact]
public void Column_comments()
public void Column_and_table_comments()
{
var database = new DatabaseModel
{
Expand All @@ -1811,6 +1811,7 @@ public void Column_comments()
new DatabaseTable
{
Name = "Table",
Comment = "A table",
Columns =
{
IdColumn,
Expand All @@ -1827,6 +1828,9 @@ public void Column_comments()

var model = _factory.Create(database, useDatabaseNames: false);

var table = model.FindEntityType("Table");
Assert.Equal("A table", table.GetComment());

var column = model.FindEntityType("Table").GetProperty("Column");
Assert.Equal("An int column", column.GetComment());
}
Expand Down

0 comments on commit 1c675ca

Please sign in to comment.