Beispiel #1
0
 public ObjectIsReadOnlyException(IReadOnly obj) : base()
 {
     ReadOnlyObject = obj;
 }
        public void TestIReadOnlyMakesPropertiesReadOnly()
        {
            //Use reflection to traverse the set of objects in the DLL, find those that implement IReadOnly, and ensure that IReadOnly works for all
            //properties of those objects.
            Type iReadOnlyType = typeof(IReadOnly);

            List <Type> typesWithIReadOnlyBase = GetTypesWhichImplementInterface(iReadOnlyType.GetTypeInfo().Assembly, iReadOnlyType, requirePublicConstructor: false).ToList();

            foreach (Type type in typesWithIReadOnlyBase)
            {
                this.testOutputHelper.WriteLine("Reading/Setting properties of type: {0}", type.ToString());

                //Create an instance of that type
                IReadOnly objectUnderTest = this.customizedObjectFactory.CreateInstance <IReadOnly>(type);

                //Mark this object as readonly
                objectUnderTest.IsReadOnly = true;

                //Get the properties for the object under test
                IEnumerable <PropertyInfo> properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

                foreach (PropertyInfo property in properties.Where(p => p.Name != "CustomBehaviors"))
                {
                    if (property.CanWrite)
                    {
                        this.testOutputHelper.WriteLine("Attempting to write property: {0}", property.Name);

                        //Attempt to write
                        //Note that for value types null is mapped to default(valueType).  See: https://msdn.microsoft.com/en-us/library/xb5dd1f1%28v=vs.110%29.aspx
                        TargetInvocationException e = Assert.Throws <TargetInvocationException>(() => property.SetValue(objectUnderTest, null));
                        Assert.IsType <InvalidOperationException>(e.InnerException);
                    }

                    if (property.CanRead)
                    {
                        this.testOutputHelper.WriteLine("Attempting to read property: {0}", property.Name);

                        //Attempt to read
                        try
                        {
                            property.GetValue(objectUnderTest);
                        }
                        catch (TargetInvocationException e)
                        {
                            if (e.InnerException is InvalidOperationException inner)
                            {
                                if (!inner.Message.Contains("while the object is in the Unbound state"))
                                {
                                    throw;
                                }
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                }

                this.testOutputHelper.WriteLine(string.Empty);
            }

            Assert.True(typesWithIReadOnlyBase.Count > 0);
        }
Beispiel #3
0
        public ReadOnlyMultiSelectPageCS(IReadOnly multiSelectReadOnly)
        {
            this.multiSelectReadOnly           = multiSelectReadOnly;
            this.multiSelectTemplateDescriptor = (MultiSelectTemplateDescriptor)this.multiSelectReadOnly.GetType()
                                                 .GetProperty(nameof(MultiSelectReadOnlyObject <ObservableCollection <string>, string> .MultiSelectTemplate))
                                                 .GetValue(this.multiSelectReadOnly);

            Content = new AbsoluteLayout
            {
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                Children          =
                {
                    new ContentView
                    {
                        Content = new StackLayout
                        {
                            Style    = LayoutHelpers.GetStaticStyleResource("MultiSelectPopupViewStyle"),
                            Children =
                            {
                                new Grid
                                {
                                    Style    = LayoutHelpers.GetStaticStyleResource("PopupHeaderStyle"),
                                    Children =
                                    {
                                        new Label
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderLabelStyle"),
                                        }.AddBinding(Label.TextProperty, new Binding("Title"))
                                    }
                                },
                                new Grid
                                {
                                    Children =
                                    {
                                        new CollectionView
                                        {
                                            Style        = LayoutHelpers.GetStaticStyleResource("MultiSelectPopupCollectionViewStyle"),
                                            ItemTemplate = EditFormViewHelpers.GetMultiSelectItemTemplateSelector(this.multiSelectTemplateDescriptor)
                                        }
                                        .AddBinding(ItemsView.ItemsSourceProperty, new Binding("Items"))
                                        .AddBinding(SelectableItemsView.SelectedItemsProperty, new Binding("SelectedItems")),
                                        new BoxView()
                                    }
                                },
                                new BoxView                  {
                                    Style = LayoutHelpers.GetStaticStyleResource("PopupFooterSeparatorStyle")
                                },
                                new Grid
                                {
                                    Style             = LayoutHelpers.GetStaticStyleResource("PopupFooterStyle"),
                                    ColumnDefinitions =
                                    {
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        }
                                    },
                                    Children =
                                    {
                                        new Button
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupCancelButtonStyle")
                                        }
                                        .AddBinding(Button.CommandProperty, new Binding("CancelCommand"))
                                        .SetGridColumn(2)
                                    }
                                }
                            }
                        }
                    }
                    .AssignDynamicResource(VisualElement.BackgroundColorProperty, "PopupViewBackgroundColor")
                    .SetAbsoluteLayoutBounds(new Rectangle(0, 0, 1, 1))
                    .SetAbsoluteLayoutFlags(AbsoluteLayoutFlags.All)
                }
            };

            this.BackgroundColor = Color.Transparent;
            Visual = VisualMarker.Material;
            this.BindingContext = this.multiSelectReadOnly;
        }
Beispiel #4
0
        public ReadOnlyChildFormPageCS(IReadOnly formReadOnly)
        {
            this.formReadOnly = formReadOnly;
            this.formLayout   = (DetailFormLayout)this.formReadOnly.GetType()
                                .GetProperty(nameof(FormReadOnlyObject <string> .FormLayout))
                                .GetValue(this.formReadOnly);

            Content = new AbsoluteLayout
            {
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                Children          =
                {
                    new ContentView
                    {
                        Content = new StackLayout
                        {
                            Style    = LayoutHelpers.GetStaticStyleResource("ChildFormPopupViewStyle"),
                            Children =
                            {
                                new Grid
                                {
                                    Style    = LayoutHelpers.GetStaticStyleResource("PopupHeaderStyle"),
                                    Children =
                                    {
                                        new Label
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderLabelStyle"),
                                        }.AddBinding(Label.TextProperty, new Binding("Title"))
                                    }
                                },
                                new ScrollView
                                {
                                    Style   = LayoutHelpers.GetStaticStyleResource("ChildFormPopupScrollViewStyle"),
                                    Content = this.formLayout.ControlGroupBoxList.Aggregate
                                              (
                                        new StackLayout(),
                                        (stackLayout, controlBox) =>
                                    {
                                        if (controlBox.IsVisible == false)
                                        {
                                            return(stackLayout);
                                        }

                                        stackLayout.Children.Add
                                        (
                                            new Label
                                        {
                                            Style          = LayoutHelpers.GetStaticStyleResource("DetailFormGroupHeaderStyle"),
                                            BindingContext = controlBox
                                        }
                                            .AddBinding
                                            (
                                                Label.TextProperty,
                                                GetLabelBinding(controlBox.HeaderBindings, $"{nameof(ReadOnlyControlGroupBox.GroupHeader)}")
                                            )
                                        );
                                        stackLayout.Children.Add
                                        (
                                            new StackLayout
                                        {
                                            VerticalOptions = LayoutOptions.StartAndExpand,
                                            BindingContext  = controlBox
                                        }
                                            .AddBinding(BindableLayout.ItemsSourceProperty, new Binding("."))
                                            .SetDataTemplateSelector(DetailFormViewHelpers.ReadOnlyControlTemplateSelector)
                                        );

                                        return(stackLayout);
                                    }
                                              )
                                },
                                new BoxView                  {
                                    Style = LayoutHelpers.GetStaticStyleResource("PopupFooterSeparatorStyle")
                                },
                                new Grid
                                {
                                    Style             = LayoutHelpers.GetStaticStyleResource("PopupFooterStyle"),
                                    ColumnDefinitions =
                                    {
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        }
                                    },
                                    Children =
                                    {
                                        new Button
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupCancelButtonStyle")
                                        }
                                        .AddBinding(Button.CommandProperty, new Binding("CancelCommand"))
                                        .SetGridColumn(2)
                                    }
                                }
                            }
                        }
                    }
                    .AssignDynamicResource(VisualElement.BackgroundColorProperty, "PopupViewBackgroundColor")
                    .SetAbsoluteLayoutBounds(new Rectangle(0, 0, 1, 1))
                    .SetAbsoluteLayoutFlags(AbsoluteLayoutFlags.All)
                }
            };

            this.BackgroundColor = Color.Transparent;
            Visual = VisualMarker.Material;
            this.BindingContext = this.formReadOnly;

            BindingBase GetLabelBinding(MultiBindingDescriptor multiBindingDescriptor, string bindingName)
            {
                if (multiBindingDescriptor == null)
                {
                    return(new Binding(bindingName));
                }

                return(new MultiBinding
                {
                    StringFormat = multiBindingDescriptor.StringFormat,
                    Bindings = multiBindingDescriptor.Fields.Select
                               (
                        field => new Binding($"{nameof(ReadOnlyControlGroupBox.BindingPropertiesDictionary)}[{field.ToBindingDictionaryKey()}].{nameof(IReadOnly.Value)}")
                               )
                               .Cast <BindingBase>()
                               .ToList()
                });
            }
        }
Beispiel #5
0
        public ReadOnlyChildFormArrayPageCS(IReadOnly formArrayReadOnly)
        {
            this.formArrayReadOnly = formArrayReadOnly;
            this.formsCollectionDisplayTemplateDescriptor = (FormsCollectionDisplayTemplateDescriptor)this.formArrayReadOnly.GetType()
                                                            .GetProperty(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .FormsCollectionDisplayTemplate))
                                                            .GetValue(this.formArrayReadOnly);

            Content = new AbsoluteLayout
            {
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.Fill,
                Children          =
                {
                    new ContentView
                    {
                        Content = new StackLayout
                        {
                            Style    = LayoutHelpers.GetStaticStyleResource("FormArrayPopupViewStyle"),
                            Children =
                            {
                                new Grid
                                {
                                    Style    = LayoutHelpers.GetStaticStyleResource("PopupHeaderStyle"),
                                    Children =
                                    {
                                        new Label
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderLabelStyle"),
                                        }.AddBinding(Label.TextProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .Title)))
                                    }
                                },
                                new CollectionView
                                {
                                    Style        = LayoutHelpers.GetStaticStyleResource("FormArrayPopupCollectionViewStyle"),
                                    ItemTemplate = LayoutHelpers.GetCollectionViewItemTemplate
                                                   (
                                        this.formsCollectionDisplayTemplateDescriptor.TemplateName,
                                        this.formsCollectionDisplayTemplateDescriptor.Bindings
                                                   )
                                }
                                .AddBinding(ItemsView.ItemsSourceProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .Items)))
                                .AddBinding(SelectableItemsView.SelectionChangedCommandProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .SelectionChangedCommand)))
                                .AddBinding(SelectableItemsView.SelectedItemProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .SelectedItem))),
                                new BoxView                  {
                                    Style = LayoutHelpers.GetStaticStyleResource("PopupFooterSeparatorStyle")
                                },
                                new Grid
                                {
                                    Style             = LayoutHelpers.GetStaticStyleResource("PopupFooterStyle"),
                                    ColumnDefinitions =
                                    {
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        }
                                    },
                                    Children =
                                    {
                                        new Button
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupDetailButtonStyle")
                                        }
                                        .AddBinding(Button.CommandProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .DetailCommand)))
                                        .SetGridColumn(2),
                                        new Button
                                        {
                                            Style = LayoutHelpers.GetStaticStyleResource("PopupCancelButtonStyle")
                                        }
                                        .AddBinding(Button.CommandProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .CancelCommand)))
                                        .SetGridColumn(3)
                                    }
                                }
                            }
                        }
                    }
                    .AssignDynamicResource(VisualElement.BackgroundColorProperty, "PopupViewBackgroundColor")
                    .SetAbsoluteLayoutBounds(new Rectangle(0, 0, 1, 1))
                    .SetAbsoluteLayoutFlags(AbsoluteLayoutFlags.All)
                }
            };

            this.BackgroundColor = Color.Transparent;
            Visual = VisualMarker.Material;
            this.BindingContext = this.formArrayReadOnly;
        }
Beispiel #6
0
 public EagerAdapter(IReadOnly manager, int cancellationTimeInMilliseconds)
     : this(manager)
 {
     tokenSource = new CancellationTokenSource(cancellationTimeInMilliseconds);
 }
Beispiel #7
0
 public EagerAdapter(IReadOnly manager)
 {
     _manager = manager;
 }