1 people like it.

xBehave QuickStart sample with pipes

xBehave QuickStart sample conversion to F# from C# with some helper functions: https://github.com/xbehave/xbehave.net/wiki/Quickstart

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
open Xbehave
open Xunit

type Calculator () = member __.Add(x,y) = x + y

Helper functions

let [<Scenario>] addition(x:int,y:int,calculator:Calculator,answer:int) =
    let x,y,calculator,answer = ref x, ref y, ref calculator, ref answer    
    "Given the number 1" 
    |> Given (fun () -> x := 1)
    "And the number 2" 
    |> And (fun () -> y := 2)        
    "And a calculator" 
    |> And (fun () -> calculator := Calculator())
    "When I add the numbers together"
    |> When (fun () -> answer := (!calculator).Add(!x, !y))
    "Then the answer is 3"
    |> Then(fun () -> Assert.Equal(3, !answer))
Multiple items
type Calculator =
  new : unit -> Calculator
  member Add : x:int * y:int -> int

Full name: Script.Calculator

--------------------
new : unit -> Calculator
member Calculator.Add : x:int * y:int -> int

Full name: Script.Calculator.Add
val x : int
val y : int
let Given f (s:string) = s.Given(System.Action< >(f)) |> ignore
let And f (s:string) = s.And(System.Action< >(f)) |> ignore
let But f (s:string) = s.But(System.Action< >(f)) |> ignore
let When f (s:string) = s.When(System.Action< >(f)) |> ignore
let Then f (s:string) = s.Then(System.Action< >(f)) |> ignore
val addition : x:int * y:int * calculator:Calculator * answer:int -> unit

Full name: Script.addition
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val calculator : Calculator
val answer : int
val x : int ref
val y : int ref
val calculator : Calculator ref
val answer : int ref
Multiple items
val ref : value:'T -> 'T ref

Full name: Microsoft.FSharp.Core.Operators.ref

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
val Given : f:'a -> s:string -> unit

Full name: Script.Given
val And : f:'a -> s:string -> unit

Full name: Script.And
val When : f:'a -> s:string -> unit

Full name: Script.When
val Then : f:'a -> s:string -> unit

Full name: Script.Then
Raw view Test code New version

More information

Link:http://fssnip.net/kn
Posted:10 years ago
Author:Phillip Trelford
Tags: xbehave , bdd