Esempio n. 1
0
        public void IsEnabled_MultipleExperimentsOverriddenWithDifferentEnvVars_DoNotConflict()
        {
            var forcedOffExperiment  = new ExperimentationConstants("TestExp1", "TEST_EXP_1");
            var forcedOnExperiment   = new ExperimentationConstants("TestExp2", "TEST_EXP_2");
            var noOverrideExperiment = new ExperimentationConstants("TestExp3", "TEST_EXP_3");
            var flightsEnabled       = new Dictionary <string, bool>()
            {
                { forcedOffExperiment.FlightFlag, true },
                { forcedOnExperiment.FlightFlag, true },
                { noOverrideExperiment.FlightFlag, true },
            };
            var envVars = new Dictionary <string, string>()
            {
                { forcedOnExperiment.FlightEnvironmentVariable, "1" },
                { forcedOffExperiment.FlightEnvironmentVariable, "0" },
            };
            var envVarWrapper = new TestEnvironmentVariableReader(envVars);
            var service       = new NuGetExperimentationService(envVarWrapper, new TestVisualStudioExperimentalService(flightsEnabled), _outputConsoleProvider);

            service.IsExperimentEnabled(forcedOffExperiment).Should().BeFalse();
            service.IsExperimentEnabled(forcedOnExperiment).Should().BeTrue();
            service.IsExperimentEnabled(noOverrideExperiment).Should().BeTrue();
            OutputMessages.Should().ContainMatch($"*{forcedOffExperiment.FlightFlag}*{forcedOffExperiment.FlightEnvironmentVariable}*0*");
            OutputMessages.Should().ContainMatch($"*{forcedOnExperiment.FlightFlag}*{forcedOnExperiment.FlightEnvironmentVariable}*1*");
            OutputMessages.Should().NotContainMatch($"*{noOverrideExperiment.FlightFlag}*{noOverrideExperiment.FlightEnvironmentVariable}*");
        }
Esempio n. 2
0
        public void IsEnabled_WithNullEnvironmentVariableForConstant_HandlesGracefully()
        {
            var service  = new NuGetExperimentationService(new EnvironmentVariableWrapper(), new TestVisualStudioExperimentalService(), _outputConsoleProvider);
            var constant = new ExperimentationConstants("flag", null);

            service.IsExperimentEnabled(constant).Should().BeFalse();
            OutputMessages.Should().NotContainMatch($"*{constant.FlightFlag}*{constant.FlightEnvironmentVariable}*");
        }
        internal static async Task <bool> IsExperimentEnabledAsync(ExperimentationConstants exp)
        {
            bool isExpEnabled;

            try
            {
                var svc = await ServiceLocator.GetComponentModelServiceAsync <INuGetExperimentationService>();

                isExpEnabled = svc?.IsExperimentEnabled(exp) ?? false;
            }
            catch (ServiceUnavailableException)
            {
                isExpEnabled = false;
            }

            return(isExpEnabled);
        }
Esempio n. 4
0
        public void Constructor_WithNullFlightExperimentalVariable_DoesNotThrow()
        {
            var constant = new ExperimentationConstants("value", null);

            constant.FlightEnvironmentVariable.Should().BeNull();
        }