Is there any possibility to override default messages of FluentAssertions
. Sometimes I just want my custom message to be print as the result of failed test. So far I haven't found any solution for this but maybe I missed something.
Example:
myOrderedList.SequenceEqual(desiredOrderedList)
.Should().BeTrue("Elements are not in correct order.\r\n" +
$"Error in JSON file: {fileName}.\r\n" +
$"Required order of elements is {string.Join(", ", desiredOrderedList)}");
Result message is:
Expected boolean to be true because Elements are not in correct order.
Error in JSON file: MyTestData.json.
Required order of elements is str1, str2, str3, but found False.
But I would like to have simply this
Elements are not in correct order.
Error in JSON file: MyTestData.json.
Required order of elements is str1, str2, str3.
EDIT: Tried this
public static class BooleanAssertionsExtensions
{
public static BooleanAssertions Should(this bool? instance)
{
return new BooleanAssertions(instance);
}
}
public class BooleanAssertions
{
public BooleanAssertions(bool? instance)
{
Subject = instance;
}
public bool? Subject { get; private set; }
public AndConstraint<BooleanAssertions> BeTrueCustom(string because = "", params object[] becauseArgs)
{
Execute.Assertion
.ForCondition(Subject == true)
.BecauseOf(because, becauseArgs)
.FailWith("{reason}");
return new AndConstraint<BooleanAssertions>(this);
}
}
but when trying to do .Should().BeTrueCustom(...
I get this error: 'BooleanAssertions' does not contain a definition for 'BeTrueCustom' and no accessible extension method 'BeTrueCustom' accepting a first argument of type 'BooleanAssertions' could be found (are you missing a using directive or an assembly reference?
I'm probably little bit slow but don't understand what am I doing wrong or how could I create new extension extending or overriding default behavior (default message). Pretty sad that FA doesn't support such fundamental thing.