Exemple #1
0
        public void Should_determine_if_elements_are_loaded()
        {
            // the important distinction here is the namespace matching
            var proc = new XamlPostProcessor();

            proc.LoadElementDefaults("<test1 a='1' />");
            proc.LoadElementDefaults($"<test2 xmlns='{Uri}' a='2' />");

            Assert.IsTrue(proc.AreElementDefaultsLoaded("test1"));
            Assert.IsTrue(proc.AreElementDefaultsLoaded("test2", Uri));
            Assert.IsFalse(proc.AreElementDefaultsLoaded("test2"));
        }
        public void Property_values_and_property_element_values_are_same()
        {
            var proc = new XamlPostProcessor();

            proc.LoadElementDefaults(XAMLTests.Nulls_ContentPage_Defaults);
            proc.LoadElementDefaults(XAMLTests.Nulls_Label_Defaults);
            proc.LoadDocument(XAMLTests.Nulls_Input);

            var doc = proc.Process();
            var els = doc?.Document?.Root?.Elements().ToArray();

            Assert.AreEqual(1, els?.Length);
        }
Exemple #3
0
        public void Should_not_load_simple_template_multiple_times()
        {
            const string tmpl = "<test a='b'></test>";
            var          proc = new XamlPostProcessor();

            var attempt1 = proc.LoadElementDefaults(tmpl);

            Assert.IsTrue(attempt1);

            var attempt2 = proc.LoadElementDefaults(tmpl);

            Assert.IsFalse(attempt2);
        }
        public void Should_remove_all_default_attributes_and_elements()
        {
            var proc = new XamlPostProcessor();

            proc.LoadElementDefaults(XAMLTests.Button_Defaults);
            proc.LoadElementDefaults(XAMLTests.Button_Page_Defaults);
            proc.LoadDocument(XAMLTests.Button_Page);

            var doc  = proc.Process();
            var root = GetRoot(doc);
            var e1   = root.Elements().FirstOrDefault();

            Assert.AreEqual("ContentPage", root.Name.LocalName);
            Assert.IsTrue(e1?.IsEmpty);
        }
Exemple #5
0
        public void Should_not_load_empty_template()
        {
            var proc   = new XamlPostProcessor();
            var loaded = proc.LoadElementDefaults(string.Empty);

            Assert.IsFalse(loaded);
        }
Exemple #6
0
        public void Should_load_simple_template()
        {
            var proc   = new XamlPostProcessor();
            var loaded = proc.LoadElementDefaults("<test a='b' />");

            Assert.IsTrue(loaded);

            var el = proc.GetElementDefaults(XName.Get("test"));

            Assert.IsTrue(el.Name == "test");
        }
        public void Should_retain_attached_property_in_original_and_not_in_modified_version()
        {
            var xtr = new XamlTreeReader(XAMLTests.AP_Test1_Page);

            xtr.Read();

            var proc = new XamlPostProcessor();

            proc.LoadElementDefaults(XAMLTests.AP_Test1_Entry_Defaults);
            proc.LoadElementDefaults(XAMLTests.AP_Test1_Page_Default);
            proc.LoadDocument(XAMLTests.AP_Test1_Page_Modified, xtr.All);

            var doc = proc.Process();
            var els = doc.Descendants().ToArray();

            var ap1 = els[1].Attributes().FirstOrDefault(a => a.Name.LocalName == "AP.Test1");
            var ap2 = els[2].Attributes().FirstOrDefault(a => a.Name.LocalName == "AP.Test1");

            Assert.AreEqual("165", ap1.Value);
            Assert.IsNull(ap2);
        }
        public void Should_only_detect_changes()
        {
            var proc = new XamlPostProcessor();

            proc.LoadElementDefaults(XAMLTests.Entry_Defaults);
            proc.LoadElementDefaults(XAMLTests.Entry_Page_Defaults);
            proc.LoadDocument(XAMLTests.Entry_Page);

            var doc     = proc.Process();
            var root    = GetRoot(doc);
            var entry   = root.Elements().First();
            var attribs = entry.Attributes().ToArray();

            var isEnabled   = GetAttribute(attribs, "IsEnabled");
            var margin      = GetAttribute(attribs, "Margin");
            var placeholder = GetAttribute(attribs, "Placeholder");

            Assert.AreEqual(5, attribs.Length);

            Assert.AreEqual("False", isEnabled.Value);
            Assert.AreEqual("30", margin.Value);
            Assert.AreEqual("Test", placeholder.Value);
        }