Exemplo n.º 1
0
        public void ShouldUpdateSelectedItemInSelectorWhenPropertyChanges()
        {
            var model = new MockModel();
            var item1 = new MockItem {
                Property = 1
            };
            var item2 = new MockItem {
                Property = 2
            };
            var itemsSource = new List <MockItem> {
                item1, item2
            };

            var selector = new ComboBox();

            selector.ItemsSource = itemsSource;
            SelectorExtensions.SetSelectedValuePath(selector, "Property");

            Binding valueBinding = new Binding("SelectedValueInModel");

            valueBinding.Mode   = BindingMode.TwoWay;
            valueBinding.Source = model;
            selector.SetBinding(SelectorExtensions.SelectedValueProperty, valueBinding);

            Assert.AreNotSame(item2, selector.SelectedItem);

            model.SelectedValueInModel = 2;

            Assert.AreSame(item2, selector.SelectedItem);
        }
Exemplo n.º 2
0
        public void ShouldUpdateModelOnSelectionChange()
        {
            var model = new MockModel();
            var item1 = new MockItem {
                Property = 1
            };
            var item2 = new MockItem {
                Property = 2
            };
            var itemsSource = new List <MockItem> {
                item1, item2
            };

            var selector = new ComboBox();

            selector.ItemsSource = itemsSource;
            SelectorExtensions.SetSelectedValuePath(selector, "Property");

            Binding valueBinding = new Binding("SelectedValueInModel");

            valueBinding.Mode   = BindingMode.TwoWay;
            valueBinding.Source = model;
            selector.SetBinding(SelectorExtensions.SelectedValueProperty, valueBinding);

            selector.SelectedItem = item1;
            Assert.AreEqual(item1.Property, model.SelectedValueInModel);

            selector.SelectedItem = item2;
            Assert.AreEqual(item2.Property, model.SelectedValueInModel);
        }
Exemplo n.º 3
0
        public void SelectorExtensionsAdd()
        {
            tlog.Debug(tag, $"SelectorExtensionsAdd START");

            Selector <Color> colors = new Selector <Color>();

            IList <SelectorItem <Color> > list = new List <SelectorItem <Color> >();

            var item = new SelectorItem <Color>()
            {
                Value = Color.Cyan,
                State = ControlState.All
            };

            item.ToString();
            list.Add(item);

            try
            {
                SelectorExtensions.Add(list, ControlState.All, Color.White);
            }
            catch (Exception e)
            {
                tlog.Debug(tag, e.Message.ToString());
                Assert.Fail("Caught Exception : Failed!");
            }

            tlog.Debug(tag, $"SelectorExtensionsAdd END (OK)");
        }
Exemplo n.º 4
0
        public void SelectorExtensionsAddWithNullList()
        {
            tlog.Debug(tag, $"SelectorExtensionsAddWithNullList START");

            Selector <Color> colors = new Selector <Color>();

            IList <SelectorItem <Color> > list = null;

            try
            {
                SelectorExtensions.Add(list, ControlState.All, Color.White);
            }
            catch (ArgumentNullException)
            {
                tlog.Debug(tag, $"SelectorExtensionsAddWithNullList END (OK)");
                Assert.Pass("Caught ArgumentNullException : Passed!");
            }
        }
Exemplo n.º 5
0
        public void InvalidValuePathThrows()
        {
            var model = new MockModel();
            var item1 = new MockItem {
                Property = 1
            };
            var itemsSource = new List <MockItem> {
                item1
            };
            var selector = new ComboBox();

            selector.ItemsSource = itemsSource;

            Binding valueBinding = new Binding("SelectedValueInModel");

            valueBinding.Mode   = BindingMode.TwoWay;
            valueBinding.Source = model;
            selector.SetBinding(SelectorExtensions.SelectedValueProperty, valueBinding);

            SelectorExtensions.SetSelectedValuePath(selector, "InvalidProperty");
        }
Exemplo n.º 6
0
        public void ShouldNotFailIfItemsSourceIsNotSetBeforeSettingTheBindingToModel()
        {
            var model = new MockModel();
            var item1 = new MockItem {
                Property = 1
            };
            var item2 = new MockItem {
                Property = 2
            };
            var itemsSource = new List <MockItem> {
                item1, item2
            };

            var selector = new ComboBox();

            SelectorExtensions.SetSelectedValuePath(selector, "Property");
            Binding valueBinding = new Binding("SelectedValueInModel");

            valueBinding.Mode   = BindingMode.TwoWay;
            valueBinding.Source = model;
            selector.SetBinding(SelectorExtensions.SelectedValueProperty, valueBinding);

            selector.ItemsSource = itemsSource;
        }