More Fluent Interfaces for NUnit.Behave

I have been enhancing the overall structure of NUnit.Behave to evolve to a more fluent interface.  The following is a working example of what I have come up with.

 

            Story("Account Holder withdraws cash")
                .As_a("savings account holder")
                .I_Want("to transfer money from my savings account")
                .So_That("I can get cash easily from an ATM")
                .Scenario("savings account is overdrawn")
                .Given("my savings account balance is", -20)
                .And("my cash account balance is", 10)
                .When("I transfer to cash account", 20)
                .Then("my savings account balance should be", -20)
                .And("my cash account balance should be", 10);

 In the test runner the following output appears.

Story: Account Holder withdraws cash
Narrative: As a savings account holder
    I want to transfer money from my savings account
    so that I can get cash easily from an ATM.

    Scenario: savings account is overdrawn
        Given my savings account balance is: -20 !PENDING Delegate IMPLEMENTATION!
        And my cash account balance is: 10 !PENDING Delegate IMPLEMENTATION!
        When I transfer to cash account: 20 !PENDING Delegate IMPLEMENTATION!
        Then my savings account balance should be: -20 !PENDING Delegate IMPLEMENTATION!
        And my cash account balance should be: 10 !PENDING Delegate IMPLEMENTATION!

Don’t worry I am working on “!PENDING” but I just needed something as placeholder for the time being.

I love this fluent interface approach though.  It really makes the code much more maintainable.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Joe Ocampo

My personal philosophy is simple: "Have a good strategy that sets the environment for success through the enablement of the whole. Be agile but with a mind towards pragmatism. Delegate to the best qualified individuals, but don’t be afraid to involve yourself in all parts of a job. Treat everyone with respect, humility, and with a genuine pursuit towards excellence." Respected business and technical leader with expertise in directing organization towards effective results driven outcomes. Proven ability to perform and communicate from both technical and business perspectives. Strong technical and business acumen developed through experience, education and training. Provides the ability to utilize technology, harness business intelligence and execute strategically by optimizing systems, tools and process. Passionate about building people, companies and software by containing cost, maximizing operational throughput and capitalize on revenue. Looks to leverage the strengths of individuals and grow the organization to their maximum potential by harnessing the power of their collective whole and deliver results. Co-Founder of LosTechies.com
This entry was posted in BDD (Behavior Driven Development). Bookmark the permalink. Follow any comments here with the RSS feed for this post.

4 Responses to More Fluent Interfaces for NUnit.Behave

  1. nobody says:

    What about:

    Story.Title(“Account Holder withdraws cash”)
    .As_a(“savings account holder”)

    That way I don’t have to inherit from an abstract class?

  2. Joe Ocampo says:

    I am working on this right now. Hope to have something out shortly.

  3. Christopher G. says:

    Love where you’re going with this! Will definitely dl this

  4. Christopher G. says:

    Love where you’re going with this! Will definitely dl this