Commit f12f80e
Changed files (4)
trunk
src
MyMoney
Presentation
Model
Menu
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/exit_command.cs
@@ -5,7 +5,7 @@ using MyMoney.Utility.Core;
namespace MyMoney.Presentation.Model.Menu.File.Commands
{
- public interface IExitCommand : ICommand
+ public interface IExitCommand : ICommand, ISaveChangesCallback
{
}
@@ -13,14 +13,35 @@ namespace MyMoney.Presentation.Model.Menu.File.Commands
{
readonly IApplicationEnvironment application;
readonly IEventAggregator broker;
+ readonly ISaveChangesCommand command;
- public exit_command(IApplicationEnvironment application, IEventAggregator broker)
+ public exit_command(IApplicationEnvironment application, IEventAggregator broker, ISaveChangesCommand command)
{
this.application = application;
+ this.command = command;
this.broker = broker;
}
public void run()
+ {
+ command.run(this);
+ }
+
+ public void saved()
+ {
+ shut_down();
+ }
+
+ public void not_saved()
+ {
+ shut_down();
+ }
+
+ public void cancelled()
+ {
+ }
+
+ void shut_down()
{
broker.publish<closing_the_application>();
application.shut_down();
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/exit_command_specs.cs
@@ -9,26 +9,50 @@ using MyMoney.Testing.spechelpers.core;
namespace MyMoney.Presentation.Model.Menu.File.Commands
{
[Concern(typeof (exit_command))]
- public class when_closing_the_application : concerns_for<IExitCommand, exit_command>
+ public abstract class behaves_like_exit_command : concerns_for<IExitCommand>
{
- it should_ask_the_application_environment_to_shut_down = () => application.was_told_to(x => x.shut_down());
-
- it should_publish_the_shut_down_event = () => broker.was_told_to(x => x.publish<closing_the_application>());
+ public override IExitCommand create_sut()
+ {
+ return new exit_command(application, broker, save_changes_command);
+ }
context c = () =>
{
- application = an<IApplicationEnvironment>();
- broker = an<IEventAggregator>();
+ application = the_dependency<IApplicationEnvironment>();
+ broker = the_dependency<IEventAggregator>();
+ save_changes_command = the_dependency<ISaveChangesCommand>();
};
- public override IExitCommand create_sut()
- {
- return new exit_command(application, broker);
- }
+ protected static IApplicationEnvironment application;
+ protected static IEventAggregator broker;
+ protected static ISaveChangesCommand save_changes_command;
+ }
+
+ public class when_closing_the_application_after_saving_the_project : behaves_like_exit_command
+ {
+ it should_ask_the_application_environment_to_shut_down = () => application.was_told_to(x => x.shut_down());
+
+ it should_publish_the_shut_down_event = () => broker.was_told_to(x => x.publish<closing_the_application>());
+
+ because b = () => sut.saved();
+ }
+
+ public class when_closing_the_application_after_declining_to_save_the_project : behaves_like_exit_command
+ {
+ it should_ask_the_application_environment_to_shut_down = () => application.was_told_to(x => x.shut_down());
+
+ it should_publish_the_shut_down_event = () => broker.was_told_to(x => x.publish<closing_the_application>());
+
+ because b = () => sut.not_saved();
+ }
+
+ public class when_closing_the_application_after_clicking_cancel_when_prompted_to_save_changes :
+ behaves_like_exit_command
+ {
+ it should_not_ask_the_application_environment_to_shut_down = () => application.was_told_to(x => x.shut_down());
- because b = () => sut.run();
+ it should_not_publish_the_shut_down_event = () => broker.was_told_to(x => x.publish<closing_the_application>());
- static IApplicationEnvironment application;
- static IEventAggregator broker;
+ because b = () => sut.not_saved();
}
}
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/open_command.cs
@@ -5,24 +5,46 @@ using MyMoney.Utility.Core;
namespace MyMoney.Presentation.Model.Menu.File.Commands
{
- public interface IOpenCommand : ICommand
+ public interface IOpenCommand : ICommand, ISaveChangesCallback
{
}
public class open_command : IOpenCommand
{
- private readonly ISelectFileToOpenDialog view;
- private readonly IProject project;
- private readonly ILoadApplicationShellCommand command;
+ readonly ISelectFileToOpenDialog view;
+ readonly IProject project;
+ readonly ILoadApplicationShellCommand command;
+ readonly ISaveChangesCommand save_changes_command;
- public open_command(ISelectFileToOpenDialog view, IProject project, ILoadApplicationShellCommand command)
+ public open_command(ISelectFileToOpenDialog view, IProject project, ILoadApplicationShellCommand command,
+ ISaveChangesCommand save_changes_command)
{
this.view = view;
+ this.save_changes_command = save_changes_command;
this.command = command;
this.project = project;
}
public void run()
+ {
+ save_changes_command.run(this);
+ }
+
+ public void saved()
+ {
+ open_project();
+ }
+
+ public void not_saved()
+ {
+ open_project();
+ }
+
+ public void cancelled()
+ {
+ }
+
+ void open_project()
{
project.open(view.tell_me_the_path_to_the_file());
command.run();
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/open_command_specs.cs
@@ -13,7 +13,7 @@ namespace MyMoney.Presentation.Model.Menu.File.Commands
{
public override IOpenCommand create_sut()
{
- return new open_command(view, project, command);
+ return new open_command(view, project, command, save_changes_command);
}
context c = () =>
@@ -21,27 +21,77 @@ namespace MyMoney.Presentation.Model.Menu.File.Commands
view = the_dependency<ISelectFileToOpenDialog>();
command = the_dependency<ILoadApplicationShellCommand>();
project = the_dependency<IProject>();
+ save_changes_command = the_dependency<ISaveChangesCommand>();
};
protected static IProject project;
protected static ISelectFileToOpenDialog view;
protected static ILoadApplicationShellCommand command;
+ protected static ISaveChangesCommand save_changes_command;
}
- public class when_attempting_to_open_an_existing_project : behaves_like_command_to_open_a_project
+ public class before_opening_a_new_project :
+ behaves_like_command_to_open_a_project
{
+ it should_check_to_see_if_you_want_to_save_the_previously_opened_project =
+ () => save_changes_command.was_told_to(x => x.run(sut));
+
+ because b = () => sut.run();
+ }
+
+ public class when_attempting_to_open_an_existing_project_after_saving_the_previous_project :
+ behaves_like_command_to_open_a_project
+ {
+ it should_open_the_project_at_the_file_path_specified = () => project.was_told_to(x => x.open(file_path));
+
+ it will_re_load_the_application_shell = () => command.was_told_to(x => x.run());
+
context c = () =>
{
file_path = "blah_blah";
when_the(view).is_told_to(x => x.tell_me_the_path_to_the_file()).it_will_return(file_path);
};
- because b = () => sut.run();
+ because b = () => sut.saved();
+
+ static file file_path;
+ }
+ public class when_opening_a_project_after_declining_to_save_the_previous_project :
+ behaves_like_command_to_open_a_project
+ {
it should_open_the_project_at_the_file_path_specified = () => project.was_told_to(x => x.open(file_path));
it will_re_load_the_application_shell = () => command.was_told_to(x => x.run());
+ context c = () =>
+ {
+ file_path = "blah_blah";
+ when_the(view).is_told_to(x => x.tell_me_the_path_to_the_file()).it_will_return(file_path);
+ };
+
+ because b = () => sut.not_saved();
+
+ static file file_path;
+ }
+
+ public class
+ when_opening_a_new_project_and_then_deciding_that_you_want_to_continue_working_on_the_previously_opened_project :
+ behaves_like_command_to_open_a_project
+ {
+ it should_not_open_the_project_at_the_file_path_specified =
+ () => project.should_not_have_been_asked_to(x => x.open(file_path));
+
+ it will_not_re_load_the_application_shell = () => command.should_not_have_been_asked_to(x => x.run());
+
+ context c = () =>
+ {
+ file_path = "blah_blah";
+ when_the(view).is_told_to(x => x.tell_me_the_path_to_the_file()).it_will_return(file_path);
+ };
+
+ because b = () => sut.cancelled();
+
static file file_path;
}
}
\ No newline at end of file