Skip to content

Instantly share code, notes, and snippets.

[When(@"I remove the (.*) product")]
public void RemoveProduct(string position)
{
// Position comes in as 1st, 2nd, 3rd, etc.
int index = ParsePosition(position);
// Snip
}
[Given("a new customer and address")]
public void GivenANewCustomerAndAddress()
{
Customer customer = new Customer
{
Salutation = "Miss",
FirstName = "Liz",
LastName = "Lemon"
};
[StepArgumentTransformation("the address")]
public Address CreateAddress(Table table)
{
return table.CreateInstance<Address>();
}
[Given(@"the address")]
public void GivenTheAddress(Address address)
{
_address = address;
[StepArgumentTransformation("the customer")]
public Customer CreateCustomer(Table table)
{
return table.CreateInstance<Customer>();
}
[Given(@"the customer")]
public void GivenTheCustomer(Customer customer)
{
_customer = customer;
[Given("a new customer and address")]
public void GivenANewCustomerAndAddress()
{
Table customer = new Table("FirstName", "LastName", "Salutation");
customer.AddRow("Miss" "Liz", "Lemon");
Table address = new Table("Line 1", "City", "State", "Zipcode");
address.AddRow("30 Rockefeller Plaza", "New York", "NY", "10112");
Given("the customer", customer);
Given the customer
| Salutation | First Name | Last Name |
| Miss | Liz | Lemon |
And the address
| Line 1 | City | State | Zipcode |
| 30 Rockefeller Plaza | New York | NY | 10112 |
public abstract class Steps
{
// Built-in context
public ScenarioContext ScenarioContext { get; }
public FeatureContext FeatureContext { get; }
public TestThreadContext TestThreadContext { get; }
public ScenarioStepContext StepContext { get; }
// Call other binding steps
public void Given(string step);
[Binding]
public sealed class AddressServiceSteps
{
private readonly IBodySerializer _bodySerializer;
public ContentTypeSteps(IBodySerializer bodySerializer)
{
_bodySerializer = bodySerializer;
}
[BeforeScenario("xml")]
public void ConfigureXml()
{
_objectContainer
.RegisterTypeAs<XmlBodySerializer, IBodySerializer>();
}
[BeforeScenario("json")]
public void ConfigureJson()
{
@json
Scenario: Invoke service with JSON payload
Given a fully populated request object
When I invoke the service
Then a valid response should be returned