Class TestData.FlagBuilder
A builder for feature flag configurations to be used with TestData.
Inherited Members
Namespace: LaunchDarkly.Sdk.Server.Integrations
Assembly: LaunchDarkly.ServerSdk.dll
Syntax
public sealed class TestData.FlagBuilder
Methods
| Edit this page View SourceBooleanFlag()
A shortcut for setting the flag to use the standard boolean configuration.
Declaration
public TestData.FlagBuilder BooleanFlag()
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This is the default for all new flags created with Flag(string).
The flag will have two variations, true
and false
(in that order); it will
return false
whenever targeting is off, and true
when targeting is on if
no other settings specify otherwise.
ClearRules()
Removes any existing rules from the flag.
Declaration
public TestData.FlagBuilder ClearRules()
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This undoes the effect of methods like IfMatch(string, params LdValue[]).
ClearTargets()
Removes any existing user/context targets from the flag.
Declaration
public TestData.FlagBuilder ClearTargets()
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This undoes the effect of methods like VariationForUser(string, bool).
ExcludeFromSummaries(bool)
Sets if the flag should be excluded from summary events.
Declaration
public TestData.FlagBuilder ExcludeFromSummaries(bool excludeFromSummaries)
Parameters
Type | Name | Description |
---|---|---|
bool | excludeFromSummaries | true to exclude the flag from summaries |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
FallthroughVariation(bool)
Specifies the fallthrough variation for a boolean flag.
Declaration
public TestData.FlagBuilder FallthroughVariation(bool variation)
Parameters
Type | Name | Description |
---|---|---|
bool | variation | true if the flag should return true by default when targeting is on |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
The fallthrough is the value that is returned if targeting is on and the context was not matched by a more specific target or rule.
If the flag was previously configured with other variations, this also changes it to a boolean flag.
FallthroughVariation(int)
Specifies the index of the fallthrough variation.
Declaration
public TestData.FlagBuilder FallthroughVariation(int variationIndex)
Parameters
Type | Name | Description |
---|---|---|
int | variationIndex | the desired fallthrough variation: 0 for the first, 1 for the second, etc. |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
The fallthrough is the value that is returned if targeting is on and the context was not matched by a more specific target or rule.
IfMatch(string, params LdValue[])
Starts defining a flag rule, using the "is one of" operator. This is a shortcut for calling IfMatchContext(ContextKind, string, params LdValue[]) with "user" as the context kind.
Declaration
public TestData.FlagRuleBuilder IfMatch(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 | a TestData.FlagRuleBuilder; call ThenReturn(bool) or ThenReturn(int) to finish the rule, or add more tests with another method like AndMatch(string, params LdValue[]) |
Remarks
For example, this creates a rule that returns true
if the name is "Patsy" or "Edina":
testData.Update(testData.Flag("flag-key")
.IfMatch("name", LdValue.Of("Patsy"), LdValue.Of("Edina"))
.ThenReturn(true));
IfMatchContext(ContextKind, string, params LdValue[])
Starts defining a flag rule, using the "is one of" operator. This matching expression only applies to contexts of a specific kind.
Declaration
public TestData.FlagRuleBuilder IfMatchContext(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 | a TestData.FlagRuleBuilder; call ThenReturn(bool) or ThenReturn(int) to finish the rule, or add more tests with another method like AndMatchContext(ContextKind, string, params LdValue[]) |
Remarks
For example, this creates a rule that returns true
if the name attribute for the
"company" context is "Ella" or "Monsoon":
testData.Update(testData.Flag("flag-key")
.IfMatchContext("company", "name", LdValue.Of("Ella"), LdValue.Of("Monsoon"))
.ThenReturn(true));
IfNotMatch(string, params LdValue[])
Starts defining a flag rule, using the "is not one of" operator. This is a shortcut for calling IfNotMatchContext(ContextKind, string, params LdValue[]) with "user" as the context kind.
Declaration
public TestData.FlagRuleBuilder IfNotMatch(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 | a TestData.FlagRuleBuilder; call ThenReturn(bool) or ThenReturn(int) to finish the rule, or add more tests with another method like AndMatch(string, params LdValue[]) |
Remarks
For example, this creates a rule that returns true
if the name is neither
"Saffron" nor "Bubble":
testData.Update(testData.Flag("flag-key")
.IfNotMatch("name", LdValue.Of("Saffron"), LdValue.Of("Bubble"))
.ThenReturn(true));
IfNotMatchContext(ContextKind, string, params LdValue[])
Starts defining a flag rule, using the "is not one of" operator. This matching expression only applies to contexts of a specific kind.
Declaration
public TestData.FlagRuleBuilder IfNotMatchContext(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 | a TestData.FlagRuleBuilder; call ThenReturn(bool) or ThenReturn(int) to finish the rule, or add more tests with another method like AndMatchContext(ContextKind, string, params LdValue[]) |
Remarks
For example, this creates a rule that returns true
if the name attribute for the
"company" context is neither "Pendant" nor "Sterling Cooper":
testData.Update(testData.Flag("flag-key")
.IfNotMatchContext("company", "name", LdValue.Of("Pendant"), LdValue.Of("Sterling Cooper"))
.ThenReturn(true));
Migration(FlagMigrationBuilder)
Used to configure migration settings for the flag.
Declaration
public TestData.FlagBuilder Migration(TestData.FlagMigrationBuilder migrationBuilder)
Parameters
Type | Name | Description |
---|---|---|
TestData.FlagMigrationBuilder | migrationBuilder |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
OffVariation(bool)
Specifies the off variation for a boolean flag.
Declaration
public TestData.FlagBuilder OffVariation(bool variation)
Parameters
Type | Name | Description |
---|---|---|
bool | variation | true if the flag should return true when targeting is off |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This is the variation that is returned whenever targeting is off.
OffVariation(int)
Specifies the index of the off variation.
Declaration
public TestData.FlagBuilder OffVariation(int variationIndex)
Parameters
Type | Name | Description |
---|---|---|
int | variationIndex | the desired off variation: 0 for the first, 1 for the second, etc. |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This is the variation that is returned whenever targeting is off.
On(bool)
Sets targeting to be on or off for this flag.
Declaration
public TestData.FlagBuilder On(bool on)
Parameters
Type | Name | Description |
---|---|---|
bool | on | true if targeting should be on |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
The effect of this depends on the rest of the flag configuration, just as it does on the
real LaunchDarkly dashboard. In the default configuration that you get from calling
Flag(string) with a new flag key, the flag will return false
whenever targeting is off, and true
when targeting is on.
SamplingRatio(long)
Sets the sampling ratio for the flag.
Declaration
public TestData.FlagBuilder SamplingRatio(long samplingRatio)
Parameters
Type | Name | Description |
---|---|---|
long | samplingRatio | the new sampling ratio |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
ValueForAll(LdValue)
Sets the flag to always return the specified variation value for all contexts.
Declaration
public TestData.FlagBuilder ValueForAll(LdValue value)
Parameters
Type | Name | Description |
---|---|---|
LdValue | value | the desired value to be returned |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
The value may be of any JSON type, as defined by LdValue. This method changes the flag to have only a single variation, which is this value, and to return the same variation regardless of whether targeting is on or off. Any existing targets or rules are removed.
See Also
| Edit this page View SourceVariationForAll(bool)
Sets the flag to always return the specified boolean variation for all contexts.
Declaration
public TestData.FlagBuilder VariationForAll(bool variation)
Parameters
Type | Name | Description |
---|---|---|
bool | variation | the desired true/false variation to be returned |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
Targeting is switched on, any existing targets or rules are removed, and the flag's variations are
set to true
and false
. The fallthrough variation is set to the specified value. The
off variation is left unchanged.
See Also
| Edit this page View SourceVariationForAll(int)
Sets the flag to always return the specified variation for all contexts.
Declaration
public TestData.FlagBuilder VariationForAll(int variationIndex)
Parameters
Type | Name | Description |
---|---|---|
int | variationIndex | the desired variation: 0 for the first, 1 for the second, etc. |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
The variation is specified by number, out of whatever variation values have already been defined. Targeting is switched on, and any existing targets or rules are removed. The fallthrough variation is set to the specified value. The off variation is left unchanged.
See Also
| Edit this page View SourceVariationForKey(ContextKind, string, bool)
Sets the flag to return the specified boolean variation for a specific context, identified by context kind and key, when targeting is on.
Declaration
public TestData.FlagBuilder VariationForKey(ContextKind contextKind, string key, bool variation)
Parameters
Type | Name | Description |
---|---|---|
ContextKind | contextKind | the context kind |
string | key | the context key |
bool | variation | the desired true/false variation to be returned for this context when targeting is on |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This does not affect the flag's off variation that is used when targeting is off.
If the flag was not already a boolean flag, this also changes it to a boolean flag.
See Also
| Edit this page View SourceVariationForKey(ContextKind, string, int)
Sets the flag to return the specified variation for a specific context, identified by context kind and key, when targeting is on.
Declaration
public TestData.FlagBuilder VariationForKey(ContextKind contextKind, string key, int variationIndex)
Parameters
Type | Name | Description |
---|---|---|
ContextKind | contextKind | the context kind |
string | key | the context key |
int | variationIndex | the desired variation to be returned for this context when targeting is on: 0 for the first, 1 for the second, etc. |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This has no effect when targeting is turned off for the flag. The variation is specified by number, out of whatever variation values have already been defined.
See Also
| Edit this page View SourceVariationForUser(string, bool)
Sets the flag to return the specified boolean variation for a specific user key (that is, for a context with that key whose context kind is "user") when targeting is on.
Declaration
public TestData.FlagBuilder VariationForUser(string userKey, bool variation)
Parameters
Type | Name | Description |
---|---|---|
string | userKey | a user key |
bool | variation | the desired true/false variation to be returned for this user when targeting is on |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This does not affect the flag's off variation that is used when targeting is off.
If the flag was not already a boolean flag, this also changes it to a boolean flag.
See Also
| Edit this page View SourceVariationForUser(string, int)
Sets the flag to return the specified variation for a specific user key (that is, for a context with that key whose context kind is "user") when targeting is on.
Declaration
public TestData.FlagBuilder VariationForUser(string userKey, int variationIndex)
Parameters
Type | Name | Description |
---|---|---|
string | userKey | a user key |
int | variationIndex | the desired variation to be returned for this user when targeting is on: 0 for the first, 1 for the second, etc. |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
This has no effect when targeting is turned off for the flag. The variation is specified by number, out of whatever variation values have already been defined.
See Also
| Edit this page View SourceVariations(params LdValue[])
Changes the allowable variation values for the flag.
Declaration
public TestData.FlagBuilder Variations(params LdValue[] values)
Parameters
Type | Name | Description |
---|---|---|
LdValue[] | values | the desired variations |
Returns
Type | Description |
---|---|
TestData.FlagBuilder | the builder |
Remarks
The value may be of any JSON type, as defined by LdValue. For instance, a boolean flag
normally has LdValue.Of(true), LdValue.Of(false)
; a string-valued flag might have
LdValue.Of("red"), LdValue.Of("green")
; etc.