Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ApiExplorer): SubstitutedType have invalid property setter #1105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ 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 )
#if NET452
;
foreach ( var substitutedProperty in substitutedType.GetRuntimeProperties() )
{
substitutedProperty.Should().NotBeNull();
substitutedProperty.GetSetMethod( true ).Should().NotBeNull()
.And.Match( p => p.ReturnType == typeof( void ) )
.And.Match( p => p.GetParameters().Length == 1 );
}
#else
.And.AllSatisfy(prop => prop.GetSetMethod(true).Should()
.NotBeNull()
.And.ReturnVoid()
.And.Match(setter => setter.GetParameters().Length == 1));
#endif
}

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