Expanded Unit Tests
This commit is contained in:
parent
4f8e6314c4
commit
555632321d
@ -8,19 +8,28 @@ namespace Week_10___Account_Library
|
|||||||
{
|
{
|
||||||
public class Account
|
public class Account
|
||||||
{
|
{
|
||||||
|
|
||||||
private decimal _balance;
|
private decimal _balance;
|
||||||
private decimal _overdraftLimit;
|
private decimal _overdraftLimit;
|
||||||
|
|
||||||
public decimal Balance => _balance;
|
public decimal Balance => _balance;
|
||||||
public decimal OverdraftLimit => _overdraftLimit;
|
public decimal OverdraftLimit => _overdraftLimit;
|
||||||
|
public AccountState StateOfAccount { get; }
|
||||||
|
|
||||||
void Deposit(decimal amount)
|
private bool ValidateAmount(decimal amount)
|
||||||
{
|
{
|
||||||
|
return amount >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deposit(decimal amount)
|
||||||
|
{
|
||||||
|
if (ValidateAmount(amount))
|
||||||
_balance += amount;
|
_balance += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Withdraw(decimal amount)
|
public void Withdraw(decimal amount)
|
||||||
{
|
{
|
||||||
|
if (ValidateAmount(amount))
|
||||||
_balance -= amount;
|
_balance -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,4 +39,12 @@ namespace Week_10___Account_Library
|
|||||||
_overdraftLimit = overdraftLimit;
|
_overdraftLimit = overdraftLimit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum AccountState
|
||||||
|
{
|
||||||
|
Safe,
|
||||||
|
InOD,
|
||||||
|
ODLimit,
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,43 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using System;
|
using System;
|
||||||
|
using Week_10___Account_Library;
|
||||||
|
|
||||||
namespace Week_10___TDD_Tests
|
namespace Week_10___TDD_Tests
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class TDDTests
|
public class TDDTests
|
||||||
{
|
{
|
||||||
[TestMethod]
|
private Account account;
|
||||||
public void TestMethod1()
|
[TestInitialize]
|
||||||
|
public void InitTests()
|
||||||
{
|
{
|
||||||
|
account = new Account(1000, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void DepositAmount()
|
||||||
|
{
|
||||||
|
account.Deposit(200);
|
||||||
|
Assert.AreEqual(1200, account.Balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void WithdrawAmount()
|
||||||
|
{
|
||||||
|
account.Withdraw(200);
|
||||||
|
Assert.AreEqual(800, account.Balance);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||||
|
public void WithdrawNegative()
|
||||||
|
{
|
||||||
|
account.Withdraw(-200);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||||
|
public void DepositNegative()
|
||||||
|
{
|
||||||
|
account.Deposit(-200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user