Skip to content

Commit 06ec635

Browse files
committed
Fix tests
1 parent 51dee66 commit 06ec635

File tree

5 files changed

+79
-30
lines changed

5 files changed

+79
-30
lines changed

test/EFCore.Cosmos.FunctionalTests/ModelBuilding/CosmosModelBuilderGenericTest.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ public override void Can_set_complex_property_annotation()
763763
var complexPropertyBuilder = modelBuilder
764764
.Ignore<IndexedClass>()
765765
.Entity<ComplexProperties>()
766+
.Ignore(e => e.Customers)
766767
.ComplexProperty(e => e.Customer)
767768
.HasTypeAnnotation("foo", "bar")
768769
.HasPropertyAnnotation("foo2", "bar2")
@@ -810,28 +811,29 @@ public override void Can_set_complex_property_annotation()
810811
var complexPropertyBuilder = modelBuilder
811812
.Ignore<IndexedClass>()
812813
.Entity<ComplexProperties>()
813-
.ComplexProperty(e => e.Customer)
814+
.Ignore(e => e.Customer)
815+
.ComplexCollection(e => e.Customers)
814816
.HasTypeAnnotation("foo", "bar")
815817
.HasPropertyAnnotation("foo2", "bar2")
816818
.Ignore(c => c.Details)
819+
.Ignore(c => c.Title)
817820
.Ignore(c => c.Orders);
818821

819822
var model = modelBuilder.FinalizeModel();
820-
var complexProperty = model.FindEntityType(typeof(ComplexProperties))!.GetComplexProperties().Single();
823+
var complexCollection = model.FindEntityType(typeof(ComplexProperties))!.GetComplexProperties().Single();
821824

822-
Assert.Equal("bar", complexProperty.ComplexType["foo"]);
823-
Assert.Equal("bar2", complexProperty["foo2"]);
824-
Assert.Equal(typeof(Customer).Name, complexProperty.Name);
825+
Assert.Equal("bar", complexCollection.ComplexType["foo"]);
826+
Assert.Equal("bar2", complexCollection["foo2"]);
827+
Assert.Equal(nameof(ComplexProperties.Customers), complexCollection.Name);
825828
Assert.Equal(
826-
@"Customer (Customer)
827-
ComplexType: ComplexProperties.Customer#Customer
829+
@"Customers (List<Customer>) Required
830+
ComplexType: ComplexProperties.Customers#Customer
828831
Properties: "
829832
+ @"
830833
AlternateKey (Guid) Required
831834
Id (int) Required
832835
Name (string)
833-
Notes (List<string>) Element type: string Required
834-
Title (string) Required", complexProperty.ToDebugString(), ignoreLineEndingDifferences: true);
836+
Notes (List<string>) Element type: string Required", complexCollection.ToDebugString(), ignoreLineEndingDifferences: true);
835837
}
836838

837839
protected override TestModelBuilder CreateModelBuilder(Action<ModelConfigurationBuilder>? configure = null)

test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public void Generic_fluent_api_methods_should_return_generic_types()
9494
|| !hidingMethod.GetParameters().Select(p => p.ParameterType)
9595
.SequenceEqual(
9696
method.GetParameters().Select(
97-
p => GetEquivalentGenericType(p.ParameterType, hidingMethod.GetGenericArguments()))))
97+
p => GetEquivalentGenericType(
98+
p.ParameterType,
99+
hidingMethod.GetGenericArguments(),
100+
method.IsGenericMethod ? method.GetGenericArguments() : []))))
98101
{
99102
continue;
100103
}
@@ -133,7 +136,9 @@ public void Generic_fluent_api_methods_should_return_generic_types()
133136
|| !hidingMethod.GetParameters().Skip(1).Select(p => p.ParameterType)
134137
.SequenceEqual(
135138
method.GetParameters().Skip(1).Select(
136-
p => GetEquivalentGenericType(p.ParameterType, hidingMethod.GetGenericArguments()))))
139+
p => GetEquivalentGenericType(p.ParameterType,
140+
hidingMethod.GetGenericArguments(),
141+
method.IsGenericMethod ? method.GetGenericArguments() : []))))
137142
{
138143
continue;
139144
}
@@ -164,24 +169,37 @@ public static string FormatGenericArguments(MethodInfo methodInfo)
164169
return arguments.Length == 0 ? "" : $"`{arguments.Length}";
165170
}
166171

167-
protected Type GetEquivalentGenericType(Type parameterType, Type[] genericArguments)
172+
protected Type GetEquivalentGenericType(Type parameterType, Type[] hidingGenericArguments, Type[] baseGenericArguments)
168173
{
169174
if (parameterType.IsGenericType
170175
&& parameterType.GetGenericTypeDefinition() == typeof(Action<>))
171176
{
172177
var builder = parameterType.GetGenericArguments()[0];
173-
if (Fixture.GenericFluentApiTypes.TryGetValue(builder, out var genericBuilder)
174-
&& genericBuilder.GetGenericArguments().Length == genericArguments.Length)
175-
{
176-
return typeof(Action<>).MakeGenericType(genericBuilder.MakeGenericType(genericArguments));
177-
}
178-
179178
if (builder.IsGenericType)
180179
{
180+
var builderArguments = builder.GetGenericArguments();
181181
var builderDefinition = builder.GetGenericTypeDefinition();
182-
if (builderDefinition.GetGenericArguments().Length == genericArguments.Length)
182+
if (builderArguments.Length == hidingGenericArguments.Length)
183+
{
184+
return typeof(Action<>).MakeGenericType(builderDefinition.MakeGenericType(hidingGenericArguments));
185+
}
186+
else if (builderArguments.Length == 1
187+
&& baseGenericArguments.Length == hidingGenericArguments.Length)
188+
{
189+
for (var i = 0; i < baseGenericArguments.Length; i++)
190+
{
191+
if (builderArguments[0] == baseGenericArguments[i])
192+
{
193+
return typeof(Action<>).MakeGenericType(builderDefinition.MakeGenericType(hidingGenericArguments[i]));
194+
}
195+
}
196+
}
197+
}
198+
else if (Fixture.GenericFluentApiTypes.TryGetValue(builder, out var genericBuilder))
199+
{
200+
if (genericBuilder.GetGenericArguments().Length == hidingGenericArguments.Length)
183201
{
184-
return typeof(Action<>).MakeGenericType(builderDefinition.MakeGenericType(genericArguments));
202+
return typeof(Action<>).MakeGenericType(genericBuilder.MakeGenericType(hidingGenericArguments));
185203
}
186204
}
187205
}
@@ -720,7 +738,9 @@ private string ValidateConventionBuilderMethodReturns(Type builderType, Type con
720738
: conventionType;
721739

722740
var parameters = method.GetParameters()
723-
.Select(p => GetEquivalentGenericType(p.ParameterType, builderType.GetGenericArguments())).ToArray();
741+
.Select(p => GetEquivalentGenericType(
742+
p.ParameterType, builderType.GetGenericArguments(),
743+
method.IsGenericMethod ? method.GetGenericArguments() : [])).ToArray();
724744
var hidingMethod = builderType.GetMethod(
725745
method.Name,
726746
method.GetGenericArguments().Length,
@@ -767,7 +787,8 @@ private string ValidateConventionBuilderMethodReturns(Type builderType, Type con
767787
var expectedParameters = new[] { builderType }.Concat(
768788
parameters
769789
.Skip(1)
770-
.Select(p => GetEquivalentGenericType(p.ParameterType, builderType.GetGenericArguments())))
790+
.Select(p => GetEquivalentGenericType(
791+
p.ParameterType, builderType.GetGenericArguments(), method.IsGenericMethod ? method.GetGenericArguments() : [])))
771792
.ToArray();
772793
var hidingMethod = extensionType.GetMethod(
773794
method.Name,
@@ -1218,7 +1239,8 @@ public bool Equals(Type sourceParameterType, Type targetParameterType)
12181239
if (_targetMethod.DeclaringType.IsGenericType
12191240
&& sourceParameterType
12201241
== _tests.GetEquivalentGenericType(
1221-
sourceParameterType, _targetMethod.DeclaringType.GetGenericArguments()))
1242+
sourceParameterType, _targetMethod.DeclaringType.GetGenericArguments(),
1243+
sourceParameterType.IsGenericType ? sourceParameterType.GetGenericArguments() : []))
12221244
{
12231245
return true;
12241246
}
@@ -1269,6 +1291,7 @@ protected ApiConsistencyFixtureBase()
12691291
{ typeof(DiscriminatorBuilder), typeof(DiscriminatorBuilder<>) },
12701292
{ typeof(EntityTypeBuilder), typeof(EntityTypeBuilder<>) },
12711293
{ typeof(ComplexPropertyBuilder), typeof(ComplexPropertyBuilder<>) },
1294+
{ typeof(ComplexCollectionBuilder), typeof(ComplexCollectionBuilder<>) },
12721295
{ typeof(IndexBuilder), typeof(IndexBuilder<>) },
12731296
{ typeof(KeyBuilder), typeof(KeyBuilder<>) },
12741297
{ typeof(NavigationBuilder), typeof(NavigationBuilder<,>) },

test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.ComplexCollections.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public virtual void Can_set_complex_property_annotation()
2424
var complexCollectionBuilder = modelBuilder
2525
.Ignore<IndexedClass>()
2626
.Entity<ComplexProperties>()
27+
.Ignore(e => e.Customer)
2728
.ComplexCollection(e => e.Customers)
2829
.HasTypeAnnotation("foo", "bar")
2930
.HasPropertyAnnotation("foo2", "bar2")
@@ -57,6 +58,7 @@ public virtual void Can_set_property_annotation()
5758
.Ignore<Product>()
5859
.Ignore<IndexedClass>()
5960
.Entity<ComplexProperties>()
61+
.Ignore(e => e.Customer)
6062
.ComplexCollection(e => e.Customers)
6163
.Ignore(c => c.Details)
6264
.Ignore(c => c.Orders)
@@ -78,6 +80,7 @@ public virtual void Can_set_property_annotation_when_no_clr_property()
7880
.Ignore<Product>()
7981
.Ignore<IndexedClass>()
8082
.Entity<ComplexProperties>()
83+
.Ignore(e => e.Customer)
8184
.ComplexCollection(e => e.Customers)
8285
.Ignore(c => c.Details)
8386
.Ignore(c => c.Orders)
@@ -99,6 +102,7 @@ public virtual void Can_set_property_annotation_by_type()
99102
.Ignore<Product>()
100103
.Ignore<IndexedClass>()
101104
.Entity<ComplexProperties>()
105+
.Ignore(e => e.Customer)
102106
.ComplexCollection(e => e.Customers)
103107
.Ignore(c => c.Details)
104108
.Ignore(c => c.Orders)
@@ -182,6 +186,7 @@ public virtual void Properties_can_be_ignored_by_type()
182186
.Ignore<Product>()
183187
.Ignore<IndexedClass>()
184188
.Entity<ComplexProperties>()
189+
.Ignore(e => e.Customer)
185190
.ComplexCollection(e => e.Customers, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
186191

187192
var model = modelBuilder.FinalizeModel();
@@ -197,6 +202,7 @@ public virtual void Can_ignore_shadow_properties_when_they_have_been_added_expli
197202
var complexCollectionBuilder = modelBuilder
198203
.Ignore<IndexedClass>()
199204
.Entity<ComplexProperties>()
205+
.Ignore(e => e.Customer)
200206
.ComplexCollection(e => e.Customers, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
201207
complexCollectionBuilder.Property<string>("Shadow");
202208
complexCollectionBuilder.Ignore("Shadow");
@@ -216,6 +222,7 @@ public virtual void Can_add_shadow_properties_when_they_have_been_ignored()
216222
.Ignore<Product>()
217223
.Ignore<IndexedClass>()
218224
.Entity<ComplexProperties>()
225+
.Ignore(e => e.Customer)
219226
.ComplexCollection(
220227
e => e.Customers,
221228
b =>
@@ -393,11 +400,11 @@ public virtual void Properties_can_be_made_concurrency_tokens()
393400
Assert.False(complexType.FindProperty("Bottom").IsConcurrencyToken);
394401

395402
Assert.Equal(-1, complexType.FindProperty(Customer.IdProperty.Name).GetOriginalValueIndex());
396-
Assert.Equal(6, complexType.FindProperty("Up").GetOriginalValueIndex());
403+
Assert.Equal(2, complexType.FindProperty("Up").GetOriginalValueIndex());
397404
Assert.Equal(-1, complexType.FindProperty("Down").GetOriginalValueIndex());
398-
Assert.Equal(4, complexType.FindProperty("Charm").GetOriginalValueIndex());
405+
Assert.Equal(0, complexType.FindProperty("Charm").GetOriginalValueIndex());
399406
Assert.Equal(-1, complexType.FindProperty("Strange").GetOriginalValueIndex());
400-
Assert.Equal(5, complexType.FindProperty("Top").GetOriginalValueIndex());
407+
Assert.Equal(1, complexType.FindProperty("Top").GetOriginalValueIndex());
401408
Assert.Equal(-1, complexType.FindProperty("Bottom").GetOriginalValueIndex());
402409

403410
Assert.Equal(ChangeTrackingStrategy.ChangingAndChangedNotifications, complexType.GetChangeTrackingStrategy());
@@ -447,6 +454,7 @@ public virtual void Access_mode_can_be_overridden_at_entity_and_property_levels(
447454

448455
modelBuilder
449456
.Entity<ComplexProperties>()
457+
.Ignore(e => e.Customer)
450458
.ComplexCollection(e => e.Customers, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
451459

452460
modelBuilder

test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.ComplexType.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public virtual void Can_set_complex_property_annotation()
2424
var complexPropertyBuilder = modelBuilder
2525
.Ignore<IndexedClass>()
2626
.Entity<ComplexProperties>()
27+
.Ignore(e => e.Customers)
2728
.ComplexProperty(e => e.Customer)
2829
.HasTypeAnnotation("foo", "bar")
2930
.HasPropertyAnnotation("foo2", "bar2")
@@ -36,7 +37,7 @@ public virtual void Can_set_complex_property_annotation()
3637

3738
Assert.Equal("bar", complexProperty.ComplexType["foo"]);
3839
Assert.Equal("bar2", complexProperty["foo2"]);
39-
Assert.Equal(typeof(Customer).Name, complexProperty.Name);
40+
Assert.Equal(nameof(ComplexProperties.Customer), complexProperty.Name);
4041
Assert.Equal(
4142
@"Customer (Customer)
4243
ComplexType: ComplexProperties.Customer#Customer
@@ -57,6 +58,7 @@ public virtual void Can_set_property_annotation()
5758
.Ignore<Product>()
5859
.Ignore<IndexedClass>()
5960
.Entity<ComplexProperties>()
61+
.Ignore(e => e.Customers)
6062
.ComplexProperty(e => e.Customer)
6163
.Ignore(c => c.Details)
6264
.Ignore(c => c.Orders)
@@ -78,6 +80,7 @@ public virtual void Can_set_property_annotation_when_no_clr_property()
7880
.Ignore<Product>()
7981
.Ignore<IndexedClass>()
8082
.Entity<ComplexProperties>()
83+
.Ignore(e => e.Customers)
8184
.ComplexProperty(e => e.Customer)
8285
.Ignore(c => c.Details)
8386
.Ignore(c => c.Orders)
@@ -99,6 +102,7 @@ public virtual void Can_set_property_annotation_by_type()
99102
.Ignore<Product>()
100103
.Ignore<IndexedClass>()
101104
.Entity<ComplexProperties>()
105+
.Ignore(e => e.Customers)
102106
.ComplexProperty(e => e.Customer)
103107
.Ignore(c => c.Details)
104108
.Ignore(c => c.Orders)
@@ -182,6 +186,7 @@ public virtual void Properties_can_be_ignored_by_type()
182186
.Ignore<Product>()
183187
.Ignore<IndexedClass>()
184188
.Entity<ComplexProperties>()
189+
.Ignore(e => e.Customers)
185190
.ComplexProperty(e => e.Customer, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
186191

187192
var model = modelBuilder.FinalizeModel();
@@ -197,6 +202,7 @@ public virtual void Can_ignore_shadow_properties_when_they_have_been_added_expli
197202
var complexPropertyBuilder = modelBuilder
198203
.Ignore<IndexedClass>()
199204
.Entity<ComplexProperties>()
205+
.Ignore(e => e.Customers)
200206
.ComplexProperty(e => e.Customer, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
201207
complexPropertyBuilder.Property<string>("Shadow");
202208
complexPropertyBuilder.Ignore("Shadow");
@@ -216,6 +222,7 @@ public virtual void Can_add_shadow_properties_when_they_have_been_ignored()
216222
.Ignore<Product>()
217223
.Ignore<IndexedClass>()
218224
.Entity<ComplexProperties>()
225+
.Ignore(e => e.Customers)
219226
.ComplexProperty(
220227
e => e.Customer,
221228
b =>
@@ -455,9 +462,7 @@ public virtual void Access_mode_can_be_overridden_at_entity_and_property_levels(
455462

456463
modelBuilder.UsePropertyAccessMode(PropertyAccessMode.Field);
457464

458-
modelBuilder
459-
.Entity<ComplexProperties>()
460-
.ComplexProperty(e => e.Customer, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
465+
modelBuilder.Ignore<Customer>();
461466

462467
modelBuilder
463468
.Entity<ComplexProperties>()
@@ -1740,6 +1745,7 @@ public virtual void Can_set_primitive_collection_annotation_when_no_clr_property
17401745
.Ignore<Product>()
17411746
.Ignore<IndexedClass>()
17421747
.Entity<ComplexProperties>()
1748+
.Ignore(e => e.Customers)
17431749
.ComplexProperty(e => e.Customer)
17441750
.Ignore(c => c.Details)
17451751
.Ignore(c => c.Orders)
@@ -1788,6 +1794,7 @@ public virtual void Can_ignore_shadow_primitive_collections_when_they_have_been_
17881794
var complexPropertyBuilder = modelBuilder
17891795
.Ignore<IndexedClass>()
17901796
.Entity<ComplexProperties>()
1797+
.Ignore(e => e.Customers)
17911798
.ComplexProperty(e => e.Customer, b => b.Ignore(c => c.Details).Ignore(c => c.Orders));
17921799
complexPropertyBuilder.PrimitiveCollection<string[]>("Shadow");
17931800
complexPropertyBuilder.Ignore("Shadow");
@@ -1807,6 +1814,7 @@ public virtual void Can_add_shadow_primitive_collections_when_they_have_been_ign
18071814
.Ignore<Product>()
18081815
.Ignore<IndexedClass>()
18091816
.Entity<ComplexProperties>()
1817+
.Ignore(e => e.Customers)
18101818
.ComplexProperty(
18111819
e => e.Customer,
18121820
b =>

test/EFCore.Tests/ApiConsistencyTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ protected override void Initialize()
4747
typeof(ComplexPropertyBuilder<>),
4848
typeof(ComplexTypePrimitiveCollectionBuilder),
4949
typeof(ComplexTypePrimitiveCollectionBuilder<>),
50+
typeof(ComplexCollectionBuilder),
51+
typeof(ComplexCollectionBuilder<>),
5052
typeof(IndexBuilder),
5153
typeof(IndexBuilder<>),
5254
typeof(TriggerBuilder),
@@ -129,6 +131,12 @@ protected override void Initialize()
129131
nameof(ComplexPropertyBuilder.ComplexProperty), 0, [typeof(Type), typeof(string)]),
130132
typeof(ComplexPropertyBuilder).GetMethod(
131133
nameof(ComplexPropertyBuilder.ComplexProperty), 0, [typeof(Type), typeof(string), typeof(string)]),
134+
typeof(ComplexCollectionBuilder).GetMethod(
135+
nameof(ComplexCollectionBuilder.ComplexCollection), 0, [typeof(string)]),
136+
typeof(ComplexCollectionBuilder).GetMethod(
137+
nameof(ComplexCollectionBuilder.ComplexCollection), 0, [typeof(Type), typeof(string)]),
138+
typeof(ComplexCollectionBuilder).GetMethod(
139+
nameof(ComplexCollectionBuilder.ComplexCollection), 0, [typeof(Type), typeof(string), typeof(string)]),
132140
typeof(OwnedNavigationBuilder).GetMethod(
133141
nameof(OwnedNavigationBuilder.OwnsOne), 0, [typeof(string), typeof(string)]),
134142
typeof(OwnedNavigationBuilder).GetMethod(

0 commit comments

Comments
 (0)