コード例 #1
0
        public void Should_activate_upstream_dependencies_first()
        {
            var order = new List<Feature>();

            var dependingFeature = new NamespaceB.MyFeature
            {
                OnActivation = f => order.Add(f)
            };
            var feature = new NamespaceA.MyFeature
            {
                OnActivation = f => order.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(dependingFeature);
            featureSettings.Add(feature);

            settings.EnableFeatureByDefault<NamespaceA.MyFeature>();

            featureSettings.SetupFeatures(null, null);

            Assert.True(dependingFeature.IsActive);

            Assert.IsInstanceOf<NamespaceA.MyFeature>(order.First(), "Upstream dependencies should be activated first");
        }
コード例 #2
0
        public void Should_activate_upstream_deps_first()
        {
            var defaultsOrder = new List<Feature>();

            var dependingFeature = new DependsOnOne_Feature
            {
                OnDefaults = f => defaultsOrder.Add(f)
            };
            var feature = new MyFeature1
            {
                OnDefaults = f => defaultsOrder.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(dependingFeature);
            featureSettings.Add(feature);

            settings.EnableFeatureByDefault<MyFeature1>();

            featureSettings.SetupFeatures(new FeatureConfigurationContext(null));

            Assert.True(dependingFeature.IsActive);

            Assert.IsInstanceOf<MyFeature1>(defaultsOrder.First(), "Upstream deps should be activated first");
        }
コード例 #3
0
        public void Should_only_activate_features_if_dependencies_are_met(FeatureCombinations setup)
        {
            var featureSettings = new FeatureActivator(new SettingsHolder());
            var dependingFeature = setup.DependingFeature;
            featureSettings.Add(dependingFeature);
            Array.ForEach(setup.AvailableFeatures, featureSettings.Add);

            featureSettings.SetupFeatures(null, null);

            Assert.AreEqual(setup.ShouldBeActive, dependingFeature.IsActive);
        }
コード例 #4
0
        public void Should_register_defaults_if_feature_is_activated()
        {
            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(new MyFeatureWithDefaults());

            featureSettings.SetupFeatures(new FeatureConfigurationContext(null));

            Assert.True(settings.HasSetting("Test1"));
        }
コード例 #5
0
        public void Should_not_register_defaults_if_feature_is_not_activated()
        {
            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(new MyFeatureWithDefaultsNotActive());
            featureSettings.Add(new MyFeatureWithDefaultsNotActiveDueToUnsatisfiedPrerequisite());

            featureSettings.SetupFeatures(new FeatureConfigurationContext(null));

            Assert.False(settings.HasSetting("Test1"));
            Assert.False(settings.HasSetting("Test2"));
        }
コード例 #6
0
        public void Should_check_prerequisites()
        {
            var featureWithTrueCondition = new MyFeatureWithSatisfiedPrerequisite();
            var featureWithFalseCondition = new MyFeatureWithUnsatisfiedPrerequisite();

            var featureSettings = new FeatureActivator(new SettingsHolder());

            featureSettings.Add(featureWithTrueCondition);
            featureSettings.Add(featureWithFalseCondition);


            featureSettings.SetupFeatures(new FeatureConfigurationContext(null));

            Assert.True(featureWithTrueCondition.IsActive);
            Assert.False(featureWithFalseCondition.IsActive);
            Assert.AreEqual("The description",
                featureSettings.Status.Single(s => s.Name == featureWithFalseCondition.Name).PrerequisiteStatus.Reasons.First());
        }
コード例 #7
0
        public void Should_enable_features_in_defaults()
        {
            var defaultsOrder = new List<Feature>();
            var activatedOrder = new List<Feature>();

            var level1 = new Activate1
            {
                OnActivation = f => activatedOrder.Add(f),
                OnDefaults = f => defaultsOrder.Add(f)
            };
            var level2 = new Activate2
            {
                OnActivation = f => activatedOrder.Add(f),
                OnDefaults = f => defaultsOrder.Add(f)
            };
            var level3 = new Activate3
            {
                OnActivation = f => activatedOrder.Add(f),
                OnDefaults = f => defaultsOrder.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            //the orders matter here to expose a bug
            featureSettings.Add(level3);
            featureSettings.Add(level2);
            featureSettings.Add(level1);

            featureSettings.SetupFeatures(new FeatureConfigurationContext(null));

            Assert.True(level1.IsActive, "Activate1 wasn't activated");
            Assert.True(level2.IsActive, "Activate2 wasn't activated");
            Assert.True(level3.IsActive, "Activate3 wasn't activated");

            Assert.IsInstanceOf<Activate1>(defaultsOrder[0], "Upstream deps should be activated first");
            Assert.IsInstanceOf<Activate2>(defaultsOrder[1], "Upstream deps should be activated first");
            Assert.IsInstanceOf<Activate3>(defaultsOrder[2], "Upstream deps should be activated first");

            CollectionAssert.AreEqual(defaultsOrder, activatedOrder);
        }
コード例 #8
0
 public void Init()
 {
     settings = new SettingsHolder();
     settings.Set<TransportDefinition>(new MsmqTransport());
     featureSettings = new FeatureActivator(settings);
 }
コード例 #9
0
        public void Should_throw_exception_when_dependency_cycle_is_found()
        {
            var order = new List<Feature>();


            var level1 = new CycleLevel1
            {
                OnActivation = f => order.Add(f)
            };
            var level2 = new CycleLevel2
            {
                OnActivation = f => order.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(level1);
            featureSettings.Add(level2);

            Assert.Throws<ArgumentException>(() => featureSettings.SetupFeatures(null, null));
        }
コード例 #10
0
        public void Should_activate_all_upstream_dependencies_when_chain_deep()
        {
            var order = new List<Feature>();


            var level1 = new Level1
            {
                OnActivation = f => order.Add(f)
            };
            var level2 = new Level2
            {
                OnActivation = f => order.Add(f)
            };
            var level3 = new Level3
            {
                OnActivation = f => order.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            //the orders matter here to expose a bug
            featureSettings.Add(level3);
            featureSettings.Add(level2);
            featureSettings.Add(level1);

            featureSettings.SetupFeatures(null, null);


            Assert.True(level1.IsActive, "Level1 wasn't activated");
            Assert.True(level2.IsActive, "Level2 wasn't activated");
            Assert.True(level3.IsActive, "Level3 wasn't activated");

            Assert.IsInstanceOf<Level1>(order[0], "Upstream dependencies should be activated first");
            Assert.IsInstanceOf<Level2>(order[1], "Upstream dependencies should be activated first");
            Assert.IsInstanceOf<Level3>(order[2], "Upstream dependencies should be activated first");
        }
コード例 #11
0
        public void Should_activate_all_upstream_dependencies_first()
        {
            var order = new List<Feature>();

            var dependingFeature = new DependsOnAtLeastOne_Feature
            {
                OnActivation = f => order.Add(f)
            };
            var feature = new MyFeature1
            {
                OnActivation = f => order.Add(f)
            };
            var feature2 = new MyFeature2
            {
                OnActivation = f => order.Add(f)
            };
            var feature3 = new MyFeature3
            {
                OnActivation = f => order.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(dependingFeature);
            featureSettings.Add(feature);
            featureSettings.Add(feature2);
            featureSettings.Add(feature3);

            settings.EnableFeatureByDefault<MyFeature1>();
            settings.EnableFeatureByDefault<MyFeature2>();
            settings.EnableFeatureByDefault<MyFeature3>();

            featureSettings.SetupFeatures(null, null);

            Assert.True(dependingFeature.IsActive);

            Assert.IsInstanceOf<MyFeature1>(order[0], "Upstream dependencies should be activated first");
            Assert.IsInstanceOf<MyFeature2>(order[1], "Upstream dependencies should be activated first");
            Assert.IsInstanceOf<MyFeature3>(order[2], "Upstream dependencies should be activated first");
        }
コード例 #12
0
        public void Should_not_activate_feature_when_named_dependency_disabled()
        {
            var order = new List<Feature>();

            var dependingFeature = new DependsOnOneByName_Feature
            {
                OnActivation = f => order.Add(f)
            };
            var feature = new MyFeature2
            {
                OnActivation = f => order.Add(f)
            };

            var settings = new SettingsHolder();
            var featureSettings = new FeatureActivator(settings);

            featureSettings.Add(dependingFeature);
            featureSettings.Add(feature);

            featureSettings.SetupFeatures(null, null);

            Assert.False(dependingFeature.IsActive);
            Assert.IsEmpty(order);
        }
コード例 #13
0
 public FeatureRunner(FeatureActivator featureActivator)
 {
     this.featureActivator = featureActivator;
 }
コード例 #14
0
 public FeatureRunner(FeatureActivator featureActivator)
 {
     this.featureActivator = featureActivator;
 }