Example #1
0
        public void SelectedItemChangedNonGenericShouldBeInvokedWhenSelectedItemChanged()
        {
            ThreadManager.IsUiThread = true;
            bool isFocusedRowChanged = false;
            var  model = new GridModel {
                Name = "test"
            };
            var listItems = new List <GridModel> {
                model
            };

            IGridViewModel gridViewModel = GetViewModel <GridViewModel <GridModel> >();

            gridViewModel.SelectedItemChanged += (sender, args) =>
            {
                if (isFocusedRowChanged)
                {
                    throw new InvalidOperationException();
                }
                isFocusedRowChanged = true;
                args.OldValue.ShouldBeNull();
                args.NewValue.ShouldEqual(model);
            };
            gridViewModel.UpdateItemsSource(listItems);
            gridViewModel.SelectedItem = model;
            isFocusedRowChanged.ShouldBeTrue();
        }
Example #2
0
        public void ItemsSourceChangedNonGenericShouldBeInvokedWhenItemsSourceChanged()
        {
            ThreadManager.IsUiThread = true;
            bool isItemsSourceChanged = false;
            var  model = new GridModel {
                Name = "test"
            };
            var listItems = new List <GridModel> {
                model
            };

            IGridViewModel gridViewModel = GetViewModel <GridViewModel <GridModel> >();

            gridViewModel.ItemsSourceChanged += (sender, data) =>
            {
                if (isItemsSourceChanged)
                {
                    throw new InvalidOperationException();
                }
                isItemsSourceChanged = true;
                gridViewModel.ItemsSource.ShouldEqual(data.Value);
            };
            gridViewModel.UpdateItemsSource(listItems);
            isItemsSourceChanged.ShouldBeTrue();
        }
        public void SelectedIndexShouldBeSynchronizedWithSelectedItem()
        {
            ThreadManager.IsUiThread = true;
            IGridViewModel gridViewModel = GetViewModel <GridViewModel <GridModel> >();

            gridViewModel.SelectedItem.ShouldBeNull();
            gridViewModel.SelectedIndex.ShouldBeLessThan(0);

            var model1 = new GridModel {
                Name = "test"
            };
            var model2 = new GridModel {
                Name = "test"
            };
            var listItems = new List <GridModel> {
                model1, model2
            };

            gridViewModel.UpdateItemsSource(listItems);

            gridViewModel.SelectedItem = model1;
            gridViewModel.SelectedItem.ShouldEqual(model1);
            gridViewModel.SelectedIndex.ShouldEqual(0);

            gridViewModel.SelectedIndex = 1;
            gridViewModel.SelectedIndex.ShouldEqual(1);
            gridViewModel.SelectedItem.ShouldEqual(model2);
        }