Exemple #1
0
        public async Task TestFailingUpdate()
        {
            var random = new Random();
            var nonDefaultEnabledFeatureId = random.Next();

            while (FeatureConfiguration.DefaultEnabledFeatureIds.Contains((FeatureId)nonDefaultEnabledFeatureId))
            {
                nonDefaultEnabledFeatureId = random.Next();
            }

            var dummyApiAccess = new DummyFeatureToggleApiAccess
            {
                ReturnValue = new List <FeatureDto>
                {
                    new FeatureDto(nonDefaultEnabledFeatureId, "Test", null, new List <int>(), new List <int>())
                }
            };

            IoCManager.RegisterInstance(typeof(IFeatureToggleApiAccess), dummyApiAccess);

            IFeatureToggleRouter router = await FeatureToggleRouter.CreateAsync();

            var feature0Observer = new CachingObserver <bool>();

            router.IsFeatureEnabled((FeatureId)nonDefaultEnabledFeatureId).Subscribe(feature0Observer);
            Assert.IsTrue(feature0Observer.Last);

            // Make network fail, make sure no change is made and value doesn't revert to default
            // state (disabled)
            IoCManager.RegisterInstance(typeof(IFeatureToggleApiAccess), new ThrowingFeatureToggleApiAccess());
            await router.RefreshEnabledFeaturesAsync();

            Assert.IsTrue(feature0Observer.Last);
        }
Exemple #2
0
        public async Task TestSuccessfulUpdate()
        {
            var dummyApiAccess = new DummyFeatureToggleApiAccess
            {
                ReturnValue = new List <FeatureDto>
                {
                    new FeatureDto(0, "Test", null, new List <int>(), new List <int>())
                }
            };

            IoCManager.RegisterInstance(typeof(IFeatureToggleApiAccess), dummyApiAccess);

            IFeatureToggleRouter router = await FeatureToggleRouter.CreateAsync();

            var feature0Observer = new CachingObserver <bool>();
            var feature1Observer = new CachingObserver <bool>();

            router.IsFeatureEnabled(0).Subscribe(feature0Observer);
            router.IsFeatureEnabled((FeatureId)1).Subscribe(feature1Observer);
            Assert.IsTrue(feature0Observer.Last);
            Assert.IsFalse(feature1Observer.Last);

            // Swap feature states
            dummyApiAccess.ReturnValue = new List <FeatureDto>
            {
                new FeatureDto(1, "Test", null, new List <int>(), new List <int>())
            };
            await router.RefreshEnabledFeaturesAsync();

            Assert.IsFalse(feature0Observer.Last);
            Assert.IsTrue(feature1Observer.Last);
        }