Skip to content

Commit

Permalink
Improve the structure of a trace log
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Feb 6, 2022
1 parent 223e9e4 commit d9b7bd9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Src/FluentAssertions/Equivalency/EquivalencyValidator.cs
Expand Up @@ -62,13 +62,14 @@ private static void UpdateScopeWithReportableContext(AssertionScope scope, Compa

private void RunStepsUntilEquivalencyIsProven(Comparands comparands, IEquivalencyValidationContext context)
{
using var _ = context.Tracer.WriteBlock(node => $"{node.Description}");

foreach (IEquivalencyStep step in AssertionOptions.EquivalencyPlan)
{
var result = step.Handle(comparands, context, this);
context.Tracer.WriteLine(_ => $"Step {step.GetType().Name} returned {result}");

if (result == EquivalencyResult.AssertionCompleted)
{
context.Tracer.WriteLine(_ => $"Equivalency was proven by {step.GetType().Name}");
return;
}
}
Expand Down
Expand Up @@ -18,7 +18,7 @@ public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationCon
context.Tracer.WriteLine(member =>
{
string strategyName = (strategy == EqualityStrategy.Equals)
? "Equals must be used" : "object overrides Equals";
? $"{expectationType} overrides Equals" : "we are forced to use Equals";
return $"Treating {member.Description} as a value type because {strategyName}.";
});
Expand Down
Expand Up @@ -195,7 +195,34 @@ public void When_collection_does_contain_equivalent_by_including_single_property
var item = new Customer { Name = "John", Age = 20 };

// Act / Assert
collection.Should().ContainEquivalentOf(item, options => options.Including(x => x.Name));
collection.Should().ContainEquivalentOf(item, options => options.Including(x => x.Name).WithTracing());
}

[Fact]
public void Tracing_should_be_included_in_the_assertion_output()
{
// Arrange
var collection = new[]
{
new Customer
{
Name = "John",
Age = 18
},
new Customer
{
Name = "Jane",
Age = 18
}
};

var item = new Customer { Name = "John", Age = 21 };

// Act
Action act = () => collection.Should().ContainEquivalentOf(item, options => options.WithTracing());

// Assert
act.Should().Throw<XunitException>().WithMessage("*Equivalency was proven*");
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/releases.md
Expand Up @@ -17,6 +17,7 @@ sidebar:
* Improved the documentation on `BeLowerCased` and `BeUpperCased` for strings with non-alphabetic characters - [#1792](https://github.com/fluentassertions/fluentassertions/pull/1792)
* Caller identification does not handle all arguments using `new` - [#1794](https://github.com/fluentassertions/fluentassertions/pull/1794)
* Resolve an issue preventing `HaveAccessModifier` from correctly recognizing internal interfaces and enums - [#1793](https://github.com/fluentassertions/fluentassertions/issues/1793)
* Improved tracing for nested `AssertionScope`s - [#1797](https://github.com/fluentassertions/fluentassertions/pull/1797)

### Fixes (Extensibility)
* Fixed a continuation issue when using `ClearExpectation` - [#1791](https://github.com/fluentassertions/fluentassertions/pull/1791)
Expand Down

0 comments on commit d9b7bd9

Please sign in to comment.