Aubergine (BDD for .net) v0.07 : support for Given-I-did-clause

Hi there,

V0.07 is here :

Auberginev0.07.zip (28,61 kb)

Changes:

* Support for "Given I did" clause (more info in this essay )
* Complete refactoring of the Account example after extending the account story (my usual Model/Service layout, although the interfaces are missing here)

Here is the current example of the account story (copied from the essay):

 

Appendix A : a working example story :



Context      Be.Corebvba.Aubergine.Examples.Accounts.Contexts.AccountContext
ContextDLL   Be.Corebvba.Aubergine.Examples.DLL

Story Transfer money between accounts

    As a user
    I want to transfer money between accounts
    So that I can have real use for my money

    Given the balance of AccountA is 3m
    Given the balance of AccountB is 2m
    Given the owner of AccountA is the current user
   
    Scenario Authenticate the current user as a 'valid or invalid' user
        Given the name of the current user is 'username'
          And the password of the current user is 'password'
        When I request authentication for the current user
        Then the process should 'fail or succeed'
       
        Example
            +--------------------+------------+------------+------------------+
            | 'valid or invalid' | 'username' | 'password' | 'fail or succeed'|
            +--------------------+------------+------------+------------------+
            | valid              | Neo        | Red pill   | succeed          |
            | invalid            | Neo        | Blue pill  | fail             |
            +--------------------+------------+------------+------------------+
               
    Scenario Authenticate the current user for 'an account'
        Given I did authenticate the current user as a valid user
        When I request authentication for 'an account' with the current user
        Then the process should 'fail or succeed'
       
        Example accounts :
            +--------------+-------------------+
            | 'an account' | 'fail or succeed' |
            +--------------+-------------------+
            |  AccountA    | succeed           |
            |  AccountB    | fail              |
            +--------------+-------------------+
       

    Scenario Transfer AAm between 2 accounts
        Given I did authenticate the current user for AccountA
        When I transfer AAm from AccountA to AccountB with the current user
        Then the balance of AccountA should be BBm 
        Then the balance of AccountB should be CCm 
        Then the process should 'fail or succeed'
       
        Example for the transfer

            +----+----+----+-------------------+
            | AA | BB | CC | 'fail or succeed' |
            +----+----+----+-------------------+
            |  1 |  2 |  3 | succeed           |
            |  2 |  1 |  4 | succeed           |
            |  3 |  0 |  5 | succeed           |
            |  4 |  3 |  2 | fail              |
            +----+----+----+-------------------+

Appendix B : the resulting output of my runner:

Aubergine Console Runner - Core bvba - Tom Janssens 2009

Processing file(s) : accounts\stories\*.txt
  Processing file : C:\Projecten\Be.Corebvba.Aubergine\Be.Corebvba.Aubergine.ConsoleRunner\bin\Debug\accounts\stories\Transfer_money_between_accounts.txt

    Story Transfer money between accounts =>OK
        Given the balance of AccountA is 3m =>OK
        Given the balance of AccountB is 2m =>OK
        Given the owner of AccountA is the current user =>OK
        Scenario Authenticate the current user as a valid user =>OK
            Given the name of the current user is Neo =>OK
            Given the password of the current user is Red pill =>OK
            When I request authentication for the current user =>OK
            Then the process should succeed =>OK

        Scenario Authenticate the current user as a invalid user =>OK
            Given the name of the current user is Neo =>OK
            Given the password of the current user is Blue pill =>OK
            When I request authentication for the current user =>OK
            Then the process should fail =>OK

        Scenario Authenticate the current user for AccountA =>OK
            Given I did authenticate the current user as a valid user =>OK
            When I request authentication for AccountA with the current user =>OK
            Then the process should succeed =>OK

        Scenario Authenticate the current user for AccountB =>OK
            Given I did authenticate the current user as a valid user =>OK
            When I request authentication for AccountB with the current user =>OK
            Then the process should fail =>OK

        Scenario Transfer 1m between 2 accounts =>OK
            Given I did authenticate the current user for AccountA =>OK
            When I transfer 1m from AccountA to AccountB with the current user =>OK
            Then the balance of AccountA should be 2m =>OK
            Then the balance of AccountB should be 3m =>OK
            Then the process should succeed =>OK

        Scenario Transfer 2m between 2 accounts =>OK
            Given I did authenticate the current user for AccountA =>OK
            When I transfer 2m from AccountA to AccountB with the current user =>OK
            Then the balance of AccountA should be 1m =>OK
            Then the balance of AccountB should be 4m =>OK
            Then the process should succeed =>OK

        Scenario Transfer 3m between 2 accounts =>OK
            Given I did authenticate the current user for AccountA =>OK
            When I transfer 3m from AccountA to AccountB with the current user =>OK
            Then the balance of AccountA should be 0m =>OK
            Then the balance of AccountB should be 5m =>OK
            Then the process should succeed =>OK

        Scenario Transfer 4m between 2 accounts =>OK
            Given I did authenticate the current user for AccountA =>OK
            When I transfer 4m from AccountA to AccountB with the current user =>OK
            Then the balance of AccountA should be 3m =>OK
            Then the balance of AccountB should be 2m =>OK
            Then the process should fail =>OK

 

Appendix C : The context + DSL

    internal class AccountContext
    {
        public User currentUser = new User();
        public Account AccountA = new Account();
        public Account AccountB = new Account();
        public AccountService AccountService = new AccountService();
        public ProcessStatus LastStatus;

        [DSL(@"the (?<member>.+) of (?<instance>.+) is (?<value>.+)")]
        void assignfield(object instance,string member,object value)
        {
            instance.Set(member, value);
        }

        [DSL(@"the (?<member>.+) of (?<instance>.+) should be (?<value>.*)")]
        bool shouldbefield(object instance, string member, object value)
        {
            var obj = instance.Get<object>(member);
            return Convert.ChangeType(value, obj.GetType()).Equals(obj);
        }

        [DSL(@"I request authentication for (?<user>.+)")]
        void authenticate_for_account_x(User user)
        {
            LastStatus = AccountService.AuthenticateUser(user);
        }

        [DSL(@"I request authentication for (?<account>.+) with (?<user>.+)")]
        void authenticate_for_account_x(User user, Account account)
        {
            LastStatus =  AccountService.AuthenticateUserForAccount(account,user);
        }
       
        [DSL(@"I transfer (?<amount>.+) from (?<from>.+) to (?<to>.+) with (?<user>.+)")]
        void transfering_xm_from_a_to_b(decimal amount, Account from, Account to,User user)
        {
            LastStatus = AccountService.Transfer(user,amount, from,to);
        }

        [DSL]
        bool The_process_should_fail()
        {
            return LastStatus.Success == false;
        }

        [DSL]
        bool The_process_should_succeed()
        {
            return LastStatus.Success == true;
        }

        [DSL("(?<name>Account[AB])")]
        Account getaccountAB(string name)
        {
            return this.Get<Account>(name);
        }

        [DSL(@"(?<amount>\d+)(?<ismillion>m?)")]
        decimal getmillion(decimal amount,string  ismillon)
        {
            return amount*(ismillon=="m"?1m:1);
        }

        [DSL]
        User the_current_user()
        {
            return currentUser;
        }
    }

 

Bookmark and Share