Skip to content

Commit

Permalink
Fix ValueGeneratedOnUpdate in scaffolding
Browse files Browse the repository at this point in the history
And add some tests.

Fixes #18579
  • Loading branch information
roji committed Oct 28, 2019
1 parent db1b4f7 commit 1b86c4a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)
: nameof(PropertyBuilder.ValueGeneratedOnAddOrUpdate);
break;

case ValueGenerated.OnUpdate:
methodName = nameof(PropertyBuilder.ValueGeneratedOnUpdate);
break;

case ValueGenerated.Never:
methodName = nameof(PropertyBuilder.ValueGeneratedNever);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,41 @@ public void ModelSameNamespaceDbContext_works()
);
}

[ConditionalFact]
public void ValueGenerated_works()
{
Test(
modelBuilder => modelBuilder.Entity(
"Entity",
x =>
{
x.Property<int>("ValueGeneratedOnAdd").ValueGeneratedOnAdd();
x.Property<int>("ValueGeneratedOnAddOrUpdate").ValueGeneratedOnAddOrUpdate();
x.Property<int>("ConcurrencyToken").IsConcurrencyToken();
x.Property<int>("ValueGeneratedOnUpdate").ValueGeneratedOnUpdate();
x.Property<int>("ValueGeneratedNever").ValueGeneratedNever();
}),
new ModelCodeGenerationOptions(),
code =>
{
Assert.Contains(@"Property(e => e.ValueGeneratedOnAdd)
.ValueGeneratedOnAdd()", code.ContextFile.Code);
Assert.Contains("Property(e => e.ValueGeneratedOnAddOrUpdate).ValueGeneratedOnAddOrUpdate()", code.ContextFile.Code);
Assert.Contains("Property(e => e.ConcurrencyToken).IsConcurrencyToken()", code.ContextFile.Code);
Assert.Contains("Property(e => e.ValueGeneratedOnUpdate).ValueGeneratedOnUpdate()", code.ContextFile.Code);
Assert.Contains("Property(e => e.ValueGeneratedNever).ValueGeneratedNever()", code.ContextFile.Code);
},
model =>
{
var entity = model.FindEntityType("TestNamespace.Entity");
Assert.Equal(ValueGenerated.OnAdd, entity.GetProperty("ValueGeneratedOnAdd").ValueGenerated);
Assert.Equal(ValueGenerated.OnAddOrUpdate, entity.GetProperty("ValueGeneratedOnAddOrUpdate").ValueGenerated);
Assert.True(entity.GetProperty("ConcurrencyToken").IsConcurrencyToken);
Assert.Equal(ValueGenerated.OnUpdate, entity.GetProperty("ValueGeneratedOnUpdate").ValueGenerated);
Assert.Equal(ValueGenerated.Never, entity.GetProperty("ValueGeneratedNever").ValueGenerated);
});
}

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

0 comments on commit 1b86c4a

Please sign in to comment.