public void SelectedItem_Validation()
        {
            using (UnitTestApplication.Start(TestServices.MockThreadingInterface))
            {
                var target = new ComboBox
                {
                    Template           = GetTemplate(),
                    VirtualizationMode = ItemVirtualizationMode.None
                };

                target.ApplyTemplate();
                target.Presenter.ApplyTemplate();

                var exception      = new System.InvalidCastException("failed validation");
                var textObservable = new BehaviorSubject <BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));
                target.Bind(ComboBox.SelectedItemProperty, textObservable);

                Assert.True(DataValidationErrors.GetHasErrors(target));
                Assert.True(DataValidationErrors.GetErrors(target).SequenceEqual(new[] { exception }));
            }
        }
Beispiel #2
0
        public void SelectedItem_Validation()
        {
            var target = new ListBox
            {
                Template           = ListBoxTemplate(),
                Items              = new[] { "Foo" },
                ItemTemplate       = new FuncDataTemplate <string>((_, __) => new Canvas()),
                SelectionMode      = SelectionMode.AlwaysSelected,
                VirtualizationMode = ItemVirtualizationMode.None
            };

            Prepare(target);

            var exception      = new System.InvalidCastException("failed validation");
            var textObservable = new BehaviorSubject <BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));

            target.Bind(ComboBox.SelectedItemProperty, textObservable);

            Assert.True(DataValidationErrors.GetHasErrors(target));
            Assert.True(DataValidationErrors.GetErrors(target).SequenceEqual(new[] { exception }));
        }