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_on_an_object_to_a_textbox : concerns
9 {
10 it should_initialize_the_text_of_the_textbox_to_the_value_of_the_property =
11 () => text_box.Text.should_be_equal_to(first_name);
12
13 context c = () =>
14 {
15 thing_to_bind_to = an<IAnInterface>();
16 text_box = new TextBox();
17 thing_to_bind_to.is_asked_for(t => t.FirstName).it_will_return(first_name);
18 };
19
20 because b = () => Create
21 .binding_for(thing_to_bind_to)
22 .bind_to_property(t => t.FirstName)
23 .bound_to_control(text_box);
24
25 static TextBox text_box;
26 static IAnInterface thing_to_bind_to;
27 static string first_name = "mO";
28 }
29
30 [Concern(typeof (Create))]
31 public class when_updating_the_text_of_a_bound_text_box : concerns
32 {
33 it should_update_the_value_of_the_property_that_the_textbox_is_bound_to =
34 () => thing_to_bind_to.FirstName.should_be_equal_to(expected_name);
35
36 context c = () =>
37 {
38 thing_to_bind_to = new AnImplementation {FirstName = "abshir"};
39 text_box = new TextBox();
40
41 Create
42 .binding_for(thing_to_bind_to)
43 .bind_to_property(t => t.FirstName)
44 .bound_to_control(text_box);
45 };
46
47 because b = () => { text_box.Text = expected_name; };
48
49 static TextBox text_box;
50 static IAnInterface thing_to_bind_to;
51 static string expected_name = "ugo";
52 }
53
54 public interface IAnInterface
55 {
56 string FirstName { get; }
57 IAnInterface Child { get; }
58 }
59
60 public class AnImplementation : IAnInterface
61 {
62 public string FirstName { get; set; }
63 public IAnInterface Child { get; set; }
64 }
65}