Example #1
0
        public void Should_return_parents_attached_properties()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());
            Tr.SetTypes(typeof(BindableProperty));

            var label1 = new Label();
            var label2 = new Label();
            var grid   = new Grid();

            grid.ColumnDefinitions = new ColumnDefinitionCollection
            {
                new ColumnDefinition {
                    Width = new GridLength(10, GridUnitType.Absolute)
                },
                new ColumnDefinition {
                    Width = new GridLength(20, GridUnitType.Absolute)
                },
            };

            grid.RowDefinitions = new RowDefinitionCollection
            {
                new RowDefinition {
                    Height = new GridLength(30, GridUnitType.Absolute)
                },
                new RowDefinition {
                    Height = new GridLength(40, GridUnitType.Absolute)
                },
            };

            grid.Children.Add(label1);
            grid.Children.Add(label2);

            Grid.SetRow(label1, 5);
            Grid.SetColumn(label1, 6);

            var page = new ContentPage
            {
                Content = grid
            };

            var id  = label1.Id.ToString();
            var ctx = new XenMessageContext();

            ctx.SetRequest <GetAttachedPropertiesRequest>(req =>
            {
                req.WidgetId = id;
            });

            XamarinFormsReaction.Register <GetAttachedPropertiesRequest, GetAttachedPropertiesReaction>(page);
            Reaction.Execute(ctx);

            var res = ctx.Get <GetAttachedPropertiesResponse>();
            var ap1 = res.Widget.AttachedProperties.First(p => p.Path[0] == "RowProperty");
            var ap2 = res.Widget.AttachedProperties.First(p => p.Path[0] == "ColumnProperty");

            Assert.AreEqual(4, res.Widget.AttachedProperties.Count);
            Assert.AreEqual(5, ap1.Value);
            Assert.AreEqual(6, ap2.Value);
        }
Example #2
0
        public void Should_not_repeat_attached_properties_when_theyre_nested()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());
            Tr.SetTypes(typeof(BindableProperty));

            var label  = new Label();
            var first  = new Grid();
            var second = new Grid();
            var id     = label.Id.ToString();

            first.Children.Add(second);
            second.Children.Add(label);
            Grid.SetRow(label, 5);

            var page = new ContentPage
            {
                Content = first
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <GetAttachedPropertiesRequest>(req =>
            {
                req.WidgetId = id;
            });

            XamarinFormsReaction.Register <GetAttachedPropertiesRequest, GetAttachedPropertiesReaction>(page);
            Reaction.Execute(ctx);

            var res = ctx.Get <GetAttachedPropertiesResponse>();
            var row = res.Widget.AttachedProperties.First(f => f.XamlPropertyName == "Grid.Row");

            Assert.AreEqual(5, row.Value);
        }
Example #3
0
        public void Should_return_Guid_as_string()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());
            Tr.SetTypes(typeof(Guid));

            var label = new Label();
            var page  = new ContentPage
            {
                Content = label
            };

            var ctx = new UIMessageContext();

            ctx.SetRequest <GetWidgetPropertiesRequest>(req =>
            {
                req.WidgetId = label.Id.ToString();
            });

            InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(page);
            Reaction.Execute(ctx);

            var res  = ctx.Get <GetWidgetPropertiesResponse>();
            var prop = res.Properties[0];

            Assert.IsFalse(prop.UIType.IsNullable);
            Assert.IsNotNull(prop.Value);
        }
Example #4
0
        public void Add_nongeneric_collection()
        {
            var grid = new Grid();
            var page = new ContentPage
            {
                Content = grid
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <EditCollectionRequest>(r =>
            {
                r.Type     = EditCollectionType.Add;
                r.Path     = new[] { "ColumnDefinitions" };
                r.WidgetId = grid.Id.ToString();
            });

            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());

            Assert.IsEmpty(grid.ColumnDefinitions);

            XamarinFormsReaction.Register <EditCollectionRequest, EditCollectionReaction>(page);
            Reaction.Execute(ctx);

            Assert.IsNotEmpty(grid.ColumnDefinitions);

            var response = ctx.Get <EditCollectionResponse>();

            Assert.IsTrue(response.Successful);
            Assert.AreEqual(EditCollectionType.Add, response.Type);
        }
        public void Should_return_LayoutOption_property_and_possible_values()
        {
            Tr.SetTypes(typeof(LayoutOptions));
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());

            var label = new Label();
            var page  = new ContentPage {
                Content = label
            };

            var ctx = new UIMessageContext();

            ctx.SetRequest <GetObjectRequest>(req =>
            {
                req.Path     = new [] { "HorizontalOptions" };
                req.WidgetId = label.Id.ToString();
            });

            InspectorReaction.Register <GetObjectRequest, GetObjectReaction>(page);
            Reaction.Execute(ctx);

            var res = ctx.Get <ObjectResponse>();
            var p   = res.Property;

            Assert.AreEqual(p.PropertyName, "HorizontalOptions");
            Assert.IsTrue(p.UIType.Descriptor.HasFlag(UIPropertyDescriptors.ValueType | UIPropertyDescriptors.Literals));
            Assert.AreEqual(8, p.UIType.PossibleValues.Length);
            Assert.IsAssignableFrom <UIProperty[]>(p.Value);

            var alignmentProp = (p.Value as UIProperty[])?[0];

            Assert.AreEqual(alignmentProp?.Value, "Fill");
            CollectionAssert.IsNotEmpty(alignmentProp?.UIType.PossibleValues);
        }
Example #6
0
        public void Should_return_property_types_and_names()
        {
            Tr.SetTypes(typeof(Enum));

            var label = new Label();
            var page  = new ContentPage
            {
                Content = label
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <GetWidgetPropertiesRequest>(r =>
            {
                r.WidgetId = label.Id.ToString();
            });

            Dr.Add(typeof(Enum), new EnumGenerator());
            XamarinFormsReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction <VisualElement> >(page);
            Reaction.Execute(ctx);

            var response = ctx.Get <GetWidgetPropertiesResponse>();

            var property = response?.Properties.FirstOrDefault(p => p.PropertyName.Equals("HorizontalTextAlignment"));

            Assert.IsNotNull(property, "Property not found.");

            Assert.AreEqual(property.Value, TextAlignment.Start.ToString());
            Assert.AreEqual(property.XenType.Descriptor, XenPropertyDescriptors.Literals);

            // if this occurs, types will not be selected correctly by the toolbox
            Assert.IsFalse(property.XenType.Descriptor.HasFlag(XenPropertyDescriptors.ValueType));
            CollectionAssert.IsNotEmpty(property.XenType.PossibleValues);
        }
Example #7
0
        public void Should_respond_with_GridLength_type_with_two_constructors()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());
            Tr.SetTypes(typeof(GridLength));

            var page = new ContentPage();
            var ctx  = new XenMessageContext();

            var typeName = typeof(GridLength).FullName;

            ctx.SetRequest <GetConstructorsRequest>(req =>
            {
                req.TypeName = typeName;
            });

            XamarinFormsReaction.Register <GetConstructorsRequest, GetConstructorsReaction <VisualElement> >(page);
            Reaction.Execute(ctx);

            var res = ctx.Get <GetConstructorsResponse>();

            Assert.IsNotNull(res.Type);
            Assert.AreEqual(typeName, res.Type.FullName);
            Assert.AreEqual(2, res.Type.Constructors.Length);

            foreach (var ctor in res.Type.Constructors)
            {
                foreach (var p in ctor.Parameters)
                {
                    Assert.IsNotEmpty(p.XenType.PossibleValues);
                    Assert.AreEqual(p.TypeName, p.XenType.FullName);
                }
            }
        }
Example #8
0
        public void Should_return_collection_values()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());

            Tr.SetTypes(typeof(GridLength),
                        typeof(RowDefinitionCollection),
                        typeof(ColumnDefinitionCollection));

            var grid = new Grid
            {
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition {
                        Width = new GridLength(2)
                    }
                },

                RowDefinitions = new RowDefinitionCollection()
            };

            var page = new ContentPage
            {
                Content = grid
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <GetObjectRequest>(r =>
            {
                r.Path     = new[] { "ColumnDefinitions[0]" };
                r.WidgetId = grid.Id.ToString();
            });

            XamarinFormsReaction.Register <GetObjectRequest, GetObjectReaction <VisualElement> >(page);
            Reaction.Execute(ctx);

            var resp = ctx.Get <ObjectResponse>();
            var val  = resp.Property.Value as ICollection <XenProperty>;

            Assert.AreEqual(0, resp.Property.ItemIndex);
            CollectionAssert.IsNotEmpty(val);

            var v = val?.ElementAt(0);

            // ReSharper disable once PossibleNullReferenceException
            Assert.IsNull(v.Value);
            Assert.AreEqual("Width", v.PropertyName);
            Assert.AreEqual("ColumnDefinitions[0]", v.Path[0]);
            Assert.AreEqual("Width", v.Path[1]);
        }
        public void Should_return_multiple_values()
        {
            Tr.SetTypes(typeof(Enum));

            var label = new Label
            {
                FontAttributes = FontAttributes.Bold | FontAttributes.Italic
            };

            var page = new ContentPage
            {
                Content = label
            };

            var ctx = new UIMessageContext();

            ctx.SetRequest <GetWidgetPropertiesRequest>(r =>
            {
                r.WidgetId = label.Id.ToString();
            });

            Dr.Add(typeof(Enum), new EnumGenerator());
            InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(page);
            Reaction.Execute(ctx);

            var response = ctx.Get <GetWidgetPropertiesResponse>();

            var property = response?.Properties.FirstOrDefault(p => p.PropertyName.Equals("FontAttributes"));

            Assert.IsNotNull(property, "Property not found.");

            Assert.AreEqual(property.Value, TextAlignment.Start.ToString());
            Assert.AreEqual(property.UIType.Descriptor, UIPropertyDescriptors.Literals);

            // if this occurs, types will not be selected correctly by the client
            Assert.IsFalse(property.UIType.Descriptor.HasFlag(UIPropertyDescriptors.ValueType));
            CollectionAssert.IsNotEmpty(property.UIType.PossibleValues);
        }
Example #10
0
        public void Should_get_nchar()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());
            Tr.SetTypes(typeof(Guid), typeof(char?));

            var page = new PageWithPrimitives();
            var ctx  = new UIMessageContext();

            ctx.SetRequest <GetWidgetPropertiesRequest>(req =>
            {
                req.WidgetId = page.Id.ToString();
            });

            InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(page);
            Reaction.Execute(ctx);

            var res  = ctx.Get <GetWidgetPropertiesResponse>();
            var type = res.Properties[0].UIType;

            Assert.IsTrue(type.IsNullable);
            Assert.AreEqual("Char?", type.ShortName);
        }
Example #11
0
        public void Should_get_nint()
        {
            Dr.Add(typeof(ValueType), new StaticGenerator());
            Dr.Add(typeof(Enum), new EnumGenerator());
            Tr.SetTypes(typeof(Guid), typeof(int?));

            var page = new PageWithPrimitives();
            var ctx  = new XenMessageContext();

            ctx.SetRequest <GetWidgetPropertiesRequest>(req =>
            {
                req.WidgetId = page.Id.ToString();
            });

            XamarinFormsReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction <VisualElement> >(page);
            Reaction.Execute(ctx);

            var res  = ctx.Get <GetWidgetPropertiesResponse>();
            var type = res.Properties[0].XenType;

            Assert.IsTrue(type.IsNullable);
            Assert.AreEqual("Int32?", type.ShortName);
        }