Skip to content

Commit

Permalink
Fix EdmTargetPath property collections (#2922) (#2948)
Browse files Browse the repository at this point in the history
Co-authored-by: Kennedy Kang'ethe <[email protected]>
  • Loading branch information
gathogojr and KenitoInc authored Apr 26, 2024
1 parent 7c57c0a commit d1840c5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private static bool IsTypeCastValid(IEdmElement element, IEdmSchemaType schemaTy

if (elementEdmType != null)
{
return schemaType.AsElementType().IsOrInheritsFrom(elementEdmType);
return schemaType.AsElementType().IsOrInheritsFrom(elementEdmType.AsElementType());
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,54 @@ public void ParsingEntitySetPropertyOnComplexTypeOutOfLineAnnotationsWorks()
Assert.Equal("Name OutOfLine MyTerm Value", nameAnnotation);
}

[Fact]
public void ParsingEntitySetPropertyOnDerivedComplexTypeCollectionOutOfLineAnnotationsWorks()
{
// Test for MySchema.MyEntityContainer/MyEntitySet/MyComplexCollectionProperty/MySchema.DerivedType/MyProperty

string types =
@"<EntityType Name=""City"">
<Key>
<PropertyRef Name=""Name""/>
</Key>
<Property Name=""Name"" Nullable=""false"" Type=""Edm.String""/>
</EntityType>
<ComplexType Name=""Address"">
<Property Name=""Road"" Type=""Edm.String"" Nullable=""false""/>
</ComplexType>
<ComplexType Name=""LocalAddress"" BaseType=""NS.Address"">
<Property Name=""BuildingInfo"" Type=""Edm.String"" Nullable=""false""/>
</ComplexType>
<Term Name=""MyTerm"" Type=""Edm.String""/>
<Annotations Target=""NS.Default/Customers/AddressInfo/NS.LocalAddress/Road"" >
<Annotation Term=""NS.MyTerm"" String=""Name OutOfLine MyTerm Value"" />
</Annotations>";

string properties =
@"<Property Name=""AddressInfo"" Type=""Collection(NS.Address)"" />";

IEdmModel model = GetModel(types: types, properties: properties);
Assert.NotNull(model);

IEnumerable<EdmError> errors;
Assert.True(model.Validate(out errors), String.Format("Errors in validating model. {0}", String.Concat(errors.Select(e => e.ErrorMessage))));

var customer = model.SchemaElements.OfType<IEdmEntityType>().FirstOrDefault(c => c.Name == "Customer");
Assert.NotNull(customer);

IEdmTerm myTerm = model.FindDeclaredTerm("NS.MyTerm");
Assert.NotNull(myTerm);

// Name
IEdmProperty nameProperty = customer.DeclaredProperties.Where(x => x.Name == "AddressInfo").FirstOrDefault();
Assert.NotNull(nameProperty);

IEdmTargetPath targetPath = model.GetTargetPath("NS.Default/Customers/AddressInfo/NS.LocalAddress/Road");

string nameAnnotation = GetAnnotation(model, targetPath, myTerm, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
Assert.Equal("Name OutOfLine MyTerm Value", nameAnnotation);
}

[Fact]
public void ParsingEntitySetPropertyOnDerivedTypeOutOfLineAnnotationsWorks()
{
Expand Down

0 comments on commit d1840c5

Please sign in to comment.