-
Notifications
You must be signed in to change notification settings - Fork 11
StepDefention: Response Content
Mahmoud A. Zaid edited this page Mar 15, 2019
·
3 revisions
Now in this lesson, we will implement the step definition to deserialize the response by creating a model for each API
you can find this class here
The API result showing as below:
{"id":"719","employee_name":"test","employee_salary":"123","employee_age":"23","profile_image":""}
So in the Employee class we will define API response proprites
public string id { get; set; }
public string employee_name { get; set; }
public string employee_salary { get; set; }
public string employee_age { get; set; }
public string profile_image { get; set; }
- Define an object from Employee class
private static Employee employee_info;
- define JsonDeserializer
private JsonDeserializer deserializer = new JsonDeserializer();
and now the implementation of StepDefination showing as below
[When(@"Deserialize the employee api content")]
public void WhenDeserializeTheEmployeeApiContent()
{
employee_info = deserializer.Deserialize<Employee>(SharedSteps.apiResult);
var type = employee_info.GetType();
}
- Firstly convert the returned table from feature file to an instance from the Employee class
var employee = table.CreateInstance<Employee>();
- Now Assert by FluentAssertion
employee_info.Should().BeEquivalentTo(employee);
so the final implementation of the StepDefintion should be like that:
[Then(@"The employee should have the following values")]
public void ThenTheEmployeeShouldHaveTheFollowingValues(Table table)
{
var employee = table.CreateInstance<Employee>();
employee_info.Should().BeEquivalentTo(employee);
}
You can find the final class implementation of this lesson here
Mahmoud A. Zaid
- Introduction
- HTTP Methods
- HTTP Request
- API Parameters
- HTTP Response
- HTTP Status Code
- Methods Examples
- Idempotence