Skip to content

Commit 245c3c1

Browse files
Adopt resiliency spector scenarios (Azure#51633)
1 parent ed4a596 commit 245c3c1

23 files changed

+1489
-2
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
@@ -59,7 +59,6 @@ $failingSpecs = @(
5959
Join-Path 'http' 'versioning' 'returnTypeChangedFrom'
6060
Join-Path 'http' 'versioning' 'typeChangedFrom'
6161
Join-Path 'http' 'client' 'naming' # pending until https://github.com/microsoft/typespec/issues/5653 is resolved
62-
Join-Path 'http' 'resiliency' 'srv-driven'
6362
Join-Path 'http' 'response' 'status-code-range' # Response namespace conflicts with Azure.Response
6463
# Azure scenarios not yet buildable
6564
Join-Path 'http' 'client' 'namespace'

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@
190190
"commandName": "Executable",
191191
"executablePath": "dotnet"
192192
},
193+
"http-resiliency-srv-driven-v1": {
194+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/resiliency/srv-driven/v1 -g AzureStubGenerator",
195+
"commandName": "Executable",
196+
"executablePath": "dotnet"
197+
},
198+
"http-resiliency-srv-driven-v2": {
199+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/resiliency/srv-driven/v2 -g AzureStubGenerator",
200+
"commandName": "Executable",
201+
"executablePath": "dotnet"
202+
},
193203
"http-routes": {
194204
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/routes -g AzureStubGenerator",
195205
"commandName": "Executable",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
extern alias SrvDrivenV1;
5+
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
using SrvDrivenV1::Resiliency.ServiceDriven;
9+
10+
namespace TestProjects.Spector.Tests.Http.Resiliency.SrvDriven.V1
11+
{
12+
/// <summary>
13+
/// Contains tests for the service-driven resiliency V1 client.
14+
/// </summary>
15+
public partial class SrvDrivenV1Tests : SpectorTestBase
16+
{
17+
private const string ServiceDeploymentV1 = "v1";
18+
private const string ServiceDeploymentV2 = "v2";
19+
20+
// This test validates the v1 client behavior when both the service deployment and api version are set to V1.
21+
[SpectorTest]
22+
public Task AddOptionalParamFromNone_V1Client_V1Service_WithApiVersionV1() => Test(async (host) =>
23+
{
24+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
25+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV1, options);
26+
var response = await client.FromNoneAsync();
27+
28+
Assert.AreEqual(204, response.Status);
29+
});
30+
31+
// This test validates the v1 client behavior when the service deployment is set to V2 and the api version is set to V1.
32+
[SpectorTest]
33+
public Task AddOptionalParamFromNone_V1Client_V2Service_WithApiVersionV1() => Test(async (host) =>
34+
{
35+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
36+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
37+
var response = await client.FromNoneAsync();
38+
39+
Assert.AreEqual(204, response.Status);
40+
});
41+
42+
[SpectorTest]
43+
public Task AddOptionalParamFromOneOptional_V1Client_V1Service_WithApiVersionV1() => Test(async (host) =>
44+
{
45+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
46+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV1, options);
47+
var response = await client.FromOneOptionalAsync("optional");
48+
49+
Assert.AreEqual(204, response.Status);
50+
});
51+
52+
[SpectorTest]
53+
public Task AddOptionalParamFromOneOptional_V1Client_V2Service_WithApiVersionV1() => Test(async (host) =>
54+
{
55+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
56+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
57+
var response = await client.FromOneOptionalAsync("optional", cancellationToken: default);
58+
59+
Assert.AreEqual(204, response.Status);
60+
});
61+
62+
[SpectorTest]
63+
public Task AddOptionalParamFromOneRequired_V1Client_V1Service_WithApiVersionV1() => Test(async (host) =>
64+
{
65+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
66+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV1, options);
67+
var response = await client.FromOneRequiredAsync("required");
68+
69+
Assert.AreEqual(204, response.Status);
70+
});
71+
72+
[SpectorTest]
73+
public Task AddOptionalParamFromOneRequired_V1Client_V2Service_WithApiVersionV1() => Test(async (host) =>
74+
{
75+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
76+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
77+
var response = await client.FromOneRequiredAsync("required");
78+
79+
Assert.AreEqual(204, response.Status);
80+
});
81+
}
82+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
extern alias SrvDrivenV2;
5+
extern alias SrvDrivenV1;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
using SrvDrivenV2::Resiliency.ServiceDriven;
9+
10+
namespace TestProjects.Spector.Tests.Http.Resiliency.SrvDriven.V2
11+
{
12+
public partial class SrvDrivenV2Tests : SpectorTestBase
13+
{
14+
private const string ServiceDeploymentV2 = "v2";
15+
16+
[SpectorTest]
17+
public Task AddOperation() => Test(async (host) =>
18+
{
19+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2);
20+
var response = await client.AddOperationAsync();
21+
22+
Assert.AreEqual(204, response.Status);
23+
});
24+
25+
// This test validates the "new" client behavior when the api version is set to V1.
26+
[SpectorTest]
27+
public Task AddOptionalParamFromNone_WithApiVersionV1() => Test(async (host) =>
28+
{
29+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
30+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
31+
var response = await client.FromNoneAsync();
32+
33+
Assert.AreEqual(204, response.Status);
34+
});
35+
36+
// This test validates the "new" client behavior when the api version is set to V2.
37+
[SpectorTest]
38+
public Task AddOptionalParamFromNone_WithApiVersionV2() => Test(async (host) =>
39+
{
40+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V2);
41+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
42+
var response = await client.FromNoneAsync("new", cancellationToken: default);
43+
44+
Assert.AreEqual(204, response.Status);
45+
});
46+
47+
[SpectorTest]
48+
public Task AddOptionalParamFromOneOptional_WithApiVersionV1() => Test(async (host) =>
49+
{
50+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
51+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
52+
var response = await client.FromOneOptionalAsync("optional");
53+
54+
Assert.AreEqual(204, response.Status);
55+
});
56+
57+
[SpectorTest]
58+
public Task AddOptionalParamFromOneOptional_WithApiVersionV2() => Test(async (host) =>
59+
{
60+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V2);
61+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
62+
var response = await client.FromOneOptionalAsync("optional", "new", cancellationToken: default);
63+
64+
Assert.AreEqual(204, response.Status);
65+
});
66+
67+
[SpectorTest]
68+
public Task AddOptionalParamFromOneRequired_WithApiVersionV1() => Test(async (host) =>
69+
{
70+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V1);
71+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
72+
var response = await client.FromOneRequiredAsync("required");
73+
74+
Assert.AreEqual(204, response.Status);
75+
});
76+
77+
[SpectorTest]
78+
public Task AddOptionalParamFromOneRequired_WithApiVersionV2() => Test(async (host) =>
79+
{
80+
var options = new ResiliencyServiceDrivenClientOptions(ResiliencyServiceDrivenClientOptions.ServiceVersion.V2);
81+
var client = new ResiliencyServiceDrivenClient(host, ServiceDeploymentV2, options);
82+
var response = await client.FromOneRequiredAsync("required", "new", cancellationToken: default);
83+
84+
Assert.AreEqual(204, response.Status);
85+
});
86+
}
87+
}

eng/packages/http-client-csharp/generator/TestProjects/Spector.Tests/TestProjects.Spector.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<ProjectReference Include="..\Spector\http\azure\client-generator-core\api-version\header\src\_Specs_.Azure.ClientGenerator.Core.ApiVersion.Header.csproj" />
2020
<ProjectReference Include="..\Spector\http\azure\client-generator-core\api-version\path\src\_Specs_.Azure.ClientGenerator.Core.ApiVersion.Path.csproj" />
2121
<ProjectReference Include="..\Spector\http\azure\client-generator-core\api-version\query\src\_Specs_.Azure.ClientGenerator.Core.ApiVersion.Query.csproj" />
22-
<ProjectReference Include="..\Spector\http\azure\client-generator-core\deserialize-empty-string-as-null\src\_Specs_.Azure.ClientGenerator.Core.DeserializeEmptyStringAsNull.csproj" />
2322
<ProjectReference Include="..\Spector\http\azure\client-generator-core\flatten-property\src\_Specs_.Azure.ClientGenerator.Core.FlattenProperty.csproj" />
2423
<ProjectReference Include="..\Spector\http\azure\client-generator-core\usage\src\_Specs_.Azure.ClientGenerator.Core.Usage.csproj" />
2524
<ProjectReference Include="..\Spector\http\azure\special-headers\client-request-id\src\Azure.SpecialHeaders.XmsClientRequestId.csproj" />
@@ -56,6 +55,8 @@
5655
<ProjectReference Include="..\Spector\http\payload\media-type\src\Payload.MediaType.csproj" />
5756
<ProjectReference Include="..\Spector\http\payload\multipart\src\Payload.MultiPart.csproj" />
5857
<ProjectReference Include="..\Spector\http\payload\pageable\src\Payload.Pageable.csproj" />
58+
<ProjectReference Include="..\Spector\http\resiliency\srv-driven\v1\src\Resiliency.SrvDriven.V1.csproj" Aliases="SrvDrivenV1" />
59+
<ProjectReference Include="..\Spector\http\resiliency\srv-driven\v2\src\Resiliency.SrvDriven.V2.csproj" Aliases="SrvDrivenV2" />
5960
<ProjectReference Include="..\Spector\http\routes\src\Routes.csproj" />
6061
<ProjectReference Include="..\Spector\http\serialization\encoded-name\json\src\Serialization.EncodedName.Json.csproj" />
6162
<ProjectReference Include="..\Spector\http\server\endpoint\not-defined\src\Server.Endpoint.NotDefined.csproj" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"package-name": "Resiliency.SrvDriven.V1",
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 17
3+
VisualStudioVersion = 17.0.31903.59
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resiliency.SrvDriven.V1", "src\Resiliency.SrvDriven.V1.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/resiliency/srv-driven/v1/src/Generated/Models/ResiliencySrvDrivenV1Context.cs

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

eng/packages/http-client-csharp/generator/TestProjects/Spector/http/resiliency/srv-driven/v1/src/Generated/ResiliencyServiceDrivenClient.cs

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

eng/packages/http-client-csharp/generator/TestProjects/Spector/http/resiliency/srv-driven/v1/src/Generated/ResiliencyServiceDrivenClientOptions.cs

Lines changed: 24 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)