public static void ProvideValueForCollectionItem() { const string NAMESPACE = "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"; var resolver = new MockNameSpaceResolver(); var type = new XmlType(NAMESPACE, "ApplyPropertiesVisitorTests+MarkupExtension", null); var listNode = new ListNode(new[] { new ElementNode(type, NAMESPACE, resolver), new ElementNode(type, NAMESPACE, resolver) }, resolver); var rootElement = new ArrayListOwner(); var rootType = new XmlType(NAMESPACE, "ApplyPropertiesVisitorTests+ArrayListOwner", null); var rootNode = new XamlLoader.RuntimeRootNode(rootType, rootElement, null); var context = new HydrationContext { RootElement = rootElement }; rootNode.Properties.Add(new XmlName(null, "ArrayList"), listNode); rootNode.Accept(new XamlNodeVisitor((node, parent) => node.Parent = parent), null); rootNode.Accept(new CreateValuesVisitor(context), null); rootNode.Accept(new ApplyPropertiesVisitor(context), null); CollectionAssert.AreEqual(new[] { "provided value", "provided value" }, rootElement.ArrayList); }
public void TestFailOnMissingOrWrongConverter() { var node = new ValueNode("baz", new MockNameSpaceResolver()); var bindable = new Bindable(); Assert.IsNull(bindable.Baz); var rootNode = new XamlLoader.RuntimeRootNode(new XmlType("clr-namespace:System.Maui.Xaml.UnitTests;assembly=System.Maui.Xaml.UnitTests", "Bindable", null), bindable, null) { Properties = { { new XmlName(null, "Baz"), node }, } }; var context = new HydrationContext { RootElement = new Label() }; rootNode.Accept(new CreateValuesVisitor(context), null); Assert.Throws <XamlParseException>(() => node.Accept(new ApplyPropertiesVisitor(context), rootNode)); }
public void TestSetPropertyWithoutConverter() { var baz = new Baz(); var node = new ValueNode(baz, new MockNameSpaceResolver()); var bindable = new Bindable(); Assert.IsNull(bindable.Baz); var rootNode = new XamlLoader.RuntimeRootNode(new XmlType("clr-namespace:System.Maui.Xaml.UnitTests;assembly=System.Maui.Xaml.UnitTests", "Bindable", null), bindable, null) { Properties = { { new XmlName(null, "Baz"), node }, } }; var context = new HydrationContext { RootElement = new Label() }; rootNode.Accept(new CreateValuesVisitor(context), null); node.Accept(new ApplyPropertiesVisitor(context), rootNode); Assert.AreEqual(baz, bindable.Baz); }
public void TestConvertAttachedBindableProperty() { var node = new ValueNode("qux", new MockNameSpaceResolver()); var bindable = new Bindable(); Assert.IsNull(Bindable.GetQux(bindable)); var rootNode = new XamlLoader.RuntimeRootNode(new XmlType("clr-namespace:System.Maui.Xaml.UnitTests;assembly=System.Maui.Xaml.UnitTests", "Bindable", null), bindable, null) { Properties = { { new XmlName("clr-namespace:System.Maui.Xaml.UnitTests;assembly=System.Maui.Xaml.UnitTests", "Bindable.Qux"), node }, } }; var context = new HydrationContext { RootElement = new Label() }; rootNode.Accept(new CreateValuesVisitor(context), null); node.Accept(new ApplyPropertiesVisitor(context), rootNode); Assert.IsNotNull(Bindable.GetQux(bindable)); Assert.That(Bindable.GetQux(bindable), Is.TypeOf <Qux>()); Assert.AreEqual("qux", Bindable.GetQux(bindable).Value); }
public void TestConvertBindableProperty() { var node = new ValueNode("bar", new MockNameSpaceResolver()); var bindable = new Bindable(); Assert.IsNull(bindable.Bar); var rootNode = new XamlLoader.RuntimeRootNode(new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests", "Bindable", null), bindable, null) { Properties = { { new XmlName(null, "Bar"), node }, } }; var context = new HydrationContext { RootElement = new Label() }; rootNode.Accept(new CreateValuesVisitor(context), null); node.Accept(new ApplyPropertiesVisitor(context), rootNode); Assert.IsNotNull(bindable.Bar); Assert.That(bindable.Bar, Is.TypeOf <Bar>()); Assert.AreEqual("bar", bindable.Bar.Value); }
public void TestConvertNonBindableProperty() { var node = new ValueNode("foo", new MockNameSpaceResolver()); var bindable = new Bindable(); Assert.IsNull(bindable.Foo); var rootNode = new XamlLoader.RuntimeRootNode(new XmlType("clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests;assembly=Microsoft.Maui.Controls.Xaml.UnitTests", "Bindable", null), bindable, null) { Properties = { { new XmlName(null, "Foo"), node }, } }; var context = new HydrationContext { RootElement = new Label() }; rootNode.Accept(new CreateValuesVisitor(context), null); node.Accept(new ApplyPropertiesVisitor(context), rootNode); Assert.IsNotNull(bindable.Foo); Assert.That(bindable.Foo, Is.TypeOf <Foo>()); Assert.AreEqual("foo", bindable.Foo.Value); }
public void TestConvertWithAttributeOnType () { var node = new ValueNode ("foobar", new MockNameSpaceResolver()); var bindable = new Bindable (); Assert.IsNull (bindable.FooBar); var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable, null) { Properties = { { new XmlName (null, "FooBar"), node }, } }; var context = new HydratationContext { RootElement = new Label () }; rootNode.Accept (new CreateValuesVisitor (context), null); node.Accept (new ApplyPropertiesVisitor (context), rootNode); Assert.IsNotNull (bindable.FooBar); Assert.That (bindable.FooBar, Is.TypeOf<FooBar> ()); Assert.AreEqual ("foobar", bindable.FooBar.Value); }
public void TestConvertAttachedBindableProperty () { var node = new ValueNode ("qux", new MockNameSpaceResolver()); var bindable = new Bindable (); Assert.IsNull (Bindable.GetQux (bindable)); var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable, null) { Properties = { { new XmlName ("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests", "Bindable.Qux"), node }, } }; var context = new HydratationContext { RootElement = new Label () }; rootNode.Accept (new CreateValuesVisitor (context), null); node.Accept (new ApplyPropertiesVisitor (context), rootNode); Assert.IsNotNull (Bindable.GetQux (bindable)); Assert.That (Bindable.GetQux (bindable), Is.TypeOf<Qux> ()); Assert.AreEqual ("qux", Bindable.GetQux (bindable).Value); }
public void TestFailOnMissingOrWrongConverter () { var node = new ValueNode ("baz", new MockNameSpaceResolver()); var bindable = new Bindable (); Assert.IsNull (bindable.Baz); var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable, null) { Properties = { { new XmlName (null, "Baz"), node }, } }; var context = new HydratationContext { RootElement = new Label () }; rootNode.Accept (new CreateValuesVisitor (context), null); Assert.Throws<XamlParseException>(()=> node.Accept (new ApplyPropertiesVisitor (context), rootNode)); }
public void TestSetPropertyWithoutConverter () { var baz = new Baz (); var node = new ValueNode (baz, new MockNameSpaceResolver()); var bindable = new Bindable (); Assert.IsNull (bindable.Baz); var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable, null) { Properties = { { new XmlName (null, "Baz"), node }, } }; var context = new HydratationContext { RootElement = new Label () }; rootNode.Accept (new CreateValuesVisitor(context), null); node.Accept (new ApplyPropertiesVisitor (context), rootNode); Assert.AreEqual (baz, bindable.Baz); }