1 people like it.

xBehave QuickStart sample

xBehave QuickStart sample direct conversion to F# from C#: 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: 
open Xbehave
open Xunit

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

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) |> ignore
    "And the number 2"
        .And(fun () -> y := 2) |> ignore
    "And a calculator"
        .And(fun () -> calculator := Calculator()) |> ignore
    "When I add the numbers together"
        .When(fun () -> answer := (!calculator).Add(!x, !y)) |> ignore
    "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
val addition : x:int * y:int * calculator:Calculator * answer:int -> 'a

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 ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Raw view Test code New version

More information

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