Skip to content

Commit 910b4da

Browse files
committed
Use AssertionScope to always include response.DebugInformation in the response body Should() assertions. This changes the way assertions are executed though, reporting on all ALL the failures. Since we do quite a few assertions in a single method this would become noisy so we hack the message to only include the first failure as before (#3408)
(cherry picked from commit df95930)
1 parent d516278 commit 910b4da

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Tests/Tests/Framework/EndpointTests/ApiIntegrationTestBase.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Elastic.Xunit.XunitPlumbing;
77
using Elasticsearch.Net;
88
using FluentAssertions;
9+
using FluentAssertions.Execution;
910
using Nest;
1011
using Tests.Core.Client;
1112
using Tests.Core.Extensions;
@@ -53,7 +54,20 @@ protected override Task AssertOnAllResponses(Action<TResponse> assert)
5354
return;
5455
}
5556

56-
assert(r);
57+
using (var scope = new AssertionScope())
58+
{
59+
assert(r);
60+
var failures = scope.Discard();
61+
if (failures.Length <= 0) return;
62+
63+
var failure = failures[0];
64+
scope.AddReportable("Failure", failure);
65+
scope.AddReportable("DebugInformation", r.DebugInformation);
66+
scope.FailWith( $@"{{Failure}}
67+
Response Under Test:
68+
{{DebugInformation}}");
69+
70+
}
5771
});
5872
}
5973
}

src/Tests/Tests/Search/Request/FieldsUsageTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ [I] protected Task FieldsAreReturned() => this.AssertOnAllResponses(r =>
6060
var name = fieldValues.Value<string>(Field<Project>(p => p.Name));
6161
name.Should().NotBeNullOrWhiteSpace();
6262

63-
6463
var commits = fieldValues.ValueOf<Project, float?>(p => p.NumberOfCommits);
6564
commits.Should().BeGreaterThan(0);
6665

0 commit comments

Comments
 (0)