Commit 7591e8c
Changed files (22)
trunk
product
Gorilla.Commons.Utility
MoMoney.DataAccess
MoMoney.Domain
Core
MoMoney.Infrastructure
Transactions2
trunk/product/Gorilla.Commons.Utility/Core/IIdentifiable.cs
@@ -0,0 +1,7 @@
+namespace Gorilla.Commons.Utility.Core
+{
+ public interface IIdentifiable<T>
+ {
+ T id { get; }
+ }
+}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/mapping_extensions_specs.cs → trunk/product/Gorilla.Commons.Utility/Extensions/MappingExtensionsSpecs.cs
File renamed without changes
trunk/product/Gorilla.Commons.Utility/Extensions/numeric_conversions_specs.cs → trunk/product/Gorilla.Commons.Utility/Extensions/NumericConversionsSpecs.cs
@@ -1,8 +1,7 @@
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Extensions;
-namespace MoMoney.Utility.Extensions
+namespace Gorilla.Commons.Utility.Extensions
{
public class when_converting_a_valid_string_to_a_long : concerns
{
trunk/product/Gorilla.Commons.Utility/Gorilla.Commons.Utility.csproj
@@ -73,6 +73,7 @@
<Compile Include="Core\IConfiguration.cs" />
<Compile Include="Core\IDisposableCommand.cs" />
<Compile Include="Core\IFactory.cs" />
+ <Compile Include="Core\IIdentifiable.cs" />
<Compile Include="Core\IMapper.cs" />
<Compile Include="Core\IParameterizedCommand.cs" />
<Compile Include="Core\IQuery.cs" />
@@ -95,9 +96,9 @@
<Compile Include="Extensions\EnumerableExtensionsSpecs.cs" />
<Compile Include="Extensions\FuncExtensions.cs" />
<Compile Include="Extensions\MappingExtensions.cs" />
- <Compile Include="Extensions\mapping_extensions_specs.cs" />
+ <Compile Include="Extensions\MappingExtensionsSpecs.cs" />
<Compile Include="Extensions\NumericConversions.cs" />
- <Compile Include="Extensions\numeric_conversions_specs.cs" />
+ <Compile Include="Extensions\NumericConversionsSpecs.cs" />
<Compile Include="Extensions\RegistryExtensions.cs" />
<Compile Include="Extensions\SpecificationExtensionsSpecs.cs" />
<Compile Include="Extensions\SpecificationExtensions.cs" />
trunk/product/MoMoney.DataAccess/ObjectDatabase.cs
@@ -1,7 +1,9 @@
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Gorilla.Commons.Infrastructure.FileSystem;
+using Gorilla.Commons.Utility.Core;
using MoMoney.Domain.Core;
using MoMoney.Infrastructure.transactions2;
@@ -18,7 +20,7 @@ namespace MoMoney.DataAccess
path = new ApplicationFile(Path.GetTempFileName());
}
- public IEnumerable<T> fetch_all<T>() where T : IEntity
+ public IEnumerable<T> fetch_all<T>() where T : IIdentifiable<Guid>
{
using (var connection = factory.open_connection_to(path_to_database()))
{
trunk/product/MoMoney.Domain/Core/Entity.cs
@@ -1,11 +1,11 @@
using System;
+using Gorilla.Commons.Utility.Core;
using Gorilla.Commons.Utility.Extensions;
namespace MoMoney.Domain.Core
{
- public interface IEntity
+ public interface IEntity : IIdentifiable<Guid>
{
- Guid id { get; }
}
[Serializable]
trunk/product/MoMoney.Infrastructure/Transactions2/ChangeTracker.cs
@@ -1,12 +1,13 @@
+using System;
using System.Collections.Generic;
using System.Linq;
using Gorilla.Commons.Infrastructure.Logging;
+using Gorilla.Commons.Utility.Core;
using Gorilla.Commons.Utility.Extensions;
-using MoMoney.Domain.Core;
namespace MoMoney.Infrastructure.transactions2
{
- public class ChangeTracker<T> : IChangeTracker<T> where T : IEntity
+ public class ChangeTracker<T> : IChangeTracker<T> where T : IIdentifiable<Guid>
{
readonly ITrackerEntryMapper<T> mapper;
readonly IStatementRegistry registry;
trunk/product/MoMoney.Infrastructure/Transactions2/ChangeTrackerFactory.cs
@@ -1,5 +1,6 @@
+using System;
using Gorilla.Commons.Infrastructure.Container;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
@@ -14,7 +15,7 @@ namespace MoMoney.Infrastructure.transactions2
this.registry = registry;
}
- public IChangeTracker<T> create_for<T>() where T : IEntity
+ public IChangeTracker<T> create_for<T>() where T : IIdentifiable<Guid>
{
return new ChangeTracker<T>(registry.get_a<ITrackerEntryMapper<T>>(), statement_registry);
}
trunk/product/MoMoney.Infrastructure/Transactions2/ChangeTrackerFactorySpecs.cs
@@ -1,6 +1,7 @@
+using System;
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
@@ -12,8 +13,8 @@ namespace MoMoney.Infrastructure.transactions2
{
it should_return_a_new_tracker = () => result.should_not_be_null();
- because b = () => { result = sut.create_for<IEntity>(); };
+ because b = () => { result = sut.create_for<IIdentifiable<Guid>>(); };
- static IChangeTracker<IEntity> result;
+ static IChangeTracker<IIdentifiable<Guid>> result;
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/ChangeTrackerSpecs.cs
@@ -1,6 +1,7 @@
+using System;
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
@@ -8,17 +9,18 @@ namespace MoMoney.Infrastructure.transactions2
{
}
- [Concern(typeof (ChangeTracker<IEntity>))]
- public abstract class behaves_like_change_tracker : concerns_for<IChangeTracker<IEntity>, ChangeTracker<IEntity>>
+ [Concern(typeof (ChangeTracker<IIdentifiable<Guid>>))]
+ public abstract class behaves_like_change_tracker :
+ concerns_for<IChangeTracker<IIdentifiable<Guid>>, ChangeTracker<IIdentifiable<Guid>>>
{
context c = () =>
{
- mapper = the_dependency<ITrackerEntryMapper<IEntity>>();
+ mapper = the_dependency<ITrackerEntryMapper<IIdentifiable<Guid>>>();
registry = the_dependency<IStatementRegistry>();
};
- protected static ITrackerEntryMapper<IEntity> mapper;
- protected static IStatementRegistry registry;
+ static protected ITrackerEntryMapper<IIdentifiable<Guid>> mapper;
+ static protected IStatementRegistry registry;
}
public class when_commit_that_changes_made_to_an_item : behaves_like_change_tracker
@@ -27,10 +29,10 @@ namespace MoMoney.Infrastructure.transactions2
context c = () =>
{
- item = an<IEntity>();
+ item = an<IIdentifiable<Guid>>();
statement = an<IStatement>();
database = an<IDatabase>();
- var entry = an<ITrackerEntry<IEntity>>();
+ var entry = an<ITrackerEntry<IIdentifiable<Guid>>>();
when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
when_the(entry).is_told_to(x => x.has_changes()).it_will_return(true);
@@ -44,7 +46,7 @@ namespace MoMoney.Infrastructure.transactions2
sut.commit_to(database);
};
- static IEntity item;
+ static IIdentifiable<Guid> item;
static IDatabase database;
static IStatement statement;
}
@@ -55,8 +57,8 @@ namespace MoMoney.Infrastructure.transactions2
context c = () =>
{
- item = an<IEntity>();
- var registration = an<ITrackerEntry<IEntity>>();
+ item = an<IIdentifiable<Guid>>();
+ var registration = an<ITrackerEntry<IIdentifiable<Guid>>>();
when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(registration);
when_the(registration).is_told_to(x => x.has_changes()).it_will_return(true);
@@ -70,7 +72,7 @@ namespace MoMoney.Infrastructure.transactions2
};
static bool result;
- static IEntity item;
+ static IIdentifiable<Guid> item;
}
public class when_checking_if_there_are_changes_and_there_are_not : behaves_like_change_tracker
@@ -79,8 +81,8 @@ namespace MoMoney.Infrastructure.transactions2
context c = () =>
{
- item = an<IEntity>();
- var entry = an<ITrackerEntry<IEntity>>();
+ item = an<IIdentifiable<Guid>>();
+ var entry = an<ITrackerEntry<IIdentifiable<Guid>>>();
when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
when_the(entry).is_told_to(x => x.has_changes()).it_will_return(false);
@@ -93,6 +95,6 @@ namespace MoMoney.Infrastructure.transactions2
};
static bool result;
- static IEntity item;
+ static IIdentifiable<Guid> item;
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/IChangeTracker.cs
@@ -1,5 +1,5 @@
using System;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
@@ -9,7 +9,7 @@ namespace MoMoney.Infrastructure.transactions2
void commit_to(IDatabase database);
}
- public interface IChangeTracker<T> : IChangeTracker where T : IEntity
+ public interface IChangeTracker<T> : IChangeTracker where T : IIdentifiable<Guid>
{
void register(T value);
void delete(T entity);
trunk/product/MoMoney.Infrastructure/Transactions2/IChangeTrackerFactory.cs
@@ -1,9 +1,10 @@
-using MoMoney.Domain.Core;
+using System;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
public interface IChangeTrackerFactory
{
- IChangeTracker<T> create_for<T>() where T : IEntity;
+ IChangeTracker<T> create_for<T>() where T : IIdentifiable<Guid>;
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/IDatabase.cs
@@ -1,11 +1,12 @@
+using System;
using System.Collections.Generic;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
public interface IDatabase
{
- IEnumerable<T> fetch_all<T>() where T : IEntity;
+ IEnumerable<T> fetch_all<T>() where T : IIdentifiable<Guid>;
void apply(IStatement statement);
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/IdentityMapProxy.cs
@@ -1,9 +1,10 @@
+using System;
using System.Collections.Generic;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
- public class IdentityMapProxy<Key, Value> : IIdentityMap<Key, Value> where Value : IEntity
+ public class IdentityMapProxy<Key, Value> : IIdentityMap<Key, Value> where Value : IIdentifiable<Guid>
{
readonly IIdentityMap<Key, Value> real_map;
readonly IChangeTracker<Value> change_tracker;
trunk/product/MoMoney.Infrastructure/Transactions2/IStatementRegistry.cs
@@ -1,10 +1,11 @@
-using MoMoney.Domain.Core;
+using System;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
public interface IStatementRegistry
{
- IStatement prepare_delete_statement_for<T>(T entity) where T : IEntity;
- IStatement prepare_command_for<T>(T entity) where T : IEntity;
+ IStatement prepare_delete_statement_for<T>(T entity) where T : IIdentifiable<Guid>;
+ IStatement prepare_command_for<T>(T entity) where T : IIdentifiable<Guid>;
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/Session.cs
@@ -1,17 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Gorilla.Commons.Utility.Core;
using Gorilla.Commons.Utility.Extensions;
-using MoMoney.Domain.Core;
namespace MoMoney.Infrastructure.transactions2
{
public interface ISession : IDisposable
{
- T find<T>(Guid guid) where T : IEntity;
- IEnumerable<T> all<T>() where T : IEntity;
- void save<T>(T entity) where T : IEntity;
- void delete<T>(T entity) where T : IEntity;
+ T find<T>(Guid guid) where T : IIdentifiable<Guid>;
+ IEnumerable<T> all<T>() where T : IIdentifiable<Guid>;
+ void save<T>(T entity) where T : IIdentifiable<Guid>;
+ void delete<T>(T entity) where T : IIdentifiable<Guid>;
void flush();
bool is_dirty();
}
@@ -29,7 +29,7 @@ namespace MoMoney.Infrastructure.transactions2
identity_maps = new Dictionary<Type, object>();
}
- public T find<T>(Guid id) where T : IEntity
+ public T find<T>(Guid id) where T : IIdentifiable<Guid>
{
if (get_identity_map_for<T>().contains_an_item_for(id))
{
@@ -41,7 +41,7 @@ namespace MoMoney.Infrastructure.transactions2
return entity;
}
- public IEnumerable<T> all<T>() where T : IEntity
+ public IEnumerable<T> all<T>() where T : IIdentifiable<Guid>
{
database
.fetch_all<T>()
@@ -50,12 +50,12 @@ namespace MoMoney.Infrastructure.transactions2
return get_identity_map_for<T>().all();
}
- public void save<T>(T entity) where T : IEntity
+ public void save<T>(T entity) where T : IIdentifiable<Guid>
{
get_identity_map_for<T>().add(entity.id, entity);
}
- public void delete<T>(T entity) where T : IEntity
+ public void delete<T>(T entity) where T : IIdentifiable<Guid>
{
get_identity_map_for<T>().evict(entity.id);
}
@@ -76,14 +76,14 @@ namespace MoMoney.Infrastructure.transactions2
if (null != transaction) transaction.rollback_changes();
}
- IIdentityMap<Guid, T> get_identity_map_for<T>() where T : IEntity
+ IIdentityMap<Guid, T> get_identity_map_for<T>() where T : IIdentifiable<Guid>
{
return identity_maps.ContainsKey(typeof (T))
? identity_maps[typeof (T)].downcast_to<IIdentityMap<Guid, T>>()
: create_map_for<T>();
}
- IIdentityMap<Guid, T> create_map_for<T>() where T : IEntity
+ IIdentityMap<Guid, T> create_map_for<T>() where T : IIdentifiable<Guid>
{
var identity_map = transaction.create_for<T>();
identity_maps.Add(typeof (T), identity_map);
trunk/product/MoMoney.Infrastructure/Transactions2/SessionSpecs.cs
@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
@@ -18,8 +18,8 @@ namespace MoMoney.Infrastructure.transactions2
database = the_dependency<IDatabase>();
};
- protected static ITransaction transaction;
- protected static IDatabase database;
+ static protected ITransaction transaction;
+ static protected IDatabase database;
}
public class when_saving_a_transient_item_to_a_session : behaves_like_session
@@ -137,7 +137,7 @@ namespace MoMoney.Infrastructure.transactions2
because b = () => { result = sut.find<ITestEntity>(id); };
static Guid id;
- static IEntity result;
+ static IIdentifiable<Guid> result;
static ITestEntity correct_item;
static ITestEntity wrong_item;
static IIdentityMap<Guid, ITestEntity> map;
@@ -171,7 +171,7 @@ namespace MoMoney.Infrastructure.transactions2
static ITestEntity entity;
}
- public interface ITestEntity : IEntity
+ public interface ITestEntity : IIdentifiable<Guid>
{
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/StatementRegistry.cs
@@ -1,22 +1,23 @@
+using System;
using Gorilla.Commons.Infrastructure.Logging;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
public class StatementRegistry : IStatementRegistry
{
- public IStatement prepare_delete_statement_for<T>(T entity) where T : IEntity
+ public IStatement prepare_delete_statement_for<T>(T entity) where T : IIdentifiable<Guid>
{
return new DeletionStatement<T>(entity);
}
- public IStatement prepare_command_for<T>(T entity) where T : IEntity
+ public IStatement prepare_command_for<T>(T entity) where T : IIdentifiable<Guid>
{
return new SaveOrUpdateStatement<T>(entity);
}
}
- public class SaveOrUpdateStatement<T> : IStatement where T : IEntity
+ public class SaveOrUpdateStatement<T> : IStatement where T : IIdentifiable<Guid>
{
readonly T entity;
trunk/product/MoMoney.Infrastructure/Transactions2/TrackerEntrySpecs.cs
@@ -1,6 +1,8 @@
+using System;
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
+using Gorilla.Commons.Utility.Extensions;
namespace MoMoney.Infrastructure.transactions2
{
@@ -49,12 +51,21 @@ namespace MoMoney.Infrastructure.transactions2
because b = () => { result = sut.has_changes(); };
+ context c = () =>
+ {
+ var id = Guid.NewGuid();
+ original = new Pillow("green", id);
+ current = new Pillow(null, id);
+ };
+
public override ITrackerEntry<Pillow> create_sut()
{
- return new TrackerEntry<Pillow>(new Pillow("green"), new Pillow(null));
+ return new TrackerEntry<Pillow>(original, current);
}
static bool result;
+ static Pillow original;
+ static Pillow current;
}
public class when_the_original_instance_has_the_same_value_as_the_current_instance :
@@ -64,21 +75,62 @@ namespace MoMoney.Infrastructure.transactions2
because b = () => { result = sut.has_changes(); };
+ context c = () =>
+ {
+ var id = Guid.NewGuid();
+ original = new Pillow("green", id);
+ current = new Pillow("green", id);
+ };
+
public override ITrackerEntry<Pillow> create_sut()
{
- return new TrackerEntry<Pillow>(new Pillow("green"), new Pillow("green"));
+ return new TrackerEntry<Pillow>(original, current);
}
static bool result;
+ static Pillow original;
+ static Pillow current;
}
- public class Pillow : Entity<Pillow>
+ public class Pillow : IIdentifiable<Guid>
{
readonly string color;
- public Pillow(string color)
+ public Pillow(string color) : this(color, Guid.NewGuid())
+ {
+ }
+
+ public Pillow(string color, Guid id)
{
this.color = color;
+ this.id = id;
+ }
+
+ public Guid id { get; set; }
+
+ public bool Equals(Pillow other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+ return other.id.Equals(id);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (Pillow)) return false;
+ return Equals((Pillow) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return id.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return "{0} id: {1}".formatted_using(base.ToString(), id);
}
}
}
\ No newline at end of file
trunk/product/MoMoney.Infrastructure/Transactions2/Transaction.cs
@@ -1,14 +1,14 @@
using System;
-using System.Linq;
using System.Collections.Generic;
+using System.Linq;
+using Gorilla.Commons.Utility.Core;
using Gorilla.Commons.Utility.Extensions;
-using MoMoney.Domain.Core;
namespace MoMoney.Infrastructure.transactions2
{
public interface ITransaction
{
- IIdentityMap<Guid, T> create_for<T>() where T : IEntity;
+ IIdentityMap<Guid, T> create_for<T>() where T : IIdentifiable<Guid>;
void commit_changes();
void rollback_changes();
bool is_dirty();
@@ -27,7 +27,7 @@ namespace MoMoney.Infrastructure.transactions2
change_trackers = new Dictionary<Type, IChangeTracker>();
}
- public IIdentityMap<Guid, T> create_for<T>() where T : IEntity
+ public IIdentityMap<Guid, T> create_for<T>() where T : IIdentifiable<Guid>
{
return new IdentityMapProxy<Guid, T>(get_change_tracker_for<T>(), new IdentityMap<Guid, T>());
}
@@ -48,7 +48,7 @@ namespace MoMoney.Infrastructure.transactions2
return change_trackers.Values.Count(x => x.is_dirty()) > 0;
}
- IChangeTracker<T> get_change_tracker_for<T>() where T : IEntity
+ IChangeTracker<T> get_change_tracker_for<T>() where T : IIdentifiable<Guid>
{
if (!change_trackers.ContainsKey(typeof (T))) change_trackers.Add(typeof (T), factory.create_for<T>());
return change_trackers[typeof (T)].downcast_to<IChangeTracker<T>>();
trunk/product/MoMoney.Infrastructure/Transactions2/TransactionSpecs.cs
@@ -1,7 +1,7 @@
using System;
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
-using MoMoney.Domain.Core;
+using Gorilla.Commons.Utility.Core;
namespace MoMoney.Infrastructure.transactions2
{
@@ -18,18 +18,18 @@ namespace MoMoney.Infrastructure.transactions2
factory = the_dependency<IChangeTrackerFactory>();
};
- protected static IStatementRegistry registry;
- protected static IDatabase database;
- protected static IChangeTrackerFactory factory;
+ static protected IStatementRegistry registry;
+ static protected IDatabase database;
+ static protected IChangeTrackerFactory factory;
}
public class when_creating_an_identity_map_for_a_specific_entity : behaves_like_transaction
{
it should_return_a_new_identity_map = () => result.should_not_be_null();
- because b = () => { result = sut.create_for<IEntity>(); };
+ because b = () => { result = sut.create_for<IIdentifiable<Guid>>(); };
- static IIdentityMap<Guid, IEntity> result;
+ static IIdentityMap<Guid, IIdentifiable<Guid>> result;
}
public class when_committing_a_transaction_and_an_item_in_the_identity_map_has_changed : behaves_like_transaction
@@ -84,7 +84,7 @@ namespace MoMoney.Infrastructure.transactions2
static IChangeTracker<IMovie> tracker;
}
- public interface IMovie : IEntity
+ public interface IMovie : IIdentifiable<Guid>
{
string name { get; }
void change_name_to(string name);
trunk/product/MoMoney.Infrastructure/MoMoney.Infrastructure.csproj
@@ -178,10 +178,6 @@
<Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
<Name>Gorilla.Commons.Utility</Name>
</ProjectReference>
- <ProjectReference Include="..\MoMoney.Domain\MoMoney.Domain.csproj">
- <Project>{BE790BCC-4412-473F-9D0A-5AA48FE7A74F}</Project>
- <Name>MoMoney.Domain</Name>
- </ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />