Commit 791e256

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-02-28 18:50:28
added observations for when a null field becomes not null and vice versa.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@33 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 90bfa48
trunk/product/MyMoney/Domain/accounting/billing/Company.cs
@@ -11,6 +11,7 @@ namespace MyMoney.Domain.accounting.billing
         void pay(IAccountHolder person, IMoney amount, IDate date_of_payment);
     }
 
+    [Serializable]
     internal class Company : Entity<ICompany>, ICompany
     {
         public Company(string name_of_the_company)
trunk/product/MyMoney/Infrastructure/Container/Windsor/windsor_dependency_registry.cs
@@ -19,12 +19,12 @@ namespace MyMoney.Infrastructure.Container.Windsor
             underlying_container = factory.create();
         }
 
-        public Interface find_an_implementation_of<Interface>()
+        public Interface get_a<Interface>()
         {
             return underlying_container.Kernel.Resolve<Interface>();
         }
 
-        public IEnumerable<Interface> all_implementations_of<Interface>()
+        public IEnumerable<Interface> all_the<Interface>()
         {
             return underlying_container.ResolveAll<Interface>();
         }
trunk/product/MyMoney/Infrastructure/Container/Windsor/windsor_dependency_registry_specs.cs
@@ -12,7 +12,7 @@ namespace MyMoney.Infrastructure.Container.Windsor
     public class when_registering_a_singleton_component_with_the_windsor_container : concerns_for<IDependencyRegistry>
     {
         it should_return_the_same_instance_each_time_its_resolved =
-            () => result.should_be_the_same_instance_as(sut.find_an_implementation_of<IBird>());
+            () => result.should_be_the_same_instance_as(sut.get_a<IBird>());
 
         it should_not_return_null = () => assertion_extensions.should_not_be_null(result);
 
@@ -21,7 +21,7 @@ namespace MyMoney.Infrastructure.Container.Windsor
             return new windsor_dependency_registry();
         }
 
-        because b = () => { result = sut.find_an_implementation_of<IBird>(); };
+        because b = () => { result = sut.get_a<IBird>(); };
 
         static IBird result;
     }
trunk/product/MyMoney/Infrastructure/Container/IDependencyRegistry.cs
@@ -4,7 +4,7 @@ namespace MyMoney.Infrastructure.Container
 {
     public interface IDependencyRegistry
     {
-        Interface find_an_implementation_of<Interface>();
-        IEnumerable<Interface> all_implementations_of<Interface>();
+        Interface get_a<Interface>();
+        IEnumerable<Interface> all_the<Interface>();
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Resolve.cs
@@ -16,7 +16,7 @@ namespace MyMoney.Infrastructure.Container
         public static DependencyToResolve dependency_for<DependencyToResolve>()
         {
             try {
-                return underlying_registry.find_an_implementation_of<DependencyToResolve>();
+                return underlying_registry.get_a<DependencyToResolve>();
             }
             catch (Exception e) {
                 throw new dependency_resolution_exception<DependencyToResolve>(e);
trunk/product/MyMoney/Infrastructure/Container/ResolveSpecs.cs
@@ -20,14 +20,14 @@ namespace MyMoney.Infrastructure.Container
                         {
                             registry = an<IDependencyRegistry>();
                             presenter = an<IPresenter>();
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(registry, x => x.find_an_implementation_of<IPresenter>()), presenter);
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(registry, x => x.get_a<IPresenter>()), presenter);
                             resolve.initialize_with(registry);
                         };
 
         because b = () => { result = resolve.dependency_for<IPresenter>(); };
 
         it should_leverage_the_underlying_container_it_was_initialized_with =
-            () => mocking_extensions.was_told_to(registry, x => x.find_an_implementation_of<IPresenter>());
+            () => mocking_extensions.was_told_to(registry, x => x.get_a<IPresenter>());
 
         it should_return_the_resolved_dependency = () => result.should_be_equal_to(presenter);
 
@@ -43,7 +43,7 @@ namespace MyMoney.Infrastructure.Container
         context c = () =>
                         {
                             registry = an<IDependencyRegistry>();
-                            mocking_extensions.it_will_throw(mocking_extensions.is_told_to(registry, x => x.find_an_implementation_of<IPresenter>()), new Exception());
+                            mocking_extensions.it_will_throw(mocking_extensions.is_told_to(registry, x => x.get_a<IPresenter>()), new Exception());
                             resolve.initialize_with(registry);
                         };
 
trunk/product/MyMoney/Infrastructure/interceptors/lazy_specs.cs
@@ -28,7 +28,7 @@ namespace MyMoney.Infrastructure.interceptors
         context c = () =>
                         {
                             target = an<ITargetObject>();
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<ITargetObject>()), target).Repeat.Once();
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<ITargetObject>()), target).Repeat.Once();
                         };
 
         because b = () =>
@@ -50,7 +50,7 @@ namespace MyMoney.Infrastructure.interceptors
                             var target = an<ITargetObject>();
 
                             mocking_extensions.it_will_return(mocking_extensions.is_told_to(target, x => x.FirstValueReturningMethod()), 10);
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<ITargetObject>()), target)
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<ITargetObject>()), target)
                                 .Repeat.Once();
                         };
 
@@ -66,12 +66,12 @@ namespace MyMoney.Infrastructure.interceptors
     public class when_calling_different_methods_on_an_proxied_object : behaves_like_a_lazy_loaded_object
     {
         it should_only_load_the_object_once =
-            () => mocking_extensions.was_told_to(test_container, x => x.find_an_implementation_of<ITargetObject>()).only_once();
+            () => mocking_extensions.was_told_to(test_container, x => x.get_a<ITargetObject>()).only_once();
 
         context c = () =>
                         {
                             var target = an<ITargetObject>();
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<ITargetObject>()), target).Repeat.Once();
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<ITargetObject>()), target).Repeat.Once();
                         };
 
         because b = () =>
@@ -95,7 +95,7 @@ namespace MyMoney.Infrastructure.interceptors
                             target = an<ITargetObject>();
 
                             mocking_extensions.it_will_return(mocking_extensions.is_told_to(target, x => x.ValueReturningMethodWithAnArgument(88)), 99);
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<ITargetObject>()), target).Repeat.Once();
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<ITargetObject>()), target).Repeat.Once();
                         };
 
         because b = () =>
@@ -117,7 +117,7 @@ namespace MyMoney.Infrastructure.interceptors
                             var target = an<ITargetObject>();
 
                             target.GetterAndSetterProperty = "mo";
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<ITargetObject>()), target).Repeat.Once();
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<ITargetObject>()), target).Repeat.Once();
                         };
 
         because b = () =>
@@ -138,7 +138,7 @@ namespace MyMoney.Infrastructure.interceptors
                         {
                             target = dependency<ITargetObject>();
 
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<ITargetObject>()), target)
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<ITargetObject>()), target)
                                 .Repeat.Once();
                         };
 
@@ -163,7 +163,7 @@ namespace MyMoney.Infrastructure.interceptors
                             target = an<IGenericInterface<string>>();
 
                             mocking_extensions.it_will_return(mocking_extensions.is_told_to(target, x => x.ValueReturningMethodWithAnArgument("blah")), "hooray");
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.find_an_implementation_of<IGenericInterface<string>>()), target).Repeat.Once();
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(test_container, t => t.get_a<IGenericInterface<string>>()), target).Repeat.Once();
                         };
 
         because b = () =>
trunk/product/MyMoney/Infrastructure/Logging/LogSpecs.cs
@@ -17,7 +17,7 @@ namespace MyMoney.Infrastructure.Logging
                             var factory = an<ILogFactory>();
                             var registry = an<IDependencyRegistry>();
                             logger = an<ILogger>();
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(registry, x => x.find_an_implementation_of<ILogFactory>()), factory);
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(registry, x => x.get_a<ILogFactory>()), factory);
 
                             mocking_extensions.it_will_return(mocking_extensions.is_told_to(factory, x => x.create_for(typeof (string))), logger);
 
trunk/product/MyMoney/Infrastructure/registries/default_registry.cs
@@ -15,7 +15,7 @@ namespace MyMoney.Infrastructure.registries
 
         public IEnumerable<T> all()
         {
-            return registry.all_implementations_of<T>();
+            return registry.all_the<T>();
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/registries/default_registry_specs.cs
@@ -14,7 +14,7 @@ namespace MyMoney.Infrastructure.registries
         concerns_for<IRegistry<int>, default_registry<int>>
     {
         it should_leverage_the_resolver_to_retrieve_all_the_implementations =
-            () => mocking_extensions.was_told_to(registry, r => r.all_implementations_of<int>());
+            () => mocking_extensions.was_told_to(registry, r => r.all_the<int>());
 
         it should_return_the_items_resolved_by_the_registry = () => assertion_extensions.should_contain(result, 24);
 
@@ -23,7 +23,7 @@ namespace MyMoney.Infrastructure.registries
                             var items_to_return = new List<int> {24};
 
                             registry = an<IDependencyRegistry>();
-                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(registry, r => r.all_implementations_of<int>()), items_to_return);
+                            mocking_extensions.it_will_return(mocking_extensions.is_told_to(registry, r => r.all_the<int>()), items_to_return);
                         };
 
         public override IRegistry<int> create_sut()
trunk/product/MyMoney/Infrastructure/Threading/background_thread_factory.cs
@@ -21,7 +21,7 @@ namespace MyMoney.Infrastructure.Threading
 
         public IBackgroundThread create_for<CommandToExecute>() where CommandToExecute : IDisposableCommand
         {
-            return new background_thread(registry.find_an_implementation_of<CommandToExecute>());
+            return new background_thread(registry.get_a<CommandToExecute>());
         }
 
         public IBackgroundThread create_for(Action action)
trunk/product/MyMoney/Infrastructure/Threading/background_thread_factory_specs.cs
@@ -26,7 +26,7 @@ namespace MyMoney.Infrastructure.Threading
         it should_return_an_instance_of_a_background_thread = () => assertion_extensions.should_not_be_null(result);
 
         it should_lookup_an_instance_of_the_command_to_execute =
-            () => mocking_extensions.was_told_to(registry, r => r.find_an_implementation_of<IDisposableCommand>());
+            () => mocking_extensions.was_told_to(registry, r => r.get_a<IDisposableCommand>());
 
         because b = () => { result = sut.create_for<IDisposableCommand>(); };
 
trunk/product/MyMoney/Infrastructure/transactions/unit_of_work_factory.cs
@@ -1,4 +1,5 @@
 using MyMoney.Domain.Core;
+using MyMoney.Infrastructure.Container;
 
 namespace MyMoney.Infrastructure.transactions
 {
@@ -10,15 +11,17 @@ namespace MyMoney.Infrastructure.transactions
     public class unit_of_work_factory : IUnitOfWorkFactory
     {
         readonly IRepository repository;
+        IDependencyRegistry registry;
 
-        public unit_of_work_factory(IRepository repository)
+        public unit_of_work_factory(IRepository repository, IDependencyRegistry registry)
         {
             this.repository = repository;
+            this.registry = registry;
         }
 
         public IUnitOfWork<T> create_for<T>() where T : IEntity
         {
-            return new unit_of_work<T>(repository, null);
+            return new unit_of_work<T>(repository, registry.get_a<IUnitOfWorkRegistrationFactory<T>>());
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions/UnitOfWork.cs
@@ -7,7 +7,8 @@ namespace MyMoney.Infrastructure.transactions
     {
         public static IUnitOfWork<T> For<T>() where T : IEntity
         {
-            if (resolve.is_initialized()) {
+            if (resolve.is_initialized())
+            {
                 return resolve.dependency_for<IUnitOfWorkRegistry>().start_unit_of_work_for<T>();
             }
             return new NullUnitOfWork<T>();
trunk/product/MyMoney/Infrastructure/transactions/UnitOfWorkRegistration.cs
@@ -28,7 +28,11 @@ namespace MyMoney.Infrastructure.transactions
             {
                 var original_value = field.GetValue(original);
                 var current_value = field.GetValue(current);
-                if (!original_value.Equals(current_value))
+                if (original_value == null && current_value != null)
+                {
+                    return true;
+                }
+                if (original_value != null && !original_value.Equals(current_value))
                 {
                     return true;
                 }
trunk/product/MyMoney/Infrastructure/transactions/UnitOfWorkRegistrationSpecs.cs
@@ -7,19 +7,65 @@ namespace MyMoney.Infrastructure.transactions
 {
     public abstract class behaves_like_unit_of_work_registration : concerns_for<IUnitOfWorkRegistration<Pillow>>
     {
+    }
+
+    public class when_comparing_the_current_instance_of_a_component_with_its_original_and_it_has_changes :
+        behaves_like_unit_of_work_registration
+    {
+        it should_indicate_that_there_are_changes = () => result.should_be_true();
+
+        because b = () => { result = sut.contains_changes(); };
+
         public override IUnitOfWorkRegistration<Pillow> create_sut()
         {
             return new UnitOfWorkRegistration<Pillow>(new Pillow("pink"), new Pillow("yellow"));
         }
+
+        static bool result;
     }
 
-    public class when_comparing_the_current_instance_of_a_component_with_its_original_and_it_has_changes :
+    public class when_the_original_instance_has_a_null_field_that_is_now_not_null :
         behaves_like_unit_of_work_registration
     {
         it should_indicate_that_there_are_changes = () => result.should_be_true();
 
         because b = () => { result = sut.contains_changes(); };
 
+        public override IUnitOfWorkRegistration<Pillow> create_sut()
+        {
+            return new UnitOfWorkRegistration<Pillow>(new Pillow(null), new Pillow("yellow"));
+        }
+
+        static bool result;
+    }
+
+    public class when_the_original_instance_had_a_non_null_field_and_the_current_instance_has_a_null_field :
+        behaves_like_unit_of_work_registration
+    {
+        it should_indicate_that_there_are_changes = () => result.should_be_true();
+
+        because b = () => { result = sut.contains_changes(); };
+
+        public override IUnitOfWorkRegistration<Pillow> create_sut()
+        {
+            return new UnitOfWorkRegistration<Pillow>(new Pillow("green"), new Pillow(null));
+        }
+
+        static bool result;
+    }
+
+    public class when_the_original_instance_has_the_same_value_as_the_current_instance :
+        behaves_like_unit_of_work_registration
+    {
+        it should_indicate_that_there_are_no_changes = () => result.should_be_false();
+
+        because b = () => { result = sut.contains_changes(); };
+
+        public override IUnitOfWorkRegistration<Pillow> create_sut()
+        {
+            return new UnitOfWorkRegistration<Pillow>(new Pillow("green"), new Pillow("green"));
+        }
+
         static bool result;
     }
 
trunk/product/MyMoney/Presentation/Model/Menu/menu_item_builder.cs
@@ -42,7 +42,7 @@ namespace MyMoney.Presentation.Model.Menu
 
         public IMenuItemBuilder that_executes<TheCommand>() where TheCommand : ICommand
         {
-            command_to_execute = () => registry.find_an_implementation_of<TheCommand>().run();
+            command_to_execute = () => registry.get_a<TheCommand>().run();
             return this;
         }
 
trunk/product/MyMoney/Presentation/Model/Menu/tool_bar_item_builder.cs
@@ -36,7 +36,7 @@ namespace MyMoney.Presentation.Model.Menu
 
         public IToolbarItemBuilder when_clicked_executes<Command>() where Command : ICommand
         {
-            the_command = registry.find_an_implementation_of<Command>();
+            the_command = registry.get_a<Command>();
             return this;
         }
 
trunk/product/MyMoney/Presentation/Model/Navigation/navigation_tree_visitor.cs
@@ -22,7 +22,7 @@ namespace MyMoney.Presentation.Model.Navigation
         public void visit(TreeView item_to_visit)
         {
             var root_node = mapper.map_from(item_to_visit);
-            registry.all_implementations_of<IBranchVisitor>().each(root_node.accept);
+            registry.all_the<IBranchVisitor>().each(root_node.accept);
         }
     }
 }
\ No newline at end of file
trunk/product/MyMoney/Presentation/Model/Navigation/navigation_tree_visitor_specs.cs
@@ -46,7 +46,7 @@ namespace MyMoney.Presentation.Model.Navigation
                                 .it_will_return(root_node);
 
                             when_the(registry)
-                                .is_told_to(x => x.all_implementations_of<IBranchVisitor>())
+                                .is_told_to(x => x.all_the<IBranchVisitor>())
                                 .it_will_return(first_node_visitor, second_node_visitor);
                         };
 
trunk/solution.sln
@@ -1,24 +1,24 @@
 
 Microsoft Visual Studio Solution File, Format Version 10.00
 # Visual Studio 2008
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMoney", "src\MyMoney\MyMoney.csproj", "{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMoney.Build", "build\MyMoney.Build.csproj", "{B8505B10-85C7-45F4-B039-D364DD556D7D}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMoney", "product\MyMoney\MyMoney.csproj", "{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
 		Release|Any CPU = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Release|Any CPU.Build.0 = Release|Any CPU
 		{B8505B10-85C7-45F4-B039-D364DD556D7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{B8505B10-85C7-45F4-B039-D364DD556D7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{B8505B10-85C7-45F4-B039-D364DD556D7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{B8505B10-85C7-45F4-B039-D364DD556D7D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{2DB82691-BF15-4538-8C5E-6BF8F4F875A9}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE