Commit 01c3d45

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-03-14 00:43:01
now closing previous project when opening a new one.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@74 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 9246e8b
trunk/product/MyMoney/DataAccess/db40/SessionFactory.cs
@@ -1,11 +1,10 @@
 using Db4objects.Db4o;
-using MoMoney.DataAccess.db40;
-using MoMoney.Utility.Core;
 
 namespace MoMoney.DataAccess.db40
 {
-    public interface ISessionFactory : IFactory<IObjectContainer>
+    public interface ISessionFactory // : IFactory<IObjectContainer>
     {
+        IObjectContainer create();
     }
 
     public class SessionFactory : ISessionFactory
trunk/product/MyMoney/Presentation/Model/Projects/CurrentProject.cs
@@ -44,7 +44,13 @@ namespace MoMoney.Presentation.Model.Projects
         public void open(IFile file)
         {
             if (!file.does_the_file_exist()) return;
+            if (is_open())
+            {
+                close();
+            }
+
             current_file = file;
+            is_project_open = true;
             configuration.change_path_to(file);
             changes_to_save = false;
             broker.publish(new new_project_opened(name()));
trunk/product/MyMoney/Presentation/Model/Projects/CurrentProjectSpecs.cs
@@ -13,11 +13,6 @@ namespace MoMoney.Presentation.Model.Projects
     [Concern(typeof (CurrentProject))]
     public abstract class behaves_like_a_project : concerns_for<IProject, CurrentProject>
     {
-        public override IProject create_sut()
-        {
-            return new CurrentProject(configuration, broker);
-        }
-
         context c = () =>
                         {
                             configuration = the_dependency<IDatabaseConfiguration>();
@@ -176,4 +171,34 @@ namespace MoMoney.Presentation.Model.Projects
         static IFile file;
         static unsaved_changes_event message;
     }
+
+    public class when_starting_a_new_project_and_a_project_was_already_open : behaves_like_a_project
+    {
+        it should_close_the_previous_project = () => broker.was_told_to(x => x.publish<closing_project_event>());
+
+        because b = () =>
+                        {
+                            sut.start_a_new_project();
+                            sut.start_a_new_project();
+                        };
+    }
+
+    public class when_opening_an_existing_project_and_a_project_was_already_open : behaves_like_a_project
+    {
+        it should_close_the_previous_project = () => broker.was_told_to(x => x.publish<closing_project_event>());
+
+        context c = () =>
+                        {
+                            file = an<IFile>();
+                            when_the(file).is_told_to(x => x.does_the_file_exist()).it_will_return(true);
+                        };
+
+        because b = () =>
+                        {
+                            sut.open(file);
+                            sut.start_a_new_project();
+                        };
+
+        static IFile file;
+    }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Projects/file.cs
@@ -1,4 +1,3 @@
-using System;
 using System.IO;
 using MoMoney.Infrastructure.Extensions;
 
@@ -29,13 +28,6 @@ namespace MoMoney.Presentation.Model.Projects
         {
             this.log().debug("copying file {0} to {1}", path, file_to_overwrite.path);
             File.Copy(path, file_to_overwrite.path, true);
-
-            //using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
-            //{
-            //    var content = new byte[fs.Length];
-            //    fs.Read(content, 0, Convert.ToInt32(fs.Length));
-            //    File.WriteAllBytes(file_to_overwrite.path, content);
-            //}
         }
 
         public static implicit operator ApplicationFile(string file_path)
trunk/product/MyMoney/Presentation/Views/core/ApplicationWindow.cs
@@ -16,6 +16,7 @@ namespace MoMoney.Presentation.Views.core
         {
             InitializeComponent();
             Icon = ApplicationIcons.Application;
+            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
         }
 
         public IApplicationWindow create_tool_tip_for(string title, string caption, Control control)
trunk/product/MyMoney/Presentation/Views/dialogs/SaveChangesView.cs
@@ -19,17 +19,17 @@ namespace MoMoney.Presentation.Views.dialogs
             ux_image.SizeMode = PictureBoxSizeMode.StretchImage;
 
             titled("Unsaved Changes")
-                .create_tool_tip_for("Save", "Save the document, and then close it.", ux_save_button)
-                .create_tool_tip_for("Don't Save", "Discard the unsaved changes.", ux_do_not_save_button)
-                .create_tool_tip_for("Cancel", "Go back.", ux_cancel_button);
+                .create_tool_tip_for("Save", "Save the document, and then close it.", save_button)
+                .create_tool_tip_for("Don't Save", "Discard the unsaved changes.", do_not_save_button)
+                .create_tool_tip_for("Cancel", "Go back.", cancel_button);
         }
 
 
         public void attach_to(ISaveChangesPresenter presenter)
         {
-            ux_save_button.Click += (sender, e) => execute(presenter.save);
-            ux_do_not_save_button.Click += (sender, e) => execute(presenter.dont_save);
-            ux_cancel_button.Click += (sender, e) => execute(presenter.cancel);
+            save_button.Click += (sender, e) => execute(presenter.save);
+            do_not_save_button.Click += (sender, e) => execute(presenter.dont_save);
+            cancel_button.Click += (sender, e) => execute(presenter.cancel);
             Closing += (sender, e) => { if (!can_be_closed) presenter.cancel(); };
         }
 
trunk/product/MyMoney/Presentation/Views/dialogs/SaveChangesView.Designer.cs
@@ -28,9 +28,9 @@ public    partial class SaveChangesView
         /// </summary>
         private void InitializeComponent()
         {
-            this.ux_save_button = new System.Windows.Forms.Button();
-            this.ux_do_not_save_button = new System.Windows.Forms.Button();
-            this.ux_cancel_button = new System.Windows.Forms.Button();
+            this.save_button = new System.Windows.Forms.Button();
+            this.do_not_save_button = new System.Windows.Forms.Button();
+            this.cancel_button = new System.Windows.Forms.Button();
             this.ux_image = new System.Windows.Forms.PictureBox();
             this.label1 = new System.Windows.Forms.Label();
             this.label2 = new System.Windows.Forms.Label();
@@ -40,33 +40,33 @@ public    partial class SaveChangesView
             // 
             // ux_save_button
             // 
-            this.ux_save_button.Location = new System.Drawing.Point(12, 100);
-            this.ux_save_button.Name = "ux_save_button";
-            this.ux_save_button.Size = new System.Drawing.Size(267, 63);
-            this.ux_save_button.TabIndex = 0;
-            this.ux_save_button.Text = "&Save";
-            this.ux_save_button.UseVisualStyleBackColor = true;
+            this.save_button.Location = new System.Drawing.Point(12, 100);
+            this.save_button.Name = "save_button";
+            this.save_button.Size = new System.Drawing.Size(267, 63);
+            this.save_button.TabIndex = 0;
+            this.save_button.Text = "&Save";
+            this.save_button.UseVisualStyleBackColor = true;
             // 
             // ux_do_not_save_button
             // 
-            this.ux_do_not_save_button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
-            this.ux_do_not_save_button.Location = new System.Drawing.Point(13, 185);
-            this.ux_do_not_save_button.Name = "ux_do_not_save_button";
-            this.ux_do_not_save_button.Size = new System.Drawing.Size(267, 63);
-            this.ux_do_not_save_button.TabIndex = 2;
-            this.ux_do_not_save_button.Text = "Do&n\'t Save";
-            this.ux_do_not_save_button.UseVisualStyleBackColor = true;
+            this.do_not_save_button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.do_not_save_button.Location = new System.Drawing.Point(13, 185);
+            this.do_not_save_button.Name = "do_not_save_button";
+            this.do_not_save_button.Size = new System.Drawing.Size(267, 63);
+            this.do_not_save_button.TabIndex = 2;
+            this.do_not_save_button.Text = "Do&n\'t Save";
+            this.do_not_save_button.UseVisualStyleBackColor = true;
             // 
             // ux_cancel_button
             // 
-            this.ux_cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-            this.ux_cancel_button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
-            this.ux_cancel_button.Location = new System.Drawing.Point(13, 254);
-            this.ux_cancel_button.Name = "ux_cancel_button";
-            this.ux_cancel_button.Size = new System.Drawing.Size(267, 63);
-            this.ux_cancel_button.TabIndex = 3;
-            this.ux_cancel_button.Text = "Cancel";
-            this.ux_cancel_button.UseVisualStyleBackColor = true;
+            this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+            this.cancel_button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+            this.cancel_button.Location = new System.Drawing.Point(13, 254);
+            this.cancel_button.Name = "cancel_button";
+            this.cancel_button.Size = new System.Drawing.Size(267, 63);
+            this.cancel_button.TabIndex = 3;
+            this.cancel_button.Text = "Cancel";
+            this.cancel_button.UseVisualStyleBackColor = true;
             // 
             // ux_image
             // 
@@ -106,18 +106,18 @@ public    partial class SaveChangesView
             // 
             // UnsavedChangesView
             // 
-            this.AcceptButton = this.ux_save_button;
+            this.AcceptButton = this.save_button;
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.CancelButton = this.ux_cancel_button;
+            this.CancelButton = this.cancel_button;
             this.ClientSize = new System.Drawing.Size(295, 327);
             this.Controls.Add(this.label3);
             this.Controls.Add(this.label2);
             this.Controls.Add(this.label1);
             this.Controls.Add(this.ux_image);
-            this.Controls.Add(this.ux_cancel_button);
-            this.Controls.Add(this.ux_do_not_save_button);
-            this.Controls.Add(this.ux_save_button);
+            this.Controls.Add(this.cancel_button);
+            this.Controls.Add(this.do_not_save_button);
+            this.Controls.Add(this.save_button);
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
             this.MaximizeBox = false;
             this.MinimizeBox = false;
@@ -134,9 +134,9 @@ public    partial class SaveChangesView
 
         #endregion
 
-    public System.Windows.Forms.Button ux_save_button;
-        public System.Windows.Forms.Button ux_do_not_save_button;
-        public System.Windows.Forms.Button ux_cancel_button;
+    public System.Windows.Forms.Button save_button;
+        public System.Windows.Forms.Button do_not_save_button;
+        public System.Windows.Forms.Button cancel_button;
         public System.Windows.Forms.PictureBox ux_image;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label label2;
trunk/product/MyMoney/Presentation/Views/dialogs/SaveChangesViewSpecs.cs
@@ -7,38 +7,38 @@ using MoMoney.Testing.spechelpers.core;
 
 namespace MoMoney.Presentation.Views.dialogs
 {
-    public class behaves_like_save_changes_view_bound_to_presenter : concerns_for<SaveChangesView>
+    public class when_prompted_to_save_changes_to_the_project : concerns_for<SaveChangesView>
     {
         context c = () => { presenter = an<ISaveChangesPresenter>(); };
 
-        because b = () => sut.attach_to(presenter);
+        after_the_sut_has_been_created after = () =>
+                                                   {
+                                                       save_changes_window = sut;
+                                                       save_changes_window.attach_to(presenter);
+                                                   };
 
-        static protected ISaveChangesPresenter presenter;
+        protected static ISaveChangesPresenter presenter;
+        protected static SaveChangesView save_changes_window;
     }
 
-    public class when_the_save_button_is_clicked : behaves_like_save_changes_view_bound_to_presenter
+    public class when_the_save_button_is_pressed : when_prompted_to_save_changes_to_the_project
     {
-        it should_forward_the_call_to_the_presenter = () => presenter.was_told_to(x => x.save());
+        it should_save_the_current_project = () => presenter.was_told_to(x => x.save());
 
-        because b =
-            () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnClick(new EventArgs()), sut.ux_save_button);
+        because b = () => save_changes_window.save_button.control_is(x => x.OnClick(new EventArgs()));
     }
 
-    public class when_the_cancel_button_is_clicked : behaves_like_save_changes_view_bound_to_presenter
+    public class when_the_cancel_button_is_pressed : when_prompted_to_save_changes_to_the_project
     {
-        it should_forward_the_call_to_the_presenter = () => presenter.was_told_to(x => x.cancel());
+        it should_not_continue_processing_the_previous_action = () => presenter.was_told_to(x => x.cancel());
 
-        because b =
-            () =>
-            EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnClick(new EventArgs()), sut.ux_cancel_button);
+        because b = () => save_changes_window.cancel_button.control_is(x => x.OnClick(new EventArgs()));
     }
 
-    public class when_the_do_not_save_button_is_clicked : behaves_like_save_changes_view_bound_to_presenter
+    public class when_the_do_not_save_button_is_pressed : when_prompted_to_save_changes_to_the_project
     {
-        it should_forward_the_call_to_the_presenter = () => presenter.was_told_to(x => x.dont_save());
+        it should_not_save_the_project = () => presenter.was_told_to(x => x.dont_save());
 
-        because b =
-            () =>
-            EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnClick(new EventArgs()), sut.ux_do_not_save_button);
+        because b = () => save_changes_window.do_not_save_button.control_is(x => x.OnClick(new EventArgs()));
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/helpers/EventTriggerExtensions.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Linq.Expressions;
+
+namespace MoMoney.Presentation.Views.helpers
+{
+    public static class EventTriggerExtensions
+    {
+        public static void control_is<Control>(this Control target, Expression<Action<Events.ControlEvents>> expression)
+            where Control : System.Windows.Forms.Control
+        {
+            EventTrigger.trigger_event(expression, target);
+        }
+    }
+}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/Shell/ApplicationShell.cs
@@ -17,7 +17,6 @@ namespace MoMoney.Presentation.Views.Shell
         public ApplicationShell()
         {
             InitializeComponent();
-            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
             regions = new Dictionary<string, Control>
                           {
                               {GetType().FullName, this},
trunk/product/MyMoney/Tasks/infrastructure/LogFileTasks.cs
@@ -12,7 +12,14 @@ namespace MoMoney.Tasks.infrastructure
     {
         public string get_the_contents_of_the_log_file()
         {
-            return File.ReadAllText(Path.Combine(this.startup_directory(), "logs/log.txt"));
+            var log_file_path = Path.Combine(this.startup_directory(), "logs/log.txt");
+            using (var file_stream = new FileStream(log_file_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+            {
+                using (var reader = new StreamReader(file_stream))
+                {
+                    return reader.ReadToEnd();
+                }
+            }
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Testing/MetaData/run_in_real_container.cs
@@ -17,15 +17,18 @@ namespace MoMoney.Testing.MetaData
     public class run_in_real_container_interceptor : DecoratorRunInvoker
     {
         public run_in_real_container_interceptor(IRunInvoker wrapper) : base(wrapper)
-        {}
+        {
+        }
 
         public override object Execute(object o, IList args)
         {
-            try {
+            try
+            {
                 resolve.initialize_with(new WindsorDependencyRegistry());
                 return Invoker.Execute(o, args);
             }
-            finally {
+            finally
+            {
                 resolve.initialize_with(null);
             }
         }
trunk/product/MyMoney/Testing/spechelpers/contexts/behaves_like_a_repository.cs
@@ -1,11 +1,13 @@
+using developwithpassion.bdd.contexts;
 using MbUnit.Framework;
 using MoMoney.Domain.Core;
 using MoMoney.Infrastructure.Container;
+using MoMoney.Infrastructure.Container.Windsor;
 using MoMoney.Testing.MetaData;
 
 namespace MoMoney.Testing.spechelpers.contexts
 {
-    [run_in_real_container]
+    //[run_in_real_container]
     [Concern(typeof (IRepository))]
     [Ignore]
     public abstract class behaves_like_a_repository : concerns_for<IRepository>
@@ -14,5 +16,9 @@ namespace MoMoney.Testing.spechelpers.contexts
         {
             return resolve.dependency_for<IRepository>();
         }
+
+        before_all_observations all = () => resolve.initialize_with(new WindsorDependencyRegistry());
+
+        after_all_observations after_all = () => resolve.initialize_with(null);
     }
 }
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -417,6 +417,7 @@
       <DependentUpon>SaveChangesView.cs</DependentUpon>
     </Compile>
     <Compile Include="Presentation\Views\dialogs\SaveChangesViewSpecs.cs" />
+    <Compile Include="Presentation\Views\helpers\EventTriggerExtensions.cs" />
     <Compile Include="Presentation\Views\IAddCompanyView.cs" />
     <Compile Include="Presentation\Views\billing\IViewAllBills.cs" />
     <Compile Include="Presentation\Views\billing\view_all_bills.cs">