LaunchDarkly Dotnet Client SDK
Search Results for

    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
    object
    TestData
    Implements
    IComponentConfigurer<IDataSource>
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: LaunchDarkly.Sdk.Client.Integrations
    Assembly: LaunchDarkly.ClientSdk.dll
    Syntax
    public sealed class TestData : 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(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

    | Edit this page View Source

    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

    | Edit this page View Source

    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.

    | Edit this page View Source

    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
    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(FlagBuilder).

    See Also
    Update(FlagBuilder)
    | Edit this page View Source

    Update(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(FlagBuilder) again.

    See Also
    Flag(string)
    | Edit this page View Source

    UpdateStatus(DataSourceState, ErrorInfo?)

    Simulates a change in the data source status.

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

    one of the constants defined by DataSourceState

    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(FlagBuilder) will still send updates.

    Implements

    IComponentConfigurer<T>
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX