Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using NUnit.Framework;
- using System;
- namespace TestApp.Tests
- {
- [TestFixture]
- public class BankAccountTests
- {
- [Test]
- public void Test_Constructor_InitialBalanceIsSet()
- {
- // Arrange
- double initialBalance = 100.0;
- // Act
- BankAccount account = new BankAccount(initialBalance);
- // Assert
- Assert.AreEqual(initialBalance, account.Balance);
- }
- [Test]
- public void Test_Deposit_PositiveAmount_IncreasesBalance()
- {
- // Arrange
- BankAccount account = new BankAccount(100.0);
- double depositAmount = 50.0;
- // Act
- account.Deposit(depositAmount);
- // Assert
- Assert.AreEqual(150.0, account.Balance);
- }
- [Test]
- public void Test_Deposit_NegativeAmount_ThrowsArgumentException()
- {
- // Arrange
- BankAccount account = new BankAccount(100.0);
- double depositAmount = -50.0;
- // Act & Assert
- Assert.Throws<ArgumentException>(() => account.Deposit(depositAmount), "Deposit with negative amount should throw an ArgumentException.");
- }
- [Test]
- public void Test_Withdraw_ValidAmount_DecreasesBalance()
- {
- // Arrange
- BankAccount account = new BankAccount(100.0);
- double withdrawAmount = 50.0;
- // Act
- account.Withdraw(withdrawAmount);
- // Assert
- Assert.AreEqual(50.0, account.Balance);
- }
- [Test]
- public void Test_Withdraw_NegativeAmount_ThrowsArgumentException()
- {
- // Arrange
- BankAccount account = new BankAccount(100.0);
- double withdrawAmount = -50.0;
- // Act & Assert
- Assert.Throws<ArgumentException>(() => account.Withdraw(withdrawAmount), "Withdraw with negative amount should throw an ArgumentException.");
- }
- [Test]
- public void Test_Withdraw_AmountGreaterThanBalance_ThrowsArgumentException()
- {
- // Arrange
- BankAccount account = new BankAccount(100.0);
- double withdrawAmount = 150.0;
- // Act & Assert
- Assert.Throws<ArgumentException>(() => account.Withdraw(withdrawAmount), "Withdraw with amount greater than balance should throw an ArgumentException.");
- }
- }
- }
Advertisement
Advertisement