Пример #1
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);
            }
        }
Пример #2
0
        public void InputManager_Scalar()
        {
            IScalars valueChangedScalars = null;
            var      scalarContainer     = ScalarContainerMock.New(x =>
            {
                valueChangedScalars = x;
            });

            var scalar = scalarContainer.CreateNew <int>(0)
                         .AddValidator(x =>
            {
                return(x > 5 ? "Value cannot be greater than 5." : null);
            });

            var valueChanged = scalar.SetValue(4);

            Assert.IsTrue(valueChanged);
            Assert.AreEqual(scalar, valueChangedScalars);
        }