Skip to content

Commit

Permalink
[bug] Prevent failing tests and add explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Jul 11, 2019
1 parent 15846ba commit 75f717a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Src/FluentAssertions/Types/PropertyInfoSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ public PropertyInfoSelector ThatAreDecoratedWith<TAttribute>()
public PropertyInfoSelector ThatAreDecoratedWithOrInherit<TAttribute>()
where TAttribute : Attribute
{
selectedProperties = selectedProperties.Where(property => property.IsDecoratedWithOrInherit<TAttribute>());
// TODO: There seems to be a bug with `GetCustomAttributes` when used as extension method
// compared to when used as a classic static method.

// When used as classic static method access, all tests are working as expected.
selectedProperties = selectedProperties.Where(property =>
CustomAttributeExtensions.GetCustomAttributes(property, true).OfType<TAttribute>().Any());

// But when used as extension method, the results differ.
// Comment the previous line and uncomment this one, now some tests will start failing because
// the inherited attribute is not found.
// selectedProperties = selectedProperties.Where(property => property.GetCustomAttributes(true).OfType<TAttribute>().Any());

return this;
}

Expand All @@ -86,7 +97,18 @@ public PropertyInfoSelector ThatAreNotDecoratedWith<TAttribute>()
public PropertyInfoSelector ThatAreNotDecoratedWithOrInherit<TAttribute>()
where TAttribute : Attribute
{
selectedProperties = selectedProperties.Where(property => !property.IsDecoratedWithOrInherit<TAttribute>());
// TODO: There seems to be a bug with `GetCustomAttributes` when used as extension method
// compared to when used as a classic static method.

// When used as classic static method access, all tests are working as expected.
selectedProperties = selectedProperties.Where(property =>
!CustomAttributeExtensions.GetCustomAttributes(property, true).OfType<TAttribute>().Any());

// But when used as extension method, the results differ.
// Comment the previous line and uncomment this one, now some tests will start failing because
// the inherited attribute is not found.
// selectedProperties = selectedProperties.Where(property => !property.GetCustomAttributes(true).OfType<TAttribute>().Any());

return this;
}

Expand Down

0 comments on commit 75f717a

Please sign in to comment.