Skip to content

Commit

Permalink
Fixed a problem in BeEquivalentTo where write-only properties would c…
Browse files Browse the repository at this point in the history
…ause a NRE.

The implementation of Type.GetProperties that Reflectify provided crashed on a write-only property that is part of an interface. We didn't have a test for that, and the only other test that covered a similar scenario wasn't properly implemented.
  • Loading branch information
dennisdoomen committed Nov 26, 2024
1 parent 4f16d15 commit b744cc4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public IEnumerable<IMember> SelectMembers(INode currentNode, IEnumerable<IMember

IEnumerable<IMember> selectedProperties = context.Type
.GetProperties(visibility.ToMemberKind())
.Where(property => property.GetMethod?.IsPrivate == false)
.Select(info => new Property(context.Type, info, currentNode));

return selectedMembers.Union(selectedProperties).ToList();
Expand Down
2 changes: 1 addition & 1 deletion Src/FluentAssertions/FluentAssertions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reflectify" Version="1.2.1">
<PackageReference Include="Reflectify" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class Accessibility
public void When_a_property_is_write_only_it_should_be_ignored()
{
// Arrange
var subject = new ClassWithWriteOnlyProperty
var expected = new ClassWithWriteOnlyProperty
{
WriteOnlyProperty = 123,
SomeOtherProperty = "whatever"
};

var expected = new
var subject = new
{
SomeOtherProperty = "whatever"
};
Expand Down
7 changes: 6 additions & 1 deletion Tests/FluentAssertions.Equivalency.Specs/TestTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ClassTwo
public int ValTwo { get; set; } = 3;
}

public class ClassWithWriteOnlyProperty
public class ClassWithWriteOnlyProperty : IHaveWriteOnlyProperty
{
private int writeOnlyPropertyValue;

Expand All @@ -49,6 +49,11 @@ public int WriteOnlyProperty
public string SomeOtherProperty { get; set; }
}

public interface IHaveWriteOnlyProperty
{
int WriteOnlyProperty { set; }
}

internal enum EnumOne
{
One = 0,
Expand Down
4 changes: 4 additions & 0 deletions docs/_pages/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ sidebar:
* Methods overwritten in `GenericAsyncFunctionAssertions` has been moved to `NonGenericAsyncFunctionAssertions`.
* Moved the non-generic `NotThrow` and `NotThrowAfter` from `DelegateAssertions<TDelegate, TAssertions>` to `ActionAssertions` - [#2371](https://github.com/fluentassertions/fluentassertions/pull/2371)

### Fixes

* Fixed a problem in `BeEquivalentTo` where write-only properties would cause a `NullReferenceException` - [#2836](https://github.com/fluentassertions/fluentassertions/pull/2836)

## 6.12.3

### Fixes
Expand Down

0 comments on commit b744cc4

Please sign in to comment.