public void TestRemoveAllForcedDecisionsRemovesDecisions()
        {
            var user = Optimizely.CreateUserContext(UserID);

            var context1 = new OptimizelyDecisionContext("flagKey", "ruleKey1");
            var context2 = new OptimizelyDecisionContext("flagKey2", "ruleKey2");
            var context3 = new OptimizelyDecisionContext("flagKey3", "ruleKey3");

            var decision1 = new OptimizelyForcedDecision("variation");
            var decision2 = new OptimizelyForcedDecision("variation2");
            var decision3 = new OptimizelyForcedDecision("variation3");

            user.SetForcedDecision(context1, decision1);
            user.SetForcedDecision(context2, decision2);
            user.SetForcedDecision(context3, decision3);

            user.RemoveAllForcedDecisions();

            var result1 = user.GetForcedDecision(context1);

            Assert.AreEqual(null, result1);

            var result2 = user.GetForcedDecision(context2);

            Assert.AreEqual(null, result2);

            var result3 = user.GetForcedDecision(context3);

            Assert.AreEqual(null, result3);
        }
        public void TestSetForcedDecisionSetsValue()
        {
            var user     = Optimizely.CreateUserContext(UserID);
            var context  = new OptimizelyDecisionContext("flag", null);
            var decision = new OptimizelyForcedDecision("variationKey");
            var result   = user.SetForcedDecision(context, decision);

            Assert.IsTrue(result);
        }
Example #3
0
        public void ForcedDecisionStoreNullContextForcedDecisionContext()
        {
            var expectedForcedDecision        = new OptimizelyForcedDecision("sample_variation_key");
            OptimizelyDecisionContext context = null;
            var forcedDecisionStore           = new ForcedDecisionsStore();

            forcedDecisionStore[context] = expectedForcedDecision;

            Assert.AreEqual(forcedDecisionStore.Count, 0);
        }
        public void TestGetForcedDecisionReturnsValueWithRuleKey()
        {
            var user     = Optimizely.CreateUserContext(UserID);
            var context  = new OptimizelyDecisionContext("flagKey", "ruleKey");
            var decision = new OptimizelyForcedDecision("variationKey");

            user.SetForcedDecision(context, decision);

            var result = user.GetForcedDecision(context);

            Assertions.AreEqual(decision, result);
        }
        public void TestGetForcedDecisionReturnsNullIfInvalidConfig()
        {
            var optly = new Optimizely(new FallbackProjectConfigManager(null));

            var user = optly.CreateUserContext(UserID);

            var context  = new OptimizelyDecisionContext("flag", null);
            var decision = new OptimizelyForcedDecision("variationKey");
            var result   = user.GetForcedDecision(context);

            Assert.IsNull(result);
        }
Example #6
0
        public void ForcedDecisionStoreRemoveAllForcedDecisionContext()
        {
            var expectedForcedDecision = new OptimizelyForcedDecision("sample_variation_key");
            var context             = new OptimizelyDecisionContext("flag_key", "rule_key");
            var forcedDecisionStore = new ForcedDecisionsStore();

            forcedDecisionStore[context] = expectedForcedDecision;

            Assert.AreEqual(forcedDecisionStore.Count, 1);
            forcedDecisionStore.RemoveAll();
            Assert.AreEqual(forcedDecisionStore.Count, 0);
        }
Example #7
0
        public void ForcedDecisionStoreGetForcedDecisionWithBothRuleAndFlagKey()
        {
            var expectedForcedDecision1 = new OptimizelyForcedDecision("sample_variation_key");
            var context1            = new OptimizelyDecisionContext("flag_key", "rule_key");
            var NullFlagKeyContext  = new OptimizelyDecisionContext(null, "rule_key");
            var forcedDecisionStore = new ForcedDecisionsStore();

            forcedDecisionStore[context1] = expectedForcedDecision1;

            Assert.AreEqual(forcedDecisionStore.Count, 1);
            Assert.AreEqual(forcedDecisionStore[context1].VariationKey, expectedForcedDecision1.VariationKey);
            Assert.IsNull(forcedDecisionStore[NullFlagKeyContext]);
        }
Example #8
0
        public void ForcedDecisionStoreRemoveForcedDecisionContextRuleKeyNotMatched()
        {
            var expectedForcedDecision = new OptimizelyForcedDecision("sample_variation_key");
            var contextNotMatched      = new OptimizelyDecisionContext("flag_key", "");
            var context             = new OptimizelyDecisionContext("flag_key", "rule_key");
            var forcedDecisionStore = new ForcedDecisionsStore();

            forcedDecisionStore[context] = expectedForcedDecision;

            Assert.AreEqual(forcedDecisionStore.Count, 1);
            Assert.IsFalse(forcedDecisionStore.Remove(contextNotMatched));
            Assert.AreEqual(forcedDecisionStore.Count, 1);
        }
        public void TestRemoveForcedDecisionRemovesDecision()
        {
            var user      = Optimizely.CreateUserContext(UserID);
            var context   = new OptimizelyDecisionContext("flagKey", "ruleKey");
            var decision  = new OptimizelyForcedDecision("variationKey");
            var setResult = user.SetForcedDecision(context, decision);

            Assert.IsTrue(setResult);

            user.RemoveForcedDecision(context);

            var result = user.GetForcedDecision(context);

            Assert.AreEqual(null, result);
        }
Example #10
0
        public void ForcedDecisionStoreGetSetForcedDecisionWithBothRuleAndFlagKey()
        {
            var expectedForcedDecision1 = new OptimizelyForcedDecision("sample_variation_key");
            var expectedForcedDecision2 = new OptimizelyForcedDecision("sample_variation_key_2");
            var context1            = new OptimizelyDecisionContext("flag_key", "rule_key");
            var context2            = new OptimizelyDecisionContext("flag_key", "rule_key1");
            var forcedDecisionStore = new ForcedDecisionsStore();

            forcedDecisionStore[context1] = expectedForcedDecision1;
            forcedDecisionStore[context2] = expectedForcedDecision2;

            Assert.AreEqual(forcedDecisionStore.Count, 2);
            Assert.AreEqual(forcedDecisionStore[context1].VariationKey, expectedForcedDecision1.VariationKey);
            Assert.AreEqual(forcedDecisionStore[context2].VariationKey, expectedForcedDecision2.VariationKey);
        }
Example #11
0
        public void ForcedDecisionStoreRemoveForcedDecisionTrue()
        {
            var expectedForcedDecision1 = new OptimizelyForcedDecision("sample_variation_key");
            var expectedForcedDecision2 = new OptimizelyForcedDecision("sample_variation_key_2");
            var context1            = new OptimizelyDecisionContext("flag_key", "rule_key");
            var context2            = new OptimizelyDecisionContext("flag_key", "rule_key1");
            var forcedDecisionStore = new ForcedDecisionsStore();

            forcedDecisionStore[context1] = expectedForcedDecision1;
            forcedDecisionStore[context2] = expectedForcedDecision2;

            Assert.AreEqual(forcedDecisionStore.Count, 2);
            Assert.IsTrue(forcedDecisionStore.Remove(context2));
            Assert.AreEqual(forcedDecisionStore.Count, 1);
            Assert.AreEqual(forcedDecisionStore[context1].VariationKey, expectedForcedDecision1.VariationKey);
            Assert.IsNull(forcedDecisionStore[context2]);
        }
Example #12
0
 public static void AreEqual(OptimizelyForcedDecision expected, OptimizelyForcedDecision actual)
 {
     Assert.AreEqual(expected.VariationKey, actual.VariationKey);
 }