public void Should_strip_multiple_object_references_from_document() { const string tmpl1 = "<tmpl0 Parent='{x:Reference __ReferenceID1}'><Reference>__ReferenceID1</Reference></tmpl0>"; var doc1 = XDocument.Parse(tmpl1); var proc = new XamlPostProcessor(); var ran = proc.ForAllElements(doc1.Descendants(), e => proc.StripObjectReferences(e)); Assert.IsTrue(ran); var root = doc1.Document.Root; Assert.IsFalse(root.HasAttributes); Assert.IsTrue(root.IsEmpty); }
public void Should_strip_object_references_everywhere() { const string tmpl1 = "<tmpl1 Assoc='{x:Reference __ReferenceID1}' />"; var e1 = XElement.Parse(tmpl1); const string tmpl2 = "<tmpl1 Assoc='{x:Reference __ReferenceID1}' Children='{x:Reference __ReferenceID1}' />"; var e2 = XElement.Parse(tmpl2); const string tmpl3 = "<tmpl0 Assoc='{x:Reference __ReferenceID1}'><tmpl1 Assoc='{x:Reference __ReferenceID1}' /></tmpl0>"; var e3 = XElement.Parse(tmpl3); const string tmpl4 = "<tmpl0 Assoc='{x:Reference __ReferenceID1}'><Reference>__ReferenceID1</Reference></tmpl0>"; var e4 = XElement.Parse(tmpl4); const string tmpl5 = "<tmpl0 Parent='{x:Reference Obj2}'><Reference>__ReferenceID1</Reference></tmpl0>"; var e5 = XElement.Parse(tmpl5); string tmpl6 = $"<Grid.Parent xmlns:x='{Uri}'><x:Reference>__ReferenceID0</x:Reference></Grid.Parent>"; var e6 = XElement.Parse(tmpl6); var proc = new XamlPostProcessor(); proc.StripObjectReferences(e1); proc.StripObjectReferences(e2); proc.StripObjectReferences(e3); proc.StripObjectReferences(e4); proc.StripObjectReferences(e5); proc.StripObjectReferences(e6); Assert.IsFalse(e1.HasAttributes); Assert.IsFalse(e2.HasAttributes); Assert.IsFalse(e3.HasAttributes); Assert.IsFalse((e3.LastNode as XElement).HasAttributes); Assert.IsFalse(e4.HasAttributes); Assert.IsNull(e4.LastNode); Assert.IsFalse(e5.HasAttributes); Assert.IsTrue(e6.IsEmpty); }