Skip to content

Commit 89b1582

Browse files
committed
adding config example
1 parent cd9ae85 commit 89b1582

File tree

12 files changed

+216
-152
lines changed

12 files changed

+216
-152
lines changed

Example/App/App.csproj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@
2121
<None Update="Config\Api\User\Response\getUserById.json">
2222
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2323
</None>
24+
<None Update="Config\Api\Order\Response\getOrderById.json">
25+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
26+
</None>
27+
<None Update="Config\Api\Order\Response\putOrder.json">
28+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
29+
</None>
30+
<None Update="Config\Api\User\Response\postUser1.json">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</None>
33+
<None Update="Config\Api\User\Response\postUser2.json">
34+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
35+
</None>
36+
<None Update="Config\Api\User\Response\searchUsersPage0.json">
37+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
38+
</None>
39+
<None Update="Config\Api\User\Response\searchUsersPage1.json">
40+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
41+
</None>
2442
</ItemGroup>
2543
<ItemGroup>
2644
<ProjectReference Include="..\..\Src\FakeApi\FakeApi.csproj" />
@@ -29,9 +47,7 @@
2947
<Folder Include="Config\" />
3048
<Folder Include="Config\Api\" />
3149
<Folder Include="Config\Api\User\" />
32-
<Folder Include="Config\Api\Order\" />
3350
<Folder Include="Config\Api\User\Response\" />
34-
<Folder Include="Config\Api\Order\Response\" />
3551
</ItemGroup>
3652
<ItemGroup>
3753
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Program.cs">

Example/App/Config/Api/Order/ordersApi.cfg.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

Example/App/Config/Api/User/Response/searchUsersPage1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"results": [
33
{
4-
"userId": 512,
4+
"id": 512,
55
"firstname": "paul",
66
"lastname": "mc cartney"
77
},

Example/App/Config/Api/User/usersApi.cfg.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,37 @@
2020
{
2121
"active": 1,
2222
"method": "POST",
23-
"file": "Config/Api/User/Response/postUser1.json"
23+
"file": "Config/Api/User/Response/postUser1.json",
24+
"cookies": [
25+
{
26+
"name": "overrideDefaultookie1",
27+
"value": "override default valCookie1",
28+
"comment": "override default Comment1",
29+
"discard": 0,
30+
"domain": "override default domain1",
31+
"expired": 1,
32+
"expires": "2012-10-12",
33+
"httpOnly": 1,
34+
"path": "path1",
35+
"port": "\"8080\", \"8090\"",
36+
"secure": 1,
37+
"version": 54
38+
},
39+
{
40+
"name": "cookie2",
41+
"value": "valCookie2"
42+
}
43+
],
44+
"headers": [
45+
{
46+
"name": "overrideDefaultHeader1",
47+
"value": "override default valHeader1"
48+
},
49+
{
50+
"name": "overrideDefaultHeader2",
51+
"value": "override default valHeader2 "
52+
}
53+
]
2454
},
2555
{
2656
"active": 0,
@@ -33,11 +63,11 @@
3363
"url": "https://localhost/api/users?pIndex={0}&pSize={1}",
3464
"responses": [
3565
{
36-
"active": 1,
66+
"active": 0,
3767
"file": "Config/Api/User/Response/searchUsersPage0.json"
3868
},
3969
{
40-
"active": 0,
70+
"active": 1,
4171
"file": "Config/Api/User/Response/searchUsersPage1.json"
4272
}
4373
]

Example/App/Config/Api/api.cfg.json

Lines changed: 25 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,37 @@
22
"defaultDelay": 250,
33
"defaultHttpCode": 200,
44
"defaultMethod": "GET",
5-
"apisDirectories": [
6-
"Config/Api/User"
7-
],
8-
"apis": [
5+
"defaultCookies": [
96
{
10-
"url": "http://localhost:8080/api/users/{idUser}",
11-
"responses": [
12-
{
13-
"active": 1,
14-
"delay": 300,
15-
"method": "GET",
16-
"httpCode": 200,
17-
"response": "{ 'firstname': 'john', 'lastname':'doe', 'id': 567 }"
18-
},
19-
{
20-
"active": 1,
21-
"delay": 300,
22-
"method": "PUT",
23-
"httpCode": 200,
24-
"response": "{ 'firstname': 'johnny', 'lastname':'doedoe', 'id': 567 }"
25-
}
26-
]
7+
"name": "cookie1",
8+
"value": "valCookie1",
9+
"comment": "Comment1",
10+
"discard": 0,
11+
"domain": "domain1",
12+
"expired": 1,
13+
"expires": "2012-10-12",
14+
"httpOnly": 1,
15+
"path": "path1",
16+
"port": "\"8080\", \"8090\"",
17+
"secure": 1,
18+
"version": 54
2719
},
2820
{
29-
"url": "http://localhost:8080/api/orders/{orderId}/addresses/{addressId}}",
30-
"responses": [
31-
{
32-
"active": 1,
33-
"delay": 135,
34-
"httpCode": 200,
35-
"cookies": [
36-
{
37-
"name": "cookie1",
38-
"value": "valCookie1",
39-
"comment": "Comment1",
40-
"discard": 0,
41-
"domain": "domain1",
42-
"expired": 1,
43-
"expires": "2012-10-12",
44-
"httpOnly": 1,
45-
"path": "path1",
46-
"port": "\"8080\", \"8090\"",
47-
"secure": 1,
48-
"version": 54
49-
},
50-
{
51-
"name": "cookie2",
52-
"value": "valCookie2"
53-
}
54-
],
55-
"headers": [
56-
{
57-
"name": "header1",
58-
"value": "valHeader1"
59-
},
60-
{
61-
"name": "header2",
62-
"value": "valHeader2 "
63-
}
64-
],
65-
"response": "{ 'orderId': 345, 'streetAddress':'2762 Highland Drive', 'city': 'Nina' }"
66-
},
67-
{
68-
"active": 0,
69-
"delay": 5000,
70-
"httpCode": 203,
71-
"response": "{ 'orderId': 345, 'streetAddress':'2762 Highland Drive', 'city': 'Nina' }"
72-
}
73-
]
74-
},
75-
{
76-
"url": "http://localhost:8080/api/ad/{adId}",
77-
"responses": [
78-
{
79-
"active": 1,
80-
"httpCode": 400,
81-
"webExceptionMessage": "Invalid ad id"
82-
}
83-
]
84-
},
21+
"name": "cookie2",
22+
"value": "valCookie2"
23+
}
24+
],
25+
"defaultHeaders": [
8526
{
86-
"url": "http://localhost:8080/api/ad/{adId}/custom-error",
87-
"responses": [
88-
{
89-
"active": 1,
90-
"httpCode": 500,
91-
"customApiException":
92-
{
93-
"fullTypeName": "App.CustomWebException, App",
94-
"constructorArgs": [
95-
"custom exception message"
96-
]
97-
}
98-
}
99-
]
27+
"name": "header1",
28+
"value": "valHeader1"
10029
},
10130
{
102-
"url": "http://localhost:8080/api/get-file",
103-
"responses": [
104-
{
105-
"active": 1,
106-
"httpCode": 200,
107-
"file": "DownloadFile.txt"
108-
}
109-
]
31+
"name": "header2",
32+
"value": "valHeader2 "
11033
}
34+
],
35+
"apisDirectories": [
36+
"Config/Api/User"
11137
]
11238
}

Example/App/Program.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Net;
45
using FakeApi;
56
using Microsoft.Extensions.DependencyInjection;
6-
using Newtonsoft.Json;
77

88
namespace App
99
{
@@ -12,27 +12,14 @@ class Program
1212
static void Main(string[] args)
1313
{
1414
var serviceCollection = new ServiceCollection();
15-
1615
serviceCollection.AddScoped<IHttpRequester, FakeHttpRequester>(provider =>
1716
{
1817
return new FakeHttpRequester("Config/Api/api.cfg.json");
1918
});
20-
21-
var serviceProvider = serviceCollection.BuildServiceProvider();
19+
var serviceProvider = serviceCollection.BuildServiceProvider();
2220
var httpRequester = serviceProvider.GetService<IHttpRequester>();
2321

24-
//Users apis
25-
var getUserByIdRequest = WebRequest.Create("https://localhost/api/users/128");
26-
var getUserByIdResponse = httpRequester.GetResponse(getUserByIdRequest);
27-
28-
using (var stream = new StreamReader(getUserByIdResponse.GetResponseStream()))
29-
{
30-
var serializer = new JsonSerializer();
31-
var user = (User)serializer.Deserialize(stream, typeof(User));
32-
33-
Console.WriteLine("Data from https://localhost/api/users/128 : ");
34-
Console.WriteLine($"UserId : {user.Id} | Firstname : {user.Firstname} | Lastname : {user.Lastname}");
35-
}
22+
UserRequestExample.Start(httpRequester);
3623

3724
Console.Read();
3825
}

Example/App/User.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
namespace App
1+
using System.Collections.Generic;
2+
3+
namespace App
24
{
35
public class User
46
{
57
public string Firstname { get; set; }
68
public string Lastname { get; set; }
79
public long Id { get; set; }
810
}
11+
12+
public class SearchUsers
13+
{
14+
public IEnumerable<User> Results { get; set; }
15+
}
916
}

0 commit comments

Comments
 (0)