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);
        }
        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);
        }