Skip to content

Commit cbd2a20

Browse files
Matthieesmitpatel
authored andcommitted
Changed format of HasData snapchat code to use multiple lines instead of a single line.
Fixes #12367
1 parent 5a80095 commit cbd2a20

File tree

2 files changed

+56
-31
lines changed

2 files changed

+56
-31
lines changed

src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,36 +1113,42 @@ protected virtual void GenerateData(
11131113
firstDatum = false;
11141114
}
11151115

1116-
stringBuilder.Append("new { ");
1116+
stringBuilder
1117+
.AppendLine("new")
1118+
.AppendLine("{");
11171119

1118-
var firstProperty = true;
1119-
foreach (var property in propertiesToOutput)
1120+
using (stringBuilder.Indent())
11201121
{
1121-
if (o.TryGetValue(property.Name, out var value)
1122-
&& value != null)
1122+
var firstProperty = true;
1123+
foreach (var property in propertiesToOutput)
11231124
{
1124-
if (!firstProperty)
1125-
{
1126-
stringBuilder.Append(", ");
1127-
}
1128-
else
1125+
if (o.TryGetValue(property.Name, out var value)
1126+
&& value != null)
11291127
{
1130-
firstProperty = false;
1128+
if (!firstProperty)
1129+
{
1130+
stringBuilder.AppendLine(",");
1131+
}
1132+
else
1133+
{
1134+
firstProperty = false;
1135+
}
1136+
1137+
stringBuilder
1138+
.Append(Code.Identifier(property.Name))
1139+
.Append(" = ")
1140+
.Append(Code.UnknownLiteral(value));
11311141
}
1132-
1133-
stringBuilder
1134-
.Append(Code.Identifier(property.Name))
1135-
.Append(" = ")
1136-
.Append(Code.UnknownLiteral(value));
11371142
}
1143+
1144+
stringBuilder.AppendLine();
11381145
}
11391146

1140-
stringBuilder.Append(" }");
1147+
stringBuilder.Append("}");
11411148
}
11421149
}
11431150

11441151
stringBuilder
1145-
.AppendLine()
11461152
.AppendLine(");");
11471153
}
11481154
}

test/EFCore.Design.Tests/Migrations/ModelSnapshotSqlServerTest.cs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,10 @@ public virtual void Owned_types_are_stored_in_snapshot()
835835
b.ToTable(""EntityWithOneProperty"");
836836
837837
b.HasData(
838-
new { Id = 1 }
839-
);
838+
new
839+
{
840+
Id = 1
841+
});
840842
});
841843
842844
builder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithStringKey"", b =>
@@ -883,8 +885,11 @@ public virtual void Owned_types_are_stored_in_snapshot()
883885
.HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", ""EntityWithStringKeyId"");
884886
885887
b1.HasData(
886-
new { AlternateId = 1, Id = -1 }
887-
);
888+
new
889+
{
890+
AlternateId = 1,
891+
Id = -1
892+
});
888893
});
889894
});
890895
@@ -1604,8 +1609,11 @@ public virtual void Property_enum_type_is_stored_in_snapshot_with_custom_convers
16041609
b.ToTable(""EntityWithEnumType"");
16051610
16061611
b.HasData(
1607-
new { Id = 1, Day = ""Fri"" }
1608-
);
1612+
new
1613+
{
1614+
Id = 1,
1615+
Day = ""Fri""
1616+
});
16091617
});
16101618
",
16111619
o =>
@@ -2652,9 +2660,15 @@ public virtual void SeedData_annotations_are_stored_in_snapshot()
26522660
b.ToTable(""EntityWithOneProperty"");
26532661
26542662
b.HasData(
2655-
new { Id = 42 },
2656-
new { Id = 43, OptionalProperty = 4.3m }
2657-
);
2663+
new
2664+
{
2665+
Id = 42
2666+
},
2667+
new
2668+
{
2669+
Id = 43,
2670+
OptionalProperty = 4.3m
2671+
});
26582672
});
26592673
",
26602674
o => Assert.Collection(
@@ -2701,8 +2715,10 @@ public virtual void SeedData_for_multiple_entities_are_stored_in_model_snapshot(
27012715
b.ToTable(""EntityWithOneProperty"");
27022716
27032717
b.HasData(
2704-
new { Id = 27 }
2705-
);
2718+
new
2719+
{
2720+
Id = 27
2721+
});
27062722
});
27072723
27082724
builder.Entity(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+EntityWithTwoProperties"", b =>
@@ -2718,8 +2734,11 @@ public virtual void SeedData_for_multiple_entities_are_stored_in_model_snapshot(
27182734
b.ToTable(""EntityWithTwoProperties"");
27192735
27202736
b.HasData(
2721-
new { Id = 42, AlternateId = 43 }
2722-
);
2737+
new
2738+
{
2739+
Id = 42,
2740+
AlternateId = 43
2741+
});
27232742
});
27242743
",
27252744
o => Assert.Collection(

0 commit comments

Comments
 (0)