Commit 8e25686
Changed files (6)
trunk
src
MyMoney
Domain
Core
Infrastructure
Testing
spechelpers
core
trunk/src/MyMoney/Domain/Core/Entity.cs
@@ -9,7 +9,7 @@ namespace MyMoney.Domain.Core
}
[Serializable]
- internal abstract class Entity<T> : IEntity where T : class, IEntity
+ public abstract class Entity<T> : IEntity where T : class, IEntity
{
protected Entity()
{
trunk/src/MyMoney/Infrastructure/transactions/IUnitOfWorkRegistration.cs
@@ -1,8 +0,0 @@
-namespace MyMoney.Infrastructure.transactions
-{
- public interface IUnitOfWorkRegistration<T>
- {
- T current { get; }
- bool contains_changes();
- }
-}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/transactions/UnitOfWorkRegistration.cs
@@ -0,0 +1,39 @@
+using System.Reflection;
+
+namespace MyMoney.Infrastructure.transactions
+{
+ public interface IUnitOfWorkRegistration<T>
+ {
+ T current { get; }
+ bool contains_changes();
+ }
+
+ public class UnitOfWorkRegistration<T> : IUnitOfWorkRegistration<T>
+ {
+ readonly T original;
+
+ public UnitOfWorkRegistration(T original, T current)
+ {
+ this.original = original;
+ this.current = current;
+ }
+
+ public T current { get; set; }
+
+ public bool contains_changes()
+ {
+ var type = original.GetType();
+ var fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
+ foreach (var field in fields)
+ {
+ var original_value = field.GetValue(original);
+ var current_value = field.GetValue(current);
+ if (!original_value.Equals(current_value))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Infrastructure/transactions/UnitOfWorkRegistrationSpecs.cs
@@ -0,0 +1,35 @@
+using jpboodhoo.bdd.contexts;
+using MyMoney.Domain.Core;
+using MyMoney.Testing.spechelpers.contexts;
+using MyMoney.Testing.spechelpers.core;
+
+namespace MyMoney.Infrastructure.transactions
+{
+ public abstract class behaves_like_unit_of_work_registration : concerns_for<IUnitOfWorkRegistration<Pillow>>
+ {
+ public override IUnitOfWorkRegistration<Pillow> create_sut()
+ {
+ return new UnitOfWorkRegistration<Pillow>(new Pillow("pink"), new Pillow("yellow"));
+ }
+ }
+
+ 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(); };
+
+ static bool result;
+ }
+
+ public class Pillow : Entity<Pillow>
+ {
+ readonly string color;
+
+ public Pillow(string color)
+ {
+ this.color = color;
+ }
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/Testing/spechelpers/core/empty_fixture.cs
@@ -0,0 +1,9 @@
+using MbUnit.Framework;
+
+namespace MyMoney.Testing.spechelpers.core
+{
+ [TestFixture]
+ public class empty_fixture
+ {
+ }
+}
\ No newline at end of file
trunk/src/MyMoney/MyMoney.csproj
@@ -236,10 +236,11 @@
<Compile Include="Infrastructure\Threading\worker_thread.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="Infrastructure\transactions\IUnitOfWorkRegistration.cs" />
<Compile Include="Infrastructure\transactions\IUnitOfWorkRegistrationFactory.cs" />
<Compile Include="Infrastructure\transactions\NullUnitOfWork.cs" />
<Compile Include="Infrastructure\transactions\UnitOfWork.cs" />
+ <Compile Include="Infrastructure\transactions\UnitOfWorkRegistration.cs" />
+ <Compile Include="Infrastructure\transactions\UnitOfWorkRegistrationSpecs.cs" />
<Compile Include="Infrastructure\transactions\unit_of_work.cs" />
<Compile Include="Infrastructure\transactions\unit_of_work_factory.cs" />
<Compile Include="Infrastructure\transactions\UnitOfWorkRegistry.cs" />
@@ -457,6 +458,7 @@
<Compile Include="Tasks\infrastructure\UpdateTasks.cs" />
<Compile Include="Testing\spechelpers\contexts\concerns_for.cs" />
<Compile Include="Testing\spechelpers\contexts\behaves_like_a_repository.cs" />
+ <Compile Include="Testing\spechelpers\core\empty_fixture.cs" />
<Compile Include="Testing\spechelpers\core\IHideObjectMembers.cs" />
<Compile Include="Testing\spechelpers\core\method_call_occurance.cs" />
<Compile Include="Testing\MetaData\run_in_real_container.cs" />