Skip to content

Commit 3a62ce4

Browse files
tests(c#): add powershell tests
1 parent f8f0212 commit 3a62ce4

File tree

3 files changed

+72
-77
lines changed

3 files changed

+72
-77
lines changed

tests/SDKTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,18 @@ class SDKTest extends TestCase
5757
],
5858
],
5959

60-
// 'csharp' => [
61-
// 'class' => 'Appwrite\SDK\Language\CSharp',
62-
// 'build' => [
63-
// 'mkdir -p tests/sdks/csharp/src/test',
64-
// 'cp tests/languages/csharp/ServiceTest.cs tests/sdks/csharp/src/test/ServiceTest.cs',
65-
// ],
66-
// 'envs' => [
67-
// // 'java-11' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/java --env PUB_CACHE=vendor maven:3.6-jdk-11-slim mvn clean install test -q'
68-
// ],
69-
// ],
60+
'csharp' => [
61+
'class' => 'Appwrite\SDK\Language\CSharp',
62+
'build' => [
63+
'mkdir -p tests/sdks/csharp/src/test',
64+
'cp tests/languages/csharp/tests.ps1 tests/sdks/csharp/src/test/tests.ps1',
65+
'cp -R tests/sdks/csharp/io/appwrite/src/* tests/sdks/csharp/src',
66+
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/csharp/src mcr.microsoft.com/dotnet/sdk:5.0.101-alpine3.12-amd64 dotnet publish -c Release -o test',
67+
],
68+
'envs' => [
69+
'powershell' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/csharp/src/test/ mcr.microsoft.com/powershell:alpine-3.11 pwsh tests.ps1',
70+
],
71+
],
7072

7173
'typescript' => [
7274
'class' => 'Appwrite\SDK\Language\Typescript',
@@ -161,7 +163,7 @@ public function testHTTPSuccess()
161163
throw new \Exception('Failed to fetch spec from Appwrite server');
162164
}
163165

164-
$whitelist = ['php', 'java', 'node', 'ruby', 'python', 'typescript', 'deno'];
166+
$whitelist = ['php', 'java', 'node', 'ruby', 'python', 'typescript', 'deno', 'csharp'];
165167

166168
foreach ($this->languages as $language => $options) {
167169
if(!empty($whitelist) && !in_array($language, $whitelist)) {

tests/languages/csharp/ServiceTest.cs

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

tests/languages/csharp/tests.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Await-Task {
2+
param (
3+
[Parameter(ValueFromPipeline=$true, Mandatory=$true)]
4+
$task
5+
)
6+
7+
process {
8+
while (-not $task.AsyncWaitHandle.WaitOne(200)) { }
9+
$task.GetAwaiter().GetResult()
10+
}
11+
}
12+
13+
function Print-Response {
14+
param (
15+
$response
16+
)
17+
Write-Host ($response.Content.ReadAsStringAsync().Result | ConvertFrom-Json).result
18+
}
19+
20+
Add-Type -Path "/app/tests/sdks/csharp/src/test/Appwrite.dll" | Out-Null
21+
22+
$client = New-Object Appwrite.Client
23+
$foo = New-Object Appwrite.Foo -ArgumentList $client
24+
$bar = New-Object Appwrite.Bar -ArgumentList $client
25+
$general = New-Object Appwrite.General -ArgumentList $client
26+
27+
$list = $("string in array")
28+
$response = $foo.get("string", 123, $list) | Await-Task
29+
Print-Response $response
30+
31+
$response = $foo.post("string", 123, $list) | Await-Task
32+
Print-Response $response
33+
34+
$response = $foo.put("string", 123, $list) | Await-Task
35+
Print-Response $response
36+
37+
$response = $foo.patch("string", 123, $list) | Await-Task
38+
Print-Response $response
39+
40+
$response = $foo.delete("string", 123, $list) | Await-Task
41+
Print-Response $response
42+
43+
$response = $bar.get("string", 123, $list) | Await-Task
44+
Print-Response $response
45+
46+
$response = $bar.post("string", 123, $list) | Await-Task
47+
Print-Response $response
48+
49+
$response = $bar.put("string", 123, $list) | Await-Task
50+
Print-Response $response
51+
52+
$response = $bar.patch("string", 123, $list) | Await-Task
53+
Print-Response $response
54+
55+
$response = $bar.delete("string", 123, $list) | Await-Task
56+
Print-Response $response
57+
58+
$response = $general.Redirect() | Await-Task
59+
Print-Response $response

0 commit comments

Comments
 (0)