Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#

Behavior-Driven Development with NBehave

Rate me:
Please Sign up or sign in to vote.
4.97/5 (35 votes)
13 Jan 2009CPOL11 min read 88.6K   376   81  
A BDD tutorial using NBehave and MbUnit.
/* Copyright (C) Dmitri Nesteruk */

namespace ConsoleApplication1
{
  using System;

  /// <summary>
  /// 
  /// </summary>
  public sealed class Account
  {
    private int balance;

    public int Balance
    {
      get { return balance; }
      set { balance = value; }
    }

    public void Deposit(int amount)
    {
      //if (amount <= 0)
        //throw new Exception();
      balance += amount;
    }

    public void Withdraw(int amount)
    {
      if (amount > balance)
        throw new Exception();

      balance -= amount;
    }

    public static void Transfer(Account from, Account to, int amount)
    {
      if (from == null) throw new ArgumentNullException("from");
      if (to == null) throw new ArgumentNullException("to");
      if (amount <= 0) throw new ArgumentException("Transfer amount must be positive");
      from.Withdraw(amount);
      to.Deposit(amount);
    }
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder ActiveMesa
United Kingdom United Kingdom
I work primarily with the .NET technology stack, and specialize in accelerated code production via code generation (static or dynamic), aspect-oriented programming, MDA, domain-specific languages and anything else that gets products out the door faster. My languages of choice are C# and C++, though I'm open to suggestions.

Comments and Discussions