Skip to content

Commit

Permalink
GREEN: Started unit testing Account, first unit test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
S-DRE committed Mar 15, 2023
1 parent 4a9d930 commit 7c168b8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Bank-Kata_C-Sharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bank", "Bank\Bank.csproj",
{1C9DCC2D-22A7-40BB-8325-37260870309A} = {1C9DCC2D-22A7-40BB-8325-37260870309A}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankShould", "BankShould\BankShould.csproj", "{1C9DCC2D-22A7-40BB-8325-37260870309A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankTests", "BankTests\BankTests.csproj", "{1C9DCC2D-22A7-40BB-8325-37260870309A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 4 additions & 2 deletions Bank/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ public class Account
{
private ProConsole proConsole;
private DateCreator dateCreator;
private WalletRepository wallet;

public Account(ProConsole proConsole, DateCreator dateCreator)
public Account(ProConsole proConsole, DateCreator dateCreator, WalletRepository wallet)
{
this.proConsole = proConsole;
this.dateCreator = dateCreator;
this.wallet = wallet;
}

public void Deposit(int amount)
{
throw new NotImplementedException();
wallet.add(1000);
}

public void Withdraw(int amount)
Expand Down
9 changes: 9 additions & 0 deletions Bank/Wallet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bank;

public class Wallet : WalletRepository
{
public void add(int amount)
{
throw new NotImplementedException("NOT IMPLEMENTED: Wallet repository not implemented");
}
}
6 changes: 6 additions & 0 deletions Bank/WalletRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Bank;

public interface WalletRepository
{
public void add(int amount);
}
23 changes: 23 additions & 0 deletions BankTests/AccountShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Bank;
using Moq;

namespace AccountShould;

public class AccountShould
{
private Account account;

private Mock<WalletRepository> walletRepository = new();


public AccountShould()
{
account = new Account(new ProConsole(), new DateCreator(), walletRepository.Object);
}

[Fact]
public void DepositTheGivenAmountAndSaveTheValue() {
account.Deposit(1000);
walletRepository.Verify(wallet => wallet.add(1000));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Bank;
using Moq;

namespace BankShould;
namespace BankTests;

public class BankShould
public class BankAcceptanceShould
{
[Fact]
public void PerformPrintAListOfPreviousDepositsAndWithdrawals()
Expand All @@ -21,8 +21,10 @@ public void PerformPrintAListOfPreviousDepositsAndWithdrawals()
var dateMocker = new Mock<DateCreator>();
DateCreator dateCreatorMock = dateMocker.Object;

var walletInMemoryRepo = new Wallet();

// given
var account = new Account(proConsoleMock, dateCreatorMock);
var account = new Account(proConsoleMock, dateCreatorMock, walletInMemoryRepo);
dateMocker.SetupSequence(x => x.CreateCurrentDate())
.Returns(DateTime.Parse("14/01/2012"))
.Returns(DateTime.Parse("13/01/2012"))
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7c168b8

Please sign in to comment.