Пример #1
0
        public void BindingIntoModelObjects()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.OneWayBind(view.ViewModel, x => x.Model.AnotherThing, x => x.SomeTextBox.Text);
            Assert.Equal("Baz", view.SomeTextBox.Text);
        }
Пример #2
0
        public void BindingToItemsControl()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.OneWayBind(view.ViewModel, x => x.SomeCollectionOfStrings, x => x.SomeListBox.ItemsSource);
            Assert.True(view.SomeListBox.ItemsSource.OfType <string>().Count() > 1);
        }
Пример #3
0
        public void ViewModelIndexerPropertyToView()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.OneWayBind(view.ViewModel, x => x.SomeCollectionOfStrings[0].Length, x => x.SomeTextBox.Text);
            Assert.Equal("3", view.SomeTextBox.Text);
        }
Пример #4
0
        public void ItemsControlShouldGetADataTemplate()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            Assert.Null(view.FakeItemsControl.ItemTemplate);
            view.OneWayBind(vm, x => x.SomeCollectionOfStrings, x => x.FakeItemsControl.ItemsSource);

            Assert.NotNull(view.FakeItemsControl.ItemTemplate);
        }
Пример #5
0
        public void BindToShouldntInitiallySetToNull()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = null
            };

            view.OneWayBind(vm, x => x.Model.AnotherThing, x => x.FakeControl.NullHatingString);
            Assert.Equal("", view.FakeControl.NullHatingString);

            view.ViewModel = vm;
            Assert.Equal(vm.Model.AnotherThing, view.FakeControl.NullHatingString);
        }
Пример #6
0
        public void ItemsControlWithDisplayMemberPathSetShouldNotGetADataTemplate()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.FakeItemsControl.DisplayMemberPath = "Bla";

            Assert.Null(view.FakeItemsControl.ItemTemplate);
            view.OneWayBind(vm, x => x.SomeCollectionOfStrings, x => x.FakeItemsControl.ItemsSource);

            Assert.Null(view.FakeItemsControl.ItemTemplate);
        }
Пример #7
0
        public void ViewModelIndexerToViewChanges()
        {
            var vm   = new PropertyBindViewModel();
            var view = new PropertyBindView()
            {
                ViewModel = vm
            };

            view.OneWayBind(view.ViewModel, x => x.SomeCollectionOfStrings[0], x => x.SomeTextBox.Text);
            Assert.Equal("Foo", view.SomeTextBox.Text);

            vm.SomeCollectionOfStrings[0] = "Bar";

            Assert.Equal("Bar", view.SomeTextBox.Text);
        }