Class TestData.FlagRuleBuilder
A builder for feature flag rules to be used with TestData.FlagBuilder.
Inherited Members
Namespace: LaunchDarkly.Sdk.Server.Integrations
Assembly: LaunchDarkly.ServerSdk.dll
Syntax
public sealed class TestData.FlagRuleBuilder
Remarks
In the LaunchDarkly model, a flag can have any number of rules, and a rule can have any number of clauses. A clause is an individual test such as "name is 'X'". A rule matches a context if all of the rule's clauses match the context.
To start defining a rule, use one of the flag builder's matching methods such as IfMatchContext(ContextKind, string, params LdValue[]). This defines the first clause for the rule. Optionally, you may add more clauses with the rule builder's methods such as AndMatchContext(ContextKind, string, params LdValue[]). Finally, call ThenReturn(bool) or ThenReturn(int) to finish defining the rule.
Methods
| Edit this page View SourceAndMatch(string, params LdValue[])
Adds another clause, using the "is one of" operator. This is a shortcut for calling AndMatchContext(ContextKind, string, params LdValue[]) with "user" as the context kind.
Declaration
public TestData.FlagRuleBuilder AndMatch(string attribute, params LdValue[] values)
Parameters
Type | Name | Description |
---|---|---|
string | attribute | the user attribute to match against |
LdValue[] | values | values to compare to |
Returns
Type | Description |
---|---|
TestData.FlagRuleBuilder | the rule builder |
Remarks
For example, this creates a rule that returns true
if the name is "Patsy" and the
country is "gb":
testData.Update(testData.Flag("flag-key")
.IfMatch("name", LdValue.Of("Patsy"))
.AndMatch("country", LdValue.Of("gb"))
.ThenReturn(true));
AndMatchContext(ContextKind, string, params LdValue[])
Adds another clause, using the "is one of" operator. This matching expression only applies to contexts of a specific kind.
Declaration
public TestData.FlagRuleBuilder AndMatchContext(ContextKind contextKind, string attribute, params LdValue[] values)
Parameters
Type | Name | Description |
---|---|---|
ContextKind | contextKind | the context kind to match |
string | attribute | the attribute to match against |
LdValue[] | values | values to compare to |
Returns
Type | Description |
---|---|
TestData.FlagRuleBuilder | the rule builder |
Remarks
For example, this creates a rule that returns true
if the name attribute for the
"company" context is "Ella" and the country is "gb":
testData.Update(testData.Flag("flag-key")
.IfMatchContext("company", "name", LdValue.Of("Ella"))
.AndMatchContext("company", "country", LdValue.Of("gb"))
.ThenReturn(true));
AndNotMatch(string, params LdValue[])
Adds another clause, using the "is not one of" operator. This is a shortcut for calling AndNotMatchContext(ContextKind, string, params LdValue[]) with "user" as the context kind.
Declaration
public TestData.FlagRuleBuilder AndNotMatch(string attribute, params LdValue[] values)
Parameters
Type | Name | Description |
---|---|---|
string | attribute | the user attribute to match against |
LdValue[] | values | values to compare to |
Returns
Type | Description |
---|---|
TestData.FlagRuleBuilder | the rule builder |
Remarks
For example, this creates a rule that returns true
if the name is "Patsy" and the
country is not "gb":
testData.Update(testData.Flag("flag-key")
.IfMatch("name", LdValue.Of("Patsy"))
.AndNotMatch("country", LdValue.Of("gb"))
.ThenReturn(true));
AndNotMatchContext(ContextKind, string, params LdValue[])
Adds another clause, using the "is not one of" operator. This matching expression only applies to contexts of a specific kind.
Declaration
public TestData.FlagRuleBuilder AndNotMatchContext(ContextKind contextKind, string attribute, params LdValue[] values)
Parameters
Type | Name | Description |
---|---|---|
ContextKind | contextKind | the context kind to match |
string | attribute | the attribute to match against |
LdValue[] | values | values to compare to |
Returns
Type | Description |
---|---|
TestData.FlagRuleBuilder | the rule builder |
Remarks
For example, this creates a rule that returns true
if the name attribute for the
"company" context is "Ella" and the country is not "gb":
testData.Update(testData.Flag("flag-key")
.IfMatchContext("company", "name", LdValue.Of("Ella"))
.AndNotMatchContext("company", "country", LdValue.Of("gb"))
.ThenReturn(true));
ThenReturn(bool)
Finishes defining the rule, specifying the result value as a boolean.
Declaration
public TestData.FlagBuilder ThenReturn(bool variation)
Parameters
Type | Name | Description |
---|---|---|
bool | variation | the value to return if the rule matches the user |
Returns
Type | Description |
---|---|
TestData.FlagBuilder |
ThenReturn(int)
Finishes defining the rule, specifying the result as a variation index.
Declaration
public TestData.FlagBuilder ThenReturn(int variationIndex)
Parameters
Type | Name | Description |
---|---|---|
int | variationIndex | the variation to return if the rule matches the user: 0 for the first, 1 for the second, etc. |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the flag builder |