Skip to content

Commit ed3f58b

Browse files
committed
Refactoring
1 parent df63791 commit ed3f58b

19 files changed

+67
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,4 @@ ASALocalRun/
328328

329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331+
.vscode/

src/Finance.Domain/Accounts/Account.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55
using System.Collections.ObjectModel;
66

7-
public class Account : IEntity, IAggregateRoot
7+
public sealed class Account : IEntity, IAggregateRoot
88
{
99
public Guid Id { get; }
1010
public Guid CustomerId { get; }
@@ -19,6 +19,13 @@ public ReadOnlyCollection<ITransaction> Transactions
1919

2020
private TransactionCollection _transactions;
2121

22+
public Account(Guid id, Guid customerId, TransactionCollection transactions)
23+
{
24+
Id = id;
25+
_transactions = transactions;
26+
CustomerId = customerId;
27+
}
28+
2229
public Account(Guid customerId)
2330
{
2431
Id = Guid.NewGuid();
@@ -52,5 +59,11 @@ public Amount GetCurrentBalance()
5259
Amount totalAmount = _transactions.GetCurrentBalance();
5360
return totalAmount;
5461
}
62+
63+
public ITransaction GetLastTransaction()
64+
{
65+
ITransaction transaction = _transactions.GetLastTransaction();
66+
return transaction;
67+
}
5568
}
5669
}

src/Finance.Domain/Accounts/AccountCannotBeClosedException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain.Accounts
22
{
3-
public class AccountCannotBeClosedException : DomainException
3+
public sealed class AccountCannotBeClosedException : DomainException
44
{
55
internal AccountCannotBeClosedException(string message)
66
: base(message)

src/Finance.Domain/Accounts/Credit.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Finance.Domain.ValueObjects;
44
using System;
55

6-
public class Credit : IEntity, ITransaction
6+
public sealed class Credit : IEntity, ITransaction
77
{
88
public Guid Id { get; }
99
public Guid AccountId { get; }
@@ -12,19 +12,22 @@ public string Description
1212
{
1313
get { return "Credit"; }
1414
}
15+
public DateTime TransactionDate { get; }
1516

16-
public Credit(Guid id, Guid accountId, Amount amount)
17+
public Credit(Guid id, Guid accountId, Amount amount, DateTime transactionDate)
1718
{
1819
Id = id;
1920
AccountId = accountId;
2021
Amount = amount;
22+
TransactionDate = transactionDate;
2123
}
2224

2325
public Credit(Guid accountId, Amount amount)
2426
{
2527
Id = Guid.NewGuid();
2628
AccountId = accountId;
2729
Amount = amount;
30+
TransactionDate = DateTime.UtcNow;
2831
}
2932
}
3033
}

src/Finance.Domain/Accounts/Debit.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Finance.Domain.ValueObjects;
44
using System;
55

6-
public class Debit : IEntity, ITransaction
6+
public sealed class Debit : IEntity, ITransaction
77
{
88
public Guid Id { get; }
99
public Guid AccountId { get; }
@@ -12,19 +12,22 @@ public string Description
1212
{
1313
get { return "Debit"; }
1414
}
15+
public DateTime TransactionDate { get; }
1516

16-
public Debit(Guid id, Guid accountId, Amount amount)
17+
public Debit(Guid id, Guid accountId, Amount amount, DateTime transactionDate)
1718
{
1819
Id = id;
1920
AccountId = accountId;
2021
Amount = amount;
22+
TransactionDate = transactionDate;
2123
}
2224

2325
public Debit(Guid accountId, Amount amount)
2426
{
2527
Id = Guid.NewGuid();
2628
AccountId = accountId;
2729
Amount = amount;
30+
TransactionDate = DateTime.UtcNow;
2831
}
2932
}
3033
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
namespace Finance.Domain.Accounts
22
{
33
using Finance.Domain.ValueObjects;
4+
using System;
45

56
public interface ITransaction
67
{
78
Amount Amount { get; }
89
string Description { get; }
10+
DateTime TransactionDate { get; }
911
}
1012
}

src/Finance.Domain/Accounts/InsuficientFundsException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain.Accounts
22
{
3-
public class InsuficientFundsException : DomainException
3+
public sealed class InsuficientFundsException : DomainException
44
{
55
internal InsuficientFundsException(string message)
66
: base(message)

src/Finance.Domain/Accounts/TransactionCollection.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
using System.Collections.Generic;
55
using System.Collections.ObjectModel;
66

7-
public class TransactionCollection : Collection<ITransaction>
7+
public sealed class TransactionCollection : Collection<ITransaction>
88
{
9+
public ITransaction GetLastTransaction()
10+
{
11+
ITransaction transaction = Items[Items.Count - 1];
12+
return transaction;
13+
}
14+
915
public void Add(IEnumerable<ITransaction> transactions)
1016
{
1117
foreach (var transaction in transactions)
@@ -17,7 +23,7 @@ public void Add(IEnumerable<ITransaction> transactions)
1723
public Amount GetCurrentBalance()
1824
{
1925
Amount totalAmount = 0;
20-
26+
2127
foreach (var item in Items)
2228
{
2329
if (item is Debit)

src/Finance.Domain/Customers/AccountCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55
using System.Collections.ObjectModel;
66

7-
public class AccountCollection : Collection<Guid>
7+
public sealed class AccountCollection : Collection<Guid>
88
{
99
public void Add(IEnumerable<Guid> accounts)
1010
{

src/Finance.Domain/Customers/Customer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace Finance.Domain.Customers
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Collections.ObjectModel;
56
using Finance.Domain.ValueObjects;
67

7-
public class Customer : IEntity, IAggregateRoot
8+
public sealed class Customer : IEntity, IAggregateRoot
89
{
910
public Guid Id { get; }
1011
public Name Name { get; }

src/Finance.Domain/IAggregateRoot.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain
22
{
3-
public interface IAggregateRoot : IEntity
3+
internal interface IAggregateRoot : IEntity
44
{
55
}
66
}

src/Finance.Domain/IEntity.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
using System;
44

5-
public interface IEntity
5+
internal interface IEntity
66
{
77
Guid Id { get; }
88
}

src/Finance.Domain/ValueObjects/Amount.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Finance.Domain.ValueObjects
44
{
5-
public class Amount
5+
public sealed class Amount
66
{
77
private double _value;
88

@@ -16,6 +16,11 @@ public override string ToString()
1616
return _value.ToString();
1717
}
1818

19+
public static implicit operator double(Amount value)
20+
{
21+
return value._value;
22+
}
23+
1924
public static Amount operator -(Amount value)
2025
{
2126
return new Amount(Math.Abs(value._value) * -1);

src/Finance.Domain/ValueObjects/InvalidSSNException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain.ValueObjects
22
{
3-
public class InvalidSSNException : DomainException
3+
internal sealed class InvalidSSNException : DomainException
44
{
55
internal InvalidSSNException(string message)
66
: base(message)

src/Finance.Domain/ValueObjects/Name.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain.ValueObjects
22
{
3-
public class Name
3+
public sealed class Name
44
{
55
private string _text;
66

@@ -22,6 +22,11 @@ public static implicit operator Name(string text)
2222
return new Name(text);
2323
}
2424

25+
public static implicit operator string(Name name)
26+
{
27+
return name._text;
28+
}
29+
2530
public override bool Equals(object obj)
2631
{
2732
if (ReferenceEquals(null, obj))

src/Finance.Domain/ValueObjects/NameShouldNotBeEmptyException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain.ValueObjects
22
{
3-
public class NameShouldNotBeEmptyException : DomainException
3+
public sealed class NameShouldNotBeEmptyException : DomainException
44
{
55
internal NameShouldNotBeEmptyException(string message)
66
: base(message)

src/Finance.Domain/ValueObjects/SSN.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Text.RegularExpressions;
2-
3-
namespace Finance.Domain.ValueObjects
1+
namespace Finance.Domain.ValueObjects
42
{
5-
public class SSN
3+
using System.Text.RegularExpressions;
4+
5+
public sealed class SSN
66
{
77
public string _text { get; private set; }
88
const string RegExForValidation = @"^\d{6,8}[-|(\s)]{0,1}\d{4}$";
@@ -31,6 +31,11 @@ public static implicit operator SSN(string text)
3131
return new SSN(text);
3232
}
3333

34+
public static implicit operator string(SSN ssn)
35+
{
36+
return ssn._text;
37+
}
38+
3439
public override bool Equals(object obj)
3540
{
3641
if (ReferenceEquals(null, obj))

src/Finance.Domain/ValueObjects/SSNShouldNotBeEmptyException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Finance.Domain.ValueObjects
22
{
3-
public class SSNShouldNotBeEmptyException : DomainException
3+
public sealed class SSNShouldNotBeEmptyException : DomainException
44
{
55
internal SSNShouldNotBeEmptyException(string message)
66
: base(message)

test/Finance.Domain.Tests/AmountTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void Positive_Amount_Should_Be_Created()
1818

1919
//
2020
// Assert
21-
Assert.Equal(positiveAmount, amount);
21+
Assert.Equal<double>(positiveAmount, amount);
2222
}
2323

2424
[Fact]

0 commit comments

Comments
 (0)