Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / .NET

Aubergine (BDD for .NET) v0.05: Text stories/HTML & Custom Output/cmdline Parser

0.00/5 (No votes)
12 Nov 2009CPOL2 min read 8.6K  
Again a new release !!* The stories are now written in text-format; unrecognized beginning of lines are skipped/not processes; example data should begin with/be seperated by |.*
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
+--------------+--------------------------------+------------------+-----------------+
| 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 |
+--------------+--------------------------------+------------------+-----------------+

The code is still the same:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using Be.Corebvba.Aubergine.Model;

namespace Be.Corebvba.Aubergine.Examples.Website.Contexts
{
    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("the result should contain (?<myurl>.*)")]
        bool ResultShouldContain(string myurl)
        {
            return (Result??"").Contains(myurl);
        }
    }
}

And this is the resulting output (please try to hover over the implementation error of the "When" step with your mouse !!

Edit: Apparently my blog engine team messes up the list layout !!! They are nested list items (although you can not see them here).

Processing file(s): Website\Stories\*.txt

  • Story: Make sure my website gets enough visibility IMPLEMENTATION ERROR
    • Scenario: Search results for BDD .NET on Google should contain www.corebvba.be OK
      • Given the current url is http://www.google.be/search?q= OK
      • When searching for BDD .NET OK
      • Then the result should contain www.corebvba.be OK
    • Scenario: Search results for core bvba tom on bing should contain www.corebvba.be OK
      • Given the current url is http://www.bing.com/search?q= OK
      • When searching for core bvba tom OK
      • Then the result should contain www.corebvba.be OK
    • Scenario: Search results for Quantum physics on bing should contain www.corebvba.be NOK
      • Given the current url is http://www.bing.com/search?q= OK
      • When searching for Quantum physics OK
      • Then the result should contain www.corebvba.be NOK
    • Scenario: Search results for core bvba tom on faulty link should contain www.corebvba.be IMPLEMENTATION ERROR
      • Given the current url is http://www.googleaaa OK
      • When searching for core bvba tom IMPLEMENTATION ERROR
      • Then the result should contain www.corebvba.be NOK

Processing file:

C:\Projecten\Be.Corebvba.Aubergine\Be.Corebvba.Aubergine.Examples\bin\Release\
    Website\Stories\Make_sure_my_Website_gets_enough_traffic.txt 

This is the postbuildstep now:

"$(ProjectDir)\lib\ConsoleRunner.exe" Accounts\Stories\*.txt Website\Stories\*.txt -html > 
"$(TargetDir)output.html"
"$(TargetDir)output.html"
exit 0

Include all the stories/txt-file in your project with the option of "copy to output directory" = "always" on each file...

More details/a Codeproject article update will follow later...

Enjoy !!

License

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