Deserboy

UnitTestingExample

Dec 14th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace UnitTesting
  6. {
  7.     public class BanckAccount
  8.     {
  9.         public BanckAccount(decimal balance)
  10.         {
  11.             this.Balance = balance;
  12.         }
  13.         private decimal balance;
  14.         public decimal Balance
  15.         {
  16.             get
  17.             {
  18.                 return this.balance;
  19.             }
  20.             private set
  21.             {
  22.                 if (value < 0)
  23.                 {
  24.                     throw new ArgumentException("Balance can not be negative.");
  25.                 }
  26.                 balance = value;
  27.             }
  28.         }
  29.         public void Deposit(decimal sum)
  30.         {
  31.             if (sum <= 0)
  32.             {
  33.                 throw new ArgumentException("Sum must be positive number.");
  34.             }
  35.             Balance += sum;
  36.         }
  37.         public void Withdraw(decimal sum)
  38.         {
  39.             if (sum <= 0)
  40.             {
  41.                 throw new ArgumentException("Sum must be positive number.");
  42.             }
  43.             Balance -= sum;
  44.         }
  45.     }
  46. }
  47. using NUnit.Framework;
  48. using System;
  49. using System.Collections.Generic;
  50. using System.Text;
  51.  
  52. namespace UnitTesting.Tests
  53. {
  54.     [TestFixture]
  55.     public class BankAccountTest
  56.     {
  57.         [Test]
  58.         public void TestNewBankAccount()
  59.         {
  60.             var bankAccount = new BanckAccount(100m);
  61.             Assert.That(bankAccount.Balance, Is.EqualTo(100m),"Creating of new Bank Account");
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment