main
1using System.Windows.Forms;
2using developwithpassion.bdd.contexts;
3using Gorilla.Commons.Testing;
4
5namespace MoMoney.Presentation.Winforms.Databinding
6{
7 [Concern(typeof (Create))]
8 public class when_binding_a_property_from_an_object_to_a_combo_box : concerns
9 {
10 it should_initialize_the_combo_box_with_the_current_value_of_the_property =
11 () => combo_box.SelectedItem.should_be_equal_to(baby_girl);
12
13 context c = () =>
14 {
15 combo_box = new ComboBox();
16 thing_to_bind_to = an<IAnInterface>();
17 baby_girl = an<IAnInterface>();
18 baby_boy = an<IAnInterface>();
19
20 combo_box.Items.Add(baby_boy);
21 combo_box.Items.Add(baby_girl);
22
23 when_the(thing_to_bind_to).is_asked_for(t => t.Child).it_will_return(baby_girl);
24 };
25
26 because b = () => Create
27 .binding_for(thing_to_bind_to)
28 .bind_to_property(t => t.Child)
29 .bound_to_control(combo_box);
30
31 static ComboBox combo_box;
32 static IAnInterface thing_to_bind_to;
33 static IAnInterface baby_girl;
34 static IAnInterface baby_boy;
35 }
36
37 [Concern(typeof (Create))]
38 public class when_changing_the_selected_item_on_a_combo_box_that_is_bound_to_a_property : concerns
39 {
40 it should_change_the_value_of_the_property_that_the_combo_box_is_bound_to =
41 () => thing_to_bind_to.Child.should_be_equal_to(baby_boy);
42
43 context c = () =>
44 {
45 combo_box = new ComboBox();
46 baby_girl = an<IAnInterface>();
47 baby_boy = an<IAnInterface>();
48 thing_to_bind_to = new AnImplementation {Child = baby_girl};
49
50 combo_box.Items.Add(baby_boy);
51 combo_box.Items.Add(baby_girl);
52
53 Create
54 .binding_for(thing_to_bind_to)
55 .bind_to_property(t => t.Child)
56 .bound_to_control(combo_box);
57 };
58
59 because b = () => { combo_box.SelectedItem = baby_boy; };
60
61 static ComboBox combo_box;
62 static IAnInterface thing_to_bind_to;
63 static IAnInterface baby_girl;
64 static IAnInterface baby_boy;
65 }
66}