Skip to content

Commit 66eb4a6

Browse files
Adopt routes scenarios (Azure#49765)
* Adopt route scenarios * Add AppendQuery overloads * Change default
1 parent 5476020 commit 66eb4a6

33 files changed

+6593
-1
lines changed

eng/packages/http-client-csharp/eng/scripts/Generate.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ $failingSpecs = @(
6868
Join-Path 'http' 'client' 'structure' 'multi-client'
6969
Join-Path 'http' 'client' 'structure' 'two-operation-group'
7070
Join-Path 'http' 'response' 'status-code-range' # Response namespace conflicts with Azure.Response
71-
Join-Path 'http' 'routes'
7271
# Azure scenarios not yet buildable
7372
Join-Path 'http' 'client' 'namespace'
7473
Join-Path 'http' 'azure' 'client-generator-core' 'access'

eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
"commandName": "Executable",
111111
"executablePath": "dotnet"
112112
},
113+
"http-routes": {
114+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/routes -g AzureStubGenerator",
115+
"commandName": "Executable",
116+
"executablePath": "dotnet"
117+
},
113118
"http-serialization-encoded-name-json": {
114119
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/serialization/encoded-name/json -g AzureStubGenerator",
115120
"commandName": "Executable",
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
using NUnit.Framework;
7+
using Routes;
8+
9+
namespace TestProjects.Spector.Tests.Http.Routes
10+
{
11+
public class PathParameterTests : SpectorTestBase
12+
{
13+
[SpectorTest]
14+
public Task InInterface() => Test(async (host) =>
15+
{
16+
var response = await new RoutesClient(host, null).GetInInterfaceClient().FixedAsync();
17+
Assert.AreEqual(204, response.Status);
18+
});
19+
20+
[SpectorTest]
21+
public Task Fixed() => Test(async (host) =>
22+
{
23+
var response = await new RoutesClient(host, null).FixedAsync();
24+
Assert.AreEqual(204, response.Status);
25+
});
26+
27+
[SpectorTest]
28+
public Task PathAnnotationOnly() => Test(async (host) =>
29+
{
30+
var response = await new RoutesClient(host, null).GetPathParametersClient().AnnotationOnlyAsync("a");
31+
Assert.AreEqual(204, response.Status);
32+
});
33+
34+
[SpectorTest]
35+
public Task PathExplicit() => Test(async (host) =>
36+
{
37+
var response = await new RoutesClient(host, null).GetPathParametersClient().ExplicitAsync("a");
38+
Assert.AreEqual(204, response.Status);
39+
});
40+
41+
[SpectorTest]
42+
public Task PathTemplateOnly() => Test(async (host) =>
43+
{
44+
var response = await new RoutesClient(host, null).GetPathParametersClient().TemplateOnlyAsync("a");
45+
Assert.AreEqual(204, response.Status);
46+
});
47+
48+
[SpectorTest]
49+
public Task ReservedAnnotation() => Test(async (host) =>
50+
{
51+
var response = await new RoutesClient(host, null).GetPathParametersClient()
52+
.GetPathParametersReservedExpansionClient()
53+
.AnnotationAsync("foo/bar baz");
54+
Assert.AreEqual(204, response.Status);
55+
});
56+
57+
[SpectorTest]
58+
public Task ReservedTemplate() => Test(async (host) =>
59+
{
60+
var response = await new RoutesClient(host, null).GetPathParametersClient()
61+
.GetPathParametersReservedExpansionClient()
62+
.TemplateAsync("foo/bar baz");
63+
Assert.AreEqual(204, response.Status);
64+
});
65+
66+
[SpectorTest]
67+
public Task Explicit() => Test(async (host) =>
68+
{
69+
var response = await new RoutesClient(host, null).GetPathParametersClient().ExplicitAsync("a");
70+
Assert.AreEqual(204, response.Status);
71+
});
72+
73+
[SpectorTest]
74+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
75+
public Task LabelExpansionExplodeArray() => Test(async (host) =>
76+
{
77+
var response = await new RoutesClient(host, null).GetPathParametersClient()
78+
.GetPathParametersLabelExpansionClient()
79+
.GetPathParametersLabelExpansionExplodeClient()
80+
.ArrayAsync(["a, b"]);
81+
Assert.AreEqual(204, response.Status);
82+
});
83+
84+
[SpectorTest]
85+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
86+
public Task LabelExpansionArray() => Test(async (host) =>
87+
{
88+
var response = await new RoutesClient(host, null).GetPathParametersClient()
89+
.GetPathParametersLabelExpansionClient()
90+
.GetPathParametersLabelExpansionStandardClient()
91+
.ArrayAsync(["a", "b"]);
92+
Assert.AreEqual(204, response.Status);
93+
});
94+
95+
[SpectorTest]
96+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
97+
public Task LabelExpansionExplodePrimitive() => Test(async (host) =>
98+
{
99+
var response = await new RoutesClient(host, null).GetPathParametersClient()
100+
.GetPathParametersLabelExpansionClient()
101+
.GetPathParametersLabelExpansionExplodeClient()
102+
.PrimitiveAsync("a");
103+
Assert.AreEqual(204, response.Status);
104+
});
105+
106+
[SpectorTest]
107+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
108+
public Task LabelExpansionPrimitive() => Test(async (host) =>
109+
{
110+
var response = await new RoutesClient(host, null).GetPathParametersClient()
111+
.GetPathParametersLabelExpansionClient()
112+
.GetPathParametersLabelExpansionExplodeClient()
113+
.PrimitiveAsync("a");
114+
Assert.AreEqual(204, response.Status);
115+
});
116+
117+
[SpectorTest]
118+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
119+
public Task LabelExpansionExplodeRecord() => Test(async (host) =>
120+
{
121+
var response = await new RoutesClient(host, null).GetPathParametersClient()
122+
.GetPathParametersLabelExpansionClient()
123+
.GetPathParametersLabelExpansionExplodeClient()
124+
.RecordAsync(new Dictionary<string, int> {{"a", 1}, {"b", 2}});
125+
Assert.AreEqual(204, response.Status);
126+
});
127+
128+
[SpectorTest]
129+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
130+
public Task LabelExpansionRecord() => Test(async (host) =>
131+
{
132+
var response = await new RoutesClient(host, null).GetPathParametersClient()
133+
.GetPathParametersLabelExpansionClient()
134+
.GetPathParametersLabelExpansionStandardClient()
135+
.RecordAsync(new Dictionary<string, int> {{"a", 1}, {"b", 2}});
136+
Assert.AreEqual(204, response.Status);
137+
});
138+
}
139+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
using NUnit.Framework;
7+
using Routes;
8+
9+
namespace TestProjects.Spector.Tests.Http.Routes
10+
{
11+
public class QueryParameterTests : SpectorTestBase
12+
{
13+
[SpectorTest]
14+
public Task QueryAnnotationOnly() => Test(async (host) =>
15+
{
16+
var response = await new RoutesClient(host, null).GetQueryParametersClient().AnnotationOnlyAsync("a");
17+
Assert.AreEqual(204, response.Status);
18+
});
19+
20+
[SpectorTest]
21+
public Task QueryExplicit() => Test(async (host) =>
22+
{
23+
var response = await new RoutesClient(host, null).GetQueryParametersClient().ExplicitAsync("a");
24+
Assert.AreEqual(204, response.Status);
25+
});
26+
27+
[SpectorTest]
28+
public Task QueryTemplateOnly() => Test(async (host) =>
29+
{
30+
var response = await new RoutesClient(host, null).GetQueryParametersClient().TemplateOnlyAsync("a");
31+
Assert.AreEqual(204, response.Status);
32+
});
33+
34+
[SpectorTest]
35+
public Task QueryExpansionPrimitive() => Test(async (host) =>
36+
{
37+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
38+
.GetQueryParametersQueryExpansionClient()
39+
.GetQueryParametersQueryExpansionStandardClient()
40+
.PrimitiveAsync("a");
41+
Assert.AreEqual(204, response.Status);
42+
});
43+
44+
[SpectorTest]
45+
public Task QueryExpansionArray() => Test(async (host) =>
46+
{
47+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
48+
.GetQueryParametersQueryExpansionClient()
49+
.GetQueryParametersQueryExpansionStandardClient()
50+
.ArrayAsync(["a", "b"]);
51+
Assert.AreEqual(204, response.Status);
52+
});
53+
54+
[SpectorTest]
55+
public Task QueryExpansionRecord() => Test(async (host) =>
56+
{
57+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
58+
.GetQueryParametersQueryExpansionClient()
59+
.GetQueryParametersQueryExpansionStandardClient()
60+
.RecordAsync(new Dictionary<string, int> {{"a", 1}, {"b", 2}});
61+
Assert.AreEqual(204, response.Status);
62+
});
63+
64+
[SpectorTest]
65+
public Task QueryExpansionExplodePrimitive() => Test(async (host) =>
66+
{
67+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
68+
.GetQueryParametersQueryExpansionClient()
69+
.GetQueryParametersQueryExpansionExplodeClient()
70+
.PrimitiveAsync("a");
71+
Assert.AreEqual(204, response.Status);
72+
});
73+
74+
[SpectorTest]
75+
public Task QueryExpansionExplodeArray() => Test(async (host) =>
76+
{
77+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
78+
.GetQueryParametersQueryExpansionClient()
79+
.GetQueryParametersQueryExpansionExplodeClient()
80+
.ArrayAsync(["a", "b"]);
81+
Assert.AreEqual(204, response.Status);
82+
});
83+
84+
[SpectorTest]
85+
public Task QueryExpansionExplodeRecord() => Test(async (host) =>
86+
{
87+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
88+
.GetQueryParametersQueryExpansionClient()
89+
.GetQueryParametersQueryExpansionExplodeClient()
90+
.RecordAsync(new Dictionary<string, int> {{"a", 1}, {"b", 2}});
91+
Assert.AreEqual(204, response.Status);
92+
});
93+
94+
[SpectorTest]
95+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
96+
public Task QueryContinuationPrimitive() => Test(async (host) =>
97+
{
98+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
99+
.GetQueryParametersQueryContinuationClient()
100+
.GetQueryParametersQueryContinuationStandardClient()
101+
.PrimitiveAsync("a");
102+
Assert.AreEqual(204, response.Status);
103+
});
104+
105+
[SpectorTest]
106+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
107+
public Task QueryContinuationArray() => Test(async (host) =>
108+
{
109+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
110+
.GetQueryParametersQueryContinuationClient()
111+
.GetQueryParametersQueryContinuationStandardClient()
112+
.ArrayAsync(["a", "b"]);
113+
Assert.AreEqual(204, response.Status);
114+
});
115+
116+
[SpectorTest]
117+
[Ignore("https://github.com/microsoft/typespec/issues/5561")]
118+
public Task QueryContinuationRecord() => Test(async (host) =>
119+
{
120+
var response = await new RoutesClient(host, null).GetQueryParametersClient()
121+
.GetQueryParametersQueryContinuationClient()
122+
.GetQueryParametersQueryContinuationStandardClient()
123+
.RecordAsync(new Dictionary<string, int> {{"a", 1}, {"b", 2}});
124+
Assert.AreEqual(204, response.Status);
125+
});
126+
}
127+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"package-name": "Routes",
3+
"license": {
4+
"name": "MIT License",
5+
"company": "Microsoft Corporation",
6+
"link": "https://mit-license.org",
7+
"header": "Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT License.",
8+
"description": "Copyright (c) Microsoft Corporation\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the “Software”), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE."
9+
}
10+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29709.97
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Routes", "src\Routes.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
41+
EndGlobalSection
42+
GlobalSection(SolutionProperties) = preSolution
43+
HideSolutionNode = FALSE
44+
EndGlobalSection
45+
GlobalSection(ExtensibilityGlobals) = postSolution
46+
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
47+
EndGlobalSection
48+
EndGlobal

eng/packages/http-client-csharp/generator/TestProjects/Spector/http/routes/src/Generated/InInterface.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)