Skip to content

Commit

Permalink
add content type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Sep 24, 2024
1 parent b3cee58 commit 9a441de
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 7 deletions.
65 changes: 65 additions & 0 deletions input/typeapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,71 @@
"$ref": "Error"
}
}]
},
"test.binary": {
"method": "POST",
"path": "/binary",
"arguments": {
"payload": {
"in": "body",
"contentType": "application/octet-stream"
}
},
"return": {
"contentType": "application/octet-stream"
}
},
"test.form": {
"method": "POST",
"path": "/form",
"arguments": {
"payload": {
"in": "body",
"contentType": "application/x-www-form-urlencoded"
}
},
"return": {
"contentType": "application/x-www-form-urlencoded"
}
},
"test.json": {
"method": "POST",
"path": "/json",
"arguments": {
"payload": {
"in": "body",
"contentType": "application/json"
}
},
"return": {
"contentType": "application/json"
}
},
"test.text": {
"method": "POST",
"path": "/text",
"arguments": {
"payload": {
"in": "body",
"contentType": "text/plain"
}
},
"return": {
"contentType": "text/plain"
}
},
"test.xml": {
"method": "POST",
"path": "/xml",
"arguments": {
"payload": {
"in": "body",
"contentType": "application/xml"
}
},
"return": {
"contentType": "application/xml"
}
}
},
"definitions": {
Expand Down
66 changes: 66 additions & 0 deletions integration/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ static async Task Main()
await AssertGetEntries(client);
await AssertInsert(client);
await AssertThrowException(client);
await AssertBinary(client);
await AssertForm(client);
await AssertJson(client);
await AssertText(client);
await AssertXml(client);
}

private static async Task AssertGetHello(Client client)
Expand Down Expand Up @@ -80,4 +85,65 @@ private static async Task AssertThrowException(Client client)
}
}
}

private static async Task AssertBinary(Client client)
{
var payload = new byte[] {0x66, 0x6F, 0x6F, 0x62, 0x61, 0x72};

var response = await client.Test().Binary(payload);

if (payload != response) {
throw new Exception("Test AssertBinary failed");
}
}

private static async Task AssertForm(Client client)
{
var payload = new System.Collections.Specialized.NameValueCollection
{
{ "foo", "bar" }
};

var response = await client.Test().Form(payload);

if (payload != response) {
throw new Exception("Test AssertForm failed");
}
}

private static async Task AssertJson(Client client)
{
var payload = new Dictionary<string, string>
{
{ "string", "bar" }
};

var response = await client.Test().Json(payload);

if (payload != response) {
throw new Exception("Test AssertJson failed");
}
}

private static async Task AssertText(Client client)
{
var payload = "foobar";

var response = await client.Test().Text(payload);

if (payload != response) {
throw new Exception("Test AssertText failed");
}
}

private static async Task AssertXml(Client client)
{
var payload = "<foo>bar</foo>";

var response = await client.Test().Xml(payload);

if (payload != response) {
throw new Exception("Test AssertXml failed");
}
}
}
133 changes: 126 additions & 7 deletions mockserver/initializerJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
"method": "GET",
"path": "/todo",
"queryStringParameters": {
"startIndex": ["0"],
"count": ["16"]
"startIndex": [
"0"
],
"count": [
"16"
]
}
},
"httpResponse": {
Expand All @@ -26,11 +30,14 @@
"totalResults": 4,
"startIndex": 0,
"itemsPerPage": 16,
"entry": [{
"title": "foo"
}, {
"title": "bar"
}]
"entry": [
{
"title": "foo"
},
{
"title": "bar"
}
]
}
}
},
Expand Down Expand Up @@ -62,5 +69,117 @@
"message": "Error"
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/binary",
"headers": {
"Content-Type": [
"application/octet-stream"
]
},
"body": {
"type": "BINARY",
"base64Bytes": "Zm9vYmFy"
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"type": "BINARY",
"base64Bytes": "Zm9vYmFy"
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/form",
"headers": {
"Content-Type": [
"application/x-www-form-urlencoded"
]
},
"body": {
"type": "PARAMETERS",
"parameters": {
"foo": "bar"
}
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"type": "PARAMETERS",
"parameters": {
"foo": "bar"
}
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/json",
"headers": {
"Content-Type": [
"application/json"
]
},
"body": {
"foo": "bar"
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"foo": "bar"
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/text",
"headers": {
"Content-Type": [
"text/plain"
]
},
"body": {
"type" : "STRING",
"xml": "foobar"
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"type" : "STRING",
"xml": "foobar"
}
}
},
{
"httpRequest": {
"method": "POST",
"path": "/xml",
"headers": {
"Content-Type": [
"application/xml"
]
},
"body": {
"type" : "XML",
"xml": "<foo>bar</foo>"
}
},
"httpResponse": {
"statusCode": 200,
"body": {
"type" : "XML",
"xml": "<foo>bar</foo>"
}
}
}
]

0 comments on commit 9a441de

Please sign in to comment.