Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }