Commit 5efa9db

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-02-26 19:57:00
updated the new command to check for changes before opening a new project.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@18 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent bb37b45
Changed files (3)
trunk
src
MyMoney
Presentation
Testing
spechelpers
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/new_command.cs
@@ -4,7 +4,7 @@ using MyMoney.Utility.Core;
 
 namespace MyMoney.Presentation.Model.Menu.File.Commands
 {
-    public interface INewCommand : ICommand
+    public interface INewCommand : ICommand, ISaveChangesCallback
     {
     }
 
@@ -12,17 +12,34 @@ namespace MyMoney.Presentation.Model.Menu.File.Commands
     {
         readonly IProject current_project;
         readonly ILoadApplicationShellCommand command;
+        readonly ISaveChangesCommand save_changes_command;
 
-        public new_command(IProject current_project, ILoadApplicationShellCommand command)
+        public new_command(IProject current_project, ILoadApplicationShellCommand command, ISaveChangesCommand save_changes_command)
         {
             this.current_project = current_project;
+            this.save_changes_command = save_changes_command;
             this.command = command;
         }
 
         public void run()
+        {
+            save_changes_command.run(this);
+        }
+
+        public void saved()
         {
             current_project.start_a_new_project();
             command.run();
         }
+
+        public void not_saved()
+        {
+            current_project.start_a_new_project();
+            command.run();
+        }
+
+        public void cancelled()
+        {
+        }
     }
 }
\ No newline at end of file
trunk/src/MyMoney/Presentation/Model/Menu/File/Commands/new_command_specs.cs
@@ -8,24 +8,53 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Model.Menu.File.Commands
 {
     [Concern(typeof (new_command))]
-    public class when_starting_a_new_project : concerns_for<INewCommand, new_command>
+    public abstract class behaves_like_new_command : concerns_for<INewCommand, new_command>
     {
-        it should_start_a_new_project = () => current_project.was_told_to(x => x.start_a_new_project());
+        public override INewCommand create_sut()
+        {
+            return new new_command(current_project, command, save_changes_command);
+        }
 
         context c = () =>
                         {
-                            current_project = an<IProject>();
-                            command = an<ILoadApplicationShellCommand>();
+                            current_project = the_dependency<IProject>();
+                            command = the_dependency<ILoadApplicationShellCommand>();
+                            save_changes_command = the_dependency<ISaveChangesCommand>();
                         };
 
+        protected static IProject current_project;
+        protected static ILoadApplicationShellCommand command;
+        protected static ISaveChangesCommand save_changes_command;
+    }
+
+    public class before_starting_a_new_project : behaves_like_new_command
+    {
+        it should_check_to_see_if_there_were_any_unsaved_changes_to_a_previous_project =
+            () => save_changes_command.was_told_to(x => x.run(sut));
+
         because b = () => sut.run();
+    }
 
-        public override INewCommand create_sut()
-        {
-            return new new_command(current_project, command);
-        }
+    public class when_starting_a_new_project_after_saving_a_previous_one : behaves_like_new_command
+    {
+        it should_start_a_new_project = () => current_project.was_told_to(x => x.start_a_new_project());
+
+        because b = () => sut.saved();
+    }
+
+    public class when_starting_a_new_project_after_declining_to_save_a_previous_one : behaves_like_new_command
+    {
+        it should_start_a_new_project = () => current_project.was_told_to(x => x.start_a_new_project());
+
+        because b = () => sut.not_saved();
+    }
+
+    public class when_starting_a_new_project_and_cancelling_when_asked_to_save_the_changes_to_a_previous_project :
+        behaves_like_new_command
+    {
+        it should_not_start_a_new_project =
+            () => current_project.should_not_have_been_asked_to(x => x.start_a_new_project());
 
-        static IProject current_project;
-        static ILoadApplicationShellCommand command;
+        because b = () => sut.cancelled();
     }
 }
\ No newline at end of file
trunk/src/MyMoney/Testing/spechelpers/core/mocking_extensions.cs
@@ -9,8 +9,7 @@ namespace MyMoney.Testing.spechelpers.core
 {
     public static class mocking_extensions
     {
-        public static method_call_occurance<T> was_told_to<T>(this T mocked_item,
-                                                              Action<T> actionToPerform)
+        public static method_call_occurance<T> was_told_to<T>(this T mocked_item, Action<T> actionToPerform)
         {
             return new method_call_occurance<T>(mocked_item, actionToPerform);
         }