예제 #1
0
        public void Set_Validation_Error_Template()
        {
            var expectedTemplate = new ControlTemplate();
            var sut = new GridLayout(expectedTemplate);

            var container = new ContentControl();
            var fields    = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01"
                }, ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text01"
                }, ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool01"
                }, ServiceLocator)
            };

            fields
            .Where(f => f.ValueControl != null)
            .All(f => Validation.GetErrorTemplate(f.ValueControl) != expectedTemplate)
            .Should().BeTrue();


            sut.DoLayout(container, fields);

            fields
            .Where(f => f.ValueControl != null)
            .All(f => Validation.GetErrorTemplate(f.ValueControl) == expectedTemplate)
            .Should().BeTrue();
        }
예제 #2
0
        public void Skip_rows_if_label_and_value_both_empty()
        {
            var sut = new GridLayout();

            var container = new ContentControl();
            var fields    = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01"
                }, ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text01"
                }, ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool01"
                }, ServiceLocator)
            };

            sut.DoLayout(container, fields);

            var grid = (Grid)container.Content;

            grid.Should().NotBeNull();

            grid.Children.Should().HaveCount(2);
            grid.Children[0].Should().Be(fields[1].ValueControl, "label should be skipped");
            grid.Children[1].Should().Be(fields[2].ValueControl, "label should be skipped");
        }
예제 #3
0
        public void Add_controls()
        {
            var sut = new StackedLayout();

            var container = new ContentControl();
            var fields    = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01", Prompt = "heading"
                }, ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text01"
                }, ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool01"
                }, ServiceLocator)
            };

            sut.DoLayout(container, fields);

            var panel = (StackPanel)container.Content;

            panel.Should().NotBeNull();

            panel.Children.Should().HaveCount(3);
            panel.Children[0].Should().Be(fields[0].LabelControl, "we have a label bu no 'value'");
            panel.Children[1].Should().Be(fields[1].ValueControl, "we have no labels");
            panel.Children[2].Should().Be(fields[2].ValueControl, "we have no labels");
        }
예제 #4
0
        public void Use_resolve_layout_on_groupfields()
        {
            var resolveLayout = Substitute.For <IResolveLayout>();
            var stackLayout   = Substitute.For <INZazuWpfLayoutStrategy>();
            var gridLayout    = Substitute.For <INZazuWpfLayoutStrategy>();

            resolveLayout.Resolve("stack").Returns(stackLayout);
            resolveLayout.Resolve("grid").Returns(gridLayout);

            var sut = new GridLayout();

            var container = new ContentControl();
            var fields1   = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01"
                }, ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text01"
                }, ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool01"
                }, ServiceLocator)
            };
            var fields2 = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01", Description = "label2"
                }, ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text01"
                }, ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool01"
                }, ServiceLocator)
            };
            var groups = new[]
            {
                new NZazuGroupField(new FieldDefinition {
                    Key = "stack01"
                }, ServiceLocator)
                {
                    Fields = fields1, Layout = "stack"
                },
                new NZazuGroupField(new FieldDefinition {
                    Key = "grid01"
                }, ServiceLocator)
                {
                    Fields = fields2, Layout = "grid"
                }
            };

            sut.DoLayout(container, groups, resolveLayout);

            stackLayout.Received().DoLayout(Arg.Any <ContentControl>(), fields1, resolveLayout);
        }
예제 #5
0
        public void Layout_fields_in_a_two_column_grid()
        {
            var sut = new GridLayout();

            var container = new ContentControl();
            var fields    = new NZazuField[]
            {
                new NZazuLabelField(
                    new FieldDefinition {
                    Key = "label01", Prompt = "label prompt", Description = "label text"
                },
                    ServiceLocator),
                new NZazuTextField(
                    new FieldDefinition {
                    Key = "text01", Prompt = "text prompt", Description = "text tooltip"
                },
                    ServiceLocator),
                new NZazuBoolField(
                    new FieldDefinition {
                    Key = "bool01", Prompt = "bool prompt", Description = "checkbox tooltip"
                },
                    ServiceLocator)
            };

            sut.DoLayout(container, fields);

            var grid = (Grid)container.Content;

            grid.Should().NotBeNull();

            var colDefs = grid.ColumnDefinitions;

            colDefs.Should().HaveCount(2);
            colDefs[0].Width.IsAuto.Should().BeTrue();
            colDefs[1].Width.IsStar.Should().BeTrue();

            var rowDefs = grid.RowDefinitions;

            rowDefs.Should().HaveCount(3);
            rowDefs.All(r => r.Height == GridLength.Auto).Should().BeTrue();

            grid.Children.Should().HaveCount(2 * fields.Length);
            for (var i = 0; i < fields.Length; i++)
            {
                grid.Children[2 * i].Should().Be(fields[i].LabelControl);
                grid.Children[2 * i + 1].Should().Be(fields[i].ValueControl);
            }
        }
예제 #6
0
        public void Align_Horizontally_And_Vertical_Top()
        {
            var sut = new StackedLayout();

            var container = new ContentControl();
            var fields    = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01"
                }, ServiceLocator)
            };

            sut.DoLayout(container, fields);

            var panel = (StackPanel)container.Content;

            panel.Should().NotBeNull();
            panel.Orientation.Should().Be(Orientation.Horizontal);
            panel.VerticalAlignment.Should().Be(VerticalAlignment.Top);
        }
예제 #7
0
        public void Recurse_on_group_fields()
        {
            var sut = new GridLayout();

            var container = new ContentControl();
            var fields1   = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label01", Prompt = "Hello", Description = "Hello"
                },
                                    ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text01", Prompt = "Hello", Description = "Hello"
                },
                                   ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool01", Prompt = "Hello", Description = "Hello"
                },
                                   ServiceLocator)
            };
            var fields2 = new NZazuField[]
            {
                new NZazuLabelField(new FieldDefinition {
                    Key = "label02", Prompt = "Hello", Description = "Hello"
                },
                                    ServiceLocator),
                new NZazuTextField(new FieldDefinition {
                    Key = "text02", Prompt = "Hello", Description = "Hello"
                },
                                   ServiceLocator),
                new NZazuBoolField(new FieldDefinition {
                    Key = "bool02", Prompt = "Hello", Description = "Hello"
                },
                                   ServiceLocator)
            };
            var groups = new[]
            {
                new NZazuGroupField(new FieldDefinition {
                    Key = "stack01"
                }, ServiceLocator)
                {
                    Fields = fields1
                },
                new NZazuGroupField(new FieldDefinition {
                    Key = "group01"
                }, ServiceLocator)
                {
                    Fields = fields2
                }
            };

            sut.DoLayout(container, groups);

            var grid = (Grid)container.Content;

            grid.Should().NotBeNull();

            grid.Children.Should().HaveCount(2);
            var content1 = (ContentControl)groups[0].ValueControl;
            var content2 = (ContentControl)groups[1].ValueControl;

            grid.Children[0].Should().Be(content1);
            grid.Children[1].Should().Be(content2);

            var grid1 = (Grid)content1.Content;

            grid1.Children.Should().HaveCount(fields1.Length * 2); // because we have label and value
            foreach (var field in fields1)
            {
                grid1.Children.Should().Contain(field.LabelControl);
                grid1.Children.Should().Contain(field.ValueControl);
            }

            var grid2 = (Grid)content2.Content;

            grid2.Children.Should().HaveCount(fields2.Length * 2); // because we have label and value
            foreach (var t in fields2)
            {
                grid2.Children.Should().Contain(t.LabelControl);
                grid2.Children.Should().Contain(t.ValueControl);
            }
        }