-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Description
When trying to apply an exclusion to a property that links to a different property, Fluent Assertions ignores the exclusion on said property, saying the test failed when
Complete minimal example reproducing the issue
Test method:
[TestMethod]
public async Task Then()
{
var obj1 = new Candidate{PersonalInfo = new CandidatePersonalInfo{Firstname = "John", Lastname = "Johnson", Initials = "JJ"}};
var obj2 = new Candidate{PersonalInfo = new CandidatePersonalInfo{Firstname = "John", Lastname = "Jameson", Initials = "JJ"}};
obj1.Should().BeEquivalentTo(obj2, opt => opt.Excluding(o => o.PersonalInfo.Fullname).Excluding(o => o.DocumentName).Excluding(o => o.PersonalInfo.Lastname));
}Relevant objects:
public class TestCandidate : TestBase
{
public override string DocumentName => PersonalInfo.Fullname;
public CandidatePersonalInfo PersonalInfo;
}
public abstract class TestBase
{
public abstract string DocumentName { get; }
}
public class CandidatePersonalInfo
{
public CandidatePersonalInfo()
{
Location = new AddressInfo();
}
public string Firstname { get; set; }
public string Middlename { get; set; }
public string Lastname { get; set; }
public string Initials { get; set; }
public Gender Gender { get; set; }
public DateTimeOffset? DateOfBirth { get; set; }
public string Fullname => ($"{Firstname} {Middlename}".Trim() + $" {Lastname}").Trim();
}Expected behavior:
The property DocumentName should be excluded from the assertion
Actual behavior:
The test case fails because the properties DocumentName are not equal
Then Failed: Expected member DocumentName to be
Expected member DocumentName to be
"John Jameson", but
"John Johnson" differs near "ohn" (index 6).
Expected member Info.CreatedAt to be <2019-06-07 13:31:57.077648 +2h>, but found <2019-06-07 13:31:57.0770104 +2h>.
With configuration:
- Use declared types and members
- Compare enums by value
- Exclude member root.PersonalInfo.Fullname
- Exclude member root.DocumentName
- Exclude member root.PersonalInfo.Lastname
- Match member by name (or throw)
- Without automatic conversion.
- Be strict about the order of items in byte arrays
at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\LateBoundTestFramework.cs:line 16
at FluentAssertions.Execution.CollectingAssertionStrategy.ThrowIfAny(IDictionary`2 context) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\CollectingAssertionStrategy.cs:line 49
at FluentAssertions.Equivalency.EquivalencyValidator.AssertEquality(EquivalencyValidationContext context) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Equivalency\EquivalencyValidator.cs:line 45
at RecruitNow.Cockpit.IntegrationTests.Candidates.GivenCandidatesController.WhenManagingCandidates.Then() in C:\Projects\RecruitNow.Cockpit 2.0\RecruitNow.Cockpit.IntegrationTests\Candidates\GivenCandidatesController\WhenManagingCandidates.cs:line 149
Versions
- Which version of Fluent Assertions are you using?
5.6.0 - Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.0.
.NET core 2.0
Additional Information
Any additional information, configuration or data that might be necessary to reproduce the issue.