Пример #1
0
        public void Should_set_subobj_property_subobj_is_class_and_readwrite()
        {
            var fake = new FakeClass {
                Name = "Empty"
            };
            var view = new ViewHasSubProps
            {
                FakeRef = fake
            };

            var page = new ContentPage
            {
                Content = view
            };

            var ctx = new XenMessageContext();

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

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

            Assert.AreEqual("New Value", fake.Name);
        }
Пример #2
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 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));
        }
Пример #3
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]);
            }
        }
Пример #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);
        }
Пример #5
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);
        }
        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.");
        }
Пример #7
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);
        }
Пример #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 Should_serialize_BindingContext()
        {
            var ctx = new UIMessageContext();

            var value = new MyBindingType
            {
                Value = "test123"
            };

            var label = new Label
            {
                BindingContext = value
            };

            var page = new ContentPage
            {
                Content = label
            };

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

            InspectorReaction.Register <GetBindingContextRequest, GetBindingContextReaction>(page);
            Reaction.Execute(ctx);

            var res = ctx.Response as GetBindingContextResponse;

            Assert.IsNotNull(res);
            Assert.AreEqual("{\"Value\":\"test123\",\"Child\":null}", res.Data);
        }
Пример #10
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 UIMessageContext();

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

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

            Assert.AreEqual(100, label.HeightRequest);
        }
Пример #11
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 UIMessageContext();

            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);
            InspectorReaction.Register <SetPropertyRequest, SetPropertyReaction>(page);
            Reaction.Execute(ctx);

            Assert.AreEqual("A New Value", view.FakeVal.Name);
        }
Пример #12
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 UIMessageContext();

            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);

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

            Assert.AreEqual(label.VerticalOptions, LayoutOptions.StartAndExpand);
        }
Пример #13
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 UIMessageContext();

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

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

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

            Assert.AreEqual(Color.Red, label.TextColor);
        }
Пример #14
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 UIMessageContext();

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

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

            Assert.IsNotNull(image.Source);
        }
Пример #15
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 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.");
        }
Пример #17
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 Register_supported_types_when_message_is_received()
        {
            var ctx = new UIMessageContext();

            ctx.SetRequest <SupportedTypesRequest>(r =>
            {
                r.Types = new[]
                {
                    new UIType
                    {
                        Descriptor = UIPropertyDescriptors.None,
                        FullName   = "String"
                    },
                    new UIType
                    {
                        Descriptor = UIPropertyDescriptors.None,
                        FullName   = "Integer"
                    }
                };
            });

            Reaction.Register <SupportedTypesRequest, SupportedTypesReaction>();
            Reaction.Execute(ctx);
            Assert.IsTrue(Tr.Types.Count == 2);
        }
Пример #19
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);
        }
Пример #20
0
        public void Should_set_widget_string_property()
        {
            var stack = new StackLayout();
            var label = new Label {
                Text = "text1"
            };

            stack.Children.Add(label);

            var page = new ContentPage
            {
                Content = stack
            };

            var ctx = new XenMessageContext();

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

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

            Assert.AreEqual("text1 set", label.Text);
        }
Пример #21
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 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);
        }
Пример #22
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 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");
        }
        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.");
        }
Пример #24
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 UIMessageContext();

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

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

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

            Assert.AreEqual(TextAlignment.End, label.HorizontalTextAlignment);
        }
Пример #25
0
        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.");
        }
Пример #26
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);
        }
Пример #27
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 UIMessageContext();

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

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

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

            Assert.AreEqual(FontAttributes.Bold | FontAttributes.Italic, label.FontAttributes);
        }
        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);
        }
Пример #29
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);
            }
        }
Пример #30
0
        public void Test_execute_called_and_no_action_found()
        {
            // Note how FakeCompletedRequest and FakeSimpleRequest are different types
            Reaction.Register <FakeSimpleRequest, FakeAttachReaction>();
            var request = UIMessage.Create <FakeCompletedRequest>();
            var ctx     = new UIMessageContext {
                Request = request
            };

            var handled = Reaction.Execute(ctx);

            Assert.IsFalse(handled);
        }