Skip to content

Commit

Permalink
Improve convention API consistency test
Browse files Browse the repository at this point in the history
Fixes #214
  • Loading branch information
AndriySvyryd committed Aug 7, 2022
1 parent 5e00822 commit cd19c90
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Conventions/BackingFieldConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public virtual void ProcessModelFinalizing(
throw new InvalidOperationException((string?)ambiguousField.Value);
}

property.RemoveAnnotation(CoreAnnotationNames.AmbiguousField);
property.Builder.HasNoAnnotation(CoreAnnotationNames.AmbiguousField);
}
}
}
Expand Down
32 changes: 21 additions & 11 deletions test/EFCore.Specification.Tests/ApiConsistencyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,25 @@ public void Metadata_types_have_expected_structure()

private string ValidateMetadata(KeyValuePair<Type, (Type, Type, Type, Type)> types)
{
var readonlyType = types.Key;
var readOnlyType = types.Key;
var (mutableType, conventionType, conventionBuilderType, runtimeType) = types.Value;

if (!readonlyType.IsAssignableFrom(mutableType))
if (!readOnlyType.IsAssignableFrom(mutableType))
{
return $"{mutableType.Name} should derive from {readonlyType.Name}";
return $"{mutableType.Name} should derive from {readOnlyType.Name}";
}

if (!readonlyType.IsAssignableFrom(conventionType))
if (!readOnlyType.IsAssignableFrom(conventionType))
{
return $"{mutableType.Name} should derive from {readonlyType.Name}";
return $"{mutableType.Name} should derive from {readOnlyType.Name}";
}

if (typeof(IAnnotation) != readonlyType
&& typeof(IReadOnlyAnnotatable) != readonlyType)
if (readOnlyType != typeof(IAnnotation)
&& readOnlyType != typeof(IReadOnlyAnnotatable))
{
if (!typeof(IReadOnlyAnnotatable).IsAssignableFrom(readonlyType))
if (!typeof(IReadOnlyAnnotatable).IsAssignableFrom(readOnlyType))
{
return $"{readonlyType.Name} should derive from IAnnotatable";
return $"{readOnlyType.Name} should derive from IReadOnlyAnnotatable";
}

if (!typeof(IMutableAnnotatable).IsAssignableFrom(mutableType))
Expand All @@ -246,16 +246,21 @@ private string ValidateMetadata(KeyValuePair<Type, (Type, Type, Type, Type)> typ
{
return $"{conventionType.Name} should derive from IConventionAnnotatable";
}

if (!typeof(IAnnotatable).IsAssignableFrom(runtimeType))
{
return $"{runtimeType.Name} should derive from IAnnotatable";
}

if (conventionBuilderType != null
&& !typeof(IConventionAnnotatableBuilder).IsAssignableFrom(conventionBuilderType))
{
return $"{conventionBuilderType.Name} should derive from IConventionAnnotatableBuilder";
}

if (readonlyType.Namespace != MetadataNamespace)
if (readOnlyType.Namespace != MetadataNamespace)
{
return $"{readonlyType.Name} is expected to be in the {MetadataNamespace} namespace";
return $"{readOnlyType.Name} is expected to be in the {MetadataNamespace} namespace";
}

if (mutableType.Namespace != MetadataNamespace)
Expand All @@ -268,6 +273,11 @@ private string ValidateMetadata(KeyValuePair<Type, (Type, Type, Type, Type)> typ
return $"{conventionType.Name} is expected to be in the {MetadataNamespace} namespace";
}

if (runtimeType.Namespace != MetadataNamespace)
{
return $"{runtimeType.Name} is expected to be in the {MetadataNamespace} namespace";
}

if (conventionBuilderType != null
&& conventionBuilderType.Namespace != MetadataBuilderNamespace)
{
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ public virtual void Overrides_ForeignKeyAttribute()

var joinEntityType = categoryFk.DeclaringEntityType;
Assert.Equal(2, joinEntityType.GetForeignKeys().Count());
Assert.Equal(new[] {"CategoryWithAttributeId", "ProductWithAttributeId"},
joinEntityType.FindPrimaryKey()!.Properties.Select(p => p.Name));
}

protected class ProductWithAttribute
Expand Down

0 comments on commit cd19c90

Please sign in to comment.