forked from Kros-sk/TeaPie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path001-Add-Car-test.csx
More file actions
35 lines (28 loc) · 1.3 KB
/
Copy path001-Add-Car-test.csx
File metadata and controls
35 lines (28 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
tp.Test("Status code of car addition should be 201 (Created).", () =>
{
// Access named responses using their names.
var statusCode = tp.Responses["AddCarRequest"].StatusCode();
Equal(201, statusCode);
});
// Approach to string variable with the name "NewCar".
var newCar = tp.GetVariable<string>("NewCar");
dynamic obj = newCar.ToExpando();
var brand = obj.Brand;
await tp.Test($"Newly added car should have '{brand}' brand.", async () =>
{
dynamic responseJson = await tp.Responses["GetNewCarRequest"].GetBodyAsExpandoAsync();
// Access JSON properties case-insensitively.
Equal(brand, responseJson.brand);
});
await tp.Test("Identifiers of added and retrieved cars should match.", async () =>
{
// Access named requests in the same way as responses.
// Use an asynchronous body retrieval (recommended).
dynamic requestJson = await tp.Requests["AddCarRequest"].GetBodyAsExpandoAsync();
dynamic responseJson = await tp.Responses["GetNewCarRequest"].GetBodyAsExpandoAsync();
var idFromDirective = tp.GetVariable<long>("IdFromDirective");
Equal(requestJson.Id, responseJson.Id);
Equal(requestJson.Id, idFromDirective);
// Each variable can have none or multiple tags ('cars', 'ids' in this case).
tp.SetVariable("NewCarId", requestJson.Id, "cars", "ids");
});