Commit 58adb1e
Changed files (17)
trunk
product
MyMoney
Presentation
Core
Presenters
Testing
win.forms
Utility
Core
windows.ui
trunk/product/MyMoney/Presentation/Core/presenter_registry.cs → trunk/product/MyMoney/Presentation/Core/PresenterRegistry.cs
@@ -7,11 +7,11 @@ namespace MyMoney.Presentation.Core
{
}
- public class presenter_registry : IPresenterRegistry
+ public class PresenterRegistry : IPresenterRegistry
{
readonly IRegistry<IPresenter> presenters;
- public presenter_registry(IRegistry<IPresenter> presenters)
+ public PresenterRegistry(IRegistry<IPresenter> presenters)
{
this.presenters = presenters;
}
trunk/product/MyMoney/Presentation/Presenters/Shell/GettingStartedPresenter.cs
@@ -0,0 +1,33 @@
+using MyMoney.Infrastructure.eventing;
+using MyMoney.Presentation.Core;
+using MyMoney.Presentation.Model.messages;
+using MyMoney.Presentation.Views.Shell;
+
+namespace MyMoney.Presentation.Presenters.Shell
+{
+ public interface IGettingStartedPresenter : IPresentationModule, IEventSubscriber<new_project_opened>
+ {
+ }
+
+ public class GettingStartedPresenter : IGettingStartedPresenter
+ {
+ readonly IGettingStartedView view;
+ readonly IEventAggregator broker;
+
+ public GettingStartedPresenter(IGettingStartedView view, IEventAggregator broker)
+ {
+ this.view = view;
+ this.broker = broker;
+ }
+
+ public void run()
+ {
+ broker.subscribe_to(this);
+ }
+
+ public void notify(new_project_opened message)
+ {
+ view.display();
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Shell/GettingStartedPresenterSpecs.cs
@@ -0,0 +1,45 @@
+using jpboodhoo.bdd.contexts;
+using MyMoney.Infrastructure.eventing;
+using MyMoney.Presentation.Model.messages;
+using MyMoney.Presentation.Views.Shell;
+using MyMoney.Testing.spechelpers.contexts;
+using MyMoney.Testing.spechelpers.core;
+
+namespace MyMoney.Presentation.Presenters.Shell
+{
+ public class GettingStartedPresenterSpecs
+ {
+ public class behaves_like_the_getting_started_presenter :
+ concerns_for<IGettingStartedPresenter, GettingStartedPresenter>
+ {
+ public override IGettingStartedPresenter create_sut()
+ {
+ return new GettingStartedPresenter(view, broker);
+ }
+
+ context c = () =>
+ {
+ view = the_dependency<IGettingStartedView>();
+ broker = the_dependency<IEventAggregator>();
+ };
+
+ protected static IEventAggregator broker;
+ protected static IGettingStartedView view;
+ }
+
+ public class when_initializing_the_getting_started_module : behaves_like_the_getting_started_presenter
+ {
+ it should_start_listening_for_when_a_new_project_is_started =
+ () => broker.was_told_to(x => x.subscribe_to(sut));
+
+ because b = () => sut.run();
+ }
+
+ public class when_a_new_project_is_opened : behaves_like_the_getting_started_presenter
+ {
+ it should_display_the_getting_started_screen = () => view.was_told_to(x => x.display());
+
+ because b = () => sut.notify(new new_project_opened(""));
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/Shell/UnhandledErrorPresenter.cs
@@ -5,7 +5,7 @@ using MyMoney.Presentation.Views.Shell;
namespace MyMoney.Presentation.Presenters.Shell
{
- public interface IUnhandledErrorPresenter : IPresenter, IEventSubscriber<unhandled_error_occurred>
+ public interface IUnhandledErrorPresenter : IPresentationModule, IEventSubscriber<unhandled_error_occurred>
{
}
trunk/product/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenter.cs
@@ -51,7 +51,7 @@ namespace MyMoney.Presentation.Presenters.updates
public void do_not_update()
{
- throw new NotImplementedException();
+ view.close();
}
public void complete()
trunk/product/MyMoney/Presentation/Views/core/ApplicationWindow.cs
@@ -1,4 +1,5 @@
-using System.Windows.Forms;
+using System;
+using System.Windows.Forms;
using MyMoney.Presentation.Resources;
namespace MyMoney.Presentation.Views.core
@@ -28,5 +29,10 @@ namespace MyMoney.Presentation.Views.core
base.Text = "MoMoney - " + title;
return this;
}
+
+ public void execute(Action action)
+ {
+ BeginInvoke(action);
+ }
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Shell/IGettingStartedView.cs
@@ -0,0 +1,9 @@
+using MyMoney.Presentation.Views.core;
+
+namespace MyMoney.Presentation.Views.Shell
+{
+ public interface IGettingStartedView : IDockedContentView
+ {
+ void display();
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Shell/UnhandledErrorView.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Windows.Forms;
+using MyMoney.Presentation.Presenters.Shell;
+
+namespace MyMoney.Presentation.Views.Shell
+{
+ public class UnhandledErrorView : IUnhandledErrorView
+ {
+ public void attach_to(IUnhandledErrorPresenter presenter)
+ {
+ }
+
+ public void display(Exception exception)
+ {
+ MessageBox.Show(exception.ToString());
+ }
+
+ public IAsyncResult BeginInvoke(Delegate method, object[] args)
+ {
+ return null;
+ }
+
+ public object EndInvoke(IAsyncResult result)
+ {
+ return new object();
+ }
+
+ public object Invoke(Delegate method, object[] args)
+ {
+ return new object();
+ }
+
+ public bool InvokeRequired
+ {
+ get { return false; }
+ }
+
+ public void Dispose()
+ {
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdates.cs → trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.cs
@@ -7,11 +7,11 @@ using MyMoney.Presentation.Views.core;
namespace MyMoney.Presentation.Views.updates
{
- public partial class CheckForUpdates : ApplicationWindow, ICheckForUpdatesView
+ public partial class CheckForUpdatesView : ApplicationWindow, ICheckForUpdatesView
{
ICheckForUpdatesPresenter the_presenter;
- public CheckForUpdates()
+ public CheckForUpdatesView()
{
InitializeComponent();
ux_image.Image = ApplicationImages.Splash;
@@ -49,8 +49,14 @@ namespace MyMoney.Presentation.Views.updates
public void update_complete()
{
+ //execute(()=> MessageBox.Show("update complete, the application will now restart.", "Complete", MessageBoxButtons.OK));
MessageBox.Show("update complete, the application will now restart.", "Complete", MessageBoxButtons.OK);
the_presenter.restart();
}
+
+ public void close()
+ {
+ Close();
+ }
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdates.Designer.cs → trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.Designer.cs
@@ -1,6 +1,6 @@
namespace MyMoney.Presentation.Views.updates
{
- partial class CheckForUpdates
+ partial class CheckForUpdatesView
{
/// <summary>
/// Required designer variable.
trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdates.resx → trunk/product/MyMoney/Presentation/Views/updates/CheckForUpdatesView.resx
File renamed without changes
trunk/product/MyMoney/Presentation/Views/updates/ICheckForUpdatesView.cs
@@ -8,5 +8,6 @@ namespace MyMoney.Presentation.Views.updates
{
void display(ApplicationVersion information);
void update_complete();
+ void close();
}
}
\ No newline at end of file
trunk/product/MyMoney/Testing/win.forms/testing_controls.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Collections.Generic;
+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;
+ static readonly IDictionary<ExpressionType, Func<Expression, object>> expression_handlers;
+
+ static EventTrigger()
+ {
+ expression_handlers = new Dictionary<ExpressionType, Func<Expression, object>>();
+ expression_handlers[ExpressionType.New] = instantiate_value;
+ expression_handlers[ExpressionType.MemberAccess] = get_value_from_member_access;
+ expression_handlers[ExpressionType.Constant] = get_constant_value;
+ }
+
+ static public void trigger_event<Target>(Expression<Action<Target>> expression_representing_event_to_raise,
+ object target) where Target : IEventTarget
+ {
+ var method_call_expression = expression_representing_event_to_raise.Body.downcast_to<MethodCallExpression>();
+ var method_args = get_parameters_from(method_call_expression.Arguments);
+ var method_name = method_call_expression.Method.Name;
+ 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()));
+
+ method.Invoke(target, method_args.ToArray());
+ }
+
+ static object get_constant_value(Expression expression)
+ {
+ return expression.downcast_to<ConstantExpression>().Value;
+ }
+
+ static object get_value_from_member_access(Expression expression)
+ {
+ throw new NotImplementedException();
+ }
+
+ static object instantiate_value(Expression expression)
+ {
+ var new_expression = expression.downcast_to<NewExpression>();
+ var args = new_expression.Arguments.Select(x => get_value_from_evaluating(x));
+ return new_expression.Constructor.Invoke(args.ToArray());
+ }
+
+ static IEnumerable<object> get_parameters_from(IEnumerable<Expression> parameter_expressions)
+ {
+ foreach (var expression in parameter_expressions)
+ {
+ if (can_handle(expression)) yield return get_value_from_evaluating(expression);
+ else cannot_handle(expression);
+ }
+ }
+
+ static void cannot_handle(Expression expression)
+ {
+ throw new NotImplementedException();
+ }
+
+ static object get_value_from_evaluating(Expression expression)
+ {
+ return expression_handlers[expression.NodeType](expression);
+ }
+
+ static bool can_handle(Expression expression)
+ {
+ 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/Utility/Core/ICallback.cs
@@ -4,4 +4,9 @@ namespace MyMoney.Utility.Core
{
void complete();
}
+
+ public interface ICallback<T>
+ {
+ void complete(T item);
+ }
}
\ No newline at end of file
trunk/product/MyMoney/windows.ui/wire_up_the_views_in_to_the.cs
@@ -36,7 +36,7 @@ namespace MyMoney.windows.ui
register.transient<IAddNewIncomeView, AddNewIncomeView>();
register.transient<IViewIncomeHistory, ViewAllIncome>();
register.transient<ISaveChangesView, SaveChangesView>();
- register.transient<ICheckForUpdatesView, CheckForUpdates>();
+ register.transient<ICheckForUpdatesView, CheckForUpdatesView>();
register.transient<INotificationIconView, NotificationIconView>();
register.transient<IStatusBarView, StatusBarView>();
}
trunk/product/MyMoney/MyMoney.csproj
@@ -277,7 +277,7 @@
<Compile Include="Presentation\Model\Navigation\branches\view_all_bills_branch.cs" />
<Compile Include="Presentation\Model\Navigation\branches\view_all_bills_report_branch.cs" />
<Compile Include="Presentation\Model\Projects\current_project.cs" />
- <Compile Include="Presentation\Core\presenter_registry.cs" />
+ <Compile Include="Presentation\Core\PresenterRegistry.cs" />
<Compile Include="Presentation\Model\Menu\create.cs" />
<Compile Include="Presentation\Model\Menu\File\Commands\exit_command.cs" />
<Compile Include="Presentation\Model\Menu\File\Commands\new_command.cs" />
@@ -342,6 +342,8 @@
<Compile Include="Presentation\Presenters\Navigation\ExpandoBuilder.cs" />
<Compile Include="Presentation\Presenters\Navigation\ExpandoItemBuilder.cs" />
<Compile Include="Presentation\Presenters\Navigation\IActionTaskPaneFactory.cs" />
+ <Compile Include="Presentation\Presenters\Shell\GettingStartedPresenter.cs" />
+ <Compile Include="Presentation\Presenters\Shell\GettingStartedPresenterSpecs.cs" />
<Compile Include="Presentation\Presenters\Shell\ToolBarPresenter.cs" />
<Compile Include="Presentation\Presenters\Navigation\MainMenuPresenter.cs" />
<Compile Include="Presentation\Presenters\Navigation\NavigationPresenter.cs" />
@@ -447,6 +449,7 @@
<Compile Include="Presentation\Views\billing\view_all_bills_report.Designer.cs">
<DependentUpon>view_all_bills_report.cs</DependentUpon>
</Compile>
+ <Compile Include="Presentation\Views\Shell\IGettingStartedView.cs" />
<Compile Include="Presentation\Views\Shell\INotificationIconView.cs" />
<Compile Include="Presentation\Views\Shell\IShell.cs" />
<Compile Include="Presentation\Views\Shell\IUnhandledErrorView.cs" />
@@ -454,11 +457,12 @@
<Compile Include="Presentation\Views\Shell\StatusBarView.cs" />
<Compile Include="Presentation\Views\Shell\TaskTrayMessage.cs" />
<Compile Include="Presentation\Views\Shell\TitleBar.cs" />
- <Compile Include="Presentation\Views\updates\CheckForUpdates.cs">
+ <Compile Include="Presentation\Views\Shell\UnhandledErrorView.cs" />
+ <Compile Include="Presentation\Views\updates\CheckForUpdatesView.cs">
<SubType>Form</SubType>
</Compile>
- <Compile Include="Presentation\Views\updates\CheckForUpdates.Designer.cs">
- <DependentUpon>CheckForUpdates.cs</DependentUpon>
+ <Compile Include="Presentation\Views\updates\CheckForUpdatesView.Designer.cs">
+ <DependentUpon>CheckForUpdatesView.cs</DependentUpon>
</Compile>
<Compile Include="Presentation\Views\updates\ICheckForUpdatesView.cs" />
<Compile Include="Tasks\application\BillingTasks.cs" />
@@ -472,6 +476,7 @@
<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="Utility\Core\ChainedConfiguration.cs" />
<Compile Include="Utility\Core\chained_mapper.cs" />
<Compile Include="Utility\Core\and_specification.cs" />
@@ -644,8 +649,8 @@
<EmbeddedResource Include="Presentation\Views\Startup\splash_screen_view.resx">
<DependentUpon>splash_screen_view.cs</DependentUpon>
</EmbeddedResource>
- <EmbeddedResource Include="Presentation\Views\updates\CheckForUpdates.resx">
- <DependentUpon>CheckForUpdates.cs</DependentUpon>
+ <EmbeddedResource Include="Presentation\Views\updates\CheckForUpdatesView.resx">
+ <DependentUpon>CheckForUpdatesView.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>