Commit 4abff51
Changed files (9)
trunk
product
MyMoney
Presentation
Views
dialogs
Shell
Testing
win.forms
trunk/product/MyMoney/Presentation/Views/dialogs/SaveChangesViewSpecs.cs
@@ -1,9 +1,9 @@
using System;
using jpboodhoo.bdd.contexts;
using MoMoney.Presentation.Model.Menu.File.Commands;
+using MoMoney.Presentation.Views.helpers;
using MoMoney.Testing.spechelpers.contexts;
using MoMoney.Testing.spechelpers.core;
-using MoMoney.Testing.win.forms;
namespace MoMoney.Presentation.Views.dialogs
{
trunk/product/MyMoney/Testing/win.forms/Events.cs → trunk/product/MyMoney/Presentation/Views/helpers/Events.cs
@@ -2,7 +2,7 @@ using System;
using System.ComponentModel;
using System.Windows.Forms;
-namespace MoMoney.Testing.win.forms
+namespace MoMoney.Presentation.Views.helpers
{
public class Events
{
trunk/product/MyMoney/Testing/win.forms/EventTrigger.cs → trunk/product/MyMoney/Presentation/Views/helpers/EventTrigger.cs
@@ -6,11 +6,11 @@ using System.Linq.Expressions;
using System.Reflection;
using jpboodhoo.bdd.core.extensions;
-namespace MoMoney.Testing.win.forms
+namespace MoMoney.Presentation.Views.helpers
{
static public class EventTrigger
{
- const BindingFlags binding_flags = BindingFlags.Instance | BindingFlags.NonPublic;
+ const BindingFlags binding_flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance;
static readonly IDictionary<ExpressionType, Func<Expression, object>> expression_handlers;
static EventTrigger()
@@ -30,9 +30,7 @@ namespace MoMoney.Testing.win.forms
var method = target.GetType().GetMethod(method_name, binding_flags);
Debug.Assert(target != null, "The target to raise the event on cannot be null");
- Debug.Assert(method != null,
- "There is no method called {0}, on a {1}".format_using(method_name,
- target.GetType().proper_name()));
+ Debug.Assert(method != null, "There is no method called {0}, on a {1}".format_using(method_name, target.GetType().proper_name()));
method.Invoke(target, method_args.ToArray());
}
@@ -45,7 +43,10 @@ namespace MoMoney.Testing.win.forms
static object get_value_from_member_access(Expression expression)
{
var member_expression = expression.downcast_to<MemberExpression>();
- throw new NotImplementedException();
+ var type = member_expression.Member.DeclaringType;
+ var member = (FieldInfo)member_expression.Member;
+ var value = member.GetValue(Activator.CreateInstance(type));
+ return value;
}
static object instantiate_value(Expression expression)
@@ -66,7 +67,7 @@ namespace MoMoney.Testing.win.forms
static void cannot_handle(Expression expression)
{
- throw new NotImplementedException();
+ throw new ArgumentException("cannot parse {0}".format_using(expression));
}
static object get_value_from_evaluating(Expression expression)
trunk/product/MyMoney/Presentation/Views/helpers/EventTriggerSpecs.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Windows.Forms;
+using jpboodhoo.bdd.contexts;
+using MbUnit.Framework;
+using MoMoney.Testing.spechelpers.contexts;
+using MoMoney.Testing.spechelpers.core;
+
+namespace MoMoney.Presentation.Views.helpers
+{
+ public class when_invoking_a_call_on_a_target_via_reflection : concerns_for
+ {
+ it should_correctly_call_that_method =
+ () =>
+ {
+ control.called_on_key_press.should_be_true();
+ control.called_on_enter.should_be_false();
+ };
+
+ context c = () => { control = new TestControl(); };
+
+ because b =
+ () =>
+ EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new KeyPressEventArgs('A')), control);
+
+ static TestControl control;
+ }
+
+ public class when_invoking_a_call_on_a_target_by_passing_in_a_parameter : concerns_for
+ {
+ it should_make_the_call_correctly = () => control.key_press_arguments.should_be_equal_to(args);
+
+ [Test]
+ public void should_make_the_call_correctly2()
+ {
+ var new_args = new KeyPressEventArgs('A');
+ control = new TestControl();
+ EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new_args), control);
+ control.key_press_arguments.should_be_equal_to(new_args);
+ }
+
+ context c = () => { control = new TestControl(); };
+
+ because b = () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(args), control);
+
+ static TestControl control;
+
+ static readonly KeyPressEventArgs args = new KeyPressEventArgs('A');
+ }
+
+ internal class TestControl
+ {
+ public bool called_on_enter;
+ public bool called_on_key_press;
+ public KeyPressEventArgs key_press_arguments;
+
+ protected void OnEnter(EventArgs args)
+ {
+ called_on_enter = true;
+ }
+
+ protected void OnKeyPress(KeyPressEventArgs args)
+ {
+ called_on_key_press = true;
+ key_press_arguments = args;
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/helpers/IEventTarget.cs
@@ -0,0 +1,6 @@
+namespace MoMoney.Presentation.Views.helpers
+{
+ public interface IEventTarget
+ {
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Shell/ApplicationShellSpecs.cs
@@ -3,7 +3,6 @@ using jpboodhoo.bdd.contexts;
using MoMoney.Presentation.Model.Menu.File.Commands;
using MoMoney.Testing.spechelpers.contexts;
using MoMoney.Testing.spechelpers.core;
-using MoMoney.Testing.win.forms;
namespace MoMoney.Presentation.Views.Shell
{
trunk/product/MyMoney/Testing/win.forms/EventTriggerSpecs.cs
@@ -1,46 +0,0 @@
-using System;
-using System.Windows.Forms;
-using jpboodhoo.bdd.contexts;
-using MbUnit.Framework;
-using MoMoney.Testing.spechelpers.contexts;
-using MoMoney.Testing.spechelpers.core;
-
-namespace MoMoney.Testing.win.forms
-{
- [Ignore]
- public class when_invoking_a_call_on_a_target_via_reflection : concerns_for
- {
- it should_correctly_call_that_method = () =>
- {
- control.key_press_arguments.should_be_equal_to(new KeyPressEventArgs('A'));
- control.called_on_key_press.should_be_true();
- control.called_on_enter.should_be_false();
- };
-
- context c = () => { control = new TestControl(); };
-
- because b = () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new KeyPressEventArgs('A')), control);
-
- static TestControl control;
-
- //static readonly KeyPressEventArgs args = new KeyPressEventArgs('A');
- }
-
- internal class TestControl
- {
- public bool called_on_enter;
- public bool called_on_key_press;
- public KeyPressEventArgs key_press_arguments;
-
- protected void OnEnter(EventArgs args)
- {
- called_on_enter = true;
- }
-
- protected void OnKeyPress(KeyPressEventArgs args)
- {
- called_on_key_press = true;
- key_press_arguments = args;
- }
- }
-}
\ No newline at end of file
trunk/product/MyMoney/Testing/win.forms/IEventTarget.cs
@@ -1,6 +0,0 @@
-namespace MoMoney.Testing.win.forms
-{
- public interface IEventTarget
- {
- }
-}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -517,10 +517,10 @@
<Compile Include="Testing\spechelpers\core\IHideObjectMembers.cs" />
<Compile Include="Testing\spechelpers\core\method_call_occurance.cs" />
<Compile Include="Testing\MetaData\run_in_real_container.cs" />
- <Compile Include="Testing\win.forms\Events.cs" />
- <Compile Include="Testing\win.forms\EventTrigger.cs" />
- <Compile Include="Testing\win.forms\IEventTarget.cs" />
- <Compile Include="Testing\win.forms\EventTriggerSpecs.cs" />
+ <Compile Include="Presentation\Views\helpers\Events.cs" />
+ <Compile Include="Presentation\Views\helpers\EventTrigger.cs" />
+ <Compile Include="Presentation\Views\helpers\IEventTarget.cs" />
+ <Compile Include="Presentation\Views\helpers\EventTriggerSpecs.cs" />
<Compile Include="Utility\Core\ChainedConfiguration.cs" />
<Compile Include="Utility\Core\chained_mapper.cs" />
<Compile Include="Utility\Core\and_specification.cs" />