@@ -124,8 +124,7 @@ public void Cleanup()
124124 #region OptimizelyHelper
125125 private class OptimizelyHelper
126126 {
127- static Type [ ] ParameterTypes = new [ ]
128- {
127+ static Type [ ] ParameterTypes = {
129128 typeof ( string ) ,
130129 typeof ( IEventDispatcher ) ,
131130 typeof ( ILogger ) ,
@@ -3417,5 +3416,92 @@ public void TestGetFeatureVariableIntegerReturnsDefaultValueWithComplexAudienceC
34173416 }
34183417
34193418 #endregion // Test Audience Combinations
3419+
3420+ #region Disposable Optimizely
3421+
3422+ [ Test ]
3423+ public void TestOptimizelyDisposeAlsoDisposedConfigManager ( )
3424+ {
3425+ var httpManager = new HttpProjectConfigManager . Builder ( )
3426+ . WithSdkKey ( "QBw9gFM8oTn7ogY9ANCC1z" )
3427+ . WithLogger ( LoggerMock . Object )
3428+ . WithPollingInterval ( TimeSpan . FromMilliseconds ( 5000 ) )
3429+ . WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 500 ) )
3430+ . Build ( ) ;
3431+ var optimizely = new Optimizely ( httpManager ) ;
3432+ optimizely . Dispose ( ) ;
3433+
3434+ Assert . True ( optimizely . Disposed ) ;
3435+ Assert . True ( httpManager . Disposed ) ;
3436+ }
3437+
3438+ [ Test ]
3439+ public void TestDisposeInvalidateObject ( )
3440+ {
3441+ var httpManager = new HttpProjectConfigManager . Builder ( )
3442+ . WithSdkKey ( "QBw9gFM8oTn7ogY9ANCC1z" )
3443+ . WithLogger ( LoggerMock . Object )
3444+ . WithPollingInterval ( TimeSpan . FromMilliseconds ( 5000 ) )
3445+ . WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 500 ) )
3446+ . Build ( ) ;
3447+ var optimizely = new Optimizely ( httpManager ) ;
3448+ optimizely . Dispose ( ) ;
3449+
3450+ Assert . False ( optimizely . IsValid ) ;
3451+ }
3452+
3453+ [ Test ]
3454+ public void TestAfterDisposeAPIsNoLongerValid ( )
3455+ {
3456+ var httpManager = new HttpProjectConfigManager . Builder ( )
3457+ . WithSdkKey ( "QBw9gFM8oTn7ogY9ANCC1z" )
3458+ . WithDatafile ( TestData . Datafile )
3459+ . WithLogger ( LoggerMock . Object )
3460+ . WithPollingInterval ( TimeSpan . FromMilliseconds ( 50000 ) )
3461+ . WithBlockingTimeoutPeriod ( TimeSpan . FromMilliseconds ( 500 ) )
3462+ . Build ( true ) ;
3463+ var optimizely = new Optimizely ( httpManager ) ;
3464+ httpManager . Start ( ) ;
3465+ var activate = optimizely . Activate ( "test_experiment" , TestUserId , new UserAttributes ( ) {
3466+ { "device_type" , "iPhone" } , { "location" , "San Francisco" } } ) ;
3467+ Assert . NotNull ( activate ) ;
3468+ optimizely . Dispose ( ) ;
3469+ var activateAfterDispose = optimizely . Activate ( "test_experiment" , TestUserId , new UserAttributes ( ) {
3470+ { "device_type" , "iPhone" } , { "location" , "San Francisco" } } ) ;
3471+ Assert . Null ( activateAfterDispose ) ;
3472+ }
3473+
3474+ [ Test ]
3475+ public void TestNonDisposableConfigManagerDontCrash ( )
3476+ {
3477+ var fallbackConfigManager = new FallbackProjectConfigManager ( Config ) ;
3478+
3479+ var optimizely = new Optimizely ( fallbackConfigManager ) ;
3480+ optimizely . Dispose ( ) ;
3481+ Assert . True ( optimizely . Disposed ) ;
3482+ }
3483+
3484+ [ Test ]
3485+ public void TestAfterDisposeAPIsShouldNotCrash ( )
3486+ {
3487+ var fallbackConfigManager = new FallbackProjectConfigManager ( Config ) ;
3488+
3489+ var optimizely = new Optimizely ( fallbackConfigManager ) ;
3490+ optimizely . Dispose ( ) ;
3491+ Assert . True ( optimizely . Disposed ) ;
3492+
3493+ Assert . IsNull ( optimizely . GetVariation ( string . Empty , string . Empty ) ) ;
3494+ Assert . IsNull ( optimizely . Activate ( string . Empty , string . Empty ) ) ;
3495+ optimizely . Track ( string . Empty , string . Empty ) ;
3496+ Assert . IsFalse ( optimizely . IsFeatureEnabled ( string . Empty , string . Empty ) ) ;
3497+ Assert . AreEqual ( optimizely . GetEnabledFeatures ( string . Empty ) . Count , 0 ) ;
3498+ Assert . IsNull ( optimizely . GetFeatureVariableBoolean ( string . Empty , string . Empty , string . Empty ) ) ;
3499+ Assert . IsNull ( optimizely . GetFeatureVariableString ( string . Empty , string . Empty , string . Empty ) ) ;
3500+ Assert . IsNull ( optimizely . GetFeatureVariableDouble ( string . Empty , string . Empty , string . Empty ) ) ;
3501+ Assert . IsNull ( optimizely . GetFeatureVariableInteger ( string . Empty , string . Empty , string . Empty ) ) ;
3502+
3503+ }
3504+
3505+ #endregion
34203506 }
34213507}
0 commit comments