@@ -1988,6 +1988,100 @@ public void CaptureUserFeedback_InvalidEmail_FeedbackDropped(string email)
19881988        _fixture . Client . Received ( 1 ) . CaptureUserFeedback ( Arg . Is < UserFeedback > ( f =>  f . Email . IsNull ( ) ) ) ; 
19891989#pragma warning restore CS0618  // Type or member is obsolete 
19901990    } 
1991+ 
1992+     private  class  TestDisposableIntegration  :  ISdkIntegration ,  IDisposable 
1993+     { 
1994+         public  int  Registered  {  get ;  private  set ;  } 
1995+         public  int  Disposed  {  get ;  private  set ;  } 
1996+ 
1997+         public  void  Register ( IHub  hub ,  SentryOptions  options ) 
1998+         { 
1999+             Registered ++ ; 
2000+         } 
2001+ 
2002+         protected  virtual  void  Cleanup ( ) 
2003+         { 
2004+             Disposed ++ ; 
2005+         } 
2006+ 
2007+         public  void  Dispose ( ) 
2008+         { 
2009+             Cleanup ( ) ; 
2010+         } 
2011+     } 
2012+ 
2013+     private  class  TestFlakyDisposableIntegration  :  TestDisposableIntegration 
2014+     { 
2015+         protected  override  void  Cleanup ( ) 
2016+         { 
2017+             throw  new  InvalidOperationException ( "Cleanup failed" ) ; 
2018+         } 
2019+     } 
2020+ 
2021+     [ Fact ] 
2022+     public  void  Dispose_IntegrationsWithCleanup_CleanupCalled ( ) 
2023+     { 
2024+         // Arrange 
2025+         var  integration1  =  new  TestDisposableIntegration ( ) ; 
2026+         var  integration2  =  Substitute . For < ISdkIntegration > ( ) ; 
2027+         var  integration3  =  new  TestDisposableIntegration ( ) ; 
2028+         _fixture . Options . AddIntegration ( integration1 ) ; 
2029+         _fixture . Options . AddIntegration ( integration2 ) ; 
2030+         _fixture . Options . AddIntegration ( integration3 ) ; 
2031+         var  hub  =  _fixture . GetSut ( ) ; 
2032+ 
2033+         // Act 
2034+         hub . Dispose ( ) ; 
2035+ 
2036+         // Assert 
2037+         integration1 . Disposed . Should ( ) . Be ( 1 ) ; 
2038+         integration3 . Disposed . Should ( ) . Be ( 1 ) ; 
2039+     } 
2040+ 
2041+     [ Fact ] 
2042+     public  void  Dispose_CleanupThrowsException_ExceptionHandledAndLogged ( ) 
2043+     { 
2044+         // Arrange 
2045+         var  integration1  =  new  TestDisposableIntegration ( ) ; 
2046+         var  integration2  =  new  TestFlakyDisposableIntegration ( ) ; 
2047+         var  integration3  =  new  TestDisposableIntegration ( ) ; 
2048+         _fixture . Options . AddIntegration ( integration1 ) ; 
2049+         _fixture . Options . AddIntegration ( integration2 ) ; 
2050+         _fixture . Options . AddIntegration ( integration3 ) ; 
2051+         _fixture . Options . Debug  =  true ; 
2052+         _fixture . Options . DiagnosticLogger  =  Substitute . For < IDiagnosticLogger > ( ) ; 
2053+         _fixture . Options . DiagnosticLogger ! . IsEnabled ( Arg . Any < SentryLevel > ( ) ) . Returns ( true ) ; 
2054+         var  hub  =  _fixture . GetSut ( ) ; 
2055+ 
2056+         // Act 
2057+         hub . Dispose ( ) ; 
2058+ 
2059+         // Assert 
2060+         integration1 . Disposed . Should ( ) . Be ( 1 ) ; 
2061+         integration2 . Disposed . Should ( ) . Be ( 0 ) ; 
2062+         integration3 . Disposed . Should ( ) . Be ( 1 ) ; 
2063+         _fixture . Options . DiagnosticLogger . Received ( 1 ) . Log ( 
2064+             SentryLevel . Error , 
2065+             Arg . Is < string > ( s =>  s . Contains ( "Failed to dispose integration" ) ) , 
2066+             Arg . Any < InvalidOperationException > ( ) , 
2067+             Arg . Any < object [ ] > ( ) ) ; 
2068+     } 
2069+ 
2070+     [ Fact ] 
2071+     public  void  Dispose_CalledMultipleTimes_CleanupCalledOnlyOnce ( ) 
2072+     { 
2073+         // Arrange 
2074+         var  integration  =  new  TestDisposableIntegration ( ) ; 
2075+         _fixture . Options . AddIntegration ( integration ) ; 
2076+         var  hub  =  _fixture . GetSut ( ) ; 
2077+ 
2078+         // Act 
2079+         hub . Dispose ( ) ; 
2080+         hub . Dispose ( ) ; 
2081+ 
2082+         // Assert 
2083+         integration . Disposed . Should ( ) . Be ( 1 ) ; 
2084+     } 
19912085} 
19922086
19932087#if NET6_0_OR_GREATER 
0 commit comments