Skip to content

Commit 8493942

Browse files
authored
Add cadl-ranch tests (#3120)
1 parent 22af400 commit 8493942

File tree

17 files changed

+1430
-3
lines changed

17 files changed

+1430
-3
lines changed

eng/Generate.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ function Add-TestServer-Swagger ([string]$testName, [string]$projectSuffix, [str
5353
Add-Swagger "$testName$projectSuffix" $projectDirectory "--require=$configurationPath --try-require=$inputReadme --input-file=$inputFile $additionalArgs"
5454
}
5555

56-
function Add-CadlRanch-Cadl([string]$testName, [string]$projectPrefix, [string]$cadlRanchProjectsDirectory) {
56+
function Add-CadlRanch-Cadl([string]$testName, [string]$projectPrefix, [string]$cadlRanchProjectsDirectory, [boolean]$generateConvenience) {
5757
$projectDirectory = Join-Path $cadlRanchProjectsDirectory $testName
5858
$cadlMain = Join-Path $cadlRanchFilePath $testName "main.cadl"
59-
Add-Cadl "$projectPrefix$testName" $projectDirectory $cadlMain "--option @azure-tools/cadl-csharp.unreferenced-types-handling=keepAll"
59+
$convenienceOption = If ($generateConvenience) {""} Else {" --option @azure-tools/cadl-csharp.generate-convenience-methods=false"}
60+
Add-Cadl "$projectPrefix$testName" $projectDirectory $cadlMain "--option @azure-tools/cadl-csharp.unreferenced-types-handling=keepAll$convenienceOption"
6061
}
6162

6263
$testNames =
@@ -252,6 +253,10 @@ if (!($Exclude -contains "Samples"))
252253

253254
# Cadl projects
254255
$cadlRanchProjectDirectory = Join-Path $repoRoot 'test' 'CadlRanchProjects'
256+
$cadlRanchProjectPathsWithoutConvenience = # Needs justification to add item
257+
'enums/extensible', # https://github.com/Azure/autorest.csharp/issues/3079
258+
'hello' # https://github.com/Azure/autorest.csharp/issues/3110
259+
255260
$cadlRanchProjectPaths =
256261
'arrays/item-types',
257262
'authentication/api-key',
@@ -265,7 +270,12 @@ if (!($Exclude -contains "CadlRanchProjects"))
265270
{
266271
foreach ($testPath in $cadlRanchProjectPaths)
267272
{
268-
Add-CadlRanch-Cadl $testPath "cadl-" $cadlRanchProjectDirectory
273+
Add-CadlRanch-Cadl $testPath "cadl-" $cadlRanchProjectDirectory $TRUE
274+
}
275+
276+
foreach ($testPath in $cadlRanchProjectPathsWithoutConvenience)
277+
{
278+
Add-CadlRanch-Cadl $testPath "cadl-" $cadlRanchProjectDirectory $FALSE
269279
}
270280
}
271281

src/AutoRest.CSharp/Properties/launchSettings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@
180180
"commandName": "Project",
181181
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\authentication\\union\\Generated"
182182
},
183+
"cadl-enums/extensible": {
184+
"commandName": "Project",
185+
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\enums\\extensible\\Generated"
186+
},
187+
"cadl-hello": {
188+
"commandName": "Project",
189+
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\hello\\Generated"
190+
},
183191
"cadl-models/property-optional": {
184192
"commandName": "Project",
185193
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\models\\property-optional\\Generated"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using AutoRest.TestServer.Tests.Infrastructure;
6+
using Azure;
7+
using Azure.Core;
8+
using Enums.Extensible;
9+
using Enums.Extensible.Models;
10+
using NUnit.Framework;
11+
12+
namespace CadlRanchProjects.Tests
13+
{
14+
public class EnumsExtensibleTests : CadlRanchTestBase
15+
{
16+
[Test]
17+
public Task Enums_Extensible_String_getKnownValue() => Test(async (host) =>
18+
{
19+
Response response = await new ExtensibleClient(host, null).GetKnownValueAsync();
20+
JsonData result = JsonData.FromBytes(response.Content.ToMemory());
21+
Assert.AreEqual(DaysOfWeekExtensibleEnum.Monday, new DaysOfWeekExtensibleEnum((string)result));
22+
});
23+
24+
[Test]
25+
public Task Enums_Extensible_String_putKnownValue() => Test(async (host) =>
26+
{
27+
Response response = await new ExtensibleClient(host, null).GetUnknownValueAsync();
28+
JsonData result = JsonData.FromBytes(response.Content.ToMemory());
29+
Assert.AreEqual(new DaysOfWeekExtensibleEnum("Weekend"), new DaysOfWeekExtensibleEnum((string)result));
30+
});
31+
32+
[Test]
33+
public Task Enums_Extensible_String_getUnknownValue() => Test(async (host) =>
34+
{
35+
Response response = await new ExtensibleClient(host, null).PutKnownValueAsync(RequestContent.Create(new JsonData(DaysOfWeekExtensibleEnum.Monday.ToString())));
36+
Assert.AreEqual(204, response.Status);
37+
});
38+
39+
[Test]
40+
public Task Enums_Extensible_String_putUnknownValue() => Test(async (host) =>
41+
{
42+
Response response = await new ExtensibleClient(host, null).PutUnknownValueAsync(RequestContent.Create(new JsonData(new DaysOfWeekExtensibleEnum("Weekend").ToString())));
43+
Assert.AreEqual(204, response.Status);
44+
});
45+
}
46+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading.Tasks;
5+
using AutoRest.TestServer.Tests.Infrastructure;
6+
using Azure;
7+
using Azure.Core;
8+
using Hello;
9+
using NUnit.Framework;
10+
11+
namespace CadlRanchProjects.Tests
12+
{
13+
public class HelloTests : CadlRanchTestBase
14+
{
15+
[Test]
16+
public Task Hello_world() => Test(async (host) =>
17+
{
18+
Response response = await new HelloClient(host, null).WorldAsync();
19+
Assert.AreEqual(200, response.Status);
20+
Assert.AreEqual("application/json; charset=utf-8", response.Headers.ContentType);
21+
JsonData responseBody = JsonData.FromBytes(response.Content.ToMemory());
22+
Assert.AreEqual("Hello World!", (string)responseBody);
23+
});
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
<Nullable>annotations</Nullable>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<DefineConstants>$(DefineConstants);EXPERIMENTAL</DefineConstants>
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<PackageReference Include="Azure.Core.Experimental" Version="0.1.0-preview.18" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="Azure.Core" Version="1.28.0" />
18+
</ItemGroup>
19+
20+
</Project>

test/CadlRanchProjects/enums/extensible/Generated/Configuration.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<doc>
3+
<members>
4+
<member name="GetKnownValueAsync(RequestContext)">
5+
<example>
6+
This sample shows how to call GetKnownValueAsync and parse the result.
7+
<code><![CDATA[
8+
var client = new ExtensibleClient();
9+
10+
Response response = await client.GetKnownValueAsync();
11+
12+
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
13+
Console.WriteLine(result.ToString());
14+
]]></code>
15+
</example>
16+
</member>
17+
<member name="GetKnownValue(RequestContext)">
18+
<example>
19+
This sample shows how to call GetKnownValue and parse the result.
20+
<code><![CDATA[
21+
var client = new ExtensibleClient();
22+
23+
Response response = client.GetKnownValue();
24+
25+
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
26+
Console.WriteLine(result.ToString());
27+
]]></code>
28+
</example>
29+
</member>
30+
<member name="GetUnknownValueAsync(RequestContext)">
31+
<example>
32+
This sample shows how to call GetUnknownValueAsync and parse the result.
33+
<code><![CDATA[
34+
var client = new ExtensibleClient();
35+
36+
Response response = await client.GetUnknownValueAsync();
37+
38+
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
39+
Console.WriteLine(result.ToString());
40+
]]></code>
41+
</example>
42+
</member>
43+
<member name="GetUnknownValue(RequestContext)">
44+
<example>
45+
This sample shows how to call GetUnknownValue and parse the result.
46+
<code><![CDATA[
47+
var client = new ExtensibleClient();
48+
49+
Response response = client.GetUnknownValue();
50+
51+
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
52+
Console.WriteLine(result.ToString());
53+
]]></code>
54+
</example>
55+
</member>
56+
<member name="PutKnownValueAsync(RequestContent,RequestContext)">
57+
<example>
58+
This sample shows how to call PutKnownValueAsync with required request content.
59+
<code><![CDATA[
60+
var client = new ExtensibleClient();
61+
62+
var data = "Monday";
63+
64+
Response response = await client.PutKnownValueAsync(RequestContent.Create(data));
65+
Console.WriteLine(response.Status);
66+
]]></code>
67+
</example>
68+
</member>
69+
<member name="PutKnownValue(RequestContent,RequestContext)">
70+
<example>
71+
This sample shows how to call PutKnownValue with required request content.
72+
<code><![CDATA[
73+
var client = new ExtensibleClient();
74+
75+
var data = "Monday";
76+
77+
Response response = client.PutKnownValue(RequestContent.Create(data));
78+
Console.WriteLine(response.Status);
79+
]]></code>
80+
</example>
81+
</member>
82+
<member name="PutUnknownValueAsync(RequestContent,RequestContext)">
83+
<example>
84+
This sample shows how to call PutUnknownValueAsync with required request content.
85+
<code><![CDATA[
86+
var client = new ExtensibleClient();
87+
88+
var data = "Monday";
89+
90+
Response response = await client.PutUnknownValueAsync(RequestContent.Create(data));
91+
Console.WriteLine(response.Status);
92+
]]></code>
93+
</example>
94+
</member>
95+
<member name="PutUnknownValue(RequestContent,RequestContext)">
96+
<example>
97+
This sample shows how to call PutUnknownValue with required request content.
98+
<code><![CDATA[
99+
var client = new ExtensibleClient();
100+
101+
var data = "Monday";
102+
103+
Response response = client.PutUnknownValue(RequestContent.Create(data));
104+
Console.WriteLine(response.Status);
105+
]]></code>
106+
</example>
107+
</member>
108+
</members>
109+
</doc>

0 commit comments

Comments
 (0)