Skip to content

Commit 4823084

Browse files
rojiCopilot
andcommitted
Add test for owned collection mapped to JSON
Addresses review feedback: adds a test covering the owned (non-complex) collection case mapped to JSON. Owned collections are always nullable (IsUnique is false), so the default value is null rather than []. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 55a935c commit 4823084

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10053,6 +10053,55 @@ public virtual void Add_complex_collection_mapped_to_json_uses_empty_array_as_de
1005310053
Assert.IsType<DropColumnOperation>(downOps[0]);
1005410054
});
1005510055

10056+
#pragma warning disable EF8001 // Owned JSON entities are obsolete
10057+
[ConditionalFact]
10058+
public virtual void Add_owned_collection_mapped_to_json_has_nullable_column()
10059+
=> Execute(
10060+
_ => { },
10061+
source =>
10062+
{
10063+
source.Entity(
10064+
"Entity", e =>
10065+
{
10066+
e.Property<int>("Id").ValueGeneratedOnAdd();
10067+
e.HasKey("Id");
10068+
});
10069+
},
10070+
target =>
10071+
{
10072+
target.Entity(
10073+
"Entity", e =>
10074+
{
10075+
e.Property<int>("Id").ValueGeneratedOnAdd();
10076+
e.HasKey("Id");
10077+
10078+
e.OwnsMany(
10079+
"Owned", "json_collection", o =>
10080+
{
10081+
o.ToJson();
10082+
o.Property<string>("Value");
10083+
o.Property<DateTime>("Date");
10084+
});
10085+
});
10086+
},
10087+
upOps =>
10088+
{
10089+
Assert.Equal(1, upOps.Count);
10090+
10091+
var operation = Assert.IsType<AddColumnOperation>(upOps[0]);
10092+
Assert.Equal("Entity", operation.Table);
10093+
Assert.Equal("json_collection", operation.Name);
10094+
// Owned collections are always nullable (IsUnique is false), so no default value
10095+
Assert.True(operation.IsNullable);
10096+
Assert.Null(operation.DefaultValue);
10097+
},
10098+
downOps =>
10099+
{
10100+
Assert.Equal(1, downOps.Count);
10101+
Assert.IsType<DropColumnOperation>(downOps[0]);
10102+
});
10103+
#pragma warning restore EF8001 // Owned JSON entities are obsolete
10104+
1005610105
[ConditionalFact]
1005710106
public virtual void Noop_on_complex_properties()
1005810107
=> Execute(

0 commit comments

Comments
 (0)