Пример #1
0
        public void When_method_binder_is_added_then_it_can_be_retrieved_by_its_event()
        {
            var button = new Button();
            var view = new UserControl();
            var vm = new MockViewModelWithAction();
            var buttonBinder = new MethodBinder<RoutedEventArgs>(button, "Click", p => vm.Action());
            var viewModelBinder = new ViewBinder<object>(view, vm);
            viewModelBinder.Add(buttonBinder);

            var binder = viewModelBinder.GetMethodBinder(button, "Click");
            Assert.AreEqual(buttonBinder, binder);
        }
Пример #2
0
        public void When_list_binder_is_added_then_it_can_be_retrieved_by_its_type()
        {
            ListBox citiesList = new ListBox();
            CustomerListViewModel vm = new CustomerListViewModel("Jeff", "Glenn");

            ListBinder<Customer,CustomerListViewModel> binder = new ListBinder<Customer,CustomerListViewModel>(citiesList, p => vm.Customers, p => vm.SelectedCustomer,vm);

            var viewModelBinder = new ViewBinder<CustomerListViewModel>(citiesList, vm);
            viewModelBinder.Add(binder);

            var binders = viewModelBinder.GetBinders<ListBinder<Customer,CustomerListViewModel>>(citiesList);
            Assert.AreEqual(binder, binders.Single(), "There should be a single list binder found");
        }
Пример #3
0
        public void When_value_binder_is_added_then_it_can_be_retrieved_by_its_type()
        {
            var view = new UserControl();
            var mockBinder = new MockBinder(view);

            var viewModelBinder = new ViewBinder<object>(view, null);
            viewModelBinder.Add(mockBinder);

            var binders = viewModelBinder.GetBinders<MockBinder>(view);
            Assert.AreEqual(mockBinder, binders.Single(), "There should be a single binder found that equals our mockBinder");
        }
Пример #4
0
        public void When_value_binder_is_added_then_it_can_be_retrieved_by_its_bound_property()
        {
            var view = new UserControl();
            var viewModel = new { Value = "my value" };
            var valueBinder = new ValueBinder<object>(view, UserControl.ContentProperty, p => viewModel.Value) {BindingMode = BindingMode.OneWay};

            var viewModelBinder = new ViewBinder<object>(view, viewModel);
            viewModelBinder.Add(valueBinder);

            var binder = viewModelBinder.GetPropertyBinder(view, UserControl.ContentProperty);
            Assert.AreEqual(valueBinder, binder);
        }