Skip to content

StepDefnition: Create New Employee

Mahmoud A. Zaid edited this page Mar 17, 2019 · 3 revisions

After what we have done in the previous lesson by creating a feature file for the creating employee test case, Now, we need to create a new Model for Create API and implement the step definition of the feature file

1. Under Model Folder > Create a new Class Create.cs and write inside it

public string name { get; set; }

public string salary { get; set; }

public string age { get; set; }

2. Serialize the request for this step

When I create a request body with the following values implement the step with the below code

[When(@"I create a request body with the following values")]
public void WhenICreateRequestBodyWithFollowingValues(Table table)
{
new_emloyee = table.CreateInstance<Create>();
var obj = new Create()
{
name = new_emloyee.name,
salary= new_emloyee.salary,
age=new_emloyee.age
};
JsonSerializer serializer = new JsonSerializer();
jsonBody = serializer.Serialize(obj);
}

3. Add the created JSON to the API request

[When(@"Add the serialized body to the API request")]
public void WhenAddTheCreatedBodyToTheAPIRequest()
{
SharedSteps.request.AddJsonBody(jsonBody);
}   

4. The remaining steps were implemeted in the first lesson of creating StepDefintions

And Execute API
Then returned status code will be "200"