public async Task IsFeatureEnabledAsync_MultipleFeaturesOverriddenWithDifferentEnvVars_DoNotConflict() { var forcedOff = new NuGetFeatureFlagConstants("TestExp1", "TEST_EXP_1", defaultState: false); var forcedOn = new NuGetFeatureFlagConstants("TestExp2", "TEST_EXP_2", defaultState: false); var noOverride = new NuGetFeatureFlagConstants("TestExp3", "TEST_EXP_3", defaultState: false); var envVars = new Dictionary <string, string>() { { forcedOn.EnvironmentVariable, "1" }, { forcedOff.EnvironmentVariable, "0" }, }; var envVarWrapper = new TestEnvironmentVariableReader(envVars); var vsFeatureFlags = Mock.Of <IVsFeatureFlags>(); Mock.Get(vsFeatureFlags) .Setup(x => x.IsFeatureEnabled( It.IsAny <string>(), It.IsAny <bool>())) .Returns(true); _globalProvider.AddService(typeof(SVsFeatureFlags), vsFeatureFlags); var service = new NuGetFeatureFlagService(envVarWrapper, AsyncServiceProvider.GlobalProvider); (await service.IsFeatureEnabledAsync(forcedOff)).Should().BeFalse(); (await service.IsFeatureEnabledAsync(forcedOn)).Should().BeTrue(); (await service.IsFeatureEnabledAsync(noOverride)).Should().BeTrue(); }
public async Task IsFeatureEnabledAsync_WithNullEnvironmentVariableForConstant_HandlesGracefully() { var featureFlagConstant = new NuGetFeatureFlagConstants("featureFlag", null, defaultState: false); var vsFeatureFlags = Mock.Of <IVsFeatureFlags>(); _globalProvider.AddService(typeof(SVsFeatureFlags), vsFeatureFlags); var service = new NuGetFeatureFlagService(new EnvironmentVariableWrapper(), AsyncServiceProvider.GlobalProvider); (await service.IsFeatureEnabledAsync(featureFlagConstant)).Should().Be(false); }
public async Task IsFeatureEnabledAsync_WithoutFlag_ReturnsDefaultValueFromConstant(bool featureFlagDefault) { var featureFlagConstant = new NuGetFeatureFlagConstants("featureFlag", "featureEnvVar", defaultState: featureFlagDefault); var vsFeatureFlags = Mock.Of <IVsFeatureFlags>(); Mock.Get(vsFeatureFlags) .Setup(x => x.IsFeatureEnabled( It.IsAny <string>(), It.IsAny <bool>())) .Returns(featureFlagDefault); _globalProvider.AddService(typeof(SVsFeatureFlags), vsFeatureFlags); var service = new NuGetFeatureFlagService(new EnvironmentVariableWrapper(), AsyncServiceProvider.GlobalProvider); (await service.IsFeatureEnabledAsync(featureFlagConstant)).Should().Be(featureFlagDefault); }
public async Task IsFeatureEnabledAsync_WithEnvVarNotSetWithEnabledFeatureFromWithFeatureFlagService_ReturnsExpectedResult(bool isFeatureEnabled, bool expectedResult) { var featureFlagConstant = new NuGetFeatureFlagConstants("featureFlag", "featureEnvVar", defaultState: false); var envVarWrapper = new TestEnvironmentVariableReader(new Dictionary <string, string>()); var vsFeatureFlags = Mock.Of <IVsFeatureFlags>(); Mock.Get(vsFeatureFlags) .Setup(x => x.IsFeatureEnabled( It.IsAny <string>(), It.IsAny <bool>())) .Returns(isFeatureEnabled); _globalProvider.AddService(typeof(SVsFeatureFlags), vsFeatureFlags); var service = new NuGetFeatureFlagService(envVarWrapper, AsyncServiceProvider.GlobalProvider); (await service.IsFeatureEnabledAsync(featureFlagConstant)).Should().Be(expectedResult); }
public async Task IsFeatureEnabledAsync_WithEnvVarWithIncorrectValue_WithEnvironmentVariable__ReturnsFalse(string value) { var featureFlagConstant = new NuGetFeatureFlagConstants("featureFlag", "featureEnvVar", defaultState: false); var envVars = new Dictionary <string, string>() { { featureFlagConstant.EnvironmentVariable, value }, }; var envVarWrapper = new TestEnvironmentVariableReader(envVars); var vsFeatureFlags = Mock.Of <IVsFeatureFlags>(); Mock.Get(vsFeatureFlags) .Setup(x => x.IsFeatureEnabled( It.IsAny <string>(), It.IsAny <bool>())) .Returns(false); _globalProvider.AddService(typeof(SVsFeatureFlags), vsFeatureFlags); var service = new NuGetFeatureFlagService(envVarWrapper, AsyncServiceProvider.GlobalProvider); (await service.IsFeatureEnabledAsync(featureFlagConstant)).Should().Be(false); }