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); }
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); }
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); }
private void SaveLinkData(VariantDefinition def, XmlNode board, string cellLinks) { // clear existing links var existingLinks = board.SelectNodes("cell/link"); foreach (XmlNode link in existingLinks) { link.ParentNode.RemoveChild(link); } var links = cellLinks.Split(outerSep, StringSplitOptions.RemoveEmptyEntries); foreach (string link in links) { var linkParts = link.Split(innerSep, 3); if (linkParts.Length != 3) { continue; } // from, dir, to var fromNode = board.SelectSingleNode(string.Format("cell[@id='{0}']", linkParts[0])); var toNode = board.SelectSingleNode(string.Format("cell[@id='{0}']", linkParts[2])); if (fromNode == null || toNode == null) { continue; } // add a child to fromNode like: <link dir="blah" to="blah" /> var linkElem = def.CreateElement("link"); linkElem.Attributes.Append(def.CreateAttribute("dir", linkParts[1])); linkElem.Attributes.Append(def.CreateAttribute("to", linkParts[2])); fromNode.AppendChild(linkElem); } }
public string Format(VariantDefinition arg) { return(arg.Name + ": " + arg.Type); }