Пример #1
0
        public void GridValidatingEditorEventForNullTest()
        {
            // Setup testing data and class dependencies
            var viewMock = new Mock<IView>();
            var serviceMock = new Mock<IService>();
            var presenter = new Presenter(viewMock.Object, serviceMock.Object);

            // Raising event view.GridValidatingEditor("B", e) to change model
            var e = new ValidateEditorEventArgs() { Value = null };
            viewMock.Raise(v => v.GridValidatingEditor += null, "B", e);

            // Verifing testing results
            Assert.AreEqual(false, e.Valid, "Validate failed validation");
            Assert.AreEqual("Field B should not be empty !", e.ErrorText, "Validate error message");
        }
Пример #2
0
        private void InitEvents()
        {
            this.Load += (s, args) => FormLoad();
            this.FormClosed += (s, args) => FormClose();

            this.increaseAButton.Click += (s, args) => {
                try
                {
                    var row = dataGridView1.CurrentRow;
                    if (row != null)
                    {
                        var model = (Model)row.DataBoundItem;
                        IncreaseAClick(model);
                    };
                }
                finally
                {
                }
            };

            this.saveButton.Click += (s, args) => {
                dataGridView1.EndEdit();
                SaveClick();
            };

            this.dataGridView1.CellValueChanged += (s, args) =>
            {
                try
                {
                    if (args.RowIndex >= 0)
                    {
                        var gridColumn = dataGridView1.Columns[args.ColumnIndex];
                        var gridRow = dataGridView1.Rows[args.RowIndex];
                        var model = (Model)gridRow.DataBoundItem;
                        GridCellValueChanged(gridColumn.DataPropertyName, model);
                    }
                }
                finally
                {
                }
            };

            dataGridView1.CellValidating += (s, args) =>
            {
                var gridColumn = dataGridView1.Columns[args.ColumnIndex];
                object value = dataGridView1.CurrentCell.Value;
                value = dataGridView1.Rows[args.RowIndex].Cells[args.ColumnIndex];
                var eventArgs = new ValidateEditorEventArgs() { Valid = true, ErrorText = string.Empty, Value = value };
                GridValidatingEditor(gridColumn.DataPropertyName, eventArgs);

                dataGridView1.Rows[args.RowIndex].Cells[args.ColumnIndex].ErrorText = eventArgs.ErrorText;
                args.Cancel = !eventArgs.Valid;
            };
        }