Skip to content

Commit 61f8b0e

Browse files
Adopt azure basic scenarios (Azure#50995)
* Adopt azure basic scenarios * regen * spectortest
1 parent 4cc7a0e commit 61f8b0e

File tree

19 files changed

+2985
-1
lines changed

19 files changed

+2985
-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
@@ -73,7 +73,6 @@ $failingSpecs = @(
7373
Join-Path 'http' 'azure' 'client-generator-core' 'api-version' 'header'
7474
Join-Path 'http' 'azure' 'client-generator-core' 'api-version' 'path'
7575
Join-Path 'http' 'azure' 'client-generator-core' 'api-version' 'query'
76-
Join-Path 'http' 'azure' 'core' 'basic'
7776
Join-Path 'http' 'azure' 'core' 'page'
7877
Join-Path 'http' 'azure' 'core' 'scalar'
7978
Join-Path 'http' 'azure' 'core' 'traits'

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
@@ -35,6 +35,11 @@
3535
"commandName": "Executable",
3636
"executablePath": "dotnet"
3737
},
38+
"http-azure-core-basic": {
39+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/azure/core/basic -g AzureStubGenerator",
40+
"commandName": "Executable",
41+
"executablePath": "dotnet"
42+
},
3843
"http-azure-core-lro-rpc": {
3944
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/azure/core/lro/rpc -g AzureStubGenerator",
4045
"commandName": "Executable",
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text.Json.Nodes;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using _Specs_.Azure.Core.Basic;
10+
using Azure;
11+
using Azure.Core;
12+
using NUnit.Framework;
13+
14+
namespace TestProjects.Spector.Tests.Http.Azure.Core.Basic
15+
{
16+
public class AzureCoreBasicTests : SpectorTestBase
17+
{
18+
[SpectorTest]
19+
public Task Azure_Core_Basic_createOrUpdate() => Test(async (host) =>
20+
{
21+
var value = new
22+
{
23+
name = "Madge"
24+
};
25+
var response = await new BasicClient(host, null).CreateOrUpdateAsync(1, RequestContent.Create(value));
26+
Assert.AreEqual(200, response.Status);
27+
JsonNode responseBody = JsonNode.Parse(response.Content!)!;
28+
Assert.AreEqual(1, (int)responseBody["id"]!);
29+
Assert.AreEqual("Madge", (string)responseBody["name"]!);
30+
Assert.AreEqual("11bdc430-65e8-45ad-81d9-8ffa60d55b59", (string)responseBody["etag"]!);
31+
});
32+
33+
[SpectorTest]
34+
public Task Azure_Core_Basic_createOrReplace() => Test(async (host) =>
35+
{
36+
User response = await new BasicClient(host, null).CreateOrReplaceAsync(1, new User("Madge"));
37+
Assert.AreEqual("Madge", response.Name);
38+
});
39+
40+
[SpectorTest]
41+
public Task Azure_Core_Basic_get() => Test(async (host) =>
42+
{
43+
User response = await new BasicClient(host, null).GetAsync(1);
44+
Assert.AreEqual("Madge", response.Name);
45+
});
46+
47+
[SpectorTest]
48+
public Task Azure_Core_Basic_list() => Test(async (host) =>
49+
{
50+
AsyncPageable<User> allPages = new BasicClient(host, null).GetAsync(5, 10, null, new[] {"id"}, "id lt 10", new[] {"id", "orders", "etag"}, new[] {"orders"});
51+
await foreach (Page<User> page in allPages.AsPages())
52+
{
53+
User firstUser = page.Values.First();
54+
Assert.AreEqual(1, firstUser.Id);
55+
Assert.AreEqual("Madge", firstUser.Name);
56+
Assert.AreEqual("11bdc430-65e8-45ad-81d9-8ffa60d55b59", firstUser.Etag.ToString());
57+
Assert.AreEqual(1, firstUser.Orders.First().Id);
58+
Assert.AreEqual(1, firstUser.Orders.First().UserId);
59+
Assert.AreEqual("a recorder", firstUser.Orders.First().Detail);
60+
61+
User secondUser = page.Values.Last();
62+
Assert.AreEqual(2, secondUser.Id);
63+
Assert.AreEqual("John", secondUser.Name);
64+
Assert.AreEqual("11bdc430-65e8-45ad-81d9-8ffa60d55b5a", secondUser.Etag.ToString());
65+
Assert.AreEqual(2, secondUser.Orders.First().Id);
66+
Assert.AreEqual(2, secondUser.Orders.First().UserId);
67+
Assert.AreEqual("a TV", secondUser.Orders.First().Detail);
68+
}
69+
});
70+
71+
[SpectorTest]
72+
public Task Azure_Core_Basic_delete() => Test(async (host) =>
73+
{
74+
var response = await new BasicClient(host, null).DeleteAsync(1);
75+
Assert.AreEqual(204, response.Status);
76+
});
77+
78+
[SpectorTest]
79+
public Task Azure_Core_Basic_export() => Test(async (host) =>
80+
{
81+
User response = await new BasicClient(host, null).ExportAsync(1, "json");
82+
Assert.AreEqual("Madge", response.Name);
83+
});
84+
85+
[SpectorTest]
86+
public Task Azure_Core_Basic_exportAllUsers() => Test(async (host) =>
87+
{
88+
var response = await new BasicClient(host, null).ExportAllUsersAsync("json");
89+
Assert.AreEqual(1, response.Value.Users.First().Id);
90+
Assert.AreEqual("Madge", response.Value.Users.First().Name);
91+
Assert.AreEqual(2, response.Value.Users.Last().Id);
92+
Assert.AreEqual("John", response.Value.Users.Last().Name);
93+
Assert.AreEqual(2, response.Value.Users.Count());
94+
});
95+
96+
[SpectorTest]
97+
public void Azure_Core_basic_RenameListMethod()
98+
{
99+
var getUsersMethod = typeof(BasicClient).GetMethod("GetAsync", new[] { typeof(int?), typeof(int?), typeof(int?), typeof(IEnumerable<string>), typeof(string), typeof(IEnumerable<string>), typeof(IEnumerable<string>), typeof(CancellationToken) });
100+
var listMethod = typeof(BasicClient).GetMethod("List", new[] { typeof(int?), typeof(int?), typeof(int?), typeof(IEnumerable<string>), typeof(string), typeof(IEnumerable<string>), typeof(IEnumerable<string>), typeof(CancellationToken) });
101+
Assert.IsNull(listMethod);
102+
Assert.IsNotNull(getUsersMethod);
103+
}
104+
}
105+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ProjectReference Include="..\Spector\http\azure\special-headers\client-request-id\src\Azure.SpecialHeaders.XmsClientRequestId.csproj" />
2121
<ProjectReference Include="..\Spector\http\azure\core\lro\standard\src\_Specs_.Azure.Core.Lro.Standard.csproj" />
2222
<ProjectReference Include="..\Spector\http\azure\core\lro\rpc\src\_Specs_.Azure.Core.Lro.Rpc.csproj" />
23+
<ProjectReference Include="..\Spector\http\azure\core\basic\src\_Specs_.Azure.Core.Basic.csproj" />
2324
<ProjectReference Include="..\Spector\http\azure\core\model\src\_Specs_.Azure.Core.Model.csproj" />
2425
<ProjectReference Include="..\Spector\http\type\array\src\Type.Array.csproj" />
2526
<ProjectReference Include="..\Spector\http\type\enum\extensible\src\Type.Enum.Extensible.csproj" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"package-name": "_Specs_.Azure.Core.Basic",
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}") = "_Specs_.Azure.Core.Basic", "src\_Specs_.Azure.Core.Basic.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/azure/core/basic/src/Generated/BasicClient.cs

Lines changed: 78 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/azure/core/basic/src/Generated/BasicClientOptions.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.

eng/packages/http-client-csharp/generator/TestProjects/Spector/http/azure/core/basic/src/Generated/Models/_Specs_AzureCoreBasicContext.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/azure/core/basic/src/Generated/User.Serialization.cs

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