main
1using System;
2using System.Windows.Forms;
3using developwithpassion.bdd.contexts;
4using Gorilla.Commons.Testing;
5using gorilla.commons.utility;
6
7namespace MoMoney.Presentation.Winforms.Helpers
8{
9 public class TextControlSpecs
10 {
11
12 [Concern(typeof (TextControl<>))]
13 public abstract class behaves_like_text_control : concerns_for<ITextControl<DateTime>, TextControl<DateTime>>
14 {
15 context c = () => { textbox = new TextBox(); };
16
17 public override ITextControl<DateTime> create_sut()
18 {
19 return new TextControl<DateTime>(textbox);
20 }
21
22 static protected TextBox textbox;
23 }
24
25 [Concern(typeof (TextControl<>))]
26 public class when_a_text_control_is_bound_to_an_item : behaves_like_text_control
27 {
28 it should_display_the_textual_version_of_the_item = () => textbox.Text.should_be_equal_to(date.ToString());
29
30 it should_bind_to_that_item = () => sut.get_selected_item().should_be_equal_to(date);
31
32 context c = () => { date = new DateTime(1984, 04, 28); };
33
34 because b = () => sut.set_selected_item(date);
35
36 static DateTime date;
37 }
38
39 [Concern(typeof (TextControl<>))]
40 public class when_the_text_changes_on_a_text_control_and_action_is_specified : behaves_like_text_control
41 {
42 it should_invoke_the_action_bound_to_it = () => action.was_told_to(x => x.run());
43
44 context c = () => { action = an<Command>(); };
45
46 because b = () =>
47 {
48 sut.when_text_is_changed = () => action.run();
49 textbox.control_is(x => x.OnLeave(new EventArgs()));
50 };
51
52 static Command action;
53 }
54
55 [Concern(typeof (TextControl<>))]
56 public class when_the_text_changes_on_a_text_control_and_action_is_not_specified : behaves_like_text_control
57 {
58 it should_not_blow_up = () => { };
59
60 because b = () => textbox.control_is(x => x.OnLeave(new EventArgs()));
61 }
62 }
63}