Skip to content

Commit 621497e

Browse files
committed
Navigation test refactoring:
- using common model for entity, owned, json and complex type navigations - 4 levels: root, trunk, branch, leaf - optional reference, required reference (dependent to principal), collection - for now just testing projection scenarios as proof of concept (tracking / notracking) TODO: - fix owned sqlite model, - add model with inheritance, - move actual tests from existing test suites, - add migration check (that model can be migrated to from scratch and that noop is actual noop), - implement InMemory tests.
1 parent a0432fe commit 621497e

File tree

58 files changed

+3527
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3527
-0
lines changed

Diff for: test/EFCore.InMemory.FunctionalTests/InMemoryComplianceTest.cs

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.EntityFrameworkCore.BulkUpdates;
5+
using Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
56

67
namespace Microsoft.EntityFrameworkCore;
78

@@ -25,6 +26,17 @@ public class InMemoryComplianceTest : ComplianceTestBase
2526
typeof(NonSharedModelBulkUpdatesTestBase),
2627
typeof(NorthwindBulkUpdatesTestBase<>),
2728
typeof(JsonQueryTestBase<>),
29+
30+
// TODO: implement later once things are baked
31+
typeof(ComplexRelationshipsInProjectionNoTrackingQueryTestBase<>),
32+
typeof(ComplexRelationshipsInProjectionQueryTestBase<>),
33+
typeof(EntityRelationshipsInProjectionNoTrackingQueryTestBase<>),
34+
typeof(EntityRelationshipsInProjectionQueryTestBase<>),
35+
typeof(JsonRelationshipsInProjectionNoTrackingQueryTestBase<>),
36+
typeof(JsonRelationshipsInProjectionQueryTestBase<>),
37+
typeof(OwnedRelationshipsInProjectionNoTrackingQueryTestBase<>),
38+
typeof(OwnedRelationshipsInProjectionQueryTestBase<>),
39+
typeof(RelationshipsInProjectionQueryTestBase<>),
2840
};
2941

3042
protected override Assembly TargetAssembly { get; } = typeof(InMemoryComplianceTest).Assembly;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.EntityFrameworkCore.TestModels.RelationshipsModel;
5+
6+
namespace Microsoft.EntityFrameworkCore.Query.Relationships;
7+
8+
public abstract class ComplexRelationshipsQueryRelationalFixtureBase : ComplexRelationshipsQueryFixtureBase
9+
{
10+
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
11+
{
12+
base.OnModelCreating(modelBuilder, context);
13+
14+
modelBuilder.Entity<RelationshipsRootEntity>().ToTable("RootEntities");
15+
modelBuilder.Entity<RelationshipsTrunkEntity>().ToTable("TrunkEntities");
16+
modelBuilder.Entity<RelationshipsTrunkEntity>().Property(x => x.Id).ValueGeneratedNever();
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.EntityFrameworkCore.TestModels.RelationshipsModel;
5+
6+
namespace Microsoft.EntityFrameworkCore.Query.Relationships;
7+
8+
public abstract class EntityRelationshipsQueryRelationalFixtureBase : EntityRelationshipsQueryFixtureBase
9+
{
10+
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
11+
{
12+
base.OnModelCreating(modelBuilder, context);
13+
14+
modelBuilder.Entity<RelationshipsRootEntity>().ToTable("RootEntities");
15+
modelBuilder.Entity<RelationshipsTrunkEntity>().ToTable("TrunkEntities");
16+
modelBuilder.Entity<RelationshipsBranchEntity>().ToTable("BranchEntities");
17+
modelBuilder.Entity<RelationshipsLeafEntity>().ToTable("LeafEntities");
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class ComplexRelationshipsInProjectionNoTrackingQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: ComplexRelationshipsInProjectionNoTrackingQueryTestBase<TFixture>(fixture)
8+
where TFixture : ComplexRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class ComplexRelationshipsInProjectionQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: ComplexRelationshipsInProjectionQueryTestBase<TFixture>(fixture)
8+
where TFixture : ComplexRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class EntityRelationshipsInProjectionNoTrackingQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: EntityRelationshipsInProjectionNoTrackingQueryTestBase<TFixture>(fixture)
8+
where TFixture : EntityRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class EntityRelationshipsInProjectionQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: EntityRelationshipsInProjectionQueryTestBase<TFixture>(fixture)
8+
where TFixture : EntityRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class JsonRelationshipsInProjectionNoTrackingQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: JsonRelationshipsInProjectionNoTrackingQueryTestBase<TFixture>(fixture)
8+
where TFixture : JsonRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class JsonRelationshipsInProjectionQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: JsonRelationshipsInProjectionQueryTestBase<TFixture>(fixture)
8+
where TFixture : JsonRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class OwnedRelationshipsInProjectionNoTrackingQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: OwnedRelationshipsInProjectionNoTrackingQueryTestBase<TFixture>(fixture)
8+
where TFixture : OwnedRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore.Query.Relationships.InProjection;
5+
6+
public abstract class OwnedRelationshipsInProjectionQueryRelationalTestBase<TFixture>(TFixture fixture)
7+
: OwnedRelationshipsInProjectionQueryTestBase<TFixture>(fixture)
8+
where TFixture : OwnedRelationshipsQueryRelationalFixtureBase, new()
9+
{
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.EntityFrameworkCore.TestModels.RelationshipsModel;
5+
6+
namespace Microsoft.EntityFrameworkCore.Query.Relationships;
7+
8+
public abstract class JsonRelationshipsQueryRelationalFixtureBase : JsonRelationshipsQueryFixtureBase
9+
{
10+
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
11+
{
12+
base.OnModelCreating(modelBuilder, context);
13+
14+
modelBuilder.Entity<RelationshipsRootEntity>().ToTable("RootEntities");
15+
modelBuilder.Entity<RelationshipsRootEntity>().OwnsOne(x => x.OptionalReferenceTrunk).ToJson();
16+
modelBuilder.Entity<RelationshipsRootEntity>().OwnsOne(x => x.RequiredReferenceTrunk).ToJson();
17+
modelBuilder.Entity<RelationshipsRootEntity>().OwnsMany(x => x.CollectionTrunk).ToJson();
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
5+
using Microsoft.EntityFrameworkCore.TestModels.RelationshipsModel;
6+
7+
namespace Microsoft.EntityFrameworkCore.Query.Relationships;
8+
9+
public abstract class OwnedRelationshipsQueryRelationalFixtureBase : OwnedRelationshipsQueryFixtureBase
10+
{
11+
protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
12+
{
13+
base.OnModelCreating(modelBuilder, context);
14+
15+
modelBuilder.Entity<RelationshipsRootEntity>().ToTable("RootEntities");
16+
modelBuilder.Entity<RelationshipsRootEntity>()
17+
.OwnsOne(x => x.OptionalReferenceTrunk, b =>
18+
{
19+
b.OwnsOne(x => x.OptionalReferenceBranch, bb =>
20+
{
21+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
22+
{
23+
bbb.ToTable("Root_OptionalReferenceTrunk_OptionalReferenceBranch_CollectionLeaf");
24+
});
25+
});
26+
27+
b.OwnsOne(x => x.RequiredReferenceBranch, bb =>
28+
{
29+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
30+
{
31+
bbb.ToTable("Root_OptionalReferenceTrunk_RequiredReferenceBranch_CollectionLeaf");
32+
});
33+
});
34+
35+
b.OwnsMany(x => x.CollectionBranch, bb =>
36+
{
37+
bb.ToTable("Root_OptionalReferenceTrunk_CollectionBranch");
38+
39+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
40+
{
41+
bbb.ToTable("Root_OptionalReferenceTrunk_CollectionBranch_CollectionLeaf");
42+
});
43+
});
44+
});
45+
46+
modelBuilder.Entity<RelationshipsRootEntity>()
47+
.OwnsOne(x => x.RequiredReferenceTrunk, b =>
48+
{
49+
b.OwnsOne(x => x.OptionalReferenceBranch, bb =>
50+
{
51+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
52+
{
53+
bbb.ToTable("Root_RequiredReferenceTrunk_OptionalReferenceBranch_CollectionLeaf");
54+
});
55+
});
56+
57+
b.OwnsOne(x => x.RequiredReferenceBranch, bb =>
58+
{
59+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
60+
{
61+
bbb.ToTable("Root_RequiredReferenceTrunk_RequiredReferenceBranch_CollectionLeaf");
62+
});
63+
});
64+
65+
b.OwnsMany(x => x.CollectionBranch, bb =>
66+
{
67+
bb.ToTable("Root_RequiredReferenceTrunk_CollectionBranch");
68+
69+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
70+
{
71+
bbb.ToTable("Root_RequiredReferenceTrunk_CollectionBranch_CollectionLeaf");
72+
});
73+
});
74+
});
75+
modelBuilder.Entity<RelationshipsRootEntity>().Navigation(x => x.RequiredReferenceTrunk).IsRequired(true);
76+
77+
modelBuilder.Entity<RelationshipsRootEntity>()
78+
.OwnsMany(x => x.CollectionTrunk, b =>
79+
{
80+
b.ToTable("Root_CollectionTrunk");
81+
82+
b.OwnsOne(x => x.OptionalReferenceBranch, bb =>
83+
{
84+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
85+
{
86+
bbb.ToTable("Root_CollectionTrunk_OptionalReferenceBranch_CollectionLeaf");
87+
});
88+
});
89+
90+
b.OwnsOne(x => x.RequiredReferenceBranch, bb =>
91+
{
92+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
93+
{
94+
bbb.ToTable("Root_CollectionTrunk_RequiredReferenceBranch_CollectionLeaf");
95+
});
96+
});
97+
98+
b.OwnsMany(x => x.CollectionBranch, bb =>
99+
{
100+
bb.ToTable("Root_CollectionTrunk_CollectionBranch");
101+
102+
bb.OwnsMany(x => x.CollectionLeaf, bbb =>
103+
{
104+
bbb.ToTable("Root_CollectionTrunk_CollectionBranch_CollectionLeaf");
105+
});
106+
});
107+
});
108+
}
109+
}

0 commit comments

Comments
 (0)