示例#1
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);
                }
            }
        }
示例#2
0
        public void Should_set_single_enum_property()
        {
            var stack = new StackLayout();
            var label = new Label {
                HorizontalTextAlignment = TextAlignment.Center
            };

            stack.Children.Add(label);

            var page = new ContentPage
            {
                Content = stack
            };

            // change from Center to End
            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.Path     = new[] { "HorizontalTextAlignment" };
                r.WidgetId = label.Id.ToString();
                r.Value    = "End";
            });

            Assert.AreEqual(TextAlignment.Center, label.HorizontalTextAlignment);

            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual(TextAlignment.End, label.HorizontalTextAlignment);
        }
示例#3
0
        public static void SetupDesignSurface(Page page)
        {
            XamarinFormsTypeConverters.EnhancedXamlConfiguration.Initialize();

            Reaction.Reset();
            Reaction.GetServices = obj => App.Kernel.Inject(obj);
            Reaction.Register <SupportedTypesRequest, SupportedTypesReaction>();

            XamarinFormsReaction.Register <GetVisualTreeRequest, GetVisualTreeReaction <VisualElement> >(page);
            XamarinFormsReaction.Register <CreateWidgetRequest, CreateWidgetReaction>(page);
            XamarinFormsReaction.Register <GetObjectRequest, GetObjectReaction <VisualElement> >(page);
            XamarinFormsReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction <VisualElement> >(page);
            XamarinFormsReaction.Register <EditCollectionRequest, EditCollectionReaction>(page);
            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            XamarinFormsReaction.Register <DeleteWidgetRequest, DeleteWidgetReaction>(page);
            XamarinFormsReaction.Register <OpenXamlRequest, OpenXamlReaction>(page);
            XamarinFormsReaction.Register <GetWidgetEventsRequest, GetWidgetEventsReaction>(page);
            XamarinFormsReaction.Register <LoadEventsRequest, LoadEventsReaction>(page);
            XamarinFormsReaction.Register <LoadProjectRequest, LoadProjectReaction>(page);
            XamarinFormsReaction.Register <CreateStackLayoutRequest, CreateStackLayoutReaction>(page);
            XamarinFormsReaction.Register <CreateGridRequest, CreateGridReaction>(page);
            XamarinFormsReaction.Register <GetConstructorsRequest, GetConstructorsReaction <VisualElement> >(page);
            XamarinFormsReaction.Register <CallConstructorRequest, CallConstructorReaction>(page);
            XamarinFormsReaction.Register <GetAttachedPropertiesRequest, GetAttachedPropertiesReaction>(page);
            XamarinFormsReaction.Register <SaveXamlRequest, SaveXamlReaction>(page);
            XamarinFormsReaction.Register <GetDesignSurfaceXamlRequest, GetDesignSurfaceXamlReaction>(page);
            XamarinFormsReaction.Register <NewPageRequest, NewPageReaction>(page);
            XamarinFormsReaction.Register <AddSupportedTypeRequest, AddSupportedTypesReaction>(page);
        }
示例#4
0
        public void Should_set_struct_value_by_using_staticfield_name()
        {
            // Ex: LayoutOptions.End to LayoutOptions.StartAndExpand

            var label = new Label
            {
                VerticalOptions = LayoutOptions.End
            };

            var page = new ContentPage
            {
                Content = label
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.WidgetId = label.Id.ToString();
                r.Path     = new [] { "VerticalOptions" };
                r.Value    = "StartAndExpand";
            });

            Assert.IsTrue(label.VerticalOptions.Expands == false &&
                          label.VerticalOptions.Alignment == LayoutAlignment.End);

            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual(label.VerticalOptions, LayoutOptions.StartAndExpand);
        }
示例#5
0
        public void Should_set_widget_double_property()
        {
            var stack = new StackLayout();
            var label = new Label {
                HeightRequest = 50
            };

            stack.Children.Add(label);

            var page = new ContentPage
            {
                Content = stack
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.Path     = new [] { "HeightRequest" };
                r.WidgetId = label.Id.ToString();
                r.Value    = 100;
            });

            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual(100, label.HeightRequest);
        }
示例#6
0
        public void Should_set_subobj_property_subobj_is_struct_and_readwrite()
        {
            var fake = new FakeStruct {
                Name = "Old Value"
            };
            var view = new ViewHasSubProps
            {
                FakeVal = fake
            };

            var page = new ContentPage
            {
                Content = view
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.WidgetId = view.Id.ToString();
                r.Path     = new[] { "FakeVal", "Name" };
                r.Value    = "A New Value";
            });

            Assert.AreEqual("Old Value", fake.Name);
            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual("A New Value", view.FakeVal.Name);
        }
示例#7
0
        public void Should_set_Image_Source_property()
        {
            var image = new Image {
                Source = null
            };
            var page = new ContentPage
            {
                Content = image
            };

            byte[] buffer;
            using (var ms = new MemoryStream())
            {
                ImageSourceTest.applogo.Save(ms, ImageFormat.Png);
                buffer = ms.ToArray();
            }

            var b64 = Convert.ToBase64String(buffer);

            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.Path     = new [] { "Source" };
                r.WidgetId = image.Id.ToString();
                r.Value    = b64;
                r.IsBase64 = true;
            });

            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.IsNotNull(image.Source);
        }
示例#8
0
        public void Should_set_color_property()
        {
            var stack = new StackLayout();
            var label = new Label {
                TextColor = Color.Black
            };

            stack.Children.Add(label);

            var page = new ContentPage
            {
                Content = stack
            };

            var json = JsonConvert.SerializeObject(Color.Red);

            // change from None to Bold | Italic
            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.Path     = new [] { "TextColor" };
                r.WidgetId = label.Id.ToString();
                r.Value    = json;
            });

            Assert.AreEqual(Color.Black, label.TextColor);

            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual(Color.Red, label.TextColor);
        }
示例#9
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);
        }
示例#10
0
        public void Color_test()
        {
            Tr.SetTypes(typeof(Color));

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

            var page = new ContentPage
            {
                Content = label
            };

            var ctx = new XenMessageContext();

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

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

            var res = ctx.Get <GetWidgetPropertiesResponse>();
            var p   = res.Properties.First(f => f.PropertyName == "BackgroundColor");
        }
示例#11
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]);
            }
        }
示例#12
0
        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 XenMessageContext();

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

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

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

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

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

            Assert.AreEqual(alignmentProp?.Value, "Fill");
            CollectionAssert.IsNotEmpty(alignmentProp?.XenType.PossibleValues);
        }
示例#13
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 XenMessageContext();

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

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

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

            var prop = res.Property;

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

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

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

            Assert.IsNotNull(xProp);
            Assert.AreEqual(xProp.XenType.FullName, typeof(double).FullName);
        }
示例#14
0
        public void Should_set_flag_enum_property()
        {
            var stack = new StackLayout();
            var label = new Label {
                FontAttributes = FontAttributes.None
            };

            stack.Children.Add(label);

            var page = new ContentPage
            {
                Content = stack
            };

            // change from None to Bold | Italic
            var ctx = new XenMessageContext();

            ctx.SetRequest <SetPropertyRequest>(r =>
            {
                r.Path     = new [] { "FontAttributes" };
                r.WidgetId = label.Id.ToString();
                r.Value    = "Bold | Italic";
            });

            Assert.AreEqual(FontAttributes.None, label.FontAttributes);

            XamarinFormsReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual(FontAttributes.Bold | FontAttributes.Italic, label.FontAttributes);
        }
示例#15
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);
        }
示例#16
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);
        }
示例#17
0
        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 XenMessageContext();

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

            XamarinFormsReaction.Register <GetObjectRequest, GetObjectReaction <VisualElement> >(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.XenType.Descriptor.HasFlag(XenPropertyDescriptors.ValueType));
        }
示例#18
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);
        }
示例#19
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 XenMessageContext();

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

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

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

            Assert.IsFalse(prop.XenType.IsNullable);
            Assert.IsNotNull(prop.Value);
        }
示例#20
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);
        }
        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.");
        }
        public void Attach_button_to_grid_and_not_set_row_and_col()
        {
            var grid = new Grid();
            var page = new ContentPage
            {
                Title   = "Testing create button action",
                Content = grid
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <CreateWidgetRequest>(r =>
            {
                r.ParentId = grid.Id.ToString();
                r.TypeName = "Xamarin.Forms.Button";
            });

            XamarinFormsReaction.Register <CreateWidgetRequest, CreateWidgetReaction>(page);
            Reaction.Execute(ctx);

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

            Assert.IsNotNull(response, "Response should not be null.");
            Assert.IsTrue(response.Parent.Type == nameof(Grid), "Expected type to be grid.");
            Assert.IsTrue(response.Widget.Type == nameof(Button), "Expected type to be button.");
            Assert.IsTrue(response.Parent.Children[0].Type == nameof(Button), "Expected child to be button.");
        }
        public void Should_return_property_types_and_names()
        {
            const string requestedType = "System.Guid";

            Tr.Types = new HashSet <XenType>(new[]
            {
                new XenType
                {
                    FullName = requestedType
                }
            });

            var entry = new Entry();
            var page  = new ContentPage
            {
                Content = entry
            };

            var ctx = new XenMessageContext();

            ctx.SetRequest <GetWidgetPropertiesRequest>(r =>
            {
                r.WidgetId = entry.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("Id"));

            Assert.IsNotNull(property, "Id property should have been found.");
            Assert.AreEqual(property.XenType.FullName, typeof(Guid).FullName);
            Assert.IsNotNull(property.Value, "Value should have been set.");
        }
        public void Should_return_properties_for_entry()
        {
            Tr.Types = new HashSet <XenType>(new[]
            {
                new XenType
                {
                    FullName = "System.String"
                }
            });

            var entry = new Entry();
            var page  = new ContentPage
            {
                Content = entry
            };

            var ctx = new XenMessageContext();

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

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

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

            Assert.IsTrue(response.Properties.Any(), "Expected properties.");
        }
        public void Should_not_return_value_for_UserObjects()
        {
            Tr.Types = new HashSet <XenType>(new[]
            {
                new XenType
                {
                    FullName = "System.String",
                },
                new XenType
                {
                    FullName = "System.Boolean"
                },
                new XenType
                {
                    FullName = "Xamarin.Forms.Rectangle"
                },
                new XenType
                {
                    FullName = "Xamarin.Forms.Font"
                }
            });

            var label = new Label
            {
                Text = "My Label"
            };

            var page = new ContentPage
            {
                Content = label
            };

            var ctx = new XenMessageContext();

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

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

            var response = ctx.Get <GetWidgetPropertiesResponse>();
            var pBounds  = response.Properties.First(p => p.PropertyName == "Bounds");

            Assert.IsNull(pBounds.Value);
            Assert.IsTrue(pBounds.XenType.Descriptor == XenPropertyDescriptors.ValueType);

            var pFont = response.Properties.First(p => p.PropertyName == "Font");

            Assert.IsNull(pFont.Value);
            Assert.IsTrue(pFont.XenType.Descriptor == XenPropertyDescriptors.ValueType);

            var pLabel = response.Properties.FirstOrDefault(p => p.PropertyName == "Text");

            Assert.IsNotNull(pLabel?.Value);
            Assert.IsTrue(pLabel.XenType.Descriptor != XenPropertyDescriptors.ValueType);
        }
示例#26
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);
            }
        }
示例#27
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_mark_getter_properties_only_as_readonly()
        {
            Tr.Types = new HashSet <XenType>(new[]
            {
                new XenType
                {
                    Descriptor = XenPropertyDescriptors.None,
                    FullName   = "System.String",
                },
                new XenType
                {
                    Descriptor = XenPropertyDescriptors.None,
                    FullName   = "System.Boolean"
                },
                new XenType
                {
                    Descriptor = XenPropertyDescriptors.None,
                    FullName   = "Xamarin.Forms.Rectangle"
                }
            });

            var label = new Label
            {
                Text = "My Label"
            };

            var page = new ContentPage
            {
                Content = label
            };

            var ctx = new XenMessageContext();

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

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

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

            Assert.IsTrue(response.Properties.Any(), "Expected properties.");

            var focused = response.Properties.FirstOrDefault(p => p.PropertyName == "IsFocused");

            Assert.IsFalse(focused?.CanWrite, "IsFocus is readonly");
        }
        public void Should_filter_unsupported_types()
        {
            const string requestedType = "System.String";

            Tr.Types = new HashSet <XenType>(new[]
            {
                new XenType
                {
                    Descriptor = XenPropertyDescriptors.None,
                    FullName   = requestedType
                }
            });

            var entry = new Entry();
            var page  = new ContentPage
            {
                Content = entry
            };

            var ctx = new XenMessageContext();

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


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

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

            Assert.IsNotNull(response, "Response should not be null.");
            Assert.IsNotNull(response.Widget, "Widget should not be null.");

            if (response.Properties != null)
            {
                foreach (var property in response.Properties)
                {
                    if (!property.XenType.FullName.Equals(requestedType, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Assert.Fail($"Expected {requestedType}, but {property.XenType.FullName} was returned.");
                    }
                }

                Assert.IsNotNull(response.Properties.First(p => p.PropertyName == "Text"), "The text property was not found.");
            }
        }
示例#30
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);
        }