Git Product home page Git Product logo

toggler's Introduction

Toggler

Feature toggling library for .NET.

How to get it?

Toggler is available through the Nuget Package Manager.

Or, you can build it from source.

How to use it?

To enable toggling at the class level, implement the IToggled interface:

public class TestFeature : IToggled
{
    public bool IsFeatureEnabled()
    {
        return this.IsOn();
    }
}

Within such a class, you can do this.IsOn() to see if the feature is enabled and take appropriate action.

You can enable or disable the features in the AppSettings:

<appSettings>
    <add key="Toggler.TestFeature" value="true"/>
    <add key="Toggler.TestFeatureDisabled" value="false"/>
</appSettings>

TestFeature and TestFeatureDisabled refers to classes that are feature toggled.

To add a feature, extend AppSettingsFeature.

public class TestToggleFeature : AppSettingsFeature
{

}

Enable or disable features in the AppSettings:

<appSettings>
    <add key="Toggler.Feature.TestToggleFeature" value="true"/>
</appSettings>

Note the Toggler.Feature. prefix.

To enable a class to use feature toggling with the feature you created, implement the IToggled<IFeature> interface:

public class TestToggledWithFeature : IToggled<TestToggleFeature>
{

}

You can now do this.IsFeatureOn<TestToggleFeature> to see if the feature TestToggleFeature is available in TestToggledWithFeatures

You can implement both IToggled and IToggled<TestToggleFeature>

Refer to the tests for impementation.

How to test it?

You can use the Toggler.TestHelper Nuget package to test toggles in your code. A typical test for toggling with feature would like below:

public class ToggledWithFeature : IToggled<Feature>
{
}

[Test]
public void ShouldBeAbleToSetupToggleWithFeatureToOn()
{
    var toggledWithFeature = new ToggledWithFeature();
    using (toggledWithFeature.SetUpToggledWithFeature(true))
    {
        Assert.That(toggledWithFeature.IsFeatureOn(), Is.True);
    }
}

You setup the test context with toggledWithFeature.SetUpToggledWithFeature(true) and make necessary action and insert within it.

The test helper makes use of Microsoft Fakes. If you are already using Fakes, you may wish to test directly with it. You can also, of course, choose to test toggles in your own way.

toggler's People

Contributors

manojlds avatar

Stargazers

Justin Hachemeister avatar Rui Pedro Silva avatar Pete Stensønes avatar  avatar Paul Mcilreavy avatar Sean Killeen avatar Regis Bittencourt avatar Richard Tasker avatar Ron Richardson avatar Daniel Ramirez avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.