Exemplo n.º 1
0
        public void RowMapper_OnDataRowUpdated_recursive_query()
        {
            var dataSet   = DataSetMock.ProductCategories(3);
            var _         = dataSet._;
            var rowMapper = CreateRecursiveRowMapper(dataSet, 0, DataRow.Where <ProductCategory>(Condition2), DataRow.OrderBy(_.Name, SortDirection.Descending));

            var subCategories = dataSet.SubCategories(0);

            subCategories._.Name[subCategories[0]] = "Name-1-4";

            var rows = rowMapper.Rows;

            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual("Name-1", rows[0].GetValue(_.Name));
            Assert.AreEqual(2, rows[0].Children.Count);
            Assert.AreEqual("Name-1-4", rows[0].Children[0].GetValue(_.Name));
            Assert.AreEqual("Name-1-2", rows[0].Children[1].GetValue(_.Name));

            subCategories._.Name[subCategories[0]] = "Name-1-5";
            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual("Name-1", rows[0].GetValue(_.Name));
            Assert.AreEqual(1, rows[0].Children.Count);
            Assert.AreEqual("Name-1-2", rows[0].Children[0].GetValue(_.Name));

            subCategories._.Name[subCategories[2]] = "Name-1-4";
            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual("Name-1", rows[0].GetValue(_.Name));
            Assert.AreEqual(2, rows[0].Children.Count);
            Assert.AreEqual("Name-1-4", rows[0].Children[0].GetValue(_.Name));
            Assert.AreEqual("Name-1-2", rows[0].Children[1].GetValue(_.Name));
        }
Exemplo n.º 2
0
        public void RowMapper_OnRowAdded_recursive()
        {
            var          dataSet       = DataSetMock.ProductCategories(3);
            RowPresenter addedRow      = null;
            int          addedRowIndex = -1;
            var          rowMapper     = CreateRecursiveRowMapper(dataSet).SetupOnRowAdded((row, index) =>
            {
                addedRow      = row;
                addedRowIndex = index;
            });

            // add row to the leaf level, this should trigger data changed events wiring to the next level.
            var newRow = dataSet.SubCategories(0).SubCategories(0).SubCategories(0).AddRow();

            var rows = rowMapper.Rows;

            Assert.AreEqual(1, rows[0].Children[0].Children[0].Children.Count);
            Verify(rows[0].Children[0].Children[0].Children[0], newRow);
            Assert.AreEqual(newRow, addedRow.DataRow);
            Assert.AreEqual(0, addedRowIndex);

            // add another row to the leaf level, to verify data changed events correctly wired.
            var newRow2 = dataSet.SubCategories(0).SubCategories(0).SubCategories(0).SubCategories(0).AddRow();

            Assert.AreEqual(1, rows[0].Children[0].Children[0].Children[0].Children.Count);
            Verify(rows[0].Children[0].Children[0].Children[0].Children[0], newRow2);
            Assert.AreEqual(newRow2, addedRow.DataRow);
            Assert.AreEqual(0, addedRowIndex);
        }
Exemplo n.º 3
0
        public void RowNormalizer_OnRowMoved()
        {
            var dataSet       = DataSetMock.ProductCategories(3);
            var _             = dataSet._;
            var rowNormalizer = CreateRowNormalizer(dataSet, 0, null, DataRow.OrderBy(_.Name, SortDirection.Descending));
            var rows          = rowNormalizer.Rows;

            rows[0].Expand();
            VerifyDepths(rows, 0, 1, 1, 1, 0, 0);
            Assert.AreEqual("Name-3-3", rows[1].GetValue(_.Name));
            Assert.AreEqual("Name-3-2", rows[2].GetValue(_.Name));
            Assert.AreEqual("Name-3-1", rows[3].GetValue(_.Name));

            var subCategories = dataSet.SubCategories(2);

            subCategories._.Name[subCategories[0]] = "Name-3-4";
            VerifyDepths(rows, 0, 1, 1, 1, 0, 0);
            Assert.AreEqual("Name-3-4", rows[1].GetValue(_.Name));
            Assert.AreEqual("Name-3-3", rows[2].GetValue(_.Name));
            Assert.AreEqual("Name-3-2", rows[3].GetValue(_.Name));

            rows[0].Collapse();
            subCategories._.Name[subCategories[1]] = "Name-3-5";
            VerifyDepths(rows, 0, 0, 0);
        }
Exemplo n.º 4
0
        public void ElementManager_RefreshElements_IsEditing()
        {
            var dataSet = DataSetMock.ProductCategories(8, false);
            var _       = dataSet._;
            RowBinding <TextBlock> textBlock = null;
            var elementManager = dataSet.CreateElementManager((builder) =>
            {
                textBlock = _.Name.BindToTextBlock();
                builder.GridColumns("100").GridRows("100")
                .AddBinding(0, 0, textBlock);
            });

            var template = elementManager.Template;
            var rows     = elementManager.Rows;

            Assert.IsFalse(rows[0].IsEditing);

            {
                var elements = elementManager.Elements;
                Assert.AreEqual(1, elements.Count);
                var rowView = (RowView)elements[0];
                Assert.AreEqual(1, rowView.Elements.Count);
                Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
            }

            rows[0].BeginEdit();
            Assert.IsTrue(rows[0].IsEditing);
        }
Exemplo n.º 5
0
        public void RowMapper_Initialize_simple()
        {
            var dataSet   = DataSetMock.ProductCategories(3);
            var rowMapper = CreateRowMapper(dataSet);
            var rows      = rowMapper.Rows;

            Assert.AreEqual(3, rows.Count);
            Verify(rows[0], dataSet[0]);
            Verify(rows[1], dataSet[1]);
            Verify(rows[2], dataSet[2]);
        }
Exemplo n.º 6
0
        public void RowNormalizer_OnRowRemoved_recursive()
        {
            var dataSet       = DataSetMock.ProductCategories(3);
            var rowNormalizer = CreateRowNormalizer(dataSet);
            var rows          = rowNormalizer.Rows;

            VerifyDepths(rows, 0, 0, 0);

            rows[0].Delete();
            VerifyDepths(rows, 0, 0);
        }
Exemplo n.º 7
0
        public void InputManager_ScalarInput()
        {
            var            dataSet = DataSetMock.ProductCategories(3, false);
            var            _       = dataSet._;
            Scalar <Int32> scalar  = ScalarContainerMock.New().CreateNew <int>().AddValidator(x =>
            {
                return(x > 5 ? "Value cannot be greater than 5." : null);
            });
            ScalarBinding <TextBox> textBox   = null;
            RowBinding <TextBlock>  textBlock = null;
            var inputManager = dataSet.CreateInputManager((builder) =>
            {
                textBox   = scalar.BindToTextBox();
                textBlock = _.Name.BindToTextBlock(); // to avoid empty RowRange
                builder.GridColumns("100").GridRows("100", "100").AddBinding(0, 0, textBox).AddBinding(0, 1, textBlock);
            }).WithScalars(new Scalar[] { scalar });

            Assert.AreEqual("0", textBox[0].Text);
            Assert.IsNull(inputManager.ScalarValidation.GetFlushingError(textBox[0]));
            {
                var errors = System.Windows.Controls.Validation.GetErrors(textBox[0]);
                Assert.AreEqual(0, errors.Count);
            }

            textBox[0].Text = "A";
            Assert.IsNotNull(inputManager.ScalarValidation.GetFlushingError(textBox[0]));
            {
                var errors = System.Windows.Controls.Validation.GetErrors(textBox[0]);
                Assert.AreEqual(1, errors.Count);
                Assert.AreEqual(inputManager.ScalarValidation.GetFlushingError(textBox[0]), errors[0].ErrorContent);
            }

            textBox[0].Text = "4";
            Assert.IsNull(inputManager.ScalarValidation.GetFlushingError(textBox[0]));
            Assert.AreEqual(4, scalar.GetValue());
            Assert.IsNull(inputManager.ScalarValidation.GetFlushingError(textBox[0]));
            {
                var errors = System.Windows.Controls.Validation.GetErrors(textBox[0]);
                Assert.AreEqual(0, errors.Count);
            }

            inputManager.ScalarValidation.UpdateProgress(textBox.Input, true, true);
            textBox[0].Text = "6";
            Assert.AreEqual("6", textBox[0].Text);
            Assert.AreEqual(1, inputManager.ScalarValidation.Errors.Count);
            {
                var errors = System.Windows.Controls.Validation.GetErrors(textBox[0]);
                Assert.AreEqual(1, errors.Count);
                Assert.AreEqual(inputManager.ScalarValidation.Errors, errors[0].ErrorContent);
            }
        }
Exemplo n.º 8
0
        public void RowNormalizer_OnRowAdded()
        {
            var dataSet       = DataSetMock.ProductCategories(3);
            var rowNormalizer = CreateRowNormalizer(dataSet);
            var rows          = rowNormalizer.Rows;

            dataSet.SubCategories(0).AddRow();
            VerifyDepths(rows, 0, 0, 0);

            rows[0].Expand();
            VerifyDepths(rows, 0, 1, 1, 1, 1, 0, 0);
            dataSet.SubCategories(0).AddRow();
            VerifyDepths(rows, 0, 1, 1, 1, 1, 1, 0, 0);
        }
Exemplo n.º 9
0
        public void RowMapper_Initialize_recursive_query()
        {
            var dataSet   = DataSetMock.ProductCategories(3);
            var _         = dataSet._;
            var rowMapper = CreateRecursiveRowMapper(dataSet, 0, DataRow.Where <ProductCategory>(Condition1), DataRow.OrderBy(_.Name, SortDirection.Descending));

            var rows = rowMapper.Rows;

            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual("Name-1", rows[0].GetValue(_.Name));
            Assert.AreEqual(2, rows[0].Children.Count);
            Assert.AreEqual("Name-1-2", rows[0].Children[0].GetValue(_.Name));
            Assert.AreEqual("Name-1-1", rows[0].Children[1].GetValue(_.Name));
        }
Exemplo n.º 10
0
        public void RowMapper_Initialize_recursive()
        {
            var dataSet   = DataSetMock.ProductCategories(3);
            var rowMapper = CreateRecursiveRowMapper(dataSet);
            var rows      = rowMapper.Rows;

            Assert.AreEqual(3, rows.Count);
            Verify(rows[0], dataSet[0], dataSet.SubCategories(0), 0, 1, 2);
            Verify(rows[0].Children[0], dataSet.SubCategories(0)[0], dataSet.SubCategories(0).SubCategories(0), 0, 1, 2);
            Verify(rows[0].Children[0].Children[0], dataSet.SubCategories(0).SubCategories(0)[0]);
            Verify(rows[0].Children[0].Children[1], dataSet.SubCategories(0).SubCategories(0)[1]);
            Verify(rows[0].Children[0].Children[2], dataSet.SubCategories(0).SubCategories(0)[2]);
            Verify(rows[0].Children[1], dataSet.SubCategories(0)[1], dataSet.SubCategories(0).SubCategories(1), 0, 1, 2);
            Verify(rows[0].Children[1].Children[0], dataSet.SubCategories(0).SubCategories(1)[0]);
            Verify(rows[0].Children[1].Children[1], dataSet.SubCategories(0).SubCategories(1)[1]);
            Verify(rows[0].Children[1].Children[2], dataSet.SubCategories(0).SubCategories(1)[2]);
            Verify(rows[0].Children[2], dataSet.SubCategories(0)[2], dataSet.SubCategories(0).SubCategories(2), 0, 1, 2);
            Verify(rows[0].Children[2].Children[0], dataSet.SubCategories(0).SubCategories(2)[0]);
            Verify(rows[0].Children[2].Children[1], dataSet.SubCategories(0).SubCategories(2)[1]);
            Verify(rows[0].Children[2].Children[2], dataSet.SubCategories(0).SubCategories(2)[2]);

            Verify(rows[1], dataSet[1], dataSet.SubCategories(1), 0, 1, 2);
            Verify(rows[1].Children[0], dataSet.SubCategories(1)[0], dataSet.SubCategories(1).SubCategories(0), 0, 1, 2);
            Verify(rows[1].Children[0].Children[0], dataSet.SubCategories(1).SubCategories(0)[0]);
            Verify(rows[1].Children[0].Children[1], dataSet.SubCategories(1).SubCategories(0)[1]);
            Verify(rows[1].Children[0].Children[2], dataSet.SubCategories(1).SubCategories(0)[2]);
            Verify(rows[1].Children[1], dataSet.SubCategories(1)[1], dataSet.SubCategories(1).SubCategories(1), 0, 1, 2);
            Verify(rows[1].Children[1].Children[0], dataSet.SubCategories(1).SubCategories(1)[0]);
            Verify(rows[1].Children[1].Children[1], dataSet.SubCategories(1).SubCategories(1)[1]);
            Verify(rows[1].Children[1].Children[2], dataSet.SubCategories(1).SubCategories(1)[2]);
            Verify(rows[1].Children[2], dataSet.SubCategories(1)[2], dataSet.SubCategories(1).SubCategories(2), 0, 1, 2);
            Verify(rows[1].Children[2].Children[0], dataSet.SubCategories(1).SubCategories(2)[0]);
            Verify(rows[1].Children[2].Children[1], dataSet.SubCategories(1).SubCategories(2)[1]);
            Verify(rows[1].Children[2].Children[2], dataSet.SubCategories(1).SubCategories(2)[2]);

            Verify(rows[2], dataSet[2], dataSet.SubCategories(2), 0, 1, 2);
            Verify(rows[2].Children[0], dataSet.SubCategories(2)[0], dataSet.SubCategories(2).SubCategories(0), 0, 1, 2);
            Verify(rows[2].Children[0].Children[0], dataSet.SubCategories(2).SubCategories(0)[0]);
            Verify(rows[2].Children[0].Children[1], dataSet.SubCategories(2).SubCategories(0)[1]);
            Verify(rows[2].Children[0].Children[2], dataSet.SubCategories(2).SubCategories(0)[2]);
            Verify(rows[2].Children[1], dataSet.SubCategories(2)[1], dataSet.SubCategories(2).SubCategories(1), 0, 1, 2);
            Verify(rows[2].Children[1].Children[0], dataSet.SubCategories(2).SubCategories(1)[0]);
            Verify(rows[2].Children[1].Children[1], dataSet.SubCategories(2).SubCategories(1)[1]);
            Verify(rows[2].Children[1].Children[2], dataSet.SubCategories(2).SubCategories(1)[2]);
            Verify(rows[2].Children[2], dataSet.SubCategories(2)[2], dataSet.SubCategories(2).SubCategories(2), 0, 1, 2);
            Verify(rows[2].Children[2].Children[0], dataSet.SubCategories(2).SubCategories(2)[0]);
            Verify(rows[2].Children[2].Children[1], dataSet.SubCategories(2).SubCategories(2)[1]);
            Verify(rows[2].Children[2].Children[2], dataSet.SubCategories(2).SubCategories(2)[2]);
        }
Exemplo n.º 11
0
        public void IScrollable_get_extent_and_position()
        {
            var dataSet       = DataSetMock.ProductCategories(9, false);
            var _             = dataSet._;
            var layoutManager = (LayoutManager)dataSet.CreateLayoutManager((builder) =>
            {
                builder.GridColumns("100", "50", "150", "100")
                .GridRows("50", "50", "50")
                .Layout(Orientation.Vertical, 3)
                .AddBinding(1, 1, _.BlockPlaceholder())
                .AddBinding(2, 1, _.RowPlaceholder());
            });

            layoutManager.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var scrollable = (IScrollable)layoutManager;

            Assert.AreEqual(6, scrollable.MaxGridExtentX);
            Assert.AreEqual(0, scrollable.GetExtentX(0));
            Assert.AreEqual(100, scrollable.GetExtentX(1));
            Assert.AreEqual(150, scrollable.GetExtentX(2));
            Assert.AreEqual(300, scrollable.GetExtentX(3));
            Assert.AreEqual(450, scrollable.GetExtentX(4));
            Assert.AreEqual(600, scrollable.GetExtentX(5));
            Assert.AreEqual(700, scrollable.GetExtentX(6));
            Assert.AreEqual(0, scrollable.GetPositionX(0, GridPlacement.Head));
            Assert.AreEqual(100, scrollable.GetPositionX(1, GridPlacement.Tail));
            Assert.AreEqual(150, scrollable.GetPositionX(2, GridPlacement.Tail));
            Assert.AreEqual(300, scrollable.GetPositionX(3, GridPlacement.Tail));
            Assert.AreEqual(450, scrollable.GetPositionX(4, GridPlacement.Tail));
            Assert.AreEqual(600, scrollable.GetPositionX(5, GridPlacement.Tail));
            Assert.AreEqual(700, scrollable.GetPositionX(6, GridPlacement.Tail));

            Assert.AreEqual(5, scrollable.MaxGridExtentY);
            Assert.AreEqual(0, scrollable.GetExtentY(0));
            Assert.AreEqual(50, scrollable.GetExtentY(1));
            Assert.AreEqual(100, scrollable.GetExtentY(2));
            Assert.AreEqual(150, scrollable.GetExtentY(3));
            Assert.AreEqual(200, scrollable.GetExtentY(4));
            Assert.AreEqual(250, scrollable.GetExtentY(5));
            Assert.AreEqual(0, scrollable.GetPositionY(0, GridPlacement.Head));
            Assert.AreEqual(50, scrollable.GetPositionY(1, GridPlacement.Tail));
            Assert.AreEqual(100, scrollable.GetPositionY(2, GridPlacement.Tail));
            Assert.AreEqual(150, scrollable.GetPositionY(3, GridPlacement.Tail));
            Assert.AreEqual(200, scrollable.GetPositionY(4, GridPlacement.Tail));
            Assert.AreEqual(250, scrollable.GetPositionY(5, GridPlacement.Tail));
        }
Exemplo n.º 12
0
        public void RowMapper_OnDataRowRemoved_recursive()
        {
            var          dataSet          = DataSetMock.ProductCategories(3);
            RowPresenter removedRowParent = null;
            int          removedRowIndex  = -1;
            var          rowMapper        = CreateRecursiveRowMapper(dataSet).SetupOnRowRemoved((parent, index) =>
            {
                removedRowParent = parent;
                removedRowIndex  = index;
            });

            dataSet.SubCategories(1).RemoveAt(1);

            var rows = rowMapper.Rows;

            Assert.AreEqual(2, rows[1].Children.Count);
            Assert.AreEqual(rows[1], removedRowParent);
            Assert.AreEqual(1, removedRowIndex);
        }
Exemplo n.º 13
0
        public void RowManager_CommitEdit_by_row_presenter_indexer()
        {
            var dataSet    = DataSetMock.ProductCategories(3);
            var rowManager = CreateRowManager(dataSet);
            var rows       = rowManager.Rows;

            rows[0].Expand();

            Assert.AreEqual("Name-1", rows[0][dataSet._.Name]);
            Assert.AreEqual("Name-1-1", rows[1][dataSet._.Name]);

            rows[0][dataSet._.Name] = "NewName-1";
            rowManager.EndEdit();
            rowManager.CurrentRow   = rows[1];
            rows[1][dataSet._.Name] = "NewName-1-1";
            rowManager.EndEdit();
            Assert.AreEqual("NewName-1", rows[0][dataSet._.Name]);
            Assert.AreEqual("NewName-1-1", rows[1][dataSet._.Name]);
        }
Exemplo n.º 14
0
        public void RowManager_CommitEdit()
        {
            var dataSet    = DataSetMock.ProductCategories(3);
            var rowManager = CreateRowManager(dataSet);
            var rows       = rowManager.Rows;

            rows[0].Expand();

            Assert.AreEqual("Name-1", rows[0].GetValue(dataSet._.Name));
            Assert.AreEqual("Name-1-1", rows[1].GetValue(dataSet._.Name));

            rows[0].EditValue(dataSet._.Name, "NewName-1");
            rowManager.EndEdit();
            rowManager.CurrentRow = rows[1];
            rows[1].EditValue(dataSet._.Name, "NewName-1-1");
            rowManager.EndEdit();
            Assert.AreEqual("NewName-1", rows[0].GetValue(dataSet._.Name));
            Assert.AreEqual("NewName-1-1", rows[1].GetValue(dataSet._.Name));
        }
Exemplo n.º 15
0
        public void ElementManager_RefreshElements()
        {
            var dataSet = DataSetMock.ProductCategories(8, false);
            var _       = dataSet._;
            RowBinding <TextBlock> textBlock = null;
            var elementManager = dataSet.CreateElementManager((builder) =>
            {
                textBlock = _.Name.BindToTextBlock();
                builder.GridColumns("100").GridRows("100").AddBinding(0, 0, textBlock);
            });

            {
                var template = elementManager.Template;
                var rows     = elementManager.Rows;

                elementManager.ContainerViewList.RealizeFirst(1);
                dataSet._.Name[1] = "CHANGED NAME";
                Assert.AreEqual(dataSet._.Name[1], textBlock[rows[1]].Text);
            }
        }
Exemplo n.º 16
0
        public void RowNormalizer_Expand_Collapse()
        {
            var productCategories = DataSetMock.ProductCategories(3);
            var rowNormalizer     = CreateRowNormalizer(productCategories);
            var rows = rowNormalizer.Rows;

            VerifyDepths(rows, 0, 0, 0);

            rows[0].Expand();
            VerifyDepths(rows, 0, 1, 1, 1, 0, 0);

            rows[1].Expand();
            VerifyDepths(rows, 0, 1, 2, 2, 2, 1, 1, 0, 0);

            rows[0].Collapse();
            VerifyDepths(rows, 0, 0, 0);

            rows[0].Expand();
            VerifyDepths(rows, 0, 1, 2, 2, 2, 1, 1, 0, 0);
        }
Exemplo n.º 17
0
        public void RowMapper_OnDataRowUpdated_simple()
        {
            var          dataSet    = DataSetMock.ProductCategories(3);
            RowPresenter rowUpdated = null;
            bool         rowMoved   = false;
            var          rowMapper  = CreateRowMapper(dataSet)
                                      .SetupOnRowUpdated((row, e) => rowUpdated = row)
                                      .SetupOnRowMoved((parent, oldIndex, newIndex) =>
            {
                rowMoved = true;
            });

            dataSet._.Name[0] = "Updated Name";

            var rows = rowMapper.Rows;

            Assert.AreEqual(3, rows.Count);
            Assert.AreEqual(rows[0], rowUpdated);
            Assert.AreEqual(false, rowMoved);
        }
Exemplo n.º 18
0
        public void LayoutZManager_Measure()
        {
            var dataSet       = DataSetMock.ProductCategories(3, false);
            var _             = dataSet._;
            var layoutManager = dataSet.CreateLayoutManager((builder) =>
            {
                builder.GridColumns("20", "Auto", "*")
                .GridRows("25", "*", "Auto")
                .AddBinding(1, 0, _.RowPlaceholder(100, 20))
                .AddBinding(2, 0, _.RowPlaceholder(200, 20))
                .AddBinding(1, 1, _.RowPlaceholder(110, 20))
                .AddBinding(2, 1, _.RowPlaceholder(200, 20))
                .AddBinding(1, 2, _.RowPlaceholder(100, 20))
                .AddBinding(2, 2, _.RowPlaceholder(200, 20));
            });

            Assert.IsInstanceOfType(layoutManager, typeof(LayoutZManager));

            var measuredSize = layoutManager.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

            Assert.AreEqual(new Size(330, 65), measuredSize);
            VerifyContainerViewRect(layoutManager, -1, new Rect(20, 0, 310, 65));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 0, new Rect(0, 0, 110, 25));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 1, new Rect(110, 0, 200, 25));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 2, new Rect(0, 25, 110, 20));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 3, new Rect(110, 25, 200, 20));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 4, new Rect(0, 45, 110, 20));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 5, new Rect(110, 45, 200, 20));

            measuredSize = layoutManager.Measure(new Size(300, 300));
            Assert.AreEqual(new Size(300, 300), measuredSize);
            VerifyContainerViewRect(layoutManager, -1, new Rect(20, 0, 280, 300));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 0, new Rect(0, 0, 110, 25));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 1, new Rect(110, 0, 170, 25));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 2, new Rect(0, 25, 110, 255));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 3, new Rect(110, 25, 170, 255));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 4, new Rect(0, 280, 110, 20));
            VerifyRowBindingRect(layoutManager, layoutManager.CurrentRow, 5, new Rect(110, 280, 170, 20));
        }
Exemplo n.º 19
0
        public void RowMapper_OnDataRowRemoved_simple()
        {
            var          dataSet          = DataSetMock.ProductCategories(3);
            RowPresenter removedRowParent = null;
            int          removedRowIndex  = -1;
            var          rowMapper        = CreateRowMapper(dataSet).SetupOnRowRemoved((parent, index) =>
            {
                removedRowParent = parent;
                removedRowIndex  = index;
            });

            dataSet.RemoveAt(0);

            var rows = rowMapper.Rows;

            Assert.AreEqual(2, rows.Count);
            Verify(rows[0], dataSet[0]);
            Verify(rows[1], dataSet[1]);

            Assert.AreEqual(null, removedRowParent);
            Assert.AreEqual(0, removedRowIndex);
        }
Exemplo n.º 20
0
        public void LayoutZManager_GridLineFigures()
        {
            var pen           = new Pen();
            var dataSet       = DataSetMock.ProductCategories(3, false);
            var _             = dataSet._;
            var layoutManager = dataSet.CreateLayoutManager((builder) =>
            {
                builder.GridColumns("20", "20")
                .GridRows("30", "30")
                .GridLineX(new GridPoint(0, 1), 2, pen)
                .GridLineY(new GridPoint(1, 0), 2, pen)
                .AddBinding(0, 0, 1, 1, _.RowPlaceholder());
            });

            layoutManager.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var gridLineFigures = layoutManager.GridLineFigures.ToArray();

            Assert.AreEqual(2, gridLineFigures.Length);
            Assert.AreEqual(new Point(0, 30), gridLineFigures[0].StartPoint);
            Assert.AreEqual(new Point(40, 30), gridLineFigures[0].EndPoint);
            Assert.AreEqual(new Point(20, 0), gridLineFigures[1].StartPoint);
            Assert.AreEqual(new Point(20, 60), gridLineFigures[1].EndPoint);
        }
Exemplo n.º 21
0
        public void RowMapper_OnDataRowAdded_simple()
        {
            var          dataSet       = DataSetMock.ProductCategories(3);
            RowPresenter addedRow      = null;
            int          addedRowIndex = -1;
            var          rowMapper     = CreateRowMapper(dataSet).SetupOnRowAdded((row, index) =>
            {
                addedRow      = row;
                addedRowIndex = index;
            });

            dataSet.AddRow();
            var rows = rowMapper.Rows;

            Assert.AreEqual(4, rows.Count);
            Verify(rows[0], dataSet[0]);
            Verify(rows[1], dataSet[1]);
            Verify(rows[2], dataSet[2]);
            Verify(rows[3], dataSet[3]);

            Assert.AreEqual(rows[3], addedRow);
            Assert.AreEqual(3, addedRowIndex);
        }
Exemplo n.º 22
0
        public void RowManager_InsertAfterChild()
        {
            var dataSet    = DataSetMock.ProductCategories(3);
            var rowManager = CreateRowManager(dataSet);
            var rows       = rowManager.Rows;

            rows[0].Expand();
            var subRows = rows[0].Children;

            Assert.AreEqual(3, subRows.Count);

            rowManager.BeginInsertAfter(rows[0], subRows[0]);
            Assert.AreEqual(rows[2], rowManager.CurrentRow);
            Assert.AreEqual(7, rows.Count);
            Assert.IsTrue(rows[2].IsInserting);
            rowManager.CancelEdit();
            Assert.AreEqual(rows[1], rowManager.CurrentRow);
            Assert.AreEqual(6, rows.Count);

            rowManager.BeginInsertAfter(rows[0], subRows[0]);
            rowManager.EndEdit();
            Assert.AreEqual(rows[2], rowManager.CurrentRow);
            Assert.AreEqual(7, rows.Count);
        }
Exemplo n.º 23
0
        public void InputManager_RowInput()
        {
            var dataSet = DataSetMock.ProductCategories(3, false);
            var _       = dataSet._;
            RowBinding <TextBox> textBox = null;
            var inputManager             = dataSet.CreateInputManager((builder) =>
            {
                textBox = _.ParentProductCategoryID.BindToTextBox();
                builder.GridColumns("100").GridRows("100").AddBinding(0, 0, textBox);
            });

            var element = textBox[inputManager.CurrentRow];

            Assert.IsTrue(string.IsNullOrEmpty(element.Text));
            Assert.IsNull(inputManager.RowValidation.GetFlushingError(element));
            {
                var errors = System.Windows.Controls.Validation.GetErrors(element);
                Assert.AreEqual(0, errors.Count);
            }

            element.Text = "A";
            Assert.IsNotNull(inputManager.RowValidation.GetFlushingError(element));
            {
                var errors = System.Windows.Controls.Validation.GetErrors(textBox[inputManager.CurrentRow]);
                Assert.AreEqual(1, errors.Count);
                Assert.AreEqual(inputManager.RowValidation.GetFlushingError(element), errors[0].ErrorContent);
            }

            element.Text = "100";
            Assert.IsNull(inputManager.RowValidation.GetFlushingError(element));
            Assert.AreEqual(100, dataSet._.ParentProductCategoryID[inputManager.CurrentRow.DataRow]);
            {
                var errors = System.Windows.Controls.Validation.GetErrors(element);
                Assert.AreEqual(0, errors.Count);
            }
        }
Exemplo n.º 24
0
        public void ElementManager_Elements()
        {
            var dataSet = DataSetMock.ProductCategories(8, false);
            var _       = dataSet._;
            ScalarBinding <TextBlock> columnHeader1 = null;
            BlockBinding <TextBlock>  blockHeader   = null;
            RowBinding <TextBlock>    textBlock     = null;
            ScalarBinding <TextBlock> columnHeader2 = null;
            var elementManager = dataSet.CreateElementManager((builder) =>
            {
                columnHeader1 = _.Name.AsScalarTextBlock();
                blockHeader   = _.AsBlockHeader();
                textBlock     = _.Name.BindToTextBlock();
                columnHeader2 = _.Name.AsScalarTextBlock().RepeatWhenFlow();
                builder.GridColumns("100", "100")
                .GridRows("100", "100", "100")
                .Layout(Orientation.Vertical, 0)
                .AddBinding(1, 0, columnHeader1)
                .AddBinding(0, 1, blockHeader)
                .AddBinding(1, 1, textBlock)
                .AddBinding(1, 2, columnHeader2);
            });

            {
                var template = elementManager.Template;
                var rows     = elementManager.Rows;

                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(3, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    var blockView = (BlockView)elements[1];
                    Assert.AreEqual(2, blockView.Elements.Count);
                    Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                    var rowView = (RowView)blockView.Elements[1];
                    Assert.AreEqual(1, rowView.Elements.Count);
                    Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                    Assert.AreEqual(columnHeader2[0], elements[2]);
                }

                elementManager.FlowRepeatCount = 3;
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(5, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    var blockView = (BlockView)elements[1];
                    Assert.AreEqual(4, blockView.Elements.Count);
                    Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                    {
                        var rowView = (RowView)blockView.Elements[1];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                    }
                    {
                        var rowView = (RowView)blockView.Elements[2];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                    }
                    {
                        var rowView = (RowView)blockView.Elements[3];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                    }
                    Assert.AreEqual(columnHeader2[0], elements[2]);
                    Assert.AreEqual(columnHeader2[1], elements[3]);
                    Assert.AreEqual(columnHeader2[2], elements[4]);
                    Assert.AreNotEqual(columnHeader2[0], columnHeader2[1]);
                    Assert.AreNotEqual(columnHeader2[0], columnHeader2[2]);
                    Assert.AreNotEqual(columnHeader2[1], columnHeader2[2]);
                }

                elementManager.ContainerViewList.RealizeFirst(1);
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(6, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    {
                        var blockView = (BlockView)elements[1];
                        Assert.AreEqual(4, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[3];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[2];
                        Assert.AreEqual(4, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[1], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[3]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[4]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[3];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[5]], rowView.Elements[0]);
                        }
                    }
                    Assert.AreEqual(columnHeader2[0], elements[3]);
                    Assert.AreEqual(columnHeader2[1], elements[4]);
                    Assert.AreEqual(columnHeader2[2], elements[5]);
                }

                elementManager.ContainerViewList.RealizePrev();
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(6, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    {
                        var blockView = (BlockView)elements[1];
                        Assert.AreEqual(4, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[3];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[2];
                        Assert.AreEqual(4, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[1], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[3]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[4]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[3];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[5]], rowView.Elements[0]);
                        }
                    }
                    Assert.AreEqual(columnHeader2[0], elements[3]);
                    Assert.AreEqual(columnHeader2[1], elements[4]);
                    Assert.AreEqual(columnHeader2[2], elements[5]);
                }

                elementManager.ContainerViewList.RealizeNext();
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(7, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    {
                        var blockView = (BlockView)elements[1];
                        Assert.AreEqual(4, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[3];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[2];
                        Assert.AreEqual(4, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[1], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[3]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[4]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[3];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[5]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[3];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[2], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[6]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[7]], rowView.Elements[0]);
                        }
                    }
                    Assert.AreEqual(columnHeader2[0], elements[4]);
                    Assert.AreEqual(columnHeader2[1], elements[5]);
                    Assert.AreEqual(columnHeader2[2], elements[6]);
                }

                elementManager.FlowRepeatCount = 2;
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(4, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    var blockView = (BlockView)elements[1];
                    Assert.AreEqual(3, blockView.Elements.Count);
                    Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                    {
                        var rowView = (RowView)blockView.Elements[1];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                    }
                    {
                        var rowView = (RowView)blockView.Elements[2];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                    }
                    Assert.AreEqual(columnHeader2[0], elements[2]);
                    Assert.AreEqual(columnHeader2[1], elements[3]);
                    Assert.AreNotEqual(columnHeader2[0], columnHeader2[1]);
                }

                elementManager.ContainerViewList.RealizeFirst(1);
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(5, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    {
                        var blockView = (BlockView)elements[1];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[2];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[1], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[3]], rowView.Elements[0]);
                        }
                    }
                    Assert.AreEqual(columnHeader2[0], elements[3]);
                    Assert.AreEqual(columnHeader2[1], elements[4]);
                }

                elementManager.ContainerViewList.RealizePrev();
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(5, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    {
                        var blockView = (BlockView)elements[1];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[2];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[1], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[3]], rowView.Elements[0]);
                        }
                    }
                    Assert.AreEqual(columnHeader2[0], elements[3]);
                    Assert.AreEqual(columnHeader2[1], elements[4]);
                }

                elementManager.ContainerViewList.RealizeNext();
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(6, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    {
                        var blockView = (BlockView)elements[1];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[2];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[1], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[2]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[3]], rowView.Elements[0]);
                        }
                    }
                    {
                        var blockView = (BlockView)elements[3];
                        Assert.AreEqual(3, blockView.Elements.Count);
                        Assert.AreEqual(blockHeader[2], blockView.Elements[0]);
                        {
                            var rowView = (RowView)blockView.Elements[1];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[4]], rowView.Elements[0]);
                        }
                        {
                            var rowView = (RowView)blockView.Elements[2];
                            Assert.AreEqual(1, rowView.Elements.Count);
                            Assert.AreEqual(textBlock[rows[5]], rowView.Elements[0]);
                        }
                    }
                    Assert.AreEqual(columnHeader2[0], elements[4]);
                    Assert.AreEqual(columnHeader2[1], elements[5]);
                }

                elementManager.ContainerViewList.VirtualizeAll();
                {
                    var elements = elementManager.Elements;
                    Assert.AreEqual(4, elements.Count);
                    Assert.AreEqual(columnHeader1[0], elements[0]);
                    var blockView = (BlockView)elements[1];
                    Assert.AreEqual(3, blockView.Elements.Count);
                    Assert.AreEqual(blockHeader[0], blockView.Elements[0]);
                    {
                        var rowView = (RowView)blockView.Elements[1];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[0]], rowView.Elements[0]);
                    }
                    {
                        var rowView = (RowView)blockView.Elements[2];
                        Assert.AreEqual(1, rowView.Elements.Count);
                        Assert.AreEqual(textBlock[rows[1]], rowView.Elements[0]);
                    }
                    Assert.AreEqual(columnHeader2[0], elements[2]);
                    Assert.AreEqual(columnHeader2[1], elements[3]);
                }

                elementManager.ClearElements();
                Assert.IsNull(elementManager.Elements);
            }
        }