Skip to content

Commit

Permalink
Test reverse engineering column comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bricelam committed Jul 18, 2019
1 parent 9b66b65 commit 4e4fe65
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)
RemoveAnnotation(ref annotations, CoreAnnotationNames.Unicode);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.DefaultValue);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.DefaultValueSql);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.Comment);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.ComputedColumnSql);
RemoveAnnotation(ref annotations, RelationalAnnotationNames.IsFixedLength);
RemoveAnnotation(ref annotations, ScaffoldingAnnotationNames.ColumnOrdinal);
Expand Down Expand Up @@ -675,6 +676,13 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)
$"({_code.Literal(property.GetDefaultValueSql())})");
}

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

if (property.GetComputedColumnSql() != null)
{
lines.Add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ public void Plugins_work()
scaffoldedModel.ContextFile.Code);
}

[Fact]
public void Comments_use_fluent_api()
{
Test(
modelBuilder => modelBuilder.Entity(
"Entity",
x =>
{
x.Property<int>("Id");
x.Property<int>("Property")
.HasComment("An int property");
}),
new ModelCodeGenerationOptions(),
code => Assert.Contains(
".HasColumn(\"An int property\")",
code.ContextFile.Code),
model => Assert.Equal(
"An int property",
model.FindEntityType("Entity").GetProperty("Property").GetComment()));
}

private class TestCodeGeneratorPlugin : ProviderCodeGeneratorPlugin
{
public override MethodCallCodeFragment GenerateProviderOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,36 @@ public void Unmapped_column_is_ignored()
Assert.Equal(1, columns.Count);
}

[Fact]
public void Column_comments()
{
var database = new DatabaseModel
{
Tables =
{
new DatabaseTable
{
Name = "Table",
Columns =
{
IdColumn,
new DatabaseColumn
{
Name = "Column",
StoreType = "int",
Comment = "An int column"
}
}
}
}
};

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

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

public class FakePluralizer : IPluralizer
{
public string Pluralize(string name)
Expand Down

0 comments on commit 4e4fe65

Please sign in to comment.