Click here to Skip to main content
13,353,322 members (48,526 online)
Click here to Skip to main content


82 bookmarked
Posted 14 Jan 2009

Behavior-Driven Development with NBehave

, 14 Jan 2009
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");

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.


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


About the Author

Dmitri Nеstеruk
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 F#, though I'm open to suggestions.

I'm a Microsoft MVP (Visual C#) since 2009. I run a collective tech blog at I use my own editor called TypograFix to typeset articles and blog posts.

Like the article and want this implemented in your product? Got a project that can benefit from Microsoft.Net goodness? Then get in touch!

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 14 Jan 2009
Article Copyright 2009 by Dmitri Nеstеruk
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid