Skip to content

Commit 669f817

Browse files
committed
Handle missing caller identifier
Fixes #3031 Regression from #3000 where previously `getCallerIdentifier() + callerPostfix` would return an empty string.
1 parent c53c9eb commit 669f817

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Src/FluentAssertions/Execution/SubjectIdentificationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public string Build()
8383

8484
if (scopeName is null)
8585
{
86-
return callerIdentifier;
86+
return callerIdentifier ?? "";
8787
}
8888
else if (callerIdentifier is null)
8989
{

Tests/FluentAssertions.Specs/Execution/AssertionChainSpecs.Chaining.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ public void Discard_a_scope_after_continuing_chained_assertion()
578578
Assert.Contains("First \"assertion\"", failures);
579579
}
580580

581+
[Fact]
582+
public void Returns_an_empty_identification_when_neither_scope_name_nor_caller_identifier_are_available()
583+
{
584+
// Arrange
585+
var assertionChain = AssertionChain.GetOrCreate();
586+
assertionChain.OverrideCallerIdentifier(() => null);
587+
588+
// Act
589+
string identification = assertionChain.CallerIdentifier;
590+
591+
// Assert
592+
identification.Should().BeEmpty();
593+
}
594+
581595
// [Fact]
582596
// public void Get_info_about_line_breaks_from_parent_scope_after_continuing_chained_assertion()
583597
// {

docs/_pages/releases.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ sidebar:
77
nav: "sidebar"
88
---
99

10+
## 8.1.2
11+
12+
## Fixes
13+
14+
* Fixed a regression from 8.1.0 where a `NullReferenceException` was thrown during subject identification - [#3036](https://github.com/fluentassertions/fluentassertions/pull/3036
15+
1016
## 8.1.1
1117

1218
## Fixes

0 commit comments

Comments
 (0)