public void Should_return_properties_for_entry() { Tr.Types = new HashSet <UIType>(new[] { new UIType { FullName = "System.String" } }); var entry = new Entry(); var page = new ContentPage { Content = entry }; var ctx = new UIMessageContext(); ctx.SetRequest <GetWidgetPropertiesRequest>(r => { r.WidgetId = entry.Id.ToString(); }); InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(page); Reaction.Execute(ctx); var response = ctx.Get <GetWidgetPropertiesResponse>(); Assert.IsTrue(response.Properties.Any(), "Expected properties."); }
protected override void OnExecute(UIMessageContext ctx) { var req = ctx.Get <GetBindingContextRequest>(); if (req == null) { return; } var pair = Surface[req.WidgetId]; if (pair == null) { return; } if (pair.UIWidget.IsDatabound == false) { return; } var data = BindingContextSerializer.SerializeObject(pair.VisualElement.BindingContext, 2); ctx.SetResponse <GetBindingContextResponse>(res => { res.WidgetId = req.WidgetId; res.Data = data; }); }
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 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("HorizontalTextAlignment")); 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); }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <GetWidgetEventsRequest>(); if (request == null) { return; } var pair = Surface[request.WidgetId]; var events = pair? .VisualElement? .GetType() .GetPublicEvents() .Select(UIEvent.Create) .ToArray(); if (events == null) { return; } ctx.SetResponse <GetWidgetEventsResponse>(r => { r.Events = events; r.WidgetId = request.WidgetId; }); }
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 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 UIMessageContext(); ctx.SetRequest <GetWidgetPropertiesRequest>(r => { r.WidgetId = grid.Id.ToString(); }); InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(page); Reaction.Execute(ctx); var response = ctx.Get <GetWidgetPropertiesResponse>(); foreach (var p in response.Properties) { var pv = p.UIType.PossibleValues; CollectionAssert.IsNotEmpty(pv); Assert.AreEqual("0", pv[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); }
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_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 UIMessageContext(); ctx.SetRequest <GetAttachedPropertiesRequest>(req => { req.WidgetId = id; }); InspectorReaction.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); }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <SetDeviceOrientationRequest>(); if (request == null) { return; } DisplayDimensions dims = null; var orientationSvc = InspectorContainer.Current.Resolve <IDeviceOrientation>(); var dimSvc = InspectorContainer.Current.Resolve <IDisplayDimensions>(); Thread.Invoke(() => { orientationSvc.SetOrientation(request.Orientation); dims = dimSvc.GetDimensions(); }); ctx.SetResponse <SetDeviceOrientationResponse>(r => { r.Height = dims.Height; r.Width = dims.Width; }); }
public void Add_nongeneric_collection() { var grid = new Grid(); var page = new ContentPage { Content = grid }; var ctx = new UIMessageContext(); 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); InspectorReaction.Register <EditCollectionRequest, EditCollectionReaction>(page); Reaction.Execute(ctx); Assert.IsNotEmpty(grid.ColumnDefinitions); var response = ctx.Get <EditCollectionResponse>(); Assert.IsTrue(response.Successful); Assert.AreEqual(EditCollectionType.Add, response.Type); }
public void Should_return_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 UIMessageContext(); ctx.SetRequest <GetAttachedPropertiesRequest>(req => { req.WidgetId = id; }); InspectorReaction.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_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 UIMessageContext(); var typeName = typeof(GridLength).FullName; ctx.SetRequest <GetConstructorsRequest>(req => { req.TypeName = typeName; }); InspectorReaction.Register <GetConstructorsRequest, GetConstructorsReaction>(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.UIType.PossibleValues); Assert.AreEqual(p.TypeName, p.UIType.FullName); } } }
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 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 UIMessageContext(); ctx.SetRequest <CreateWidgetRequest>(r => { r.ParentId = grid.Id.ToString(); r.TypeName = "Xamarin.Forms.Button"; }); InspectorReaction.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 <UIType>(new[] { new UIType { FullName = requestedType } }); var entry = new Entry(); var page = new ContentPage { Content = entry }; var ctx = new UIMessageContext(); ctx.SetRequest <GetWidgetPropertiesRequest>(r => { r.WidgetId = entry.Id.ToString(); }); InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(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.UIType.FullName, typeof(Guid).FullName); Assert.IsNotNull(property.Value, "Value should have been set."); }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <GetDisplayDimensionsRequest>(); if (request == null) { return; } var dimensionService = InspectorContainer.Current.Resolve <IDisplayDimensions>(); var dimensions = new DisplayDimensions(); Thread.Invoke(() => { dimensions = dimensionService.GetDimensions(); }); ctx.SetResponse <GetDisplayDimensionsResponse>(r => { r.Density = dimensions.Density; r.Height = dimensions.Height; r.Width = dimensions.Width; r.NavigationBarHeight = dimensions.NavigationBarHeight; r.StatusBarHeight = dimensions.StatusBarHeight; }); }
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 UIMessageContext(); ctx.SetRequest <GetWidgetPropertiesRequest>(r => { r.WidgetId = page.Id.ToString(); }); InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(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.UIType.FullName, typeof(String).FullName); Assert.IsNotNull(property.Value, "Value should have been set."); }
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)); }
protected override void OnExecute(UIMessageContext ctx) { var req = ctx.Get <AddSupportedTypeRequest>(); if (req == null) { return; } var res = UIMessage.Create <AddSupportedTypeResponse>(); try { if (TypeRegistrar.Instance.IsRegistered(req.Type)) { res.AlreadyRegistered = true; res.DisplayMessage = $"The type '{req.Type.FullName} is already registered."; } else { if (!string.IsNullOrWhiteSpace(req.Type?.FullName)) { var match = TypeFinder.Find(req.Type.FullName); if (match == null) { res.DisplayMessage = $"The type '{req.Type.FullName}' was not found."; } else { if (match.GetTypeInfo().IsValueType) { res.Added = TypeRegistrar.Instance.AddType(req.Type); res.Suggest <GetVisualTreeRequest>(); if (res.Added) { res.DisplayMessage = $"The type '{req.Type.FullName}' can now be used."; } } else { res.DisplayMessage = "You can only add value types in the beta."; } } } else { res.DisplayMessage = "You must enter a type name."; } } } catch (Exception ex) { res.UnhandledExceptionOccurred = true; res.ExceptionMessage = ex.ToString(); } ctx.Response = res; }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <DeleteWidgetRequest>(); if (request == null) { return; } var pair = Surface[request.WidgetId]; if (pair == null) { return; } if (!pair.UIWidget.CanDelete) { return; } Thread.Invoke(() => { Surface.Remove(request.WidgetId); }); ctx.SetResponse <OkResponse>(r => { r.Suggest <GetVisualTreeRequest>(); }); }
public void Get_methods() { var ctx = new UIMessageContext { Request = new ServerStoppedOk(), Response = new OkResponse() }; var req = ctx.Get <ServerStoppedOk>(); Assert.AreEqual(ctx.Request, req, "Request check failed."); var res = ctx.Get <OkResponse>(); Assert.AreEqual(ctx.Response, res, "Response check failed."); }
protected override void OnExecute(UIMessageContext ctx) { var req = ctx.Get <CreateGridRequest>(); if (req == null) { return; } var target = Surface[req.ParentId]; if (target == null) { return; } var attached = false; var rowCollection = new RowDefinitionCollection(); var colCollection = new ColumnDefinitionCollection(); for (var i = 0; i < req.Rows; i++) { var row = new RowDefinition(); rowCollection.Add(row); } for (var j = 0; j < req.Columns; j++) { var col = new ColumnDefinition(); colCollection.Add(col); } var view = new Grid { RowDefinitions = rowCollection, ColumnDefinitions = colCollection, ColumnSpacing = req.ColumnSpacing, RowSpacing = req.RowSpacing }; Thread.Invoke(() => { attached = Surface.SetParent(view, target); }); if (!attached) { return; } var pair = Surface[view.Id]; ctx.SetResponse <CreateWidgetResponse>(res => { res.Widget = pair.UIWidget; res.Parent = target.UIWidget; res.Suggest <GetVisualTreeRequest>(); }); }
public void Should_not_return_value_for_UserObjects() { Tr.Types = new HashSet <UIType>(new[] { new UIType { FullName = "System.String", }, new UIType { FullName = "System.Boolean" }, new UIType { FullName = "Xamarin.Forms.Rectangle" }, new UIType { FullName = "Xamarin.Forms.Font" } }); var label = new Label { Text = "My Label" }; var page = new ContentPage { Content = label }; var ctx = new UIMessageContext(); ctx.SetRequest <GetWidgetPropertiesRequest>(r => { r.WidgetId = label.Id.ToString(); }); InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(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.UIType.Descriptor == UIPropertyDescriptors.ValueType); var pFont = response.Properties.First(p => p.PropertyName == "Font"); Assert.IsNull(pFont.Value); Assert.IsTrue(pFont.UIType.Descriptor == UIPropertyDescriptors.ValueType); var pLabel = response.Properties.FirstOrDefault(p => p.PropertyName == "Text"); Assert.IsNotNull(pLabel?.Value); Assert.IsTrue(pLabel.UIType.Descriptor != UIPropertyDescriptors.ValueType); }
protected override void OnExecute(UIMessageContext ctx) { _req = ctx.Get <SetPropertyRequest>(); if (_req == null) { return; } SetPropertyValue(_req.WidgetId, _req.Path, _req.Value, _req.IsBase64, _req.IsAttachedProperty); }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <SupportedTypesRequest>(); if (request == null) { return; } TypeRegistrar.Instance.Types = new HashSet <UIType>(request.Types); }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <CreateStackLayoutRequest>(); if (request == null) { return; } var orientation = StackOrientation.Vertical; if (string.IsNullOrWhiteSpace(request.Orientation) || request.Orientation.ToLower() == "vertical") { orientation = StackOrientation.Vertical; } else if (request.Orientation.ToLower() == "horizontal") { orientation = StackOrientation.Horizontal; } var view = new StackLayout { Orientation = orientation, Spacing = request.Spacing }; var target = Surface[request.ParentId]; if (target == null) { return; } var attached = false; Thread.Invoke(() => { attached = Surface.SetParent(view, target); }); if (!attached) { return; } var pair = Surface[view.Id]; ctx.SetResponse <CreateWidgetResponse>(r => { r.Widget = pair.UIWidget; r.Parent = target.UIWidget; r.Suggest <GetVisualTreeRequest>(); }); }
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 UIMessageContext(); ctx.SetRequest <GetWidgetPropertiesRequest>(r => { r.WidgetId = view.Id.ToString(); }); InspectorReaction.Register <GetWidgetPropertiesRequest, GetWidgetPropertiesReaction>(page); Reaction.Execute(ctx); var response = ctx.Get <GetWidgetPropertiesResponse>(); foreach (var p in response.Properties) { var d = p.UIType.Descriptor; if (p.PropertyName == "Enumerable") { Assert.AreEqual(d, UIPropertyDescriptors.Enumerable); } if (p.PropertyName == "Collection") { Assert.AreEqual(d, UIPropertyDescriptors.Enumerable | UIPropertyDescriptors.Collection); } if (p.PropertyName == "List") { Assert.AreEqual(d, UIPropertyDescriptors.Enumerable | UIPropertyDescriptors.Collection | UIPropertyDescriptors.List); } Assert.IsNull(p.UIType.PossibleValues); } }
protected override void OnExecute(UIMessageContext ctx) { if (ctx.Request == null) { return; } var req = ctx.Get <GetConstructorsRequest>(); if (req == null) { return; } var type = TypeFinder.Find(req.TypeName); if (type == null) { return; } var ctors = UIConstructorMethods.GetConstructors(type); foreach (var ctor in ctors) { foreach (var p in ctor.Parameters) { var pType = TypeFinder.Find(p.TypeName); p.UIType = new UIType { Descriptor = Descriptor.GetDescriptors(pType), FullName = pType.FullName, }; Descriptor.SetPossibleValues(pType, p.UIType); } } ctx.SetResponse <GetConstructorsResponse>(res => { var descs = Descriptor.GetDescriptors(type); res.Type = new UIType { FullName = req.TypeName, Descriptor = descs, Constructors = ctors }; }); }
protected override void OnExecute(UIMessageContext ctx) { var request = ctx.Get <CreateWidgetRequest>(); if (request == null) { return; } var viewType = TypeFinder.Find(request.TypeName); if (viewType == null) { return; } var view = Activator.CreateInstance(viewType) as View; if (view == null) { return; } var target = Surface[request.ParentId]; if (target == null) { return; } var attached = false; Thread.Invoke(() => { attached = Surface.SetParent(view, target); }); if (!attached) { return; } var pair = Surface[view.Id]; ctx.SetResponse <CreateWidgetResponse>(r => { r.Widget = pair.UIWidget; r.Parent = target.UIWidget; r.Suggest <GetVisualTreeRequest>(); }); }