Commit 21626ea
Changed files (5)
product
client
server
commons
utility
support
unit
server
domain
accounting
product/client/server/domain/Entity.cs
@@ -3,19 +3,20 @@ using gorilla.commons.utility;
namespace presentation.windows.server.domain
{
- public class Entity : IEquatable<Entity>
+ public class Entity : IEquatable<Entity>, Identifiable<Guid>
{
protected Entity()
{
id = Id<Guid>.Default;
}
- public virtual Guid id { get; set; }
+ public virtual Guid id { get; set; }
public virtual bool Equals(Entity other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
+ if (id.Equals(Id<Guid>.Default) || other.id.Equals(Id<Guid>.Default)) return false;
return other.id.Equals(id);
}
product/client/server/domain/Identifiable.cs
@@ -0,0 +1,7 @@
+namespace presentation.windows.server.domain
+{
+ public interface Identifiable<T>
+ {
+ T id { get; }
+ }
+}
\ No newline at end of file
product/client/server/server.csproj
@@ -131,6 +131,7 @@
<Compile Include="domain\accounting\TransactionDoesNotBalance.cs" />
<Compile Include="domain\accounting\TransactionType.cs" />
<Compile Include="domain\accounting\Withdrawal.cs" />
+ <Compile Include="domain\Identifiable.cs" />
<Compile Include="handlers\AddNewFamilyMemberHandler.cs" />
<Compile Include="orm\mappings\DetailAccountMapping.cs" />
<Compile Include="ServerBootstrapper.cs" />
product/commons/utility/Id.cs
@@ -1,46 +1,46 @@
-using System;
-
-namespace gorilla.commons.utility
-{
- [Serializable]
- public class Id<T>
- {
+using System;
+
+namespace gorilla.commons.utility
+{
+ [Serializable]
+ public class Id<T>
+ {
static public readonly Id<T> Default = new Id<T>(default(T));
- public T id { get; private set; }
-
- public Id(T id)
- {
- this.id = id;
- }
-
- static public implicit operator Id<T>(T id)
- {
- return new Id<T>(id);
- }
-
- static public implicit operator T(Id<T> id)
- {
- return id.id;
- }
-
- public bool Equals(Id<T> other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return Equals(other.id, id);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Id<T>)) return false;
- return Equals((Id<T>) obj);
- }
-
- public override int GetHashCode()
- {
- return id.GetHashCode();
- }
- }
+ public T id { get; private set; }
+
+ public Id(T id)
+ {
+ this.id = id;
+ }
+
+ static public implicit operator Id<T>(T id)
+ {
+ return new Id<T>(id);
+ }
+
+ static public implicit operator T(Id<T> id)
+ {
+ return id.id;
+ }
+
+ public bool Equals(Id<T> other)
+ {
+ if (ReferenceEquals(null, other)) return false;
+ if (ReferenceEquals(this, other)) return true;
+ return Equals(other.id, id);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (obj.GetType() != typeof (Id<T>)) return false;
+ return Equals((Id<T>) obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return id.GetHashCode();
+ }
+ }
}
\ No newline at end of file
product/support/unit/server/domain/accounting/SummaryAccountSpecs.cs
@@ -11,20 +11,19 @@ namespace unit.server.domain.accounting
{
Establish c = () =>
{
- cash = DetailAccount.New(Currency.CAD);
- cash.id = Guid.NewGuid();
- credit = DetailAccount.New(Currency.CAD);
- credit.id = Guid.NewGuid();
+ var cash = DetailAccount.New(Currency.CAD);
+ var credit = DetailAccount.New(Currency.CAD);
cash.deposit(50, Currency.CAD);
credit.deposit(50, Currency.CAD);
+
sut = SummaryAccount.New(Currency.CAD);
+ sut.add(cash);
+ sut.add(credit);
};
Because b = () =>
{
- sut.add(cash);
- sut.add(credit);
result = sut.balance();
};
@@ -34,9 +33,7 @@ namespace unit.server.domain.accounting
};
static Quantity result;
- static DetailAccount cash;
- static DetailAccount credit;
- static protected SummaryAccount sut;
+ static SummaryAccount sut;
}
}
}
\ No newline at end of file