@@ -2059,6 +2059,132 @@ public void TestTrackListener(UserAttributes userAttributes, EventTags eventTags
20592059 NotificationCallbackMock . Verify ( nc => nc . TestAnotherTrackCallback ( eventKey , TestUserId , userAttributes , eventTags , logEvent ) , Times . Exactly ( 1 ) ) ;
20602060 }
20612061
2062+ #region Decision Listener
2063+
2064+ [ Test ]
2065+ public void TestActivateSendsDecisionNotificationWithActualVariationKey ( )
2066+ {
2067+ var experimentKey = "group_experiment_1" ;
2068+ var variationKey = "group_exp_1_var_1" ;
2069+ var experiment = Config . GetExperimentFromKey ( experimentKey ) ;
2070+ var variation = Config . GetVariationFromKey ( experimentKey , variationKey ) ;
2071+ var userAttributes = new UserAttributes
2072+ {
2073+ { "device_type" , "iPhone" } ,
2074+ { "company" , "Optimizely" } ,
2075+ { "location" , "San Francisco" }
2076+ } ;
2077+
2078+ // Mocking objects.
2079+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
2080+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
2081+ DecisionServiceMock . Setup ( ds => ds . GetVariation ( experiment , TestUserId , userAttributes ) ) . Returns ( variation ) ;
2082+
2083+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2084+ var optStronglyTyped = optly . GetObject ( ) as Optimizely ;
2085+
2086+ optStronglyTyped . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
2087+ optly . SetFieldOrProperty ( "DecisionService" , DecisionServiceMock . Object ) ;
2088+
2089+ optly . Invoke ( "Activate" , experimentKey , TestUserId , userAttributes ) ;
2090+ var decisionInfo = new Dictionary < string , object >
2091+ {
2092+ { "experimentKey" , experimentKey } ,
2093+ { "variationKey" , variationKey } ,
2094+ } ;
2095+
2096+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionInfoTypes . EXPERIMENT , TestUserId , userAttributes , decisionInfo ) , Times . Once ) ;
2097+ }
2098+
2099+ [ Test ]
2100+ public void TestActivateSendsDecisionNotificationWithNullVariationKey ( )
2101+ {
2102+ var experimentKey = "group_experiment_1" ;
2103+ var experiment = Config . GetExperimentFromKey ( experimentKey ) ;
2104+
2105+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
2106+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
2107+ DecisionServiceMock . Setup ( ds => ds . GetVariation ( experiment , TestUserId , null ) ) . Returns < Variation > ( null ) ;
2108+
2109+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2110+ var optStronglyTyped = optly . GetObject ( ) as Optimizely ;
2111+
2112+ optStronglyTyped . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
2113+ optly . SetFieldOrProperty ( "DecisionService" , DecisionServiceMock . Object ) ;
2114+
2115+ optly . Invoke ( "Activate" , experimentKey , TestUserId , null ) ;
2116+ var decisionInfo = new Dictionary < string , object >
2117+ {
2118+ { "experimentKey" , experimentKey } ,
2119+ { "variationKey" , null } ,
2120+ } ;
2121+
2122+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionInfoTypes . EXPERIMENT , TestUserId , new UserAttributes ( ) , decisionInfo ) , Times . Once ) ;
2123+ }
2124+
2125+ [ Test ]
2126+ public void TestGetVariationSendsDecisionNotificationWithActualVariationKey ( )
2127+ {
2128+ var experimentKey = "group_experiment_1" ;
2129+ var variationKey = "group_exp_1_var_1" ;
2130+ var experiment = Config . GetExperimentFromKey ( experimentKey ) ;
2131+ var variation = Config . GetVariationFromKey ( experimentKey , variationKey ) ;
2132+ var userAttributes = new UserAttributes
2133+ {
2134+ { "device_type" , "iPhone" } ,
2135+ { "company" , "Optimizely" } ,
2136+ { "location" , "San Francisco" }
2137+ } ;
2138+
2139+ // Mocking objects.
2140+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
2141+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
2142+ DecisionServiceMock . Setup ( ds => ds . GetVariation ( experiment , TestUserId , userAttributes ) ) . Returns ( variation ) ;
2143+
2144+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2145+ var optStronglyTyped = optly . GetObject ( ) as Optimizely ;
2146+
2147+ optStronglyTyped . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
2148+ optly . SetFieldOrProperty ( "DecisionService" , DecisionServiceMock . Object ) ;
2149+
2150+ optly . Invoke ( "GetVariation" , experimentKey , TestUserId , userAttributes ) ;
2151+ var decisionInfo = new Dictionary < string , object >
2152+ {
2153+ { "experimentKey" , experimentKey } ,
2154+ { "variationKey" , variationKey } ,
2155+ } ;
2156+
2157+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionInfoTypes . EXPERIMENT , TestUserId , userAttributes , decisionInfo ) , Times . Once ) ;
2158+ }
2159+
2160+ [ Test ]
2161+ public void TestGetVariationSendsDecisionNotificationWithNullVariationKey ( )
2162+ {
2163+ var experimentKey = "group_experiment_1" ;
2164+ var experiment = Config . GetExperimentFromKey ( experimentKey ) ;
2165+
2166+ NotificationCallbackMock . Setup ( nc => nc . TestDecisionCallback ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ,
2167+ It . IsAny < UserAttributes > ( ) , It . IsAny < Dictionary < string , object > > ( ) ) ) ;
2168+ DecisionServiceMock . Setup ( ds => ds . GetVariation ( experiment , TestUserId , null ) ) . Returns < Variation > ( null ) ;
2169+
2170+ var optly = Helper . CreatePrivateOptimizely ( ) ;
2171+ var optStronglyTyped = optly . GetObject ( ) as Optimizely ;
2172+
2173+ optStronglyTyped . NotificationCenter . AddNotification ( NotificationCenter . NotificationType . Decision , NotificationCallbackMock . Object . TestDecisionCallback ) ;
2174+ optly . SetFieldOrProperty ( "DecisionService" , DecisionServiceMock . Object ) ;
2175+
2176+ optly . Invoke ( "GetVariation" , experimentKey , TestUserId , null ) ;
2177+ var decisionInfo = new Dictionary < string , object >
2178+ {
2179+ { "experimentKey" , experimentKey } ,
2180+ { "variationKey" , null } ,
2181+ } ;
2182+
2183+ NotificationCallbackMock . Verify ( nc => nc . TestDecisionCallback ( DecisionInfoTypes . EXPERIMENT , TestUserId , new UserAttributes ( ) , decisionInfo ) , Times . Once ) ;
2184+ }
2185+
2186+ #endregion // Decision Listener
2187+
20622188 #endregion // Test NotificationCenter
20632189
20642190 #region Test GetEnabledFeatures
0 commit comments