Skip to content

Commit

Permalink
Changed format of HasData snapchat code to use multiple lines instead…
Browse files Browse the repository at this point in the history
… of a single line.

Fixes #12367
  • Loading branch information
Matthiee authored and smitpatel committed Sep 4, 2018
1 parent 5a80095 commit cbd2a20
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
42 changes: 24 additions & 18 deletions src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,36 +1113,42 @@ protected virtual void GenerateForeignKeyAnnotations([NotNull] IForeignKey forei
firstDatum = false;
}

stringBuilder.Append("new { ");
stringBuilder
.AppendLine("new")
.AppendLine("{");

var firstProperty = true;
foreach (var property in propertiesToOutput)
using (stringBuilder.Indent())
{
if (o.TryGetValue(property.Name, out var value)
&& value != null)
var firstProperty = true;
foreach (var property in propertiesToOutput)
{
if (!firstProperty)
{
stringBuilder.Append(", ");
}
else
if (o.TryGetValue(property.Name, out var value)
&& value != null)
{
firstProperty = false;
if (!firstProperty)
{
stringBuilder.AppendLine(",");
}
else
{
firstProperty = false;
}

stringBuilder
.Append(Code.Identifier(property.Name))
.Append(" = ")
.Append(Code.UnknownLiteral(value));
}

stringBuilder
.Append(Code.Identifier(property.Name))
.Append(" = ")
.Append(Code.UnknownLiteral(value));
}

stringBuilder.AppendLine();
}

stringBuilder.Append(" }");
stringBuilder.Append("}");
}
}

stringBuilder
.AppendLine()
.AppendLine(");");
}
}
Expand Down
45 changes: 32 additions & 13 deletions test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,10 @@ public virtual void Owned_types_are_stored_in_snapshot()
b.ToTable(""EntityWithOneProperty"");
b.HasData(
new { Id = 1 }
);
new
{
Id = 1
});
});
builder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b =>
Expand Down Expand Up @@ -883,8 +885,11 @@ public virtual void Owned_types_are_stored_in_snapshot()
.HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithStringKeyId"");
b1.HasData(
new { AlternateId = 1, Id = -1 }
);
new
{
AlternateId = 1,
Id = -1
});
});
});
Expand Down Expand Up @@ -1604,8 +1609,11 @@ public virtual void Property_enum_type_is_stored_in_snapshot_with_custom_convers
b.ToTable(""EntityWithEnumType"");
b.HasData(
new { Id = 1, Day = ""Fri"" }
);
new
{
Id = 1,
Day = ""Fri""
});
});
",
o =>
Expand Down Expand Up @@ -2652,9 +2660,15 @@ public virtual void SeedData_annotations_are_stored_in_snapshot()
b.ToTable(""EntityWithOneProperty"");
b.HasData(
new { Id = 42 },
new { Id = 43, OptionalProperty = 4.3m }
);
new
{
Id = 42
},
new
{
Id = 43,
OptionalProperty = 4.3m
});
});
",
o => Assert.Collection(
Expand Down Expand Up @@ -2701,8 +2715,10 @@ public virtual void SeedData_for_multiple_entities_are_stored_in_model_snapshot(
b.ToTable(""EntityWithOneProperty"");
b.HasData(
new { Id = 27 }
);
new
{
Id = 27
});
});
builder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b =>
Expand All @@ -2718,8 +2734,11 @@ public virtual void SeedData_for_multiple_entities_are_stored_in_model_snapshot(
b.ToTable(""EntityWithTwoProperties"");
b.HasData(
new { Id = 42, AlternateId = 43 }
);
new
{
Id = 42,
AlternateId = 43
});
});
",
o => Assert.Collection(
Expand Down

0 comments on commit cbd2a20

Please sign in to comment.