main
 1using System;
 2using System.Windows.Forms;
 3using developwithpassion.bdd.contexts;
 4using Gorilla.Commons.Testing;
 5
 6namespace MoMoney.Presentation.Winforms.Helpers
 7{
 8    [Concern(typeof (EventTrigger))]
 9    public class when_invoking_a_call_on_a_target_via_reflection : concerns
10    {
11        it should_correctly_call_that_method =
12            () =>
13                {
14                    control.called_on_key_press.should_be_true();
15                    control.called_on_enter.should_be_false();
16                };
17
18        context c = () => { control = new TestControl(); };
19
20        because b =
21            () =>
22            EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new KeyPressEventArgs('A')), control);
23
24        static TestControl control;
25    }
26
27    [Concern(typeof (EventTrigger))]
28    public class when_invoking_a_call_on_a_target_by_passing_in_a_parameter : concerns
29    {
30        it should_make_the_call_correctly = () => control.key_press_arguments.should_be_equal_to(args);
31
32        //[Test]
33        //public void should_make_the_call_correctly2()
34        //{
35        //    var new_args = new KeyPressEventArgs('A');
36        //    control = new TestControl();
37        //    EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new_args), control);
38        //    control.key_press_arguments.should_be_equal_to(new_args);
39        //}
40
41        context c = () => { control = new TestControl(); };
42
43        because b = () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(args), control);
44
45        static TestControl control;
46
47        static readonly KeyPressEventArgs args = new KeyPressEventArgs('A');
48    }
49
50    internal class TestControl
51    {
52        public bool called_on_enter;
53        public bool called_on_key_press;
54        public KeyPressEventArgs key_press_arguments;
55
56        protected void OnEnter(EventArgs args)
57        {
58            called_on_enter = true;
59        }
60
61        protected void OnKeyPress(KeyPressEventArgs args)
62        {
63            called_on_key_press = true;
64            key_press_arguments = args;
65        }
66    }
67}