Skip to content

Commit

Permalink
fix(ApiExplorer): SubstitutedType have invalid property setter
Browse files Browse the repository at this point in the history
The PropertySetter of the SubstitutedType have 0 parameters: they had the same signature of the Getter.

resolves: dotnet#1104
  • Loading branch information
AndreaCuneo committed Aug 28, 2024
1 parent 3fc0719 commit 27ac7c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private static PropertyBuilder AddProperty(
var field = addTo.DefineField( "_" + name, shouldBeAdded, FieldAttributes.Private );
var propertyBuilder = addTo.DefineProperty( name, PropertyAttributes.HasDefault, shouldBeAdded, null );
var getter = addTo.DefineMethod( "get_" + name, propertyMethodAttributes, shouldBeAdded, Type.EmptyTypes );
var setter = addTo.DefineMethod( "set_" + name, propertyMethodAttributes, shouldBeAdded, Type.EmptyTypes );
var setter = addTo.DefineMethod( "set_" + name, propertyMethodAttributes, null, [shouldBeAdded] );
var il = getter.GetILGenerator();

il.Emit( OpCodes.Ldarg_0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,27 @@ public void substitute_should_resolve_types_that_reference_a_model_that_match_th
substitutionType.Should().NotBeOfType<TypeBuilder>();
}

[Fact]
public void substituted_type_should_have_valid_runtime_properties__issue1104()
{
// arrange
var modelBuilder = new ODataConventionModelBuilder();

var address = modelBuilder.EntitySet<Address>( nameof( Address ) ).EntityType;
address.Ignore( x => x.City ); // force substitution
var addressType = typeof( Address );

var context = NewContext( modelBuilder.GetEdmModel() );

// act
var substitutedType = addressType.SubstituteIfNecessary( context );

// assert
substitutedType.Should().NotBe( addressType );
substitutedType.GetRuntimeProperties().Should().HaveCount( 5 )
.And.AllSatisfy(prop => prop.GetSetMethod(true).Should().NotBeNull().And.ReturnVoid().And.Match(setter => setter.GetParameters().Length == 1));
}

public static IEnumerable<object[]> SubstitutionNotRequiredData
{
get
Expand Down

0 comments on commit 27ac7c3

Please sign in to comment.