Exemple #1
0
    public async Task SetValueShouldRaiseOnFeatureUpdated()
    {
        // Arrange
        int calls = 0;

        InitializeFeaturesData();

        var settings = new Settings
        {
            OnServerFeatureUpdated = _ =>
            {
                calls++;
            }
        };

        var featuresService = new FeaturesService(_db, settings);

        string newValue = "dark";

        // Act
        var result = await featuresService.SetValue("Theme", newValue);

        // Assert
        calls.ShouldBe(1);
    }
Exemple #2
0
    public async Task SetValueShouldFailIfMismatchTypeForStringValue()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        // Act
        var exception = await featuresService.SetValue("Theme", true).ShouldThrowAsync <Exception>();

        // Assert
        exception.Message.ShouldBe("The feature Theme is a string feature...");
    }
Exemple #3
0
    public async Task SetValueShouldFailIfMismatchTypeForDecimalValue()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        // Act
        var exception = await featuresService.SetValue("TaxPercent", "123").ShouldThrowAsync <Exception>();

        // Assert
        exception.Message.ShouldBe("The feature TaxPercent is a decimal feature...");
    }
Exemple #4
0
    public async Task SetValueShouldFailIfMismatchTypeForIntValue()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        // Act
        var exception = await featuresService.SetValue("Delay", false).ShouldThrowAsync <Exception>();

        // Assert
        exception.Message.ShouldBe("The feature Delay is an integer feature...");
    }
Exemple #5
0
    public async Task SetValueShouldFailIfMismatchTypeForBooleanValue()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        // Act
        var exception = await featuresService.SetValue("Beta", 10).ShouldThrowAsync <Exception>();

        // Assert
        exception.Message.ShouldBe("The feature Beta is a boolean feature...");
    }
Exemple #6
0
    public async Task SetValueShouldFailIfNoFeatureFound()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        string featureName = "X";

        // Act
        var exception = await featuresService.SetValue(featureName, "test").ShouldThrowAsync <Exception>();

        // Assert
        exception.Message.ShouldBe($"The feature {featureName} does not exist...");
    }
Exemple #7
0
    public async Task SetValueShouldFailIfNotInsideTheAvailableStringChoices()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        string featureName = "Theme";
        string newValue    = "Blue";

        // Act
        var exception = await featuresService.SetValue(featureName, newValue).ShouldThrowAsync <Exception>();

        // Assert
        exception.Message.ShouldBe($"The value {newValue} is not a valid choice for feature {featureName}...");
    }
Exemple #8
0
    public async Task SetValueShouldUpdateStringFeature()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        string newValue = "dark";

        // Act
        var result = await featuresService.SetValue("Theme", newValue);

        // Assert
        result.Server.ShouldNotBeNull();

        if (result.Server != null)
        {
            result.Server.BooleanValue.ShouldBeNull();
            result.Server.IntValue.ShouldBeNull();
            result.Server.DecimalValue.ShouldBeNull();
            result.Server.StringValue.ShouldBe(newValue);
        }
    }
Exemple #9
0
    public async Task SetValueShouldUpdateBooleanFeature()
    {
        // Arrange
        InitializeFeaturesData();
        var featuresService = new FeaturesService(_db, new Settings());

        // Act
        var result = await featuresService.SetValue("Beta", false);

        // Assert
        result.Server.ShouldNotBeNull();

        if (result.Server != null)
        {
            result.Server.BooleanValue.HasValue.ShouldBeTrue();
            if (result.Server.BooleanValue.HasValue)
            {
                result.Server.BooleanValue.Value.ShouldBeFalse();
            }
            result.Server.IntValue.ShouldBeNull();
            result.Server.DecimalValue.ShouldBeNull();
            result.Server.StringValue.ShouldBeNull();
        }
    }