Commit 9cafdd9
Changed files (7)
trunk
product
MyMoney
Presentation
Testing
spechelpers
contexts
trunk/product/MyMoney/Presentation/Core/application_controller_specs.cs
@@ -1,5 +1,3 @@
-using System.Collections.Generic;
-using System.Linq;
using jpboodhoo.bdd.contexts;
using MyMoney.Presentation.Views.core;
using MyMoney.Presentation.Views.Shell;
@@ -12,19 +10,19 @@ namespace MyMoney.Presentation.Core
[Concern(typeof (application_controller))]
public abstract class behaves_like_an_application_controller : concerns_for<IApplicationController, application_controller>
{
- public override IApplicationController create_sut()
- {
- return new application_controller(presenter_registry, shell);
- }
+ //public override IApplicationController create_sut()
+ //{
+ // return new application_controller(presenter_registry, shell);
+ //}
context c = () =>
{
- presenter_registry = an<IPresenterRegistry>();
- shell = an<IShell>();
+ presenter_registry = the_dependency<IPresenterRegistry>();
+ shell = the_dependency<IShell>();
};
- protected static IShell shell;
- protected static IPresenterRegistry presenter_registry;
+ static protected IShell shell;
+ static protected IPresenterRegistry presenter_registry;
}
public class when_the_application_controller_is_asked_to_run_a_presenter : behaves_like_an_application_controller
@@ -35,12 +33,12 @@ namespace MyMoney.Presentation.Core
presenter_registry
.is_told_to(r => r.all())
.it_will_return(implementation_of_the_presenter);
-
};
because b = () => sut.run<IPresenter>();
- it should_ask_the_registered_presenters_for_an_instance_of_the_presenter_to_run = () => presenter_registry. was_told_to( r => r.all());
+ it should_ask_the_registered_presenters_for_an_instance_of_the_presenter_to_run =
+ () => presenter_registry.was_told_to(r => r.all());
it should_initialize_the_presenter_to_run = () => implementation_of_the_presenter.was_told_to(p => p.run());
@@ -56,7 +54,7 @@ namespace MyMoney.Presentation.Core
view = an<IDockedContentView>();
var presenter = an<IContentPresenter>();
- presenter_registry.is_told_to(r => r.all()) .it_will_return(presenter);
+ presenter_registry.is_told_to(r => r.all()).it_will_return(presenter);
presenter.is_told_to(x => x.View).it_will_return(view);
};
trunk/product/MyMoney/Testing/spechelpers/contexts/concerns_for.cs
@@ -7,29 +7,31 @@ namespace MyMoney.Testing.spechelpers.contexts
public abstract class concerns_for<Contract> : observations_for_a_sut_without_a_contract<Contract>,
IHideObjectMembers
{
- protected static T when_the<T>(T item)
+ }
+
+ public abstract class concerns_for<Contract, Implementation> :
+ observations_for_a_sut_with_a_contract<Contract, Implementation>, IHideObjectMembers
+ where Implementation : Contract
+ {
+ static protected T when_the<T>(T item)
{
return item;
}
- protected static T dependency<T>() where T : class
+ static protected T dependency<T>() where T : class
{
return MockRepository.GenerateMock<T>();
}
}
- public abstract class concerns_for<Contract, Implementation> : concerns_for<Contract>, IHideObjectMembers where Implementation : Contract
- {
- }
-
public abstract class concerns_for : observations_for_a_static_sut, IHideObjectMembers
{
- protected static T dependency<T>() where T : class
+ static protected T dependency<T>() where T : class
{
return MockRepository.GenerateMock<T>();
}
- public static T when_the<T>(T item)
+ static public T when_the<T>(T item)
{
return item;
}
trunk/product/MyMoney/Testing/win.forms/Events.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Windows.Forms;
+
+namespace MyMoney.Testing.win.forms
+{
+ public class Events
+ {
+ public interface ControlEvents : IEventTarget
+ {
+ void OnEnter(EventArgs args);
+ void OnKeyPress(KeyPressEventArgs args);
+ }
+
+ public interface FormEvents : ControlEvents
+ {
+ void OnActivated(EventArgs e);
+ void OnDeactivate(EventArgs e);
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Testing/win.forms/testing_controls.cs → trunk/product/MyMoney/Testing/win.forms/EventTrigger.cs
@@ -4,26 +4,10 @@ using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
-using System.Windows.Forms;
-using jpboodhoo.bdd.contexts;
using jpboodhoo.bdd.core.extensions;
-using MyMoney.Testing.spechelpers.contexts;
-using MyMoney.Testing.spechelpers.core;
namespace MyMoney.Testing.win.forms
{
- public class when_invoking_a_call_on_a_target_via_reflection : concerns_for
- {
- it should_correctly_call_that_method = () => control.was_told_to(x => x.OnKeyPress(args));
-
- context c = () => { control = an<Events.ControlEvents>(); };
-
- because b = () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(args), control);
-
- static Events.ControlEvents control;
- static readonly KeyPressEventArgs args = new KeyPressEventArgs('A');
- }
-
static public class EventTrigger
{
const BindingFlags binding_flags = BindingFlags.Instance | BindingFlags.NonPublic;
@@ -60,6 +44,7 @@ namespace MyMoney.Testing.win.forms
static object get_value_from_member_access(Expression expression)
{
+ var member_expression = expression.downcast_to<MemberExpression>();
throw new NotImplementedException();
}
@@ -94,23 +79,4 @@ namespace MyMoney.Testing.win.forms
return expression_handlers.ContainsKey(expression.NodeType);
}
}
-
- public interface IEventTarget
- {
- }
-
- public class Events
- {
- public interface ControlEvents : IEventTarget
- {
- void OnEnter(EventArgs args);
- void OnKeyPress(KeyPressEventArgs args);
- }
-
- public interface FormEvents : ControlEvents
- {
- void OnActivated(EventArgs e);
- void OnDeactivate(EventArgs e);
- }
- }
}
\ No newline at end of file
trunk/product/MyMoney/Testing/win.forms/EventTriggerSpecs.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Windows.Forms;
+using jpboodhoo.bdd.contexts;
+using MbUnit.Framework;
+using MyMoney.Testing.spechelpers.contexts;
+using MyMoney.Testing.spechelpers.core;
+
+namespace MyMoney.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
@@ -0,0 +1,6 @@
+namespace MyMoney.Testing.win.forms
+{
+ public interface IEventTarget
+ {
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -476,7 +476,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\testing_controls.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="Utility\Core\ChainedConfiguration.cs" />
<Compile Include="Utility\Core\chained_mapper.cs" />
<Compile Include="Utility\Core\and_specification.cs" />