public void ShouldReturnVariant2()
        {
            // Arrange
            var v1 = new VariantDefinition("a", 33, new Payload("string", "asd"), new Collection <VariantOverride>());
            var v2 = new VariantDefinition("b", 33);
            var v3 = new VariantDefinition("c", 34);

            var toggle = new FeatureToggle(
                "test.variants",
                "release",
                true,
                new List <ActivationStrategy> {
                defaultStrategy
            },
                new List <VariantDefinition> {
                v1, v2, v3
            });

            var context = new UnleashContext
            {
                UserId        = "163",
                SessionId     = "sessionId",
                RemoteAddress = "remoteAddress",
                Properties    = new Dictionary <string, string>()
            };

            // Act
            var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT);

            // Assert
            variant.Name.Should().Be(v2.Name);
        }
        private Variant GetVariant(string toggleName, UnleashContext context, Variant defaultValue)
        {
            var toggle = GetToggle(toggleName);

            var enabled = CheckIsEnabled(toggleName, context, false);
            var variant = enabled ? VariantUtils.SelectVariant(toggle, context, defaultValue) : defaultValue;

            RegisterVariant(toggleName, variant);
            return(variant);
        }
        public void ShouldReturnDefaultVariantWhenToggleHasNoVariants()
        {
            // Arrange
            var toggle = new FeatureToggle("test.variants", "release", true, new List <ActivationStrategy> {
                defaultStrategy
            });
            var context = new UnleashContext
            {
                UserId        = "userA",
                SessionId     = "sessionId",
                RemoteAddress = "remoteAddress",
                Properties    = new Dictionary <string, string>()
            };

            // Act
            var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT);

            // Assert
            variant.Should().BeSameAs(Variant.DISABLED_VARIANT);
        }
        public void ShouldReturnVariantOverrideOnSessionId()
        {
            // Arrange
            var sessionId = "122221";

            var v1               = new VariantDefinition("a", 33);
            var override_env     = new VariantOverride("env", "dev");
            var override_session = new VariantOverride("sessionId", sessionId);
            var v2               = new VariantDefinition("b", 33, null, new List <VariantOverride> {
                override_env, override_session
            });
            var v3 = new VariantDefinition("c", 34);

            var toggle = new FeatureToggle(
                "test.variants",
                "release",
                true,
                new List <ActivationStrategy> {
                defaultStrategy
            },
                new List <VariantDefinition> {
                v1, v2, v3
            });

            var context = new UnleashContext
            {
                UserId        = "11",
                SessionId     = sessionId,
                RemoteAddress = "remoteAddress",
                Properties    = new Dictionary <string, string> {
                    { "env", "prod" }
                }
            };

            // Act
            var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT);

            // Assert
            variant.Name.Should().Be(v2.Name);
        }
示例#5
0
        public void Custom_Stickiness_CustomField_112_Yields_Yellow()
        {
            // Arrange
            var sessionId = "122221";

            var val1Payload = new Payload("string", "val1");
            var blue        = new VariantDefinition("blue", 25, val1Payload, null, "customField");
            var red         = new VariantDefinition("red", 25, val1Payload, null, "customField");
            var green       = new VariantDefinition("green", 25, val1Payload, null, "customField");
            var yellow      = new VariantDefinition("yellow", 25, val1Payload, null, "customField");
            var toggle      = new FeatureToggle(
                "Feature.flexible.rollout.custom.stickiness_100",
                "release",
                true,
                new List <ActivationStrategy> {
                defaultStrategy
            },
                new List <VariantDefinition> {
                blue, red, green, yellow
            });

            var context = new UnleashContext
            {
                UserId        = "13",
                SessionId     = sessionId,
                RemoteAddress = "remoteAddress",
                Properties    = new Dictionary <string, string> {
                    { "env", "prod" }, { "customField", "112" }
                }
            };

            // Act
            var variant = VariantUtils.SelectVariant(toggle, context, Variant.DISABLED_VARIANT);

            // Assert
            variant.Name.Should().Be(yellow.Name);
        }