Commit 8574c80
Changed files (56)
trunk
build
config
product
MyMoney
boot
container
DataAccess
Domain
accounting
billing
repositories
Infrastructure
Container
Windsor
configuration
proxies
Interceptors
transactions
transactions2
Presentation
Model
Projects
Presenters
Views
Tasks
infrastructure
core
Testing
MetaData
spechelpers
contexts
trunk/build/config/log4net.config.xml.template
@@ -7,12 +7,12 @@
<maximumFileSize value='100000KB' />
<staticLogFileName value='true' />
<layout type='log4net.Layout.PatternLayout'>
- <conversionPattern value="%d %-5p %c - [thread %t] %m%n" />
+ <conversionPattern value="%d %-5p %c - [%t] %m%n" />
</layout>
</appender>
<appender name="Console" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="%d %-5p %c - [thread %t] %m%n" />
+ <conversionPattern value="%d %-5p %c - [%t] %m%n" />
</layout>
</appender>
<root>
trunk/product/MyMoney/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs
@@ -28,6 +28,8 @@ namespace MoMoney.boot.container.registration
registry.transient(typeof (IUnitOfWorkRegistrationFactory<>), typeof (UnitOfWorkRegistrationFactory<>));
registry.transient(typeof (ITrackerEntryMapper<>), typeof (TrackerEntryMapper<>));
+ registry.transient(typeof (IKey<>), typeof (TypedKey<>));
+ registry.singleton<IContext, Context>();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/wire_up_the_services_in_to_the.cs
@@ -6,6 +6,7 @@ using MoMoney.Infrastructure.interceptors;
using MoMoney.Infrastructure.proxies;
using MoMoney.Tasks.application;
using MoMoney.Utility.Core;
+using IUnitOfWorkInterceptor=MoMoney.Infrastructure.transactions2.IUnitOfWorkInterceptor;
namespace MoMoney.boot.container.registration
{
@@ -23,7 +24,7 @@ namespace MoMoney.boot.container.registration
registry.proxy(new ServiceLayerConfiguration<IBillingTasks>(
x =>
{
- x.register_new_company(null);
+ //x.register_new_company(null);
x.save_a_new_bill_using(null);
}
),
@@ -37,7 +38,9 @@ namespace MoMoney.boot.container.registration
registry.proxy(
new ServiceLayerConfiguration<IIncomeTasks>(x => x.add_new(null)),
- () => new IncomeTasks(Lazy.load<IDatabaseGateway>(), Lazy.load<ICustomerTasks>()));
+ () => new IncomeTasks(Lazy.load<ICustomerTasks>(),
+ Lazy.load<ICompanyRepository>(),
+ Lazy.load<IIncomeRepository>()));
}
}
@@ -52,7 +55,9 @@ namespace MoMoney.boot.container.registration
public void configure(IProxyBuilder<T> item)
{
- configure_it(item.add_interceptor(Lazy.load<IUnitOfWorkInterceptor>()).intercept_on);
+ var selector = item.add_interceptor(Lazy.load<IUnitOfWorkInterceptor>());
+ selector.intercept_all();
+ //configure_it(selector.intercept_on);
}
}
}
\ No newline at end of file
trunk/product/MyMoney/DataAccess/db40/AttachedSession.cs
@@ -1,9 +1,6 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
using Db4objects.Db4o;
using MoMoney.Domain.Core;
-using MoMoney.Infrastructure.Extensions;
namespace MoMoney.DataAccess.db40
{
@@ -17,12 +14,10 @@ namespace MoMoney.DataAccess.db40
public class AttachedSession : ISession
{
readonly IObjectContainer connection;
- readonly Guid session_id;
public AttachedSession(IObjectContainer connection)
{
this.connection = connection;
- session_id = Guid.NewGuid();
}
public IEnumerable<T> query<T>() where T : IEntity
@@ -32,11 +27,6 @@ namespace MoMoney.DataAccess.db40
public void save<T>(T item) where T : IEntity
{
- if (query<T>().Count(x => x.Id.Equals(item.Id)) > 0)
- {
- this.log().debug("already added: {0}, from {1}", item, session_id);
- }
- this.log().debug("adding item: {0}, {1}", item, session_id);
connection.Store(item);
}
trunk/product/MyMoney/DataAccess/db40/DetachedSession.cs
@@ -1,8 +1,6 @@
-using System;
using System.Collections.Generic;
using System.Linq;
using MoMoney.Domain.Core;
-using MoMoney.Infrastructure.Extensions;
using MoMoney.Utility.Extensions;
namespace MoMoney.DataAccess.db40
@@ -10,31 +8,21 @@ namespace MoMoney.DataAccess.db40
public class DetachedSession : ISession
{
readonly HashSet<object> items;
- readonly Guid session_id;
public DetachedSession()
{
items = new HashSet<object>();
- session_id = Guid.NewGuid();
}
public IEnumerable<T> query<T>() where T : IEntity
{
- var enumerable = items
+ return items
.where(x => x.is_an_implementation_of<T>())
.Select(x => x.downcast_to<T>());
- this.log().debug("items in session: {0}", enumerable.Count());
- enumerable.each(x => this.log().debug("session item {0}", x));
- return enumerable;
}
public void save<T>(T item) where T : IEntity
{
- if (query<T>().Count(x => x.Id.Equals(item.Id)) > 0)
- {
- this.log().debug("already added: {0}, from {1}", item, session_id);
- }
- this.log().debug("adding item: {0}, from {1}", item, session_id);
items.Add(item);
}
trunk/product/MyMoney/DataAccess/db40/ObjectDatabaseGateway.cs
@@ -1,33 +1,35 @@
using System.Collections.Generic;
using MoMoney.DataAccess.core;
using MoMoney.Domain.Core;
+using MoMoney.Infrastructure.transactions2;
namespace MoMoney.DataAccess.db40
{
public class ObjectDatabaseGateway : IDatabaseGateway
{
readonly ISessionContext context;
+ readonly ISessionProvider session_provider;
- public ObjectDatabaseGateway(ISessionContext context)
+ public ObjectDatabaseGateway(ISessionContext context, ISessionProvider session_provider)
{
this.context = context;
+ this.session_provider = session_provider;
}
public IEnumerable<T> all<T>() where T : IEntity
{
- return open_session_with_database().query<T>();
+ return open_session_with_database().all<T>();
}
public void save<T>(T item) where T : IEntity
{
- var session = open_session_with_database();
- session.save(item);
- //session.commit();
+ open_session_with_database().save(item);
}
- ISession open_session_with_database()
+ Infrastructure.transactions2.ISession open_session_with_database()
{
- return context.current_session();
+ return session_provider.get_the_current_session();
+ //return context.current_session();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/DataAccess/db40/ObjectDatabaseGatewaySpecs.cs
@@ -2,6 +2,7 @@ using System.Collections.Generic;
using developwithpassion.bdd.contexts;
using MoMoney.DataAccess.core;
using MoMoney.Domain.Core;
+using MoMoney.Infrastructure.transactions2;
using MoMoney.Testing.MetaData;
using MoMoney.Testing.spechelpers.contexts;
using MoMoney.Testing.spechelpers.core;
@@ -11,9 +12,14 @@ namespace MoMoney.DataAccess.db40
[Concern(typeof (ObjectDatabaseGateway))]
public abstract class behaves_like_a_object_repository : concerns_for<IDatabaseGateway, ObjectDatabaseGateway>
{
- context c = () => { _context = the_dependency<ISessionContext>(); };
+ context c = () =>
+ {
+ context = the_dependency<ISessionContext>();
+ provider = the_dependency<ISessionProvider>();
+ };
- protected static ISessionContext _context;
+ protected static ISessionContext context;
+ protected static ISessionProvider provider;
}
public class when_loading_all_the_items_from_the_database : behaves_like_a_object_repository
@@ -28,11 +34,14 @@ namespace MoMoney.DataAccess.db40
{
first_item = an<IEntity>();
second_item = an<IEntity>();
- var session = an<ISession>();
+ var session = an<Infrastructure.transactions2.ISession>();
+
+ //context.is_told_to(x => x.current_session()).it_will_return(session);
+ //session.is_told_to(x => x.query<IEntity>()).it_will_return(new List<IEntity> {first_item, second_item});
+
- _context.is_told_to(x => x.current_session()).it_will_return(session);
- session.is_told_to(x => x.query<IEntity>()).it_will_return(new List<IEntity>
- {first_item, second_item});
+ provider.is_told_to(x => x.get_the_current_session()).it_will_return(session);
+ when_the(session).is_told_to(x => x.all<IEntity>()).it_will_return(first_item, second_item);
};
because b = () => { result = sut.all<IEntity>(); };
trunk/product/MyMoney/DataAccess/repositories/BillRepositorySpecs.cs
@@ -10,7 +10,7 @@ namespace MoMoney.DataAccess.repositories
{
public class when_loading_all_the_bills_from_the_repository : behaves_like_a_repository
{
- public it should_return_all_the_bills_in_the_database = () => results.should_contain(first_bill);
+ it should_return_all_the_bills_in_the_database = () => results.should_contain(first_bill);
context c = () => { first_bill = new Bill(new Company("mokhan.ca"), new Money(1, 00), DateTime.Now); };
trunk/product/MyMoney/DataAccess/repositories/CompanyRepository.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Linq;
using MoMoney.DataAccess.core;
@@ -9,7 +10,7 @@ namespace MoMoney.DataAccess.repositories
{
public class CompanyRepository : ICompanyRepository
{
- IDatabaseGateway gateway;
+ readonly IDatabaseGateway gateway;
public CompanyRepository(IDatabaseGateway gateway)
{
@@ -27,5 +28,15 @@ namespace MoMoney.DataAccess.repositories
.all<ICompany>()
.SingleOrDefault(x => x.name.is_equal_to_ignoring_case(name));
}
+
+ public ICompany find_company_by(Guid id)
+ {
+ return gateway.all<ICompany>().SingleOrDefault(x => x.id.Equals(id));
+ }
+
+ public void save(ICompany company)
+ {
+ gateway.save(company);
+ }
}
}
\ No newline at end of file
trunk/product/MyMoney/DataAccess/repositories/IncomeRepository.cs
@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using MoMoney.DataAccess.core;
+using MoMoney.Domain.accounting.financial_growth;
+using MoMoney.Domain.repositories;
+
+namespace MoMoney.DataAccess.repositories
+{
+ public class IncomeRepository : IIncomeRepository
+ {
+ readonly IDatabaseGateway gateway;
+
+ public IncomeRepository(IDatabaseGateway gateway)
+ {
+ this.gateway = gateway;
+ }
+
+ public IEnumerable<IIncome> all()
+ {
+ return gateway.all<IIncome>();
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Domain/accounting/billing/company_specs.cs
@@ -1,60 +0,0 @@
-using System;
-using developwithpassion.bdd.contexts;
-using MoMoney.Domain.accounting.financial_growth;
-using MoMoney.Domain.Core;
-using MoMoney.Testing.MetaData;
-using MoMoney.Testing.spechelpers.contexts;
-using MoMoney.Testing.spechelpers.core;
-
-namespace MoMoney.Domain.accounting.billing
-{
- [Concern(typeof (Company))]
- public abstract class behaves_like_a_company : concerns_for<ICompany>
- {
- public override ICompany create_sut()
- {
- company_name = "enmax";
- return new Company(company_name);
- }
-
- protected string company_name;
- }
-
- public class when_a_company_issues_a_bill_to_a_customer : behaves_like_a_company
- {
- it should_issue_the_bill_to_the_customer_for_the_previous_billing_month =
- () => customer.was_told_to(x => x.recieve(new Bill(sut, for_amount, that_is_due_on)));
-
- context c = () =>
- {
- customer = an<IAccountHolder>();
- for_amount = new Money(53, 24);
- that_is_due_on = new DateTime(2008, 02, 12);
- };
-
- because b = () => sut.issue_bill_to(customer, that_is_due_on, for_amount);
-
- static IAccountHolder customer;
- static IMoney for_amount;
- static DateTime that_is_due_on;
- }
-
- public class when_a_company_pays_an_employee_or_consultant_for_services : behaves_like_a_company
- {
- it should_pay_the_total_amount_that_is_due =
- () => person.was_told_to(x => x.recieve(new Income(date_of_payment, two_thousand_dollars, sut)));
-
- context c = () =>
- {
- two_thousand_dollars = new Money(2000);
- person = an<IAccountHolder>();
- date_of_payment = an<IDate>();
- };
-
- because b = () => sut.pay(person, two_thousand_dollars, date_of_payment);
-
- static Money two_thousand_dollars;
- static IAccountHolder person;
- static IDate date_of_payment;
- }
-}
\ No newline at end of file
trunk/product/MyMoney/Domain/Core/date_extensions.cs → trunk/product/MyMoney/Domain/Core/DateExtensions.cs
@@ -2,7 +2,7 @@ using System;
namespace MoMoney.Domain.Core
{
- public static class date_extensions
+ public static class DateExtensions
{
public static IDate as_a_date(this DateTime date)
{
@@ -11,7 +11,7 @@ namespace MoMoney.Domain.Core
public static IYear as_a_year(this int year)
{
- return new year(new DateTime(year, 01, 01));
+ return new Year(new DateTime(year, 01, 01));
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Domain/Core/Entity.cs
@@ -1,12 +1,11 @@
using System;
-using MoMoney.Infrastructure.transactions;
using MoMoney.Utility.Extensions;
namespace MoMoney.Domain.Core
{
public interface IEntity
{
- Guid Id { get; }
+ Guid id { get; }
}
[Serializable]
@@ -14,17 +13,17 @@ namespace MoMoney.Domain.Core
{
protected Entity()
{
- Id = Guid.NewGuid();
- UnitOfWork.For<T>().register(this as T);
+ id = Guid.NewGuid();
+ //UnitOfWork.For<T>().register(this as T);
}
- public Guid Id { get; private set; }
+ public Guid id { get; private set; }
public bool Equals(Entity<T> obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
- return obj.Id.Equals(Id);
+ return obj.id.Equals(id);
}
public override bool Equals(object obj)
@@ -37,12 +36,12 @@ namespace MoMoney.Domain.Core
public override int GetHashCode()
{
- return Id.GetHashCode();
+ return id.GetHashCode();
}
public override string ToString()
{
- return "{0} id: {1}".formatted_using(base.ToString(), Id);
+ return "{0} id: {1}".formatted_using(base.ToString(), id);
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Domain/Core/IYear.cs
@@ -7,16 +7,16 @@ namespace MoMoney.Domain.Core
bool represents(DateTime time);
}
- internal class year : IYear
+ public class Year : IYear
{
private readonly int the_underlying_year;
- public year(DateTime date)
+ public Year(DateTime date)
{
the_underlying_year = date.Year;
}
- public bool Equals(year obj)
+ public bool Equals(Year obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
@@ -27,8 +27,8 @@ namespace MoMoney.Domain.Core
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (year)) return false;
- return Equals((year) obj);
+ if (obj.GetType() != typeof (Year)) return false;
+ return Equals((Year) obj);
}
public override int GetHashCode()
trunk/product/MyMoney/Domain/repositories/ICompanyRepository.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using MoMoney.Domain.accounting.billing;
@@ -7,5 +8,7 @@ namespace MoMoney.Domain.repositories
{
IEnumerable<ICompany> all();
ICompany find_company_named(string name);
+ ICompany find_company_by(Guid id);
+ void save(ICompany company);
}
}
\ No newline at end of file
trunk/product/MyMoney/Domain/repositories/IIncomeRepository.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using MoMoney.Domain.accounting.financial_growth;
+
+namespace MoMoney.Domain.repositories
+{
+ public interface IIncomeRepository
+ {
+ IEnumerable<IIncome> all();
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/ComponentExclusionSpecificationSpecs.cs
@@ -92,7 +92,7 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
public class FakeEntity : IEntity
{
- public Guid Id
+ public Guid id
{
get { throw new NotImplementedException(); }
}
trunk/product/MyMoney/Infrastructure/Container/Windsor/configuration/LogComponent.cs
@@ -1,5 +1,4 @@
using Castle.MicroKernel.Registration;
-using MoMoney.Infrastructure.Extensions;
namespace MoMoney.Infrastructure.Container.Windsor.configuration
{
@@ -8,7 +7,6 @@ namespace MoMoney.Infrastructure.Container.Windsor.configuration
public void configure(ComponentRegistration registration)
{
var implementation = registration.Implementation;
- this.log().debug("registering: {0}", implementation);
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/proxies/Interceptors/MethodCallTracker.cs
@@ -1,7 +1,5 @@
-using System;
using System.Collections.Generic;
using Castle.Core.Interceptor;
-using MoMoney.Infrastructure.Extensions;
using MoMoney.Utility.Extensions;
namespace MoMoney.Infrastructure.proxies.Interceptors
@@ -23,12 +21,8 @@ namespace MoMoney.Infrastructure.proxies.Interceptors
public void Intercept(IInvocation invocation)
{
- this.log().debug("recording: {0}", invocation.Method);
set_return_value_for(invocation);
- if (the_name_of_each_method_to_intercept.Contains(invocation.Method.Name))
- {
- return;
- }
+ if (the_name_of_each_method_to_intercept.Contains(invocation.Method.Name)) return;
the_name_of_each_method_to_intercept.Add(invocation.Method.Name);
}
@@ -43,10 +37,5 @@ namespace MoMoney.Infrastructure.proxies.Interceptors
if (return_type == typeof (void)) return;
invocation.ReturnValue = return_type.default_value();
}
-
- //static object get_default_value_for(Type return_type)
- //{
- // return (return_type.IsValueType ? Activator.CreateInstance(return_type) : null);
- //}
}
}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions/unit_of_work.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using MoMoney.DataAccess.core;
using MoMoney.Domain.Core;
-using MoMoney.Infrastructure.Extensions;
using MoMoney.Utility.Extensions;
namespace MoMoney.Infrastructure.transactions
@@ -34,13 +33,11 @@ namespace MoMoney.Infrastructure.transactions
public void register(T entity)
{
- this.log().debug("registering: {0}", entity);
registered_items.Add(factory.map_from(entity));
}
public void commit()
{
- this.log().debug("commiting: {0}", typeof(T));
registered_items.each(x => { if (x.contains_changes()) gateway.save(x.current); });
}
trunk/product/MyMoney/Infrastructure/transactions2/ConnectionFactory.cs
@@ -1,5 +1,4 @@
using Db4objects.Db4o;
-using Db4objects.Db4o.Events;
using MoMoney.Infrastructure.Extensions;
using MoMoney.Presentation.Model.Projects;
@@ -21,15 +20,10 @@ namespace MoMoney.Infrastructure.transactions2
public IObjectContainer open_connection_to(IFile the_path_to_the_database_file)
{
+ this.log().debug("opening connection to: {0}", the_path_to_the_database_file);
var configuration = Db4oFactory.NewConfiguration();
setup.configure(configuration);
-
- var container = Db4oFactory.OpenFile(configuration, the_path_to_the_database_file.path);
-
- var registry = EventRegistryFactory.ForObjectContainer(container);
- registry.Creating += (sender, args) => this.log().debug("{0}", args.Object);
- registry.QueryStarted += (sender, args) => this.log().debug("{0}", args.Query);
- return container;
+ return Db4oFactory.OpenFile(configuration, the_path_to_the_database_file.path);
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/Context.cs
@@ -0,0 +1,46 @@
+using System.Collections;
+
+namespace MoMoney.Infrastructure.transactions2
+{
+ public interface IContext
+ {
+ bool contains<T>(IKey<T> key);
+ void add<T>(IKey<T> key, T value);
+ T value_for<T>(IKey<T> key);
+ void remove<T>(IKey<T> key);
+ }
+
+ public class Context : IContext
+ {
+ readonly IDictionary items;
+
+ public Context() : this(new Hashtable())
+ {
+ }
+
+ public Context(IDictionary items)
+ {
+ this.items = items;
+ }
+
+ public bool contains<T>(IKey<T> key)
+ {
+ return key.is_found_in(items);
+ }
+
+ public void add<T>(IKey<T> key, T value)
+ {
+ key.add_value_to(items, value);
+ }
+
+ public T value_for<T>(IKey<T> key)
+ {
+ return key.parse_from(items);
+ }
+
+ public void remove<T>(IKey<T> key)
+ {
+ key.remove_from(items);
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/Database.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
using MoMoney.Domain.Core;
namespace MoMoney.Infrastructure.transactions2
@@ -18,7 +19,7 @@ namespace MoMoney.Infrastructure.transactions2
{
using (var connection = factory.open_connection_to(configuration.path_to_database()))
{
- return connection.Query<T>();
+ return connection.Query<T>().ToList();
}
}
trunk/product/MyMoney/Infrastructure/transactions2/EmptyUnitOfWork.cs
@@ -0,0 +1,18 @@
+namespace MoMoney.Infrastructure.transactions2
+{
+ public class EmptyUnitOfWork : IUnitOfWork
+ {
+ public void commit()
+ {
+ }
+
+ public bool is_dirty()
+ {
+ return false;
+ }
+
+ public void Dispose()
+ {
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/IdentityMapProxy.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using MoMoney.Domain.Core;
+using MoMoney.Infrastructure.Extensions;
namespace MoMoney.Infrastructure.transactions2
{
@@ -22,6 +23,7 @@ namespace MoMoney.Infrastructure.transactions2
public void add(Key key, Value value)
{
change_tracker.register(value);
+ this.log().debug("registered: {0},{1}", key, value);
real_map.add(key, value);
}
trunk/product/MyMoney/Infrastructure/transactions2/IIdentityMap.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
namespace MoMoney.Infrastructure.transactions2
@@ -28,7 +27,7 @@ namespace MoMoney.Infrastructure.transactions2
public IEnumerable<TValue> all()
{
- throw new NotImplementedException();
+ return items_in_map.Values;
}
public void add(TKey key, TValue value)
trunk/product/MyMoney/Infrastructure/transactions2/Session.cs
@@ -36,28 +36,28 @@ namespace MoMoney.Infrastructure.transactions2
return get_identity_map_for<T>().item_that_belongs_to(id);
}
- var entity = database.fetch_all<T>().Single(x => x.Id.Equals(id));
+ var entity = database.fetch_all<T>().Single(x => x.id.Equals(id));
get_identity_map_for<T>().add(id, entity);
return entity;
}
public IEnumerable<T> all<T>() where T : IEntity
{
- var uncached_items = database
+ database
.fetch_all<T>()
- .where(x => !get_identity_map_for<T>().contains_an_item_for(x.Id));
- uncached_items.each(x => get_identity_map_for<T>().add(x.Id, x));
+ .where(x => !get_identity_map_for<T>().contains_an_item_for(x.id))
+ .each(x => get_identity_map_for<T>().add(x.id, x));
return get_identity_map_for<T>().all();
}
public void save<T>(T entity) where T : IEntity
{
- get_identity_map_for<T>().add(entity.Id, entity);
+ get_identity_map_for<T>().add(entity.id, entity);
}
public void delete<T>(T entity) where T : IEntity
{
- get_identity_map_for<T>().evict(entity.Id);
+ get_identity_map_for<T>().evict(entity.id);
}
public void flush()
trunk/product/MyMoney/Infrastructure/transactions2/SessionNotStartedException.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace MoMoney.Infrastructure.transactions2
+{
+ public class SessionNotStartedException : Exception
+ {
+ public SessionNotStartedException() : base("A session could not be found. Did you forget to open a session?")
+ {
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/SessionProvider.cs
@@ -0,0 +1,28 @@
+namespace MoMoney.Infrastructure.transactions2
+{
+ public interface ISessionProvider
+ {
+ ISession get_the_current_session();
+ }
+
+ public class SessionProvider : ISessionProvider
+ {
+ readonly IContext context;
+ readonly IKey<ISession> session_key;
+
+ public SessionProvider(IContext context, IKey<ISession> session_key)
+ {
+ this.context = context;
+ this.session_key = session_key;
+ }
+
+ public ISession get_the_current_session()
+ {
+ if (!context.contains(session_key))
+ {
+ throw new SessionNotStartedException();
+ }
+ return context.value_for(session_key);
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/SessionSpecs.cs
@@ -35,7 +35,7 @@ namespace MoMoney.Infrastructure.transactions2
entity = an<ITestEntity>();
map = an<IIdentityMap<Guid, ITestEntity>>();
- when_the(entity).is_told_to(x => x.Id).it_will_return(guid);
+ when_the(entity).is_told_to(x => x.id).it_will_return(guid);
when_the(transaction).is_told_to(x => x.create_for<ITestEntity>()).it_will_return(map);
};
@@ -87,9 +87,9 @@ namespace MoMoney.Infrastructure.transactions2
database_item = an<ITestEntity>();
uncached_item = an<ITestEntity>();
- when_the(cached_item).is_told_to(x => x.Id).it_will_return(id);
- when_the(database_item).is_told_to(x => x.Id).it_will_return(id);
- when_the(uncached_item).is_told_to(x => x.Id).it_will_return(id_of_the_uncached_item);
+ when_the(cached_item).is_told_to(x => x.id).it_will_return(id);
+ when_the(database_item).is_told_to(x => x.id).it_will_return(id);
+ when_the(uncached_item).is_told_to(x => x.id).it_will_return(id_of_the_uncached_item);
when_the(transaction).is_told_to(x => x.create_for<ITestEntity>()).it_will_return(
identity_map);
when_the(identity_map).is_told_to(x => x.contains_an_item_for(id)).it_will_return(true);
@@ -126,8 +126,8 @@ namespace MoMoney.Infrastructure.transactions2
wrong_item = an<ITestEntity>();
correct_item = an<ITestEntity>();
map = an<IIdentityMap<Guid, ITestEntity>>();
- when_the(wrong_item).is_told_to(x => x.Id).it_will_return(Guid.NewGuid());
- when_the(correct_item).is_told_to(x => x.Id).it_will_return(id);
+ when_the(wrong_item).is_told_to(x => x.id).it_will_return(Guid.NewGuid());
+ when_the(correct_item).is_told_to(x => x.id).it_will_return(id);
when_the(database)
.is_told_to(x => x.fetch_all<ITestEntity>())
.it_will_return(wrong_item, correct_item);
@@ -156,7 +156,7 @@ namespace MoMoney.Infrastructure.transactions2
entity = an<ITestEntity>();
map = an<IIdentityMap<Guid, ITestEntity>>();
- when_the(entity).is_told_to(x => x.Id).it_will_return(id);
+ when_the(entity).is_told_to(x => x.id).it_will_return(id);
when_the(transaction).is_told_to(x => x.create_for<ITestEntity>()).it_will_return(map);
when_the(database).is_told_to(x => x.fetch_all<ITestEntity>()).it_will_return(entity);
};
trunk/product/MyMoney/Infrastructure/transactions2/StatementRegistry.cs
@@ -28,7 +28,7 @@ namespace MoMoney.Infrastructure.transactions2
public void prepare(IObjectContainer connection)
{
- var query = connection.Query<T>(x => x.Id.Equals(entity.Id));
+ var query = connection.Query<T>(x => x.id.Equals(entity.id));
query.each(x => connection.Delete(x));
connection.Store(entity);
}
trunk/product/MyMoney/Infrastructure/transactions2/TrackerEntry.cs
@@ -1,4 +1,5 @@
using System.Reflection;
+using MoMoney.Infrastructure.Extensions;
namespace MoMoney.Infrastructure.transactions2
{
@@ -23,20 +24,22 @@ namespace MoMoney.Infrastructure.transactions2
public bool has_changes()
{
var type = original.GetType();
- var fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
- foreach (var field in fields)
+ foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
{
var original_value = field.GetValue(original);
var current_value = field.GetValue(current);
if (original_value == null && current_value != null)
{
+ this.log().debug("has changes: {0}", original);
return true;
}
if (original_value != null && !original_value.Equals(current_value))
{
+ this.log().debug("has changes: {0}", original);
return true;
}
}
+ this.log().debug("does not have changes: {0}", original);
return false;
}
}
trunk/product/MyMoney/Infrastructure/transactions2/TransactionSpecs.cs
@@ -49,7 +49,7 @@ namespace MoMoney.Infrastructure.transactions2
because b = () =>
{
- sut.create_for<IMovie>().add(movie.Id, movie);
+ sut.create_for<IMovie>().add(movie.id, movie);
movie.change_name_to("Austin Powers");
sut.commit_changes();
};
@@ -76,8 +76,8 @@ namespace MoMoney.Infrastructure.transactions2
because b = () =>
{
var map = sut.create_for<IMovie>();
- map.add(movie.Id, movie);
- map.evict(movie.Id);
+ map.add(movie.id, movie);
+ map.evict(movie.id);
sut.commit_changes();
};
@@ -95,7 +95,7 @@ namespace MoMoney.Infrastructure.transactions2
{
public Movie(string name)
{
- Id = Guid.NewGuid();
+ id = Guid.NewGuid();
this.name = name;
}
@@ -106,6 +106,6 @@ namespace MoMoney.Infrastructure.transactions2
name = new_name;
}
- public Guid Id { get; set; }
+ public Guid id { get; set; }
}
}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/TypedKey.cs
@@ -0,0 +1,58 @@
+using System.Collections;
+
+namespace MoMoney.Infrastructure.transactions2
+{
+ public interface IKey<T>
+ {
+ bool is_found_in(IDictionary items);
+ T parse_from(IDictionary items);
+ void remove_from(IDictionary items);
+ void add_value_to(IDictionary items, T value);
+ }
+
+ public class TypedKey<T> : IKey<T>
+ {
+ public bool is_found_in(IDictionary items)
+ {
+ return items.Contains(create_key());
+ }
+
+ public T parse_from(IDictionary items)
+ {
+ return (T) items[create_key()];
+ }
+
+ public void remove_from(IDictionary items)
+ {
+ if (is_found_in(items)) items.Remove(create_key());
+ }
+
+ public void add_value_to(IDictionary items, T value)
+ {
+ items[create_key()] = value;
+ }
+
+ public bool Equals(TypedKey<T> obj)
+ {
+ return !ReferenceEquals(null, obj);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (TypedKey<T>)) return false;
+ return Equals((TypedKey<T>) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return GetType().GetHashCode();
+ }
+
+ string create_key()
+ {
+ return GetType().FullName;
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/UnitOfWork.cs
@@ -0,0 +1,40 @@
+using System;
+
+namespace MoMoney.Infrastructure.transactions2
+{
+ public interface IUnitOfWork : IDisposable
+ {
+ void commit();
+ bool is_dirty();
+ }
+
+ public class UnitOfWork : IUnitOfWork
+ {
+ readonly ISession session;
+ readonly IContext request;
+ readonly IKey<ISession> key;
+
+ public UnitOfWork(ISession session, IContext request, IKey<ISession> key)
+ {
+ this.session = session;
+ this.request = request;
+ this.key = key;
+ }
+
+ public void commit()
+ {
+ if (is_dirty()) session.flush();
+ }
+
+ public bool is_dirty()
+ {
+ return session.is_dirty();
+ }
+
+ public void Dispose()
+ {
+ request.remove(key);
+ session.Dispose();
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/UnitOfWorkFactory.cs
@@ -0,0 +1,39 @@
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Infrastructure.transactions2
+{
+ public interface IUnitOfWorkFactory : IFactory<IUnitOfWork>
+ {
+ }
+
+ public class UnitOfWorkFactory : IUnitOfWorkFactory
+ {
+ readonly IContext context;
+ readonly ISessionFactory factory;
+ readonly IKey<ISession> key;
+
+ public UnitOfWorkFactory(IContext current_request, ISessionFactory factory, IKey<ISession> key)
+ {
+ context = current_request;
+ this.key = key;
+ this.factory = factory;
+ }
+
+ public IUnitOfWork create()
+ {
+ return unit_of_work_been_started() ? new EmptyUnitOfWork() : start_a_new_unit_of_work();
+ }
+
+ bool unit_of_work_been_started()
+ {
+ return context.contains(key);
+ }
+
+ IUnitOfWork start_a_new_unit_of_work()
+ {
+ var session = factory.create();
+ context.add(key, session);
+ return new UnitOfWork(session, context, key);
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Infrastructure/transactions2/UnitOfWorkInterceptor.cs
@@ -11,9 +11,9 @@ namespace MoMoney.Infrastructure.transactions2
public class UnitOfWorkInterceptor : IUnitOfWorkInterceptor
{
readonly IEventAggregator broker;
- readonly ISessionFactory factory;
+ readonly IUnitOfWorkFactory factory;
- public UnitOfWorkInterceptor(IEventAggregator broker, ISessionFactory factory)
+ public UnitOfWorkInterceptor(IEventAggregator broker, IUnitOfWorkFactory factory)
{
this.broker = broker;
this.factory = factory;
@@ -21,12 +21,12 @@ namespace MoMoney.Infrastructure.transactions2
public void Intercept(IInvocation invocation)
{
- using (var session = factory.create())
+ using (var unit_of_work = factory.create())
{
invocation.Proceed();
- if (session.is_dirty())
+ if (unit_of_work.is_dirty())
{
- session.flush();
+ unit_of_work.commit();
broker.publish<UnsavedChangesEvent>();
}
}
trunk/product/MyMoney/Presentation/Model/Projects/file.cs
@@ -1,3 +1,4 @@
+using System;
using System.IO;
namespace MoMoney.Presentation.Model.Projects
@@ -51,5 +52,10 @@ namespace MoMoney.Presentation.Model.Projects
{
return (path != null ? path.GetHashCode() : 0);
}
+
+ public override string ToString()
+ {
+ return path;
+ }
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/billing/dto/register_new_company.cs → trunk/product/MyMoney/Presentation/Presenters/billing/dto/RegisterNewCompany.cs
@@ -1,6 +1,6 @@
namespace MoMoney.Presentation.Presenters.billing.dto
{
- public class register_new_company
+ public class RegisterNewCompany
{
public string company_name { get; set; }
}
trunk/product/MyMoney/Presentation/Presenters/income/dto/income_submission_dto.cs → trunk/product/MyMoney/Presentation/Presenters/income/dto/IncomeSubmissionDto.cs
@@ -1,11 +1,10 @@
using System;
-using MoMoney.Domain.accounting.billing;
namespace MoMoney.Presentation.Presenters.income.dto
{
- public class income_submission_dto
+ public class IncomeSubmissionDto
{
- public ICompany company { get; set; }
+ public Guid company_id;
public double amount { get; set; }
public DateTime recieved_date { get; set; }
}
trunk/product/MyMoney/Presentation/Presenters/income/AddNewIncomePresenter.cs
@@ -12,7 +12,7 @@ namespace MoMoney.Presentation.Presenters.income
{
public interface IAddNewIncomePresenter : IContentPresenter
{
- void submit_new(income_submission_dto income);
+ void submit_new(IncomeSubmissionDto income);
}
public class AddNewIncomePresenter : IAddNewIncomePresenter
@@ -33,7 +33,7 @@ namespace MoMoney.Presentation.Presenters.income
view.display(tasks.retrive_all_income().map_all_using(x => map_from(x)));
}
- public void submit_new(income_submission_dto income)
+ public void submit_new(IncomeSubmissionDto income)
{
if (similar_income_has_been_submitted(income))
{
@@ -43,13 +43,13 @@ namespace MoMoney.Presentation.Presenters.income
view.display(tasks.retrive_all_income().map_all_using(x => map_from(x)));
}
- private bool similar_income_has_been_submitted(income_submission_dto income)
+ private bool similar_income_has_been_submitted(IncomeSubmissionDto income)
{
if (tasks.retrive_all_income().Count() == 0) return false;
return tasks
.retrive_all_income()
.where(x => x.amount_tendered.Equals(income.amount.as_money()))
- .where(x => x.company.Equals(income.company))
+ .where(x => x.company.id.Equals(income.company_id))
.where(x => x.date_of_issue.Equals(income.recieved_date.as_a_date()))
.Count() > 0 ;
}
trunk/product/MyMoney/Presentation/Presenters/income/AddNewIncomePresenterSpecs.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using developwithpassion.bdd.contexts;
using MoMoney.Domain.accounting.billing;
@@ -31,13 +32,13 @@ namespace MoMoney.Presentation.Presenters.income
context c = () =>
{
- income = new income_submission_dto {};
+ income = new IncomeSubmissionDto {};
when_the(tasks).is_told_to(x => x.retrive_all_income()).it_will_return_nothing();
};
because b = () => sut.submit_new(income);
- static income_submission_dto income;
+ static IncomeSubmissionDto income;
}
public class when_loading_the_add_new_income_screen : behaves_like_add_new_income_presenter
@@ -68,22 +69,24 @@ namespace MoMoney.Presentation.Presenters.income
var a_company = an<ICompany>();
var matching_income = an<IIncome>();
var today = new Date(2008, 12, 26);
+ var id = Guid.NewGuid();
- income = new income_submission_dto
+ income = new IncomeSubmissionDto
{
amount = 100.00,
- company = a_company,
+ company_id = id,
recieved_date = today,
};
when_the(matching_income).is_asked_for(x => x.amount_tendered).it_will_return(100.as_money());
when_the(matching_income).is_asked_for(x => x.company).it_will_return(a_company);
when_the(matching_income).is_asked_for(x => x.date_of_issue).it_will_return(today);
+ when_the(a_company).is_asked_for(x => x.id).it_will_return(id);
when_the(tasks).is_told_to(x => x.retrive_all_income()).it_will_return(matching_income);
};
because b = () => sut.submit_new(income);
- static income_submission_dto income;
+ static IncomeSubmissionDto income;
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Presenters/AddCompanyPresenter.cs
@@ -4,23 +4,26 @@ using MoMoney.Presentation.Presenters.billing.dto;
using MoMoney.Presentation.Views;
using MoMoney.Presentation.Views.core;
using MoMoney.Tasks.application;
+using MoMoney.Tasks.infrastructure.core;
using MoMoney.Utility.Extensions;
namespace MoMoney.Presentation.Presenters
{
public interface IAddCompanyPresenter : IContentPresenter
{
- void submit(register_new_company dto);
+ void submit(RegisterNewCompany dto);
}
public class AddCompanyPresenter : IAddCompanyPresenter
{
- private readonly IAddCompanyView view;
- private readonly IBillingTasks tasks;
+ readonly IAddCompanyView view;
+ readonly IBillingTasks tasks;
+ readonly ICommandPump pump;
- public AddCompanyPresenter(IAddCompanyView view, IBillingTasks tasks)
+ public AddCompanyPresenter(IAddCompanyView view, IBillingTasks tasks, ICommandPump pump)
{
this.view = view;
+ this.pump = pump;
this.tasks = tasks;
}
@@ -30,7 +33,7 @@ namespace MoMoney.Presentation.Presenters
view.display(tasks.all_companys());
}
- public void submit(register_new_company dto)
+ public void submit(RegisterNewCompany dto)
{
if (company_has_already_been_registered(dto))
{
@@ -38,17 +41,18 @@ namespace MoMoney.Presentation.Presenters
}
else
{
- tasks.register_new_company(dto);
+ pump.run<IRegisterNewCompanyCommand, RegisterNewCompany>(dto);
+ //tasks.register_new_company(dto);
view.display(tasks.all_companys());
}
}
- private bool company_has_already_been_registered(register_new_company dto)
+ bool company_has_already_been_registered(RegisterNewCompany dto)
{
return tasks.all_companys().Count(x => x.name.is_equal_to_ignoring_case(dto.company_name)) > 0;
}
- private string create_error_message_from(register_new_company dto)
+ string create_error_message_from(RegisterNewCompany dto)
{
return "A Company named {0}, has already been submitted!".formatted_using(dto.company_name);
}
trunk/product/MyMoney/Presentation/Presenters/AddCompanyPresenterSpecs.cs
@@ -2,6 +2,7 @@ using developwithpassion.bdd.contexts;
using MoMoney.Presentation.Presenters.billing.dto;
using MoMoney.Presentation.Views;
using MoMoney.Tasks.application;
+using MoMoney.Tasks.infrastructure.core;
using MoMoney.Testing.MetaData;
using MoMoney.Testing.spechelpers.contexts;
using MoMoney.Testing.spechelpers.core;
@@ -9,16 +10,19 @@ using MoMoney.Testing.spechelpers.core;
namespace MoMoney.Presentation.Presenters
{
[Concern(typeof (AddCompanyPresenter))]
- public abstract class behaves_like_the_add_company_presenter : concerns_for<IAddCompanyPresenter, AddCompanyPresenter>
+ public abstract class behaves_like_the_add_company_presenter :
+ concerns_for<IAddCompanyPresenter, AddCompanyPresenter>
{
context c = () =>
{
view = the_dependency<IAddCompanyView>();
tasks = the_dependency<IBillingTasks>();
+ pump = the_dependency<ICommandPump>();
};
protected static IAddCompanyView view;
protected static IBillingTasks tasks;
+ protected static ICommandPump pump;
}
public class when_the_user_is_about_to_add_an_expense : behaves_like_the_add_company_presenter
@@ -34,12 +38,14 @@ namespace MoMoney.Presentation.Presenters
because b = () =>
{
- dto = new register_new_company {company_name = "Microsoft"};
+ dto = new RegisterNewCompany {company_name = "Microsoft"};
sut.submit(dto);
};
- it should_add_the_new_company = () => tasks.was_told_to(x => x.register_new_company(dto));
+ //it should_add_the_new_company = () => tasks.was_told_to(x => x.register_new_company(dto));
+ it should_add_the_new_company =
+ () => pump.was_told_to(x => x.run<IRegisterNewCompanyCommand, RegisterNewCompany>(dto));
- static register_new_company dto;
+ static RegisterNewCompany dto;
}
}
\ No newline at end of file
trunk/product/MyMoney/Presentation/Views/core/ApplicationWindow.cs
@@ -19,7 +19,7 @@ namespace MoMoney.Presentation.Views.core
{
InitializeComponent();
Icon = ApplicationIcons.Application;
- this.log().debug("created {0}", GetType());
+ //this.log().debug("created {0}", GetType());
}
public IApplicationWindow create_tool_tip_for(string title, string caption, Control control)
trunk/product/MyMoney/Presentation/Views/income/AddNewIncomeView.cs
@@ -41,11 +41,11 @@ namespace MoMoney.Presentation.Views.income
MessageBox.Show(builder.ToString(), "Ooops...", MessageBoxButtons.OK);
}
- income_submission_dto create_income()
+ IncomeSubmissionDto create_income()
{
- return new income_submission_dto
+ return new IncomeSubmissionDto
{
- company = ux_companys.SelectedItem.downcast_to<ICompany>(),
+ company_id = ux_companys.SelectedItem.downcast_to<ICompany>().id,
amount = ux_amount.Text.to_double(),
recieved_date = ux_date_received.Value
};
trunk/product/MyMoney/Presentation/Views/Startup/SplashScreenView.cs
@@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
-using MoMoney.Infrastructure.Extensions;
using MoMoney.Presentation.Model.interaction;
using MoMoney.Presentation.Resources;
using MoMoney.Presentation.Views.core;
@@ -12,7 +11,6 @@ namespace MoMoney.Presentation.Views.Startup
public SplashScreenView()
{
InitializeComponent();
- this.log().debug("created splash screen");
}
protected override void OnLoad(EventArgs e)
trunk/product/MyMoney/Presentation/Views/AddCompanyView.cs
@@ -16,13 +16,13 @@ namespace MoMoney.Presentation.Views
{
public partial class AddCompanyView : ApplicationDockedWindow, IAddCompanyView
{
- readonly register_new_company dto;
+ readonly RegisterNewCompany dto;
public AddCompanyView()
{
InitializeComponent();
titled("Add A Company");
- dto = new register_new_company();
+ dto = new RegisterNewCompany();
initialize1();
initialize2();
@@ -61,13 +61,6 @@ namespace MoMoney.Presentation.Views
public void display(IEnumerable<ICompany> companies)
{
- this.log().debug("companys to display {0}", companies.Count());
- if (companies.Count() > 0)
- {
- //this.log().debug("companys 1 display {0}", companies.ElementAt(0));
- //this.log().debug("companys 2 display {0}", companies.ElementAt(1));
- companies.each(x => this.log().debug("company {0}", x));
- }
ux_companys_listing.DataSource = companies.databind();
listView1.Items.Clear();
@@ -76,8 +69,6 @@ namespace MoMoney.Presentation.Views
listView2.Items.Clear();
listView2.Items.AddRange(companies.Select(x => new ListViewItem(x.name)).ToArray());
- //var tlist = new TypedObjectListView<ICompany>(objectListView1);
- //tlist.GetColumn(0).AspectGetter = (ICompany x) => x.name;
objectListView1.SetObjects(companies.ToList());
}
trunk/product/MyMoney/Tasks/application/BillingTasks.cs
@@ -1,9 +1,7 @@
using System.Collections.Generic;
-using Castle.Core;
using MoMoney.Domain.accounting.billing;
using MoMoney.Domain.Core;
using MoMoney.Domain.repositories;
-using MoMoney.Infrastructure.interceptors;
using MoMoney.Presentation.Presenters.billing.dto;
namespace MoMoney.Tasks.application
@@ -12,11 +10,9 @@ namespace MoMoney.Tasks.application
{
void save_a_new_bill_using(add_new_bill_dto dto);
IEnumerable<IBill> all_bills();
- void register_new_company(register_new_company dto);
IEnumerable<ICompany> all_companys();
}
- [Interceptor(typeof (IUnitOfWorkInterceptor))]
public class BillingTasks : IBillingTasks
{
readonly IBillRepository bills;
@@ -42,11 +38,6 @@ namespace MoMoney.Tasks.application
return bills.all();
}
- public void register_new_company(register_new_company dto)
- {
- new Company(dto.company_name);
- }
-
public IEnumerable<ICompany> all_companys()
{
return companys.all();
trunk/product/MyMoney/Tasks/application/CustomerTasks.cs
@@ -1,8 +1,6 @@
using System.Linq;
-using Castle.Core;
using MoMoney.DataAccess.core;
using MoMoney.Domain.accounting;
-using MoMoney.Infrastructure.interceptors;
namespace MoMoney.Tasks.application
{
@@ -11,10 +9,9 @@ namespace MoMoney.Tasks.application
IAccountHolder get_the_current_customer();
}
- [Interceptor(typeof (IUnitOfWorkInterceptor))]
public class CustomerTasks : ICustomerTasks
{
- private readonly IDatabaseGateway repository;
+ readonly IDatabaseGateway repository;
public CustomerTasks(IDatabaseGateway repository)
{
@@ -25,8 +22,11 @@ namespace MoMoney.Tasks.application
{
var c = repository.all<IAccountHolder>().SingleOrDefault();
- if (null == c) {
- return new AccountHolder();
+ if (null == c)
+ {
+ var customer = new AccountHolder();
+ repository.save(customer);
+ return customer;
}
return c;
trunk/product/MyMoney/Tasks/application/IncomeTasks.cs
@@ -1,37 +1,36 @@
using System.Collections.Generic;
-using Castle.Core;
-using MoMoney.DataAccess.core;
using MoMoney.Domain.accounting.billing;
using MoMoney.Domain.accounting.financial_growth;
using MoMoney.Domain.Core;
-using MoMoney.Infrastructure.interceptors;
+using MoMoney.Domain.repositories;
using MoMoney.Presentation.Presenters.income.dto;
namespace MoMoney.Tasks.application
{
public interface IIncomeTasks
{
- void add_new(income_submission_dto income);
+ void add_new(IncomeSubmissionDto income);
IEnumerable<ICompany> all_companys();
IEnumerable<IIncome> retrive_all_income();
}
- [Interceptor(typeof (IUnitOfWorkInterceptor))]
public class IncomeTasks : IIncomeTasks
{
- private readonly IDatabaseGateway repository;
- private readonly ICustomerTasks tasks;
+ readonly ICustomerTasks tasks;
+ readonly ICompanyRepository companys;
+ readonly IIncomeRepository incomes;
- public IncomeTasks(IDatabaseGateway repository, ICustomerTasks tasks)
+ public IncomeTasks(ICustomerTasks tasks, ICompanyRepository companys, IIncomeRepository incomes)
{
- this.repository = repository;
+ this.incomes = incomes;
+ this.companys = companys;
this.tasks = tasks;
}
- public void add_new(income_submission_dto income)
+ public void add_new(IncomeSubmissionDto income)
{
- income
- .company.pay(
+ var company = companys.find_company_by(income.company_id);
+ company.pay(
tasks.get_the_current_customer(),
income.amount.as_money(),
income.recieved_date.as_a_date()
@@ -40,12 +39,12 @@ namespace MoMoney.Tasks.application
public IEnumerable<ICompany> all_companys()
{
- return repository.all<ICompany>();
+ return companys.all();
}
public IEnumerable<IIncome> retrive_all_income()
{
- return repository.all<IIncome>();
+ return incomes.all();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/Tasks/application/RegisterNewCompanyCommand.cs
@@ -0,0 +1,26 @@
+using MoMoney.Domain.accounting.billing;
+using MoMoney.Domain.repositories;
+using MoMoney.Presentation.Presenters.billing.dto;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Tasks.application
+{
+ public interface IRegisterNewCompanyCommand : IParameterizedCommand<RegisterNewCompany>
+ {
+ }
+
+ public class RegisterNewCompanyCommand : IRegisterNewCompanyCommand
+ {
+ readonly ICompanyRepository companys;
+
+ public RegisterNewCompanyCommand(ICompanyRepository companys)
+ {
+ this.companys = companys;
+ }
+
+ public void run(RegisterNewCompany item)
+ {
+ companys.save(new Company(item.company_name));
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Tasks/infrastructure/core/CommandPump.cs
@@ -0,0 +1,48 @@
+using MoMoney.Infrastructure.Container;
+using MoMoney.Infrastructure.Threading;
+using MoMoney.Utility.Core;
+
+namespace MoMoney.Tasks.infrastructure.core
+{
+ public interface ICommandPump
+ {
+ void run<Command>() where Command : ICommand;
+ void run<Command>(Command command) where Command : ICommand;
+ void run<Command, T>(T input) where Command : IParameterizedCommand<T>;
+ void run<T>(ICallback<T> item, IQuery<T> query);
+ }
+
+ public class CommandPump : ICommandPump
+ {
+ readonly ICommandProcessor processor;
+ readonly IDependencyRegistry registry;
+ readonly ICommandFactory factory;
+
+ public CommandPump(ICommandProcessor processor, IDependencyRegistry registry, ICommandFactory factory)
+ {
+ this.processor = processor;
+ this.factory = factory;
+ this.registry = registry;
+ }
+
+ public void run<Command>() where Command : ICommand
+ {
+ run(registry.get_a<Command>());
+ }
+
+ public void run<Command>(Command command) where Command : ICommand
+ {
+ processor.add(command);
+ }
+
+ public void run<Command, T>(T input) where Command : IParameterizedCommand<T>
+ {
+ processor.add(() => registry.get_a<Command>().run(input));
+ }
+
+ public void run<T>(ICallback<T> item, IQuery<T> query)
+ {
+ run(factory.create_for(item, query));
+ }
+ }
+}
\ No newline at end of file
trunk/product/MyMoney/Testing/MetaData/run_in_real_container.cs → trunk/product/MyMoney/Testing/MetaData/RunInRealContainer.cs
@@ -5,17 +5,17 @@ using MoMoney.boot.container;
namespace MoMoney.Testing.MetaData
{
- public class run_in_real_container : DecoratorPatternAttribute
+ public class RunInRealContainer : DecoratorPatternAttribute
{
public override IRunInvoker GetInvoker(IRunInvoker wrapper)
{
- return new run_in_real_container_interceptor(wrapper);
+ return new RunInRealContainerInterceptor(wrapper);
}
}
- public class run_in_real_container_interceptor : DecoratorRunInvoker
+ public class RunInRealContainerInterceptor : DecoratorRunInvoker
{
- public run_in_real_container_interceptor(IRunInvoker wrapper) : base(wrapper)
+ public RunInRealContainerInterceptor(IRunInvoker wrapper) : base(wrapper)
{
}
trunk/product/MyMoney/Testing/spechelpers/contexts/behaves_like_a_repository.cs
@@ -1,20 +1,40 @@
+using System;
+using developwithpassion.bdd.contexts;
using MoMoney.DataAccess.core;
using MoMoney.Infrastructure.Container;
+using MoMoney.Infrastructure.transactions2;
using MoMoney.Testing.MetaData;
namespace MoMoney.Testing.spechelpers.contexts
{
- [run_in_real_container]
+ [RunInRealContainer]
[Concern(typeof (IDatabaseGateway))]
public abstract class behaves_like_a_repository : concerns_for<IDatabaseGateway>
{
public override IDatabaseGateway create_sut()
{
+ Console.Out.WriteLine("create sut");
return resolve.dependency_for<IDatabaseGateway>();
}
- //before_all_observations all = () => resolve.initialize_with(new WindsorDependencyRegistry());
+ context c = () =>
+ {
+ //};
+ //before_each_observation before =
+ // () =>
+ // {
+ session = resolve.dependency_for<ISessionFactory>().create();
+ resolve.dependency_for<IContext>().add(resolve.dependency_for<IKey<ISession>>(), session);
+ Console.Out.WriteLine("before each");
+ };
- //after_all_observations after_all = () => resolve.initialize_with(null);
+ after_each_observation after =
+ () =>
+ {
+ session.Dispose();
+ Console.Out.WriteLine("after each");
+ };
+
+ static ISession session;
}
}
\ No newline at end of file
trunk/product/MyMoney/MyMoney.csproj
@@ -182,12 +182,13 @@
<Compile Include="DataAccess\repositories\BillRepository.cs" />
<Compile Include="DataAccess\repositories\BillRepositorySpecs.cs" />
<Compile Include="DataAccess\repositories\CompanyRepository.cs" />
+ <Compile Include="DataAccess\repositories\IncomeRepository.cs" />
<Compile Include="Domain\accounting\billing\IEmployee.cs" />
<Compile Include="Domain\accounting\financial_growth\income.cs" />
<Compile Include="Domain\accounting\financial_growth\income_extensions.cs" />
<Compile Include="Domain\accounting\IInvoice.cs" />
<Compile Include="Domain\Core\Clock.cs" />
- <Compile Include="Domain\Core\date_extensions.cs" />
+ <Compile Include="Domain\Core\DateExtensions.cs" />
<Compile Include="Domain\Core\date_specs.cs" />
<Compile Include="Domain\Core\day.cs" />
<Compile Include="Domain\Core\Entity.cs" />
@@ -197,7 +198,7 @@
<Compile Include="DataAccess\db40\SessionContextSpecs.cs" />
<Compile Include="Domain\accounting\billing\billing_extensions.cs" />
<Compile Include="Domain\accounting\billing\Company.cs" />
- <Compile Include="Domain\accounting\billing\company_specs.cs" />
+ <Compile Include="Domain\accounting\billing\CompanySpecs.cs" />
<Compile Include="Domain\accounting\AccountHolder.cs" />
<Compile Include="Domain\accounting\AccountHolderSpecs.cs" />
<Compile Include="Domain\accounting\billing\total_payments_calculator.cs" />
@@ -211,14 +212,17 @@
<Compile Include="Domain\Core\range_specs.cs" />
<Compile Include="Domain\repositories\IBillRepository.cs" />
<Compile Include="Domain\repositories\ICompanyRepository.cs" />
+ <Compile Include="Domain\repositories\IIncomeRepository.cs" />
<Compile Include="Infrastructure\transactions2\ChangeTracker.cs" />
<Compile Include="Infrastructure\transactions2\ChangeTrackerFactory.cs" />
<Compile Include="Infrastructure\transactions2\ChangeTrackerFactorySpecs.cs" />
<Compile Include="Infrastructure\transactions2\ChangeTrackerSpecs.cs" />
<Compile Include="Infrastructure\transactions2\ConfigureDatabaseStep.cs" />
<Compile Include="Infrastructure\transactions2\ConnectionFactory.cs" />
+ <Compile Include="Infrastructure\transactions2\Context.cs" />
<Compile Include="Infrastructure\transactions2\Database.cs" />
<Compile Include="Infrastructure\transactions2\DatabaseConfiguration.cs" />
+ <Compile Include="Infrastructure\transactions2\EmptyUnitOfWork.cs" />
<Compile Include="Infrastructure\transactions2\IChangeTracker.cs" />
<Compile Include="Infrastructure\transactions2\IChangeTrackerFactory.cs" />
<Compile Include="Infrastructure\transactions2\IdentityMapProxy.cs" />
@@ -313,6 +317,8 @@
<Compile Include="Infrastructure\transactions2\Session.cs" />
<Compile Include="Infrastructure\transactions2\SessionFactory.cs" />
<Compile Include="Infrastructure\transactions2\SessionFactorySpecs.cs" />
+ <Compile Include="Infrastructure\transactions2\SessionNotStartedException.cs" />
+ <Compile Include="Infrastructure\transactions2\SessionProvider.cs" />
<Compile Include="Infrastructure\transactions2\SessionSpecs.cs" />
<Compile Include="Infrastructure\transactions2\StatementRegistry.cs" />
<Compile Include="Infrastructure\transactions2\TrackerEntry.cs" />
@@ -320,6 +326,9 @@
<Compile Include="Infrastructure\transactions2\TrackerEntrySpecs.cs" />
<Compile Include="Infrastructure\transactions2\Transaction.cs" />
<Compile Include="Infrastructure\transactions2\TransactionSpecs.cs" />
+ <Compile Include="Infrastructure\transactions2\TypedKey.cs" />
+ <Compile Include="Infrastructure\transactions2\UnitOfWork.cs" />
+ <Compile Include="Infrastructure\transactions2\UnitOfWorkFactory.cs" />
<Compile Include="Infrastructure\transactions2\UnitOfWorkInterceptor.cs" />
<Compile Include="Infrastructure\transactions\IUnitOfWorkRegistrationFactory.cs" />
<Compile Include="Infrastructure\transactions\NullUnitOfWork.cs" />
@@ -393,7 +402,7 @@
<Compile Include="Presentation\Presenters\AddCompanyPresenterSpecs.cs" />
<Compile Include="Presentation\Presenters\billing\dto\add_new_bill_dto.cs" />
<Compile Include="Presentation\Presenters\billing\dto\bill_information_dto.cs" />
- <Compile Include="Presentation\Presenters\billing\dto\register_new_company.cs" />
+ <Compile Include="Presentation\Presenters\billing\dto\RegisterNewCompany.cs" />
<Compile Include="Presentation\Presenters\billing\ViewAllBillsPresenter.cs" />
<Compile Include="Presentation\Presenters\Commands\RestartCommand.cs" />
<Compile Include="Presentation\Presenters\Commands\RunPresenterCommand.cs" />
@@ -411,7 +420,7 @@
<Compile Include="Presentation\Presenters\income\AddNewIncomePresenter.cs" />
<Compile Include="Presentation\Presenters\income\AddNewIncomePresenterSpecs.cs" />
<Compile Include="Presentation\Presenters\income\dto\income_information_dto.cs" />
- <Compile Include="Presentation\Presenters\income\dto\income_submission_dto.cs" />
+ <Compile Include="Presentation\Presenters\income\dto\IncomeSubmissionDto.cs" />
<Compile Include="Presentation\Presenters\income\dto\monthly_summary_dto.cs" />
<Compile Include="Presentation\Presenters\income\ViewIncomeHistoryPresenter.cs" />
<Compile Include="Presentation\Presenters\Menu\Help\AboutTheApplicationPresenter.cs" />
@@ -588,6 +597,8 @@
<Compile Include="Tasks\application\BillingTasks.cs" />
<Compile Include="Tasks\application\CustomerTasks.cs" />
<Compile Include="Tasks\application\IncomeTasks.cs" />
+ <Compile Include="Tasks\application\RegisterNewCompanyCommand.cs" />
+ <Compile Include="Tasks\infrastructure\core\CommandPump.cs" />
<Compile Include="Tasks\infrastructure\core\ICallbackCommand.cs" />
<Compile Include="Tasks\infrastructure\LogFileTasks.cs" />
<Compile Include="Tasks\infrastructure\core\CommandFactory.cs" />
@@ -607,7 +618,7 @@
<Compile Include="Testing\spechelpers\core\empty_fixture.cs" />
<Compile Include="Testing\spechelpers\core\IHideObjectMembers.cs" />
<Compile Include="Testing\spechelpers\core\MethodCallOccurance.cs" />
- <Compile Include="Testing\MetaData\run_in_real_container.cs" />
+ <Compile Include="Testing\MetaData\RunInRealContainer.cs" />
<Compile Include="Presentation\Views\helpers\Events.cs" />
<Compile Include="Presentation\Views\helpers\EventTrigger.cs" />
<Compile Include="Presentation\Views\helpers\IEventTarget.cs" />