示例#1
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);
        }
示例#2
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);
                }
            }
        }
        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);
        }
示例#4
0
        public void Empty_collections()
        {
            Tr.SetTypes(typeof(RowDefinitionCollection), typeof(ColumnDefinitionCollection));

            var grid = new Grid
            {
                ColumnDefinitions = new ColumnDefinitionCollection(),
                RowDefinitions    = new RowDefinitionCollection()
            };

            var page = new ContentPage
            {
                Content = grid
            };

            var ctx = new XenMessageContext();

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

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

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

            foreach (var p in response.Properties)
            {
                var pv = p.XenType.PossibleValues;
                CollectionAssert.IsNotEmpty(pv);
                Assert.AreEqual("0", pv[0]);
            }
        }
示例#5
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);
        }
        public void Private_setters_should_return_struct_as_readonly()
        {
            Tr.SetTypes(typeof(Rectangle));

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

            var ctx = new UIMessageContext();

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

            InspectorReaction.Register <GetObjectRequest, GetObjectReaction>(page);
            Reaction.Execute(ctx);
            var res = ctx.Get <ObjectResponse>();

            var prop = res.Property;

            Assert.AreEqual(prop.PropertyName, "Bounds");

            Assert.IsFalse(prop.CanWrite);
            Assert.IsTrue(prop.UIType.Descriptor.HasFlag(UIPropertyDescriptors.ValueType));
        }
示例#7
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);
        }
示例#8
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);
        }
        public void Color_test()
        {
            Tr.SetTypes(typeof(Color));

            var label = new Label
            {
                BackgroundColor = Color.Red
            };

            var page = new ContentPage
            {
                Content = label
            };

            var ctx = new UIMessageContext();

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

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

            var res = ctx.Get <GetWidgetPropertiesResponse>();
            var p   = res.Properties.First(f => f.PropertyName == "BackgroundColor");
        }
示例#10
0
        public void Should_return_public_properties_of_Bounds_type()
        {
            Tr.SetTypes(typeof(Rectangle));

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

            var ctx = new UIMessageContext();

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

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

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

            var prop = res.Property;

            Assert.AreEqual(prop.PropertyName, "Bounds");

            Assert.IsAssignableFrom <UIProperty[]>(prop.Value);

            var boundProps = (UIProperty[])prop.Value;
            var xProp      = boundProps.FirstOrDefault(b => b.PropertyName == "X");

            Assert.IsNotNull(xProp);
            Assert.AreEqual(xProp.UIType.FullName, typeof(double).FullName);
        }
        public void Should_return_properties_for_ContentPage()
        {
            Tr.SetTypes(typeof(String));

            var page = new ContentPage
            {
                Title   = "Important",
                Content = new Label {
                    Text = "Does Nothing"
                }
            };

            var ctx = new XenMessageContext();

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

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

            var response = ctx.Get <GetWidgetPropertiesResponse>();
            var property = response?.Properties.FirstOrDefault(p => p.PropertyName.Equals("Title"));

            Assert.IsNotNull(property, "Title property should have been found.");
            Assert.AreEqual(property.XenType.FullName, typeof(String).FullName);
            Assert.IsNotNull(property.Value, "Value should have been set.");
        }
示例#12
0
        public void Test_accessing_out_of_bound_element()
        {
            Tr.SetTypes(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[1]" };
                r.WidgetId = grid.Id.ToString();
            });

            XamarinFormsReaction.Register <GetObjectRequest, GetObjectReaction <VisualElement> >(page);
            Reaction.Execute(ctx);
            Assert.IsNull(ctx.Response);
        }
示例#13
0
        public void Null_collections()
        {
            Tr.SetTypes(typeof(IEnumerable <object>), typeof(ICollection <string>), typeof(IList <int>));

            var view = new NullCollectionView
            {
                Enumerable = null,
                Collection = null,
                List       = null
            };

            var page = new ContentPage
            {
                Content = view
            };

            var ctx = new XenMessageContext();

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

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

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

            foreach (var p in response.Properties)
            {
                var d = p.XenType.Descriptor;

                if (p.PropertyName == "Enumerable")
                {
                    Assert.AreEqual(d, XenPropertyDescriptors.Enumerable);
                }

                if (p.PropertyName == "Collection")
                {
                    Assert.AreEqual(d, XenPropertyDescriptors.Enumerable | XenPropertyDescriptors.Collection);
                }

                if (p.PropertyName == "List")
                {
                    Assert.AreEqual(d, XenPropertyDescriptors.Enumerable
                                    | XenPropertyDescriptors.Collection
                                    | XenPropertyDescriptors.List);
                }

                Assert.IsNull(p.XenType.PossibleValues);
            }
        }
示例#14
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]);
        }
示例#15
0
        public void Return_object_properties_from_a_collection_property_of_a_view()
        {
            var path = new[] { "ColumnDefinitions[0]", "Width" };

            Tr.SetTypes(typeof(GridLength), 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     = path;
                r.WidgetId = grid.Id.ToString();
            });

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

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

            Assert.IsNotNull(v);
            CollectionAssert.IsNotEmpty(v);
            Assert.AreEqual(path, res.Property.Path);

            var widthProp = v.First(i => i.PropertyName == "Value");

            Assert.AreEqual("2", widthProp.Value);
            Assert.AreEqual(path.Union(new[] { "Value" }), widthProp.Path);
        }
示例#16
0
        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);
        }
示例#17
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);
        }
示例#18
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);
        }
示例#19
0
        public void Enumerable_collection_and_list_interfaces_found()
        {
            Tr.SetTypes(typeof(GridLength), typeof(RowDefinitionCollection),
                        typeof(ColumnDefinitionCollection), typeof(RowDefinition), typeof(ColumnDefinition));

            var grid = new Grid
            {
                ColumnDefinitions =
                {
                    // 3 columns required for test
                    new ColumnDefinition {
                        Width = new GridLength(50, GridUnitType.Absolute)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(25, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(25, GridUnitType.Auto)
                    },
                },

                RowDefinitions =
                {
                    // 3 rows required for test
                    new RowDefinition {
                        Height = new GridLength(100)
                    },
                    new RowDefinition {
                        Height = new GridLength(100, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = new GridLength(100, GridUnitType.Star)
                    },
                }
            };

            var page = new ContentPage
            {
                Content = grid
            };

            var ctx = new XenMessageContext();

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

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

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

            foreach (var p in response.Properties)
            {
                var pv = p.XenType.PossibleValues;
                var d  = p.XenType.Descriptor;

                CollectionAssert.IsNotEmpty(pv);
                Assert.AreEqual(1, pv.Length);
                Assert.AreEqual("3", pv[0]);

                Assert.IsNull(p.Value);

                Assert.IsTrue
                (
                    d.HasFlag(XenPropertyDescriptors.Enumerable) &&
                    d.HasFlag(XenPropertyDescriptors.Collection) &&
                    d.HasFlag(XenPropertyDescriptors.List)
                );
            }
        }