Click here to Skip to main content
Licence CPOL
First Posted 12 Nov 2009
Views 4,167
Downloads 0
Bookmarked 1 time

Aubergine (BDD for .net) v0.06 : support for parameter tables in given/when/then

By Tom Janssens | 12 Nov 2009 | Technical Blog
Ok, we keep on going; now we support parameter tables for given/when/then, which are parsed as array members.I am now getting very close to full cucumber-like support !!! Oh, I forgot to mention that the "And" keyword is also supported now !!An example of the new syntax:Context    Be.Corebvba.Au
A Technical Blog article. View original blog here.[^]
Context    Be.Corebvba.Aubergine.Examples.Website.Contexts.BrowserContext
ContextDLL Be.Corebvba.Aubergine.Examples.DLL

Story Make sure my website gets enough visibility. As a website owner. I want to make sure that I get enough visibility. So that I can get enough traffic

Scenario Search results for 'keywords' on searchengine should contain 'my url'

  • Given the current url is 'search url'
  • When searching for 'keywords'
  • Then the result should contain 'my url'
        Example
        +--------------+--------------------------------+------------------+-----------------+
        | searchengine | search url                     | keywords         | my url          |
        +--------------+--------------------------------+------------------+-----------------+
        | google       | http://www.google.be/search?q= | BDD .Net         | www.corebvba.be |
        | bing         | http://www.bing.com/search?q=  | core bvba tom    | www.corebvba.be |
        | bing         | http://www.bing.com/search?q=  | Quantum physics  | www.corebvba.be |
        | faulty link  | http://www.googleaaa           | core bvba tom    | www.corebvba.be |
        +--------------+--------------------------------+------------------+-----------------+

    Scenario Search results on google for keywords should contain 'www.corebvba.be' 
        Given the current url is 'http://www.google.be/search?q=' 
        When searching for the following keywords
            +-----------+
            | keywords  |
            +-----------+
            | Aubergine |
            | BDD       |
            +-----------+
        Then the result should contain 'www.corebvba.be' and the following markup elements
            +------------------+
            | type | inner     |
            +------------------+
            | em   | BDD       |
            | em   | Aubergine |
            +------------------+

And the context :

    public class BrowserContext
    {
        public string Url { get; set; }
        public string Result { get; set; }

        private WebClient wc = new WebClient();
            
        [DSL("the current url is '(?<url>.*)'")]
        void SetUrl(string url)
        {
            Url = url;
        }

        [DSL("searching for '(?<keywords>.*)'")]
        void SearchForKeyWords(string keywords)
        {
            Result = wc.DownloadString(Url + HttpUtility.UrlEncode(keywords));
        }

        [DSL("searching for the following keywords")]
        void SearchForKeyWords(string[] keywords)
        {
            Result = wc.DownloadString(Url + HttpUtility.UrlEncode(string.Join(" ",keywords)));
        }


        [DSL("the result should contain '(?<myurl>.*)'")]
        bool ResultShouldContain(string myurl)
        {
            return (Result??"").Contains(myurl);
        }

        [DSL("the result should contain '(?<avalue>.+)' and the following markup elements")]
        bool ResultShouldContain(string avalue,string[] type,string[]inner)
        {
            if (string.IsNullOrEmpty(Result) ||type.Length==0) 
                return false;
            if (!Result.Contains(avalue)) return false;
            for (var i = 0;i < type.Length ; i++)
            {
                var searchstring = string.Format("<{0}>{1}</{0}>", type[i], inner[i]);
                if (!Result.Contains(searchstring))
                    return false;
            }
            return true;
        }
    }

It looks a bit messy, but thats because it is a stupid example. A good example would be loading a repository with some products.

Enjoy !!

License

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

About the Author

Tom Janssens

Founder
Core bvba
Belgium Belgium

Member
Tom Janssens, owner of Core, a software and consultancy company.
Father of two sons named Quinten & Matisse, and married to a beautiful woman named Liesbeth.
 
Blog
Github
Twitter
LinkedIn

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 12 Nov 2009
Article Copyright 2009 by Tom Janssens
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid