Skip to content

Commit 27ac7c3

Browse files
committed
fix(ApiExplorer): SubstitutedType have invalid property setter
The PropertySetter of the SubstitutedType have 0 parameters: they had the same signature of the Getter. resolves: #1104
1 parent 3fc0719 commit 27ac7c3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Common/src/Common.OData.ApiExplorer/OData/DefaultModelTypeBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private static PropertyBuilder AddProperty(
417417
var field = addTo.DefineField( "_" + name, shouldBeAdded, FieldAttributes.Private );
418418
var propertyBuilder = addTo.DefineProperty( name, PropertyAttributes.HasDefault, shouldBeAdded, null );
419419
var getter = addTo.DefineMethod( "get_" + name, propertyMethodAttributes, shouldBeAdded, Type.EmptyTypes );
420-
var setter = addTo.DefineMethod( "set_" + name, propertyMethodAttributes, shouldBeAdded, Type.EmptyTypes );
420+
var setter = addTo.DefineMethod( "set_" + name, propertyMethodAttributes, null, [shouldBeAdded] );
421421
var il = getter.GetILGenerator();
422422

423423
il.Emit( OpCodes.Ldarg_0 );

src/Common/test/Common.OData.ApiExplorer.Tests/OData/DefaultModelTypeBuilderTest.cs

+21
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,27 @@ public void substitute_should_resolve_types_that_reference_a_model_that_match_th
409409
substitutionType.Should().NotBeOfType<TypeBuilder>();
410410
}
411411

412+
[Fact]
413+
public void substituted_type_should_have_valid_runtime_properties__issue1104()
414+
{
415+
// arrange
416+
var modelBuilder = new ODataConventionModelBuilder();
417+
418+
var address = modelBuilder.EntitySet<Address>( nameof( Address ) ).EntityType;
419+
address.Ignore( x => x.City ); // force substitution
420+
var addressType = typeof( Address );
421+
422+
var context = NewContext( modelBuilder.GetEdmModel() );
423+
424+
// act
425+
var substitutedType = addressType.SubstituteIfNecessary( context );
426+
427+
// assert
428+
substitutedType.Should().NotBe( addressType );
429+
substitutedType.GetRuntimeProperties().Should().HaveCount( 5 )
430+
.And.AllSatisfy(prop => prop.GetSetMethod(true).Should().NotBeNull().And.ReturnVoid().And.Match(setter => setter.GetParameters().Length == 1));
431+
}
432+
412433
public static IEnumerable<object[]> SubstitutionNotRequiredData
413434
{
414435
get

0 commit comments

Comments
 (0)