-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce13c3c
commit e09c966
Showing
13 changed files
with
343 additions
and
44 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
1 Hands-on Legacy Code/DDDBankingExample.sln.DotSettings.user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=ad113830_002Db0ea_002D46e8_002Da5c7_002D6f1c301f86ab/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="testAMSTransferMoney" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> | ||
<TestAncestor> | ||
<TestId>xUnit::C37DC3E6-5409-48E1-8029-A3F8200D9DC0::net8.0::Banking.Application.AccountManagementServiceTest.testAMSTransferMoney</TestId> | ||
</TestAncestor> | ||
</SessionState></s:String></wpf:ResourceDictionary> |
75 changes: 75 additions & 0 deletions
75
1 Hands-on Legacy Code/src/Banking/Application/AccountManagementService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Banking.Models; | ||
|
||
namespace Banking.Application; | ||
|
||
public class AccountManagementService | ||
{ | ||
private IDictionary<int, Customer> customerList = new Dictionary<int, Customer>(); | ||
private int customerNumberCounter = 0; | ||
private IDictionary<int, Account> accountList = new Dictionary<int, Account>(); | ||
private int accountNumberCounter = 0; | ||
|
||
public AccountManagementService() | ||
{ | ||
} | ||
|
||
public Customer NewCustomer(String firstName, String familyName, DateOnly dateOfBirth) | ||
{ | ||
Customer customer = new Customer(firstName, familyName, dateOfBirth, customerNumberCounter++); | ||
customerList.Add(customer.GetCustomerNumber(), customer); | ||
return customer; | ||
} | ||
|
||
public Account NewAccount(float balance, Customer customer) | ||
{ | ||
Account account = new Account(accountNumberCounter++, customer); | ||
account.SetBalance(balance); | ||
accountList.Add(account.GetAccountnumber(), account); | ||
customer.GetAccountList().Add(account); | ||
return account; | ||
} | ||
|
||
public CreditAccount NewCreditAccount(Credit credit) | ||
{ | ||
CreditAccount account = new CreditAccount(accountNumberCounter++, credit); | ||
accountList.Add(account.GetAccountnumber(), account); | ||
credit.GetCustomer().GetAccountList().Add(account); | ||
return account; | ||
} | ||
|
||
public IList<Account> GetAccountList() | ||
{ | ||
return new List<Account>(accountList.Values); | ||
} | ||
|
||
public IList<Customer> GetCustomerList() | ||
{ | ||
return new List<Customer>(customerList.Values); | ||
} | ||
|
||
public void TransferMoney(float amount, int debitorAccountNumber, int creditorAccountNumber) | ||
{ | ||
float balance = accountList[debitorAccountNumber].GetBalance(); | ||
balance = balance - amount; | ||
accountList[debitorAccountNumber].SetBalance(balance); | ||
|
||
balance = accountList[creditorAccountNumber].GetBalance(); | ||
balance = balance + amount; | ||
accountList[creditorAccountNumber].SetBalance(balance); | ||
} | ||
|
||
public ICollection<int> GetAccountNumberList() | ||
{ | ||
return accountList.Keys; | ||
} | ||
|
||
public Account GetAccount(int accountNumber) { | ||
return accountList[accountNumber]; | ||
} | ||
|
||
public Customer GetCustomer(int accountNumber) | ||
{ | ||
return accountList[accountNumber].GetAccountowner(); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
1 Hands-on Legacy Code/src/Banking/Application/CreditService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Banking.Models; | ||
|
||
namespace Banking.Application; | ||
|
||
public class CreditService | ||
{ | ||
private AccountManagementService accountManagementService = null; | ||
Check warning on line 7 in 1 Hands-on Legacy Code/src/Banking/Application/CreditService.cs GitHub Actions / build
|
||
|
||
private int creditNumberCounter = 0; | ||
private IDictionary<int, Credit> creditList = new Dictionary<int, Credit>(); | ||
|
||
public CreditService(AccountManagementService accountManagementService) | ||
{ | ||
this.accountManagementService = accountManagementService; | ||
} | ||
|
||
public int ApplyForCredit(float amount, Customer customer) | ||
{ | ||
int creditNumber = creditNumberCounter++; | ||
Credit credit = new Credit(creditNumber, customer, amount); | ||
creditList.Add(creditNumber, credit); | ||
|
||
return creditNumber; | ||
} | ||
|
||
public CreditAccount GrantCredit(int creditNumber) | ||
{ | ||
Credit credit = this.GetCredit(creditNumber); | ||
credit.SetStatus(Credit.Status.Granted); | ||
CreditAccount newCreditAccount = accountManagementService.NewCreditAccount(credit); | ||
credit.SetAccount(newCreditAccount); | ||
return newCreditAccount; | ||
} | ||
|
||
public Credit GetCredit(int creditNumber) | ||
{ | ||
return creditList[creditNumber]; | ||
} | ||
|
||
public Credit GetCreditFromAccountNumber(int accountNumber) | ||
{ | ||
CreditAccount account = (CreditAccount) accountManagementService.GetAccount(accountNumber); | ||
return creditList[account.getCredit().GetCreditNumber()]; | ||
} | ||
|
||
public void MakePaymentForCredit(int creditNumber, float amount) | ||
{ | ||
Credit credit = creditList[creditNumber]; | ||
CreditAccount creditAccount = credit.GetAccount(); | ||
Check warning on line 49 in 1 Hands-on Legacy Code/src/Banking/Application/CreditService.cs GitHub Actions / build
|
||
float balance = creditAccount.GetBalance(); | ||
Check warning on line 50 in 1 Hands-on Legacy Code/src/Banking/Application/CreditService.cs GitHub Actions / build
|
||
balance = balance + amount; | ||
creditAccount.SetBalance(balance); | ||
} | ||
|
||
public void MakePaymentForCreditAccount(int accountNumber, float amount) | ||
{ | ||
Account account = accountManagementService.GetAccount(accountNumber); | ||
float balance = account.GetBalance(); | ||
balance = balance + amount; | ||
account.SetBalance(balance); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
1 Hands-on Legacy Code/tests/Banking.Test/Application/AccountManagementServiceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Banking.Models; | ||
|
||
namespace Banking.Application; | ||
|
||
public class AccountManagementServiceTest | ||
{ | ||
|
||
public static AccountManagementService PrepareTestData() { | ||
AccountManagementService ams = new AccountManagementService(); | ||
Customer customer = ams.NewCustomer("Carola", "Lilienthal", new DateOnly(1967, 9, 11)); | ||
ams.NewAccount(1000, customer); | ||
ams.NewAccount(5000, customer); | ||
ams.NewAccount(2000, customer); | ||
|
||
customer = ams.NewCustomer("Hans", "Lilienthal", new DateOnly(1968, 9, 11)); | ||
ams.NewAccount(2000, customer); | ||
ams.NewAccount(5000, customer); | ||
|
||
customer = ams.NewCustomer("Dieter", "Lilienthal", new DateOnly(1969, 9, 11)); | ||
ams.NewAccount(3000, customer); | ||
ams.NewAccount(5000, customer); | ||
|
||
customer = ams.NewCustomer("Franz", "Lilienthal", new DateOnly(1964, 9, 11)); | ||
ams.NewAccount(4000, customer); | ||
ams.NewAccount(5000, customer); | ||
|
||
customer = ams.NewCustomer("Carsten", "Lilienthal", new DateOnly(1965, 9, 11)); | ||
ams.NewAccount(5000, customer); | ||
|
||
return ams; | ||
} | ||
|
||
[Fact] | ||
void TestAmsCreation() { | ||
AccountManagementService ams = AccountManagementServiceTest.PrepareTestData(); | ||
Assert.NotNull(ams.GetAccountList()); | ||
Assert.NotNull(ams.GetCustomerList()); | ||
Assert.Equal(5, ams.GetCustomerList().Count); | ||
Assert.Equal(10, ams.GetAccountList().Count); | ||
int counter = 0; | ||
foreach (Customer customer in ams.GetCustomerList()) { | ||
counter = counter + customer.GetAccountList().Count; | ||
} | ||
Assert.Equal(10, counter); | ||
} | ||
|
||
[Fact] | ||
void TestAmsNewCustomerNewAccount() { | ||
AccountManagementService ams = AccountManagementServiceTest.PrepareTestData(); | ||
|
||
Customer newCustomer = ams.NewCustomer("Tea", "Ginster", new DateOnly(1950, 12, 2)); | ||
Assert.Contains(newCustomer, ams.GetCustomerList()); | ||
|
||
Account newAccount = ams.NewAccount(2000, newCustomer); | ||
Assert.Contains(newAccount, ams.GetAccountList()); | ||
Assert.Equal(newAccount, ams.GetAccount(newAccount.GetAccountnumber())); | ||
Assert.Equal(newCustomer, ams.GetAccount(newAccount.GetAccountnumber()).GetAccountowner()); | ||
Assert.Contains(newAccount, newCustomer.GetAccountList()); | ||
Assert.Equal(11, ams.GetAccountList().Count); | ||
|
||
Credit credit = new Credit(1000, newCustomer, 10); | ||
CreditAccount newCreditAccount = ams.NewCreditAccount(credit); | ||
Assert.Contains(newCreditAccount, ams.GetAccountList()); | ||
Assert.Equal(newCreditAccount, ams.GetAccount(newCreditAccount.GetAccountnumber())); | ||
Assert.Equal(12, ams.GetAccountList().Count); | ||
|
||
Assert.Contains(newAccount.GetAccountnumber(), ams.GetAccountNumberList()); | ||
Assert.Contains(newCreditAccount.GetAccountnumber(), ams.GetAccountNumberList()); | ||
Assert.Contains(newCreditAccount, newCustomer.GetAccountList()); | ||
|
||
} | ||
|
||
[Fact] | ||
void TestAmsTransferMoney() { | ||
AccountManagementService ams = AccountManagementServiceTest.PrepareTestData(); | ||
|
||
ICollection<int> accountNumbers = ams.GetAccountNumberList(); | ||
using var enumerator = accountNumbers.GetEnumerator(); | ||
enumerator.MoveNext(); | ||
int debitorAccountNumber = enumerator.Current; | ||
enumerator.MoveNext(); | ||
int creditorAccountNumber = enumerator.Current; | ||
float debitorSaldo = ams.GetAccount(debitorAccountNumber).GetBalance(); | ||
float creditorSaldo = ams.GetAccount(creditorAccountNumber).GetBalance(); | ||
ams.TransferMoney(100, debitorAccountNumber, creditorAccountNumber); | ||
Assert.Equal(debitorSaldo - 100, ams.GetAccount(debitorAccountNumber).GetBalance()); | ||
Assert.Equal(creditorSaldo + 100, ams.GetAccount(creditorAccountNumber).GetBalance()); | ||
|
||
} | ||
} |
Oops, something went wrong.