Exemplo n.º 1
0
 public void When_constructed_then_it_is_bound_to_the_list_on_the_viewmodel()
 {
     ListBox customerList = new ListBox();
     CustomerListViewModel vm = new CustomerListViewModel("Jeff", "Glenn");
     ListBinder<Customer, CustomerListViewModel> binder = new ListBinder<Customer, CustomerListViewModel>(customerList, p => p.Customers, p => p.SelectedCustomer, vm);
     binder.Bind();
     Assert.AreEqual(2, customerList.Items.Count);
 }
Exemplo n.º 2
0
 public void When_adding_a_template_binder_then_it_can_be_retrieved()
 {
     var customer = new Customer() { FirstName = "Jeff", LastName = "Handley" };
     var customerListVM = new CustomerListViewModel(customer);
     var templateView = new StackPanel();
     var view = new ListBox();
     var viewBinder = ViewBinder.For(view, customerListVM).
         Template<Customer>("Customer", null);
     var templateBinder = viewBinder.GetTemplateBinder("Customer");
     Assert.IsNotNull(templateBinder);
 }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public void When_selected_property_is_updated_in_the_vm_then_list_is_updated()
        {
            ListBox customerList = new ListBox();
            CustomerListViewModel vm = new CustomerListViewModel("Jeff", "Glenn");

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

            vm.SelectedCustomer = vm.Customers[1];

            Assert.AreEqual("Glenn", ((Customer)customerList.SelectedItem).FirstName);
        }
Exemplo n.º 5
0
        public void When_selected_items_exist_at_load_then_the_view_reflects_the_items()
        {
            ListBox customerList = new ListBox();
            customerList.SelectionMode = SelectionMode.Multiple;
            CustomerListViewModel vm = new CustomerListViewModel("Nick", "Jeff", "Glenn", "Hamilton");

            vm.SelectedCustomers.Add(vm.Customers[1]);
            vm.SelectedCustomers.Add(vm.Customers[2]);

            ListBinder<Customer, CustomerListViewModel> binder = new ListBinder<Customer, CustomerListViewModel>(customerList, p => p.Customers, p => p.SelectedCustomers, vm);
            binder.Bind();

            Assert.AreEqual(2, customerList.SelectedItems.Count);
            Assert.AreEqual("Jeff", ((Customer)customerList.SelectedItems[0]).FirstName);
            Assert.AreEqual("Glenn", ((Customer)customerList.SelectedItems[1]).FirstName);
        }
Exemplo n.º 6
0
        public void When_multiple_items_are_selected_then_vm_selected_items_are_updated()
        {
            ListBox customerList = new ListBox();
            customerList.SelectionMode = SelectionMode.Multiple;
            CustomerListViewModel vm = new CustomerListViewModel("Nick", "Jeff", "Glenn", "Hamilton");

            ListBinder<Customer, CustomerListViewModel> binder = new ListBinder<Customer, CustomerListViewModel>(customerList, p => p.Customers, p => p.SelectedCustomers, vm);
            binder.Bind();

            customerList.SelectedItems.Add(customerList.Items[1]);
            customerList.SelectedItems.Add(customerList.Items[2]);

            Assert.AreEqual(2, vm.SelectedCustomers.Count);
            Assert.AreEqual("Jeff", vm.SelectedCustomers[0].FirstName);
            Assert.AreEqual("Glenn", vm.SelectedCustomers[1].FirstName);
        }
Exemplo n.º 7
0
        public void When_list_item_is_selected_then_viewmodel_is_updated()
        {
            ListBox customerList = new ListBox();
            CustomerListViewModel vm = new CustomerListViewModel("Jeff", "Glenn");

            ListBinder<Customer, CustomerListViewModel> binder = new ListBinder<Customer, CustomerListViewModel>(customerList, p => p.Customers, p => p.SelectedCustomer, vm);
            binder.Bind();
            customerList.SelectedIndex = 1;

            Assert.AreEqual("Glenn", vm.SelectedCustomer.FirstName);
        }
Exemplo n.º 8
0
        public void When_constructed_with_a_ListBox_then_selected_item_binder_is_set_to_selected_convention()
        {
            ListBox customerList = new ListBox();
            customerList.Name = "Customers";
            CustomerListViewModel vm = new CustomerListViewModel("Jeff", "Glenn");
            customerList.SetValue(ViewBinder.ModelProperty, vm);

            ListBinder<Customer, CustomerListViewModel> binder = new ListBinder<Customer, CustomerListViewModel>(customerList);
            Assert.AreEqual("SelectedCustomer", binder.SelectedItemBinder.TargetPath);
        }