@@ -3,130 +3,66 @@ namespace Sentry.Tests.Platforms.Android;
33
44public class SentrySdkTests
55{
6- [ Fact ]
7- public void BeforeSendWrapper_Suppress_SIGSEGV_ReturnsNull ( )
8- {
9- // Arrange
10- var options = new SentryOptions ( ) ;
11- options . Android . SuppressSegfaults = true ;
12- var evt = new SentryEvent
13- {
14- SentryExceptions = new [ ]
15- {
16- new SentryException
17- {
18- Type = "SIGSEGV" ,
19- Value = "Segfault"
20- }
21- }
22- } ;
23- var hint = new SentryHint ( ) ;
24-
25- // Act
26- var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
27-
28- // Assert
29- result . Should ( ) . BeNull ( ) ;
30- }
31-
32- [ Fact ]
33- public void BeforeSendWrapper_DontSupress_SIGSEGV_ReturnsEvent ( )
6+ [ Theory ]
7+ [ InlineData ( false , true ) ]
8+ [ InlineData ( true , false ) ]
9+ public void CreateBeforeSendCallback_NoEnabledFilter_ReturnsNull ( bool enabled , bool hasFilter )
3410 {
35- // Arrange
3611 var options = new SentryOptions ( ) ;
3712 options . Android . SuppressSegfaults = false ;
38- var evt = new SentryEvent
13+ options . Native . EnableBeforeSend = enabled ;
14+ if ( hasFilter )
3915 {
40- SentryExceptions = new [ ]
41- {
42- new SentryException
43- {
44- Type = "SIGSEGV" ,
45- Value = "Segfault"
46- }
47- }
48- } ;
49- var hint = new SentryHint ( ) ;
50-
51- // Act
52- var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
53-
54- // Assert
55- result . Should ( ) . Be ( evt ) ;
56- }
57-
58- [ Fact ]
59- public void BeforeSendWrapper_BeforeSendCallbackDefined_CallsBeforeSend ( )
60- {
61- // Arrange
62- var beforeSend = Substitute . For < Func < SentryEvent , SentryHint , SentryEvent > > ( ) ;
63- beforeSend . Invoke ( Arg . Any < SentryEvent > ( ) , Arg . Any < SentryHint > ( ) ) . Returns ( callInfo => callInfo . Arg < SentryEvent > ( ) ) ;
16+ options . SetBeforeSend ( ( evt , _ ) => evt ) ;
17+ }
18+ using var javaOptions = new JavaSdk . SentryOptions ( ) ;
6419
65- var options = new SentryOptions ( ) ;
66- options . Native . EnableBeforeSend = true ;
67- options . SetBeforeSend ( beforeSend ) ;
68- var evt = new SentryEvent ( ) ;
69- var hint = new SentryHint ( ) ;
70-
71- // Act
72- var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
73-
74- // Assert
75- beforeSend . Received ( 1 ) . Invoke ( Arg . Any < SentryEvent > ( ) , Arg . Any < SentryHint > ( ) ) ;
76- result . Should ( ) . Be ( evt ) ;
77- }
78-
79- [ Fact ]
80- public void BeforeSendWrapper_NoBeforeSendCallback_ReturnsEvent ( )
81- {
82- // Arrange
83- var options = new SentryOptions ( ) ;
84- options . Native . EnableBeforeSend = true ;
85- var evt = new SentryEvent ( ) ;
86- var hint = new SentryHint ( ) ;
87-
88- // Act
89- var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
90-
91- // Assert
92- result . Should ( ) . Be ( evt ) ;
20+ SentrySdk . CreateBeforeSendCallback ( options , javaOptions ) . Should ( ) . BeNull ( ) ;
9321 }
9422
9523 [ Fact ]
96- public void BeforeSendWrapper_NativeBeforeSendDisabled_ReturnsEvent ( )
24+ public void CreateBeforeSendCallback_SuppressionWithDisabledFilter_ReturnsUnconvertedEventWithoutCallingFilter ( )
9725 {
98- // Arrange
99- var beforeSend = Substitute . For < Func < SentryEvent , SentryHint , SentryEvent > > ( ) ;
100- beforeSend . Invoke ( Arg . Any < SentryEvent > ( ) , Arg . Any < SentryHint > ( ) ) . Returns ( _ => null ) ;
101-
10226 var options = new SentryOptions ( ) ;
103- options . SetBeforeSend ( beforeSend ) ;
27+ options . Android . SuppressSegfaults = true ;
10428 options . Native . EnableBeforeSend = false ;
105- var evt = new SentryEvent ( ) ;
106- var hint = new SentryHint ( ) ;
29+ var called = false ;
30+ options . SetBeforeSend ( ( evt , _ ) =>
31+ {
32+ called = true ;
33+ return evt ;
34+ } ) ;
35+ using var javaOptions = new JavaSdk . SentryOptions ( ) ;
36+ using var callback = SentrySdk . CreateBeforeSendCallback ( options , javaOptions ) ;
37+ using var evt = new JavaSdk . SentryEvent
38+ {
39+ EventId = new JavaSdk . Protocol . SentryId ( new string ( 'z' , 32 ) )
40+ } ;
41+ using var hint = new JavaSdk . Hint ( ) ;
10742
108- // Act
109- var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
43+ var result = callback ! . Execute ( evt , hint ) ;
11044
111- // Assert
112- beforeSend . DidNotReceive ( ) . Invoke ( Arg . Any < SentryEvent > ( ) , Arg . Any < SentryHint > ( ) ) ;
113- result . Should ( ) . Be ( evt ) ;
45+ called . Should ( ) . BeFalse ( ) ;
46+ result . Should ( ) . BeSameAs ( evt ) ;
11447 }
11548
11649 [ Fact ]
117- public void BeforeSendWrapper_BeforeSendThrows_ReturnsNullAndLogsError ( )
50+ public void CreateBeforeSendCallback_BeforeSendThrows_ReturnsNullAndLogsError ( )
11851 {
11952 // Arrange
12053 var exception = new InvalidOperationException ( "callback failed" ) ;
12154 var logger = new InMemoryDiagnosticLogger ( ) ;
12255 var options = new SentryOptions { Debug = true , DiagnosticLogger = logger } ;
12356 options . Native . EnableBeforeSend = true ;
12457 options . SetBeforeSend ( ( SentryEvent _ , SentryHint _ ) => throw exception ) ;
125- var evt = new SentryEvent ( ) ;
126- var hint = new SentryHint ( ) ;
58+ options . Android . SuppressSegfaults = false ;
59+ using var javaOptions = new JavaSdk . SentryOptions ( ) ;
60+ using var callback = SentrySdk . CreateBeforeSendCallback ( options , javaOptions ) ;
61+ using var evt = new JavaSdk . SentryEvent ( ) ;
62+ using var hint = new JavaSdk . Hint ( ) ;
12763
12864 // Act
129- var result = SentrySdk . BeforeSendWrapper ( options ) . Invoke ( evt , hint ) ;
65+ var result = callback ! . Execute ( evt , hint ) ;
13066
13167 // Assert
13268 result . Should ( ) . BeNull ( ) ;
0 commit comments