Skip to content
MorganPersson edited this page Nov 26, 2012 · 1 revision

You can let nbehave instantiate types for you so you dont have to implement your steps with only primitive data types. The type parameter the step takes must have a default public constructor and the parameters from the text step must be public properties.

Given this step implementation:

[Given("a book with title $title and isbn $isbn")]
public void StepImpl(string title, string isbn)
{ }

You could implement the step with the following code:

[Given("a book with title $title and isbn $isbn")]
public void StepImpl(Book book)
{ }

public class Book
{
  public string Title { get; set; }
  public string Isbn { get; set; }
}

This works for lists too. Example:

Given some books:
  | title | isbn |
  | aaaaa | 1111 |
  | bbbbb | 2222 |

and implement the step like

[Given("some books:")]
public void StepImpl(List<Book> books)
{ }
Clone this wiki locally