1: [Test]
2: public void Transfer_to_cash_account()
3: { 4:
5: Account savings = null;
6: Account cash = null;
7:
8: Story transferStory = new Story("Transfer to cash account"); 9:
10: transferStory
11: .AsA("savings account holder") 12: .IWant("to transfer money from my savings account") 13: .SoThat("I can get cash easily from an ATM"); 14:
15: transferStory
16: .WithScenario("Savings account is in credit") 17:
18: .Given("my savings account balance is", 100, delegate(int accountBalance) { savings = new Account(accountBalance); }) 19: .And("my cash account balance is", 10, delegate(int accountBalance) { cash = new Account(accountBalance); }) 20: .When("I transfer to cash account", 20, delegate(int transferAmount) { savings.TransferTo(cash, transferAmount); }) 21: .Then("my savings account balance should be", 80, delegate(int expectedBalance) { Assert.AreEqual(expectedBalance, savings.Balance); }) 22: .And("my cash account balance should be", 30, delegate(int expectedBalance) { Assert.AreEqual(expectedBalance, cash.Balance); }) 23:
24: //Reuse the declarations and associated actions from before
25: .Given("my savings account balance is", 400) 26: .And("my cash account balance is", 100) 27: .When("I transfer to cash account", 100) 28: .Then("my savings account balance should be", 300) 29: .And("my cash account balance should be", 200) 30:
31: transferStory
32: .WithScenario("Savings account is overdrawn") 33:
34: .Given("my savings account balance is", -20) 35: .And("my cash account balance is", 10) 36: .When("I transfer to cash account", 20) 37: .Then("my savings account balance should be", -20) 38: .And("my cash account balance should be", 10); 39:
40: }
Over all I think the API is very nice. Readable. I like how it "behaves" if you will. It is still rough around the edges, but assuming its already usable and no seious bugs, the only real possible problem may be the "multiple asserts" thing, which I'm not sure is really a problem. But what might inhibit a team fro using it?
I think this is a good opportunity to start a real conversation about BDD.