using NUnit.Framework; using System.Linq; using System; using System.Collections.Generic; using Xamarin.Forms.Core.UnitTests; namespace Xamarin.Forms.Xaml.UnitTests { [ContentProperty ("Content")] public class CustomView : View { public string NotBindable { get; set; } public View Content { get; set; } public MockFlags MockFlags { get; set; } } [ContentProperty ("Children")] public class ViewWithChildrenContent : View { public ViewWithChildrenContent () { Children = DefaultChildren = new ViewList (); } public ViewList DefaultChildren; public ViewList Children { get; set; } } public class ViewList : List { } public class ReverseConverter : IValueConverter { public static ReverseConverter Instance = new ReverseConverter (); public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var s = value as string; if (s == null) return value; return new string (s.Reverse ().ToArray ()); } public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var s = value as string; if (s == null) return value; return new string (s.Reverse ().ToArray ()); } } public class Catalog { public static readonly BindableProperty MessageProperty = #pragma warning disable 618 BindableProperty.CreateAttached (bindable => GetMessage (bindable), default(string), #pragma warning restore 618 propertyChanged: (bindable, oldvalue, newvalue) => { var label = bindable as Label; if (label != null) label.SetValue (Label.TextProperty, new string (newvalue.Reverse ().ToArray ())); }); public static string GetMessage (BindableObject bindable) { return (string)bindable.GetValue (MessageProperty); } public static void SetMessage (BindableObject bindable, string value) { bindable.SetValue (MessageProperty, value); } } [Flags] public enum MockFlags { Foo = 1<<0, Bar = 1<<1, Baz = 1<<2, Qux = 1<<3, } [TestFixture] public class LoaderTests : BaseTestFixture { [Test] public void TestRootName () { var xaml = @" "; var view = new CustomView (); view.LoadFromXaml (xaml); Assert.AreSame (view, ((Forms.Internals.INameScope)view).FindByName("customView")); } [Test] public void TestFindByXName () { var xaml = @" "; var stacklayout = new StackLayout (); stacklayout.LoadFromXaml (xaml); var label = stacklayout.FindByName