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 multiplied ConversionSelector's descriptions appearing in assertion message #941

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions Src/FluentAssertions/Equivalency/ConversionSelector.cs
Expand Up @@ -14,24 +14,24 @@ public class ConversionSelector
{
private List<Func<IMemberInfo, bool>> inclusions = new List<Func<IMemberInfo, bool>>();
private List<Func<IMemberInfo, bool>> exclusions = new List<Func<IMemberInfo, bool>>();
private StringBuilder description = new StringBuilder();
private StringBuilder descriptionBuilder = new StringBuilder();

public void IncludeAll()
{
inclusions.Add(_ => true);
description.Append("Try conversion of all members. ");
descriptionBuilder.Append("Try conversion of all members. ");
}

public void Include(Expression<Func<IMemberInfo, bool>> predicate)
{
inclusions.Add(predicate.Compile());
description.Append("Try conversion of member ").Append(predicate.Body).Append(". ");
descriptionBuilder.Append("Try conversion of member ").Append(predicate.Body).Append(". ");
}

public void Exclude(Expression<Func<IMemberInfo, bool>> predicate)
{
exclusions.Add(predicate.Compile());
description.Append("Do not convert member ").Append(predicate.Body).Append(". ");
descriptionBuilder.Append("Do not convert member ").Append(predicate.Body).Append(". ");
}

public bool RequiresConversion(IMemberInfo info)
Expand All @@ -41,7 +41,7 @@ public bool RequiresConversion(IMemberInfo info)

public override string ToString()
{
string result = description.ToString();
string result = descriptionBuilder.ToString();
return (result.Length > 0) ? result : "Without automatic conversion.";
}

Expand All @@ -51,7 +51,7 @@ public ConversionSelector Clone()
{
inclusions = new List<Func<IMemberInfo, bool>>(inclusions),
exclusions = new List<Func<IMemberInfo, bool>>(exclusions),
description = description
descriptionBuilder = new StringBuilder(descriptionBuilder.ToString())
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/Shared.Specs/BasicEquivalencySpecs.cs
Expand Up @@ -2581,7 +2581,10 @@ public void When_a_specific_mismatching_property_is_excluded_from_conversion_it_
//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
act.Should().Throw<XunitException>().WithMessage("Expected*<1973-09-20>*\"1973-09-20\"*");
string exceptionMessage = act.Should().Throw<XunitException>().Which.Message;
krajek marked this conversation as resolved.
Show resolved Hide resolved
exceptionMessage.Should().Match("Expected*<1973-09-20>*\"1973-09-20\"*", "{0} field is of mismatched type", nameof(expectation.Birthdate));
exceptionMessage.Should().NotMatch("*Try conversion of all members*", "conversion description should be present");
exceptionMessage.Should().NotMatch("*Try conversion of all members*Try conversion of all members*", "conversion description should not be duplicated");
}

[Fact]
Expand Down