Commit 2e50560

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-02-28 18:11:36
clean up, clean up... everyone do your share. clean up clean up, everybody every where.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@30 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 8e25686
trunk/src/MyMoney/Domain/accounting/billing/company_specs.cs
@@ -9,7 +9,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Domain.accounting.billing
 {
     [Concern(typeof (Company))]
-    public class behaves_like_a_company : concerns_for<ICompany>
+    public abstract class behaves_like_a_company : concerns_for<ICompany>
     {
         protected string company_name;
 
trunk/src/MyMoney/Domain/accounting/account_holder_specs.cs
@@ -12,7 +12,7 @@ using mocking_extensions=MyMoney.Testing.spechelpers.core.mocking_extensions;
 namespace MyMoney.Domain.accounting
 {
     [Concern(typeof (account_holder))]
-    public class behaves_like_an_account_holder : concerns_for<IAccountHolder>
+    public abstract class behaves_like_an_account_holder : concerns_for<IAccountHolder>
     {
         public override IAccountHolder create_sut()
         {
trunk/src/MyMoney/Domain/accounting/GeneralLedgerSpecs.cs
@@ -10,12 +10,8 @@ using mocking_extensions=MyMoney.Testing.spechelpers.core.mocking_extensions;
 
 namespace MyMoney.Domain.accounting
 {
-    public class GeneralLedgerSpecs
-    {
-    }
-
     [Concern(typeof (general_ledger))]
-    public class behaves_like_a_general_ledger : concerns_for<IGeneralLedger, general_ledger>
+    public abstract class behaves_like_a_general_ledger : concerns_for<IGeneralLedger, general_ledger>
     {
         public override IGeneralLedger create_sut()
         {
trunk/src/MyMoney/Domain/Core/range_specs.cs
@@ -6,7 +6,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Domain.Core
 {
     [Concern(typeof (range<int>))]
-    public class behaves_like_a_range_from_1_to_10 : concerns_for<IRange<int>>
+    public abstract class behaves_like_a_range_from_1_to_10 : concerns_for<IRange<int>>
     {
         public override IRange<int> create_sut()
         {
@@ -15,7 +15,7 @@ namespace MyMoney.Domain.Core
     }
 
     [Concern(typeof (range<int>))]
-    public class behaves_like_a_range_from_10_to_1 : concerns_for<IRange<int>>
+    public abstract class behaves_like_a_range_from_10_to_1 : concerns_for<IRange<int>>
     {
         public override IRange<int> create_sut()
         {
trunk/src/MyMoney/Infrastructure/cloning/BinarySerializer.cs
@@ -0,0 +1,11 @@
+using System.Runtime.Serialization.Formatters.Binary;
+
+namespace MyMoney.Infrastructure.cloning
+{
+    public class BinarySerializer<T> : Serializer<T>
+    {
+        public BinarySerializer(string file_path) : base(file_path, new BinaryFormatter())
+        {
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/cloning/BinarySerializerSpecs.cs
@@ -0,0 +1,74 @@
+using System;
+using System.IO;
+using jpboodhoo.bdd.contexts;
+using MbUnit.Framework;
+using MyMoney.Testing.MetaData;
+using MyMoney.Testing.spechelpers.contexts;
+using MyMoney.Testing.spechelpers.core;
+
+namespace MyMoney.Infrastructure.cloning
+{
+    [Concern(typeof(BinarySerializer<TestItem>))]
+    public abstract class behaves_like_serializer : concerns_for<ISerializer<TestItem>>
+    {
+        public override ISerializer<TestItem> create_sut()
+        {
+            return new BinarySerializer<TestItem>(file_name);
+        }
+
+        context c = () => { file_name = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Serialized.dat"); };
+
+        after_each_observation aeo = () => { if (File.Exists(file_name)) File.Delete(file_name); };
+
+        protected static string file_name;
+    }
+
+    public class when_serializing_an_item : behaves_like_serializer
+    {
+        it should_serialize_the_item_to_a_file = () => FileAssert.Exists(file_name);
+
+        because b = () => sut.serialize(new TestItem(string.Empty));
+    }
+
+    public class when_deserializing_an_item : behaves_like_serializer
+    {
+        it should_be_able_to_deserialize_from_a_serialized_file = () => result.should_be_equal_to(original);
+
+        context c = () => { original = new TestItem("hello world"); };
+
+        because b = () =>
+                        {
+                            sut.serialize(original);
+                            result = sut.deserialize();
+                        };
+
+        static TestItem original;
+        static TestItem result;
+    }
+
+    [Serializable]
+    public class TestItem : IEquatable<TestItem>
+    {
+        public TestItem(string text)
+        {
+            Text = text;
+        }
+
+        public string Text { get; set; }
+
+        public bool Equals(TestItem testItem)
+        {
+            return testItem != null;
+        }
+
+        public override bool Equals(object obj)
+        {
+            return ReferenceEquals(this, obj) || Equals(obj as TestItem);
+        }
+
+        public override int GetHashCode()
+        {
+            return 0;
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/cloning/ISerializer.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace MyMoney.Infrastructure.cloning
+{
+    public interface ISerializer<T> : IDisposable
+    {
+        void serialize(T to_serialize);
+        T deserialize();
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/cloning/Prototype.cs
@@ -0,0 +1,21 @@
+using System.IO;
+
+namespace MyMoney.Infrastructure.cloning
+{
+    public interface IPrototype
+    {
+        T clone<T>(T item);
+    }
+
+    public class Prototype : IPrototype
+    {
+        public T clone<T>(T item)
+        {
+            using (var serializer = new BinarySerializer<T>(Path.GetTempFileName()))
+            {
+                serializer.serialize(item);
+                return serializer.deserialize();
+            }
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/cloning/Serializer.cs
@@ -0,0 +1,38 @@
+using System.IO;
+using System.Runtime.Serialization;
+
+namespace MyMoney.Infrastructure.cloning
+{
+    public class Serializer<T> : ISerializer<T>
+    {
+        public Serializer(string file_path, IFormatter formatter)
+        {
+            this.file_path = file_path;
+            this.formatter = formatter;
+        }
+
+        public void serialize(T toSerialize)
+        {
+            using (var stream = new FileStream(file_path, FileMode.Create, FileAccess.Write))
+            {
+                formatter.Serialize(stream, toSerialize);
+            }
+        }
+
+        public T deserialize()
+        {
+            using (var stream = new FileStream(file_path, FileMode.Open, FileAccess.Read))
+            {
+                return (T) formatter.Deserialize(stream);
+            }
+        }
+
+        public void Dispose()
+        {
+            File.Delete(file_path);
+        }
+
+        readonly string file_path;
+        readonly IFormatter formatter;
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/Threading/background_thread_factory_specs.cs
@@ -9,8 +9,7 @@ using mocking_extensions=MyMoney.Testing.spechelpers.core.mocking_extensions;
 namespace MyMoney.Infrastructure.Threading
 {
     [Concern(typeof (background_thread_factory))]
-    public class behaves_like_a_background_thread_factory :
-        concerns_for<IBackgroundThreadFactory, background_thread_factory>
+    public abstract class behaves_like_a_background_thread_factory : concerns_for<IBackgroundThreadFactory, background_thread_factory>
     {
         public override IBackgroundThreadFactory create_sut()
         {
trunk/src/MyMoney/Infrastructure/Threading/background_thread_specs.cs
@@ -18,7 +18,6 @@ namespace MyMoney.Infrastructure.Threading
         context c = () =>
                         {
                             command_to_execute = the_dependency<IDisposableCommand>();
-                            //worker_thread = the_dependency<worker_thread>();
                             worker_thread = dependency<worker_thread>();
                         };
 
trunk/src/MyMoney/Infrastructure/transactions/IUnitOfWorkRegistrationFactory.cs
@@ -2,7 +2,5 @@ using MyMoney.Utility.Core;
 
 namespace MyMoney.Infrastructure.transactions
 {
-    public interface IUnitOfWorkRegistrationFactory<T> : IMapper<T, IUnitOfWorkRegistration<T>>
-    {
-    }
+
 }
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/transactions/unit_of_work_registry_specs.cs
@@ -7,7 +7,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Infrastructure.transactions
 {
     [Concern(typeof (UnitOfWorkRegistry))]
-    public class behaves_like_unit_of_work_registery : concerns_for<IUnitOfWorkRegistry>
+    public abstract class behaves_like_unit_of_work_registery : concerns_for<IUnitOfWorkRegistry>
     {
         public override IUnitOfWorkRegistry create_sut()
         {
trunk/src/MyMoney/Infrastructure/transactions/unit_of_work_specs.cs
@@ -7,7 +7,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Infrastructure.transactions
 {
     [Concern(typeof (unit_of_work<IEntity>))]
-    public class behaves_like_a_unit_of_work : concerns_for<IUnitOfWork<IEntity>, unit_of_work<IEntity>>
+    public abstract class behaves_like_a_unit_of_work : concerns_for<IUnitOfWork<IEntity>, unit_of_work<IEntity>>
     {
         public override IUnitOfWork<IEntity> create_sut()
         {
trunk/src/MyMoney/Infrastructure/transactions/UnitOfWorkRegistrationFactory.cs
@@ -0,0 +1,29 @@
+using MyMoney.Infrastructure.cloning;
+using MyMoney.Utility.Core;
+
+namespace MyMoney.Infrastructure.transactions
+{
+    public interface IUnitOfWorkRegistrationFactory<T> : IMapper<T, IUnitOfWorkRegistration<T>>
+    {
+    }
+
+    public class UnitOfWorkRegistrationFactory<T> : IUnitOfWorkRegistrationFactory<T>
+    {
+        IPrototype prototype;
+
+        public UnitOfWorkRegistrationFactory(IPrototype prototype)
+        {
+            this.prototype = prototype;
+        }
+
+        public IUnitOfWorkRegistration<T> map_from(T item)
+        {
+            return new UnitOfWorkRegistration<T>(create_prototype(item), item);
+        }
+
+        T create_prototype(T item)
+        {
+            return prototype.clone(item);
+        }
+    }
+}
\ No newline at end of file
trunk/src/MyMoney/Presentation/Databindings/property_binder_specs.cs
@@ -7,7 +7,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Databindings
 {
     [Concern(typeof (property_binder<IAnInterface, string>))]
-    public class behaves_like_a_property_binder : concerns_for<IPropertyBinder<IAnInterface, string>, property_binder<IAnInterface, string>>
+    public abstract class behaves_like_a_property_binder : concerns_for<IPropertyBinder<IAnInterface, string>, property_binder<IAnInterface, string>>
     {
         public override IPropertyBinder<IAnInterface, string> create_sut()
         {
trunk/src/MyMoney/Presentation/Presenters/Menu/main_menu_presenter_specs.cs
@@ -8,7 +8,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Presenters.Menu
 {
     [Concern(typeof (main_menu_presenter))]
-    public class behaves_like_the_main_menu_presenter : concerns_for<IMainMenuPresenter, main_menu_presenter>
+    public abstract class behaves_like_the_main_menu_presenter : concerns_for<IMainMenuPresenter, main_menu_presenter>
     {
         public override IMainMenuPresenter create_sut()
         {
trunk/src/MyMoney/Presentation/Presenters/Shell/TitleBarPresenterSpecs.cs
@@ -10,7 +10,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Presenters.Shell
 {
     [Concern(typeof (TitleBarPresenter))]
-    public class behaves_like_a_title_bar_presenter : concerns_for<ITitleBarPresenter, TitleBarPresenter>
+    public abstract class behaves_like_a_title_bar_presenter : concerns_for<ITitleBarPresenter, TitleBarPresenter>
     {
         public override ITitleBarPresenter create_sut()
         {
trunk/src/MyMoney/Presentation/Presenters/Startup/splash_screen_presenter_specs.cs
@@ -9,7 +9,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Presenters.Startup
 {
     [Concern(typeof (splash_screen_presenter))]
-    public class behaves_like_splash_screen_presenter : concerns_for<ISplashScreenPresenter, splash_screen_presenter>
+    public abstract class behaves_like_splash_screen_presenter : concerns_for<ISplashScreenPresenter, splash_screen_presenter>
     {
         public override ISplashScreenPresenter create_sut()
         {
trunk/src/MyMoney/Presentation/Presenters/updates/CheckForUpdatesPresenterSpecs.cs
@@ -10,7 +10,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Presenters.updates
 {
     [Concern(typeof (CheckForUpdatesPresenter))]
-    public class behaves_like_check_for_updates_presenter :
+    public abstract class behaves_like_check_for_updates_presenter :
         concerns_for<ICheckForUpdatesPresenter, CheckForUpdatesPresenter>
     {
         public override ICheckForUpdatesPresenter create_sut()
trunk/src/MyMoney/Presentation/Presenters/add_company_presenter_specs.cs
@@ -9,7 +9,7 @@ using MyMoney.Testing.spechelpers.core;
 namespace MyMoney.Presentation.Presenters
 {
     [Concern(typeof (add_company_presenter))]
-    public class behaves_like_the_add_company_presenter : concerns_for<IAddCompanyPresenter, add_company_presenter>
+    public abstract class behaves_like_the_add_company_presenter : concerns_for<IAddCompanyPresenter, add_company_presenter>
     {
         public override IAddCompanyPresenter create_sut()
         {
trunk/src/MyMoney/MyMoney.csproj
@@ -190,6 +190,11 @@
     <Compile Include="Domain\Core\range.cs" />
     <Compile Include="Domain\Core\range_specs.cs" />
     <Compile Include="Domain\repositories\company_repository_extensions.cs" />
+    <Compile Include="Infrastructure\cloning\BinarySerializer.cs" />
+    <Compile Include="Infrastructure\cloning\BinarySerializerSpecs.cs" />
+    <Compile Include="Infrastructure\cloning\ISerializer.cs" />
+    <Compile Include="Infrastructure\cloning\Prototype.cs" />
+    <Compile Include="Infrastructure\cloning\Serializer.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\ApplyLoggingInterceptor.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\ComponentExclusionSpecification.cs" />
     <Compile Include="Infrastructure\Container\Windsor\configuration\ConfigureComponentLifestyle.cs" />
@@ -240,6 +245,7 @@
     <Compile Include="Infrastructure\transactions\NullUnitOfWork.cs" />
     <Compile Include="Infrastructure\transactions\UnitOfWork.cs" />
     <Compile Include="Infrastructure\transactions\UnitOfWorkRegistration.cs" />
+    <Compile Include="Infrastructure\transactions\UnitOfWorkRegistrationFactory.cs" />
     <Compile Include="Infrastructure\transactions\UnitOfWorkRegistrationSpecs.cs" />
     <Compile Include="Infrastructure\transactions\unit_of_work.cs" />
     <Compile Include="Infrastructure\transactions\unit_of_work_factory.cs" />