public void Feature_Bindings_shall_requery_if_contextid_is_changed_at_the_element()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(false, false) },
                { "One/Two/AlteredThree", new Feature(true, true) },
                { "One/Two/TemplatedThree", new Feature(false, false) },
                { "One/Two/AlteredTemplatedThree", new Feature(true, true) }
            };

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Collapsed, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);

            UiFeatureManagement.SetContext(ControlTree.Three, "AlteredThree");
            UiFeatureManagement.SetContext(ControlTree.TemplatedThree, "AlteredTemplatedThree");

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
        }
        public void Feature_Bindings_shall_requery_if_bound_contextid_is_changed_at_the_ancestor()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/BoundTwo/Three", new Feature(false, false) },
                { "One/AlteredTwo/Three", new Feature(true, true) },
                { "One/BoundTwo/TemplatedThree", new Feature(false, false) },
                { "One/AlteredTwo/TemplatedThree", new Feature(true, true) }
            };
            ContextValues ContextValues = new ContextValues("BoundTwo");

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            ControlTree.DataContext = ContextValues;
            ControlTree.Two.SetBinding(UiFeatureManagement.ContextProperty, "Context");
            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Collapsed, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);

            ContextValues.Context = "AlteredTwo";

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
            Assert.IsTrue(ControlTree.TemplatedThree.IsEnabled);
        }
        public void Feature_Bindings_shall_reflect_values_of_manager()
        {
            TestFeatureSource TestSource     = new TestFeatureSource(true, true);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.ReadonlyThree.IsReadOnly);

            TestSource.Enabled = false;

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsTrue(ControlTree.ReadonlyThree.IsReadOnly);

            TestSource.Visible = false;

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsTrue(ControlTree.ReadonlyThree.IsReadOnly);
        }
Example #4
0
        public void Feature_shall_be_disabled_if_at_least_one_source_returns_disabled()
        {
            TestFeatureSource TestFeatureSource1 = new TestFeatureSource(true, false);
            TestFeatureSource TestFeatureSource2 = new TestFeatureSource(true, false);
            UiFeatureManager  UIFeatureManager   = new UiFeatureManager(new[] { TestFeatureSource1, TestFeatureSource2 });

            bool Enabled = UIFeatureManager.IsEnabled("");

            Assert.IsFalse(Enabled);
        }
Example #5
0
        public void Feature_shall_be_enabled_if_all_sources_return_enabled()
        {
            TestFeatureSource TestFeatureSource1 = new TestFeatureSource(true, true);
            TestFeatureSource TestFeatureSource2 = new TestFeatureSource(true, true);
            UiFeatureManager  UIFeatureManager   = new UiFeatureManager(new[] { TestFeatureSource1, TestFeatureSource2 });

            bool Enabled = UIFeatureManager.IsEnabled("");

            Assert.IsTrue(Enabled);
        }
Example #6
0
        public void Feature_shall_be_invisible_if_all_sources_return_invisible()
        {
            TestFeatureSource TestFeatureSource1 = new TestFeatureSource(false, true);
            TestFeatureSource TestFeatureSource2 = new TestFeatureSource(false, true);
            UiFeatureManager  UIFeatureManager   = new UiFeatureManager(new[] { TestFeatureSource1, TestFeatureSource2 });

            bool Visible = UIFeatureManager.IsVisible("");

            Assert.IsFalse(Visible);
        }
Example #7
0
        public void Feature_shall_be_visible_if_at_least_one_source_returns_visible()
        {
            TestFeatureSource TestFeatureSource1 = new TestFeatureSource(true, true);
            TestFeatureSource TestFeatureSource2 = new TestFeatureSource(false, true);
            UiFeatureManager  UIFeatureManager   = new UiFeatureManager(new[] { TestFeatureSource1, TestFeatureSource2 });

            bool Visible = UIFeatureManager.IsVisible("");

            Assert.IsTrue(Visible);
        }
Example #8
0
        public void Invisible_features_shall_also_not_be_enabled()
        {
            TestFeatureSource TestFeatureSource = new TestFeatureSource(false, true);
            UiFeatureManager  UIFeatureManager  = new UiFeatureManager(new[] { TestFeatureSource });

            bool Enabled = UIFeatureManager.IsEnabled("ContextString");
            bool Visible = UIFeatureManager.IsVisible("OtherContextString");

            Assert.IsFalse(Enabled);
            Assert.IsFalse(Visible);
        }
Example #9
0
        public void FeatureChanged_event_shall_be_forwarded()
        {
            TestFeatureSource TestFeatureSource = new TestFeatureSource(false, true);
            UiFeatureManager  UIFeatureManager  = new UiFeatureManager(new[] { TestFeatureSource });

            bool EventCalled = false;

            UIFeatureManager.FeaturesChanged += delegate { EventCalled = true; };

            TestFeatureSource.InvokeFeaturesChanged();

            Assert.IsTrue(EventCalled);
        }
Example #10
0
        public void UIFeatureManager_shall_return_the_results_of_underlying_source()
        {
            TestFeatureSource TestFeatureSource = new TestFeatureSource(true, true);
            UiFeatureManager  UIFeatureManager  = new UiFeatureManager(new[] { TestFeatureSource });

            bool Enabled = UIFeatureManager.IsEnabled("ContextString");

            Assert.IsTrue(Enabled);
            Assert.AreEqual("ContextString", TestFeatureSource.EnabledContext);

            bool Visible = UIFeatureManager.IsVisible("OtherContextString");

            Assert.IsTrue(Visible);
            Assert.AreEqual("OtherContextString", TestFeatureSource.VisibleContext);
        }
        public void Feature_Bindings_shall_requery_if_manager_sends_featurechanged_event()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(false, false) },
                { "One/Two/TemplatedThree", new Feature(false, false) },
                { "One/Two/Hyperlink", new Feature(false, false) },
            };

            Dictionary <string, Feature> NewRules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(true, true) },
                { "One/Two/TemplatedThree", new Feature(true, true) },
                { "One/Two/Hyperlink", new Feature(true, true) },
            };

            TestFeatureSource TestSource        = new TestFeatureSource(Rules);
            TestFeatureSource NewTestSource     = new TestFeatureSource(NewRules);
            IUiFeatureManager FeatureManager    = new UiFeatureManager(new[] { TestSource });
            IUiFeatureManager NewFeatureManager = new UiFeatureManager(new[] { NewTestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Collapsed, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Collapsed, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsFalse(ControlTree.Hyperlink.IsEnabled);

            UiFeatureManagement.SetManager(ControlTree, NewFeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsTrue(ControlTree.Three.IsEnabled);
            Assert.IsTrue(ControlTree.TemplatedThree.IsEnabled);
            Assert.IsTrue(ControlTree.Hyperlink.IsEnabled);
        }
        public void Feature_Bindings_shall_query_the_right_contextids()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/Three", new Feature(true, false) },
                { "One/Two/TemplatedThree", new Feature(true, false) },
                { "One/Two/OtherThree", new Feature(true, true) },
            };

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
            Assert.AreEqual(Visibility.Visible, ControlTree.OtherThree.Visibility);
            Assert.IsTrue(ControlTree.OtherThree.IsEnabled);
        }
        public void Feature_Bindings_shall_query_the_right_bound_contextids()
        {
            Dictionary <string, Feature> Rules = new Dictionary <string, Feature>
            {
                { "One/Two/BoundThree", new Feature(true, false) },
                { "One/Two/BoundTemplatedThree", new Feature(true, false) },
            };

            TestFeatureSource TestSource     = new TestFeatureSource(Rules);
            IUiFeatureManager FeatureManager = new UiFeatureManager(new[] { TestSource });

            UiFeatureManagementControlTree ControlTree = new UiFeatureManagementControlTree();

            ControlTree.DataContext = new ContextValues("BoundThree");
            ControlTree.Three.SetBinding(UiFeatureManagement.ContextProperty, "Context");
            ControlTree.TemplatedThree.DataContext = new ContextValues("BoundTemplatedThree");
            ControlTree.TemplatedThree.SetBinding(UiFeatureManagement.ContextProperty, "Context");
            UiFeatureManagement.SetManager(ControlTree, FeatureManager);

            Assert.AreEqual(Visibility.Visible, ControlTree.Three.Visibility);
            Assert.AreEqual(Visibility.Visible, ControlTree.TemplatedThree.Visibility);
            Assert.IsFalse(ControlTree.Three.IsEnabled);
            Assert.IsFalse(ControlTree.TemplatedThree.IsEnabled);
        }