Skip to content

Commit 743d3bf

Browse files
test: use Arrange/Act/Assert comments in new handled tests
Match the AAA comment convention for the SentryClientExtensions and MainExceptionProcessor chain-inheritance tests added in this branch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6c19b6f commit 743d3bf

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

test/Sentry.Tests/Internals/MainExceptionProcessorTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ public void Process_ExceptionWith_HandledTrue_WhenCaught()
106106
[Fact]
107107
public void Process_InnerExceptionChain_UnhandledOuter_PropagatesHandledFalseToInner()
108108
{
109+
// Arrange
109110
var sut = _fixture.GetSut();
110111
var evt = new SentryEvent();
111112
var outer = new Exception("outer", new Exception("inner"));
112113
outer.Data[Mechanism.HandledKey] = false;
113114

115+
// Act
114116
sut.Process(outer, evt);
115117

118+
// Assert
116119
Assert.NotNull(evt.SentryExceptions);
117120
// Discriminating: the default is handled=true, so inner reporting false proves it inherited the outer value.
118121
Assert.Equal(false, evt.SentryExceptions.Single(e => e.Value == "outer").Mechanism!.Handled);
@@ -122,12 +125,15 @@ public void Process_InnerExceptionChain_UnhandledOuter_PropagatesHandledFalseToI
122125
[Fact]
123126
public void Process_InnerExceptionChain_NoExplicitFlag_DefaultsBothToHandledTrue()
124127
{
128+
// Arrange
125129
var sut = _fixture.GetSut();
126130
var evt = new SentryEvent();
127131
var outer = new Exception("outer", new Exception("inner"));
128132

133+
// Act
129134
sut.Process(outer, evt);
130135

136+
// Assert
131137
Assert.NotNull(evt.SentryExceptions);
132138
Assert.Equal(true, evt.SentryExceptions.Single(e => e.Value == "outer").Mechanism!.Handled);
133139
Assert.Equal(true, evt.SentryExceptions.Single(e => e.Value == "inner").Mechanism!.Handled);
@@ -136,15 +142,18 @@ public void Process_InnerExceptionChain_NoExplicitFlag_DefaultsBothToHandledTrue
136142
[Fact]
137143
public void Process_InnerExceptionChain_ExplicitFlagOnInner_WinsOverInheritedParentValue()
138144
{
145+
// Arrange
139146
var sut = _fixture.GetSut();
140147
var evt = new SentryEvent();
141148
var inner = new Exception("inner");
142149
inner.Data[Mechanism.HandledKey] = true;
143150
var outer = new Exception("outer", inner);
144151
outer.Data[Mechanism.HandledKey] = false;
145152

153+
// Act
146154
sut.Process(outer, evt);
147155

156+
// Assert
148157
Assert.NotNull(evt.SentryExceptions);
149158
// The inner's explicit handled=true wins over the false it would otherwise inherit from the outer.
150159
Assert.Equal(false, evt.SentryExceptions.Single(e => e.Value == "outer").Mechanism!.Handled);
@@ -154,6 +163,7 @@ public void Process_InnerExceptionChain_ExplicitFlagOnInner_WinsOverInheritedPar
154163
[Fact]
155164
public void Process_ThreeLevelChain_ExplicitFlagOnMiddle_PropagatesToItsDescendant()
156165
{
166+
// Arrange
157167
var sut = _fixture.GetSut();
158168
var evt = new SentryEvent();
159169
var deepest = new Exception("deepest");
@@ -162,8 +172,10 @@ public void Process_ThreeLevelChain_ExplicitFlagOnMiddle_PropagatesToItsDescenda
162172
var outer = new Exception("outer", middle);
163173
outer.Data[Mechanism.HandledKey] = true;
164174

175+
// Act
165176
sut.Process(outer, evt);
166177

178+
// Assert
167179
Assert.NotNull(evt.SentryExceptions);
168180
// Discriminating: default and outer are both true, so deepest reporting false proves it
169181
// inherited the middle's explicit value rather than the default or the root.

test/Sentry.Tests/SentryClientExtensionsTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,57 @@ public void CaptureException_EnabledClient_CapturesEvent()
2525
[Fact]
2626
public void CaptureException_ExplicitHandledFalse_SetsFlag()
2727
{
28+
// Arrange
2829
_ = _sut.IsEnabled.Returns(true);
2930
var ex = new Exception("caught and rethrown");
3031

32+
// Act
3133
_ = _sut.CaptureException(ex, handled: false);
3234

35+
// Assert
3336
Assert.Equal(false, ex.Data[Mechanism.HandledKey]);
3437
}
3538

3639
[Fact]
3740
public void CaptureException_ExplicitHandledTrue_SetsFlag()
3841
{
42+
// Arrange
3943
_ = _sut.IsEnabled.Returns(true);
4044
var ex = new Exception("caught");
4145

46+
// Act
4247
_ = _sut.CaptureException(ex, handled: true);
4348

49+
// Assert
4450
Assert.Equal(true, ex.Data[Mechanism.HandledKey]);
4551
}
4652

4753
[Fact]
4854
public void CaptureException_NoHandledArgument_PreservesPresetFlag()
4955
{
56+
// Arrange
5057
_ = _sut.IsEnabled.Returns(true);
5158
var ex = new Exception("preset mechanism");
5259
ex.SetSentryMechanism("MyHandler", handled: false);
5360

61+
// Act
5462
_ = _sut.CaptureException(ex);
5563

64+
// Assert
5665
Assert.Equal(false, ex.Data[Mechanism.HandledKey]);
5766
}
5867

5968
[Fact]
6069
public void CaptureException_DisabledClientExplicitHandled_DoesNotMutateExceptionData()
6170
{
71+
// Arrange
6272
_ = _sut.IsEnabled.Returns(false);
6373
var ex = new Exception("captured while disabled");
6474

75+
// Act
6576
var id = _sut.CaptureException(ex, handled: false);
6677

78+
// Assert
6779
Assert.False(ex.Data.Contains(Mechanism.HandledKey));
6880
Assert.Equal(SentryId.Empty, id);
6981
_ = _sut.DidNotReceive().CaptureEvent(Arg.Any<SentryEvent>());

0 commit comments

Comments
 (0)