Show / Hide Table of Contents

Class TestData

A mechanism for providing dynamically updatable feature flag state in a simplified form to an SDK client in test scenarios.

Inheritance
System.Object
TestData
Implements
IComponentConfigurer<IDataSource>
Namespace: LaunchDarkly.Sdk.Client.Integrations
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public sealed class TestData : Object, IComponentConfigurer<IDataSource>
Remarks

This mechanism does not use any external resources. It provides only the data that the application has put into it using the Update(TestData.FlagBuilder) method.

The example code below uses a simple boolean flag, but more complex configurations are possible using the methods of the TestData.FlagBuilder that is returned by Flag(String).

If the same TestData instance is used to configure multiple LdClient instances, any changes made to the data will propagate to all of the LdClients.

Examples
    var td = TestData.DataSource();
    td.Update(td.Flag("flag-key-1").BooleanFlag().Variation(true));

    var config = Configuration.Builder("sdk-key")
        .DataSource(td)
        .Build();
    var client = new LdClient(config);

    // flags can be updated at any time:
    td.update(testData.flag("flag-key-2")
        .VariationForUser("some-user-key", false));

Methods

Build(LdClientContext)

Called internally by the SDK to create an implementation instance. Applications should not need to call this method.

Declaration
public IDataSource Build(LdClientContext clientContext)
Parameters
Type Name Description
LdClientContext clientContext
Returns
Type Description
IDataSource

a instance of the component type

DataSource()

Creates a new instance of the test data source.

Declaration
public static TestData DataSource()
Returns
Type Description
TestData

a new configurable test data source

Remarks

See TestData for details.

Flag(String)

Creates or copies a TestData.FlagBuilder for building a test flag configuration.

Declaration
public TestData.FlagBuilder Flag(string key)
Parameters
Type Name Description
System.String key

the flag key

Returns
Type Description
TestData.FlagBuilder

a flag configuration builder

Remarks

If this flag key has already been defined in this TestData instance, then the builder starts with the same configuration that was last provided for this flag.

Otherwise, it starts with a new default configuration in which the flag has true and false variations, and is true by default for all contexts. You can change any of those properties, and provide more complex behavior, using the TestData.FlagBuilder methods.

Once you have set the desired configuration, pass the builder to Update(TestData.FlagBuilder).

See Also
Update(TestData.FlagBuilder)

Update(TestData.FlagBuilder)

Updates the test data with the specified flag configuration.

Declaration
public TestData Update(TestData.FlagBuilder flagBuilder)
Parameters
Type Name Description
TestData.FlagBuilder flagBuilder

a flag configuration builder

Returns
Type Description
TestData

the same TestData instance

Remarks

This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard. It immediately propagates the flag change to any LdClient instance(s) that you have already configured to use this TestData. If no LdClient has been started yet, it simply adds this flag to the test data which will be provided to any LdClient that you subsequently configure.

Any subsequent changes to this TestData.FlagBuilder instance do not affect the test data, unless you call Update(TestData.FlagBuilder) again.

See Also
Flag(String)

UpdateStatus(DataSourceState, Nullable<DataSourceStatus.ErrorInfo>)

Simulates a change in the data source status.

Declaration
public TestData UpdateStatus(DataSourceState newState, Nullable<DataSourceStatus.ErrorInfo> newError)
Parameters
Type Name Description
DataSourceState newState

one of the constants defined by DataSourceState

System.Nullable<DataSourceStatus.ErrorInfo> newError

an optional DataSourceStatus.ErrorInfo instance

Returns
Type Description
TestData

the same TestData instance

Remarks

Use this if you want to test the behavior of application code that uses DataSourceStatusProvider to track whether the data source is having problems (for example, a network failure interrupting the streaming connection). It does not actually stop the TestData data source from working, so even if you have simulated an outage, calling Update(TestData.FlagBuilder) will still send updates.

Implements

IComponentConfigurer<T>
In This Article
Back to top Generated by DocFX