@@ -240,6 +240,173 @@ public void TestCreateUserContextMultipleAttribute()
240240 Assert . AreEqual ( attribute2 , optlyUserContext2 . GetAttributes ( ) ) ;
241241 }
242242
243+ [ Test ]
244+ public void TestDecisionNotificationSentWhenSendFlagDecisionsFalseAndFeature ( )
245+ {
246+ var featureKey = "boolean_feature" ;
247+ var variables = Optimizely . GetAllFeatureVariables ( featureKey , TestUserId ) ;
248+ var userAttributes = new UserAttributes
249+ {
250+ { "device_type" , "iPhone" } ,
251+ { "location" , "San Francisco" }
252+ } ;
253+ Config . SendFlagDecisions = false ;
254+ var fallbackConfigManager = new FallbackProjectConfigManager ( Config ) ;
255+ var optimizely = new Optimizely ( fallbackConfigManager ,
256+ NotificationCenter ,
257+ EventDispatcherMock . Object ,
258+ LoggerMock . Object ,
259+ ErrorHandlerMock . Object ,
260+ null ,
261+ new ForwardingEventProcessor ( EventDispatcherMock . Object , NotificationCenter , LoggerMock . Object , ErrorHandlerMock . Object ) ,
262+ null ) ;
263+
264+ // Mocking objects.
265+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
266+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
267+ optimizely . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
268+
269+ var optimizelyUserContext = optimizely . CreateUserContext ( TestUserId , userAttributes ) ;
270+ optimizelyUserContext . Decide ( featureKey ) ;
271+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionNotificationTypes . FLAG , TestUserId , userAttributes , It . Is < Dictionary < string , object > > ( info => TestData . CompareObjects ( info , new Dictionary < string , object > {
272+ { "flagKey" , featureKey } ,
273+ { "enabled" , false } ,
274+ { "variables" , variables . ToDictionary ( ) } ,
275+ { "variationKey" , "group_exp_2_var_1" } ,
276+ { "ruleKey" , "group_experiment_2" } ,
277+ { "reasons" , new OptimizelyDecideOption [ 0 ] } ,
278+ { "decisionEventDispatched" , true }
279+ } ) ) ) , Times . Once ) ;
280+ EventDispatcherMock . Verify ( dispatcher => dispatcher . DispatchEvent ( It . IsAny < LogEvent > ( ) ) , Times . Once ) ;
281+ }
282+
283+ [ Test ]
284+ public void TestDecisionNotificationSentWhenSendFlagDecisionsTrueAndFeature ( )
285+ {
286+ var featureKey = "boolean_feature" ;
287+ var variables = Optimizely . GetAllFeatureVariables ( featureKey , TestUserId ) ;
288+ var userAttributes = new UserAttributes
289+ {
290+ { "device_type" , "iPhone" } ,
291+ { "location" , "San Francisco" }
292+ } ;
293+ var fallbackConfigManager = new FallbackProjectConfigManager ( Config ) ;
294+ var optimizely = new Optimizely ( fallbackConfigManager ,
295+ NotificationCenter ,
296+ EventDispatcherMock . Object ,
297+ LoggerMock . Object ,
298+ ErrorHandlerMock . Object ,
299+ null ,
300+ new ForwardingEventProcessor ( EventDispatcherMock . Object , NotificationCenter , LoggerMock . Object , ErrorHandlerMock . Object ) ,
301+ null ) ;
302+
303+ // Mocking objects.
304+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
305+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
306+ optimizely . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
307+
308+ var optimizelyUserContext = optimizely . CreateUserContext ( TestUserId , userAttributes ) ;
309+ optimizelyUserContext . Decide ( featureKey ) ;
310+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionNotificationTypes . FLAG , TestUserId , userAttributes , It . Is < Dictionary < string , object > > ( info => TestData . CompareObjects ( info , new Dictionary < string , object > {
311+ { "flagKey" , featureKey } ,
312+ { "enabled" , false } ,
313+ { "variables" , variables . ToDictionary ( ) } ,
314+ { "variationKey" , "group_exp_2_var_1" } ,
315+ { "ruleKey" , "group_experiment_2" } ,
316+ { "reasons" , new OptimizelyDecideOption [ 0 ] } ,
317+ { "decisionEventDispatched" , true }
318+ } ) ) ) , Times . Once ) ;
319+ EventDispatcherMock . Verify ( dispatcher => dispatcher . DispatchEvent ( It . IsAny < LogEvent > ( ) ) , Times . Once ) ;
320+ }
321+
322+ [ Test ]
323+ public void TestDecisionNotificationNotSentWhenSendFlagDecisionsFalseAndRollout ( )
324+ {
325+ var featureKey = "boolean_single_variable_feature" ;
326+ var featureFlag = Config . GetFeatureFlagFromKey ( featureKey ) ;
327+ var variables = Optimizely . GetAllFeatureVariables ( featureKey , TestUserId ) ;
328+ var userAttributes = new UserAttributes
329+ {
330+ { "device_type" , "iPhone" } ,
331+ { "location" , "San Francisco" }
332+ } ;
333+ var experiment = Config . GetRolloutFromId ( "166660" ) . Experiments [ 1 ] ;
334+ var ruleKey = experiment . Key ;
335+ var variation = Config . GetVariationFromKey ( experiment . Key , "177773" ) ;
336+ Config . SendFlagDecisions = false ;
337+ var fallbackConfigManager = new FallbackProjectConfigManager ( Config ) ;
338+ var optimizely = new Optimizely ( fallbackConfigManager ,
339+ NotificationCenter ,
340+ EventDispatcherMock . Object ,
341+ LoggerMock . Object ,
342+ ErrorHandlerMock . Object ,
343+ null ,
344+ new ForwardingEventProcessor ( EventDispatcherMock . Object , NotificationCenter , LoggerMock . Object , ErrorHandlerMock . Object ) ,
345+ null ) ;
346+
347+ // Mocking objects.
348+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
349+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
350+ optimizely . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
351+
352+ var optimizelyUserContext = optimizely . CreateUserContext ( TestUserId , userAttributes ) ;
353+ optimizelyUserContext . Decide ( featureKey ) ;
354+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionNotificationTypes . FLAG , TestUserId , userAttributes , It . Is < Dictionary < string , object > > ( info => TestData . CompareObjects ( info , new Dictionary < string , object > {
355+ { "flagKey" , featureKey } ,
356+ { "enabled" , true } ,
357+ { "variables" , variables . ToDictionary ( ) } ,
358+ { "variationKey" , variation . Key } ,
359+ { "ruleKey" , ruleKey } ,
360+ { "reasons" , new OptimizelyDecideOption [ 0 ] } ,
361+ { "decisionEventDispatched" , false }
362+ } ) ) ) , Times . Once ) ;
363+ EventDispatcherMock . Verify ( dispatcher => dispatcher . DispatchEvent ( It . IsAny < LogEvent > ( ) ) , Times . Never ) ;
364+ }
365+
366+ [ Test ]
367+ public void TestDecisionNotificationSentWhenSendFlagDecisionsTrueAndRollout ( )
368+ {
369+ var featureKey = "boolean_single_variable_feature" ;
370+ var featureFlag = Config . GetFeatureFlagFromKey ( featureKey ) ;
371+ var variables = Optimizely . GetAllFeatureVariables ( featureKey , TestUserId ) ;
372+ var userAttributes = new UserAttributes
373+ {
374+ { "device_type" , "iPhone" } ,
375+ { "location" , "San Francisco" }
376+ } ;
377+ var experiment = Config . GetRolloutFromId ( "166660" ) . Experiments [ 1 ] ;
378+ var ruleKey = experiment . Key ;
379+ var variation = Config . GetVariationFromKey ( experiment . Key , "177773" ) ;
380+ Config . SendFlagDecisions = true ;
381+ var fallbackConfigManager = new FallbackProjectConfigManager ( Config ) ;
382+ var optimizely = new Optimizely ( fallbackConfigManager ,
383+ NotificationCenter ,
384+ EventDispatcherMock . Object ,
385+ LoggerMock . Object ,
386+ ErrorHandlerMock . Object ,
387+ null ,
388+ new ForwardingEventProcessor ( EventDispatcherMock . Object , NotificationCenter , LoggerMock . Object , ErrorHandlerMock . Object ) ,
389+ null ) ;
390+
391+ // Mocking objects.
392+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
393+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
394+ optimizely . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
395+
396+ var optimizelyUserContext = optimizely . CreateUserContext ( TestUserId , userAttributes ) ;
397+ optimizelyUserContext . Decide ( featureKey ) ;
398+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionNotificationTypes . FLAG , TestUserId , userAttributes , It . Is < Dictionary < string , object > > ( info => TestData . CompareObjects ( info , new Dictionary < string , object > {
399+ { "flagKey" , featureKey } ,
400+ { "enabled" , true } ,
401+ { "variables" , variables . ToDictionary ( ) } ,
402+ { "variationKey" , variation . Key } ,
403+ { "ruleKey" , ruleKey } ,
404+ { "reasons" , new OptimizelyDecideOption [ 0 ] } ,
405+ { "decisionEventDispatched" , true }
406+ } ) ) ) , Times . Once ) ;
407+ EventDispatcherMock . Verify ( dispatcher => dispatcher . DispatchEvent ( It . IsAny < LogEvent > ( ) ) , Times . Once ) ;
408+ }
409+
243410 [ Test ]
244411 public void TestChangeAttributeDoesNotEffectValues ( )
245412 {
0 commit comments