Skip to content

Commit 5774e51

Browse files
Adopt client structure specs (Azure#51261)
1 parent dff2cf0 commit 5774e51

File tree

64 files changed

+3570
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3570
-9
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ $failingSpecs = @(
5757
Join-Path 'http' 'versioning' 'renamedFrom'
5858
Join-Path 'http' 'versioning' 'returnTypeChangedFrom'
5959
Join-Path 'http' 'versioning' 'typeChangedFrom'
60-
Join-Path 'http' 'client' 'naming'
60+
Join-Path 'http' 'client' 'naming' # pending until https://github.com/microsoft/typespec/issues/5653 is resolved
6161
Join-Path 'http' 'resiliency' 'srv-driven'
62-
Join-Path 'http' 'client' 'structure' 'client-operation-group'
63-
Join-Path 'http' 'client' 'structure' 'renamed-operation'
64-
Join-Path 'http' 'client' 'structure' 'multi-client'
65-
Join-Path 'http' 'client' 'structure' 'two-operation-group'
6662
Join-Path 'http' 'response' 'status-code-range' # Response namespace conflicts with Azure.Response
6763
# Azure scenarios not yet buildable
6864
Join-Path 'http' 'client' 'namespace'

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,31 @@
7575
"commandName": "Executable",
7676
"executablePath": "dotnet"
7777
},
78+
"http-client-structure-client-operation-group": {
79+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/client/structure/client-operation-group -g AzureStubGenerator",
80+
"commandName": "Executable",
81+
"executablePath": "dotnet"
82+
},
7883
"http-client-structure-default": {
7984
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/client/structure/default -g AzureStubGenerator",
8085
"commandName": "Executable",
8186
"executablePath": "dotnet"
8287
},
88+
"http-client-structure-multi-client": {
89+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/client/structure/multi-client -g AzureStubGenerator",
90+
"commandName": "Executable",
91+
"executablePath": "dotnet"
92+
},
93+
"http-client-structure-renamed-operation": {
94+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/client/structure/renamed-operation -g AzureStubGenerator",
95+
"commandName": "Executable",
96+
"executablePath": "dotnet"
97+
},
98+
"http-client-structure-two-operation-group": {
99+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/client/structure/two-operation-group -g AzureStubGenerator",
100+
"commandName": "Executable",
101+
"executablePath": "dotnet"
102+
},
83103
"http-encode-bytes": {
84104
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/encode/bytes -g AzureStubGenerator",
85105
"commandName": "Executable",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
extern alias ClientStructureClientOperationGroup;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using ClientStructureClientOperationGroup::Client.Structure.AnotherClientOperationGroup;
8+
using ClientStructureClientOperationGroup::Client.Structure.ClientOperationGroup;
9+
using NUnit.Framework;
10+
using ClientType = ClientStructureClientOperationGroup::Client.Structure.Service.ClientType;
11+
12+
namespace TestProjects.Spector.Tests.Http.Client.Structure.ClientOperationGroup
13+
{
14+
public class ClientOperationGroupTests : SpectorTestBase
15+
{
16+
[Test]
17+
public void VerifyMethods()
18+
{
19+
/*check methods in FirstClient. */
20+
var methodsOfFirstClient = typeof(FirstClient).GetMethods();
21+
Assert.IsNotNull(methodsOfFirstClient);
22+
Assert.AreEqual(2, methodsOfFirstClient.Where(method => method.Name.EndsWith("Async")).Count());
23+
Assert.IsNotNull(typeof(FirstClient).GetMethods().Where(m => m.Name == "OneAsync").FirstOrDefault());
24+
//check existence of method to get the operation group client
25+
Assert.AreNotEqual(null, typeof(FirstClient).GetMethod("GetGroup3Client"));
26+
Assert.AreNotEqual(null, typeof(FirstClient).GetMethod("GetGroup4Client"));
27+
/*check methods in operation group3 client. */
28+
var methodsOfGroup3 = typeof(Group3).GetMethods();
29+
Assert.IsNotNull(methodsOfGroup3);
30+
Assert.AreEqual(4, methodsOfGroup3.Where(method => method.Name.EndsWith("Async")).ToArray().Length);
31+
Assert.IsNotNull(typeof(Group3).GetMethods().Where(m => m.Name == "TwoAsync").FirstOrDefault());
32+
Assert.IsNotNull(typeof(Group3).GetMethods().Where(m => m.Name == "ThreeAsync").FirstOrDefault());
33+
/*check methods in operation group4 client. */
34+
var methodsOfGroup4 = typeof(Group4).GetMethods();
35+
Assert.IsNotNull(methodsOfGroup4);
36+
Assert.AreEqual(2, methodsOfGroup4.Where(method => method.Name.EndsWith("Async")).ToArray().Length);
37+
Assert.IsNotNull(typeof(Group4).GetMethods().Where(m => m.Name == "FourAsync").FirstOrDefault());
38+
39+
/*check methods in SecondClient. */
40+
var methodsOfSecondClient = typeof(SubNamespaceSecondClient).GetMethods();
41+
Assert.IsNotNull(methodsOfSecondClient);
42+
Assert.AreEqual(2, methodsOfSecondClient.Where(method => method.Name.EndsWith("Async")).Count());
43+
Assert.IsNotNull(typeof(SubNamespaceSecondClient).GetMethods().Where(m => m.Name == "FiveAsync").FirstOrDefault());
44+
//check existence of method to get the operation group client
45+
Assert.AreNotEqual(null, typeof(SubNamespaceSecondClient).GetMethod("GetGroup5Client"));
46+
/*check methods in operation group5 client. */
47+
var methodsOfGroup5 = typeof(Group5).GetMethods();
48+
Assert.IsNotNull(methodsOfGroup5);
49+
Assert.AreEqual(2, methodsOfGroup5.Where(method => method.Name.EndsWith("Async")).ToArray().Length);
50+
Assert.IsNotNull(typeof(Group5).GetMethods().Where(m => m.Name == "SixAsync").FirstOrDefault());
51+
}
52+
53+
[SpectorTest]
54+
public Task One() => Test(async (host) =>
55+
{
56+
var response = await new FirstClient(host, ClientType.ClientOperationGroup, null).OneAsync();
57+
Assert.AreEqual(204, response.Status);
58+
});
59+
60+
[SpectorTest]
61+
public Task Two() => Test(async (host) =>
62+
{
63+
var response = await new FirstClient(host, ClientType.ClientOperationGroup, null).GetGroup3Client().TwoAsync();
64+
Assert.AreEqual(204, response.Status);
65+
});
66+
67+
[SpectorTest]
68+
public Task Three() => Test(async (host) =>
69+
{
70+
var response = await new FirstClient(host, ClientType.ClientOperationGroup, null).GetGroup3Client().ThreeAsync();
71+
Assert.AreEqual(204, response.Status);
72+
});
73+
74+
[SpectorTest]
75+
public Task Four() => Test(async (host) =>
76+
{
77+
var response = await new FirstClient(host, ClientType.ClientOperationGroup, null).GetGroup4Client().FourAsync();
78+
Assert.AreEqual(204, response.Status);
79+
});
80+
81+
[SpectorTest]
82+
public Task Five() => Test(async (host) =>
83+
{
84+
var response = await new SubNamespaceSecondClient(host, ClientType.ClientOperationGroup, null).FiveAsync();
85+
Assert.AreEqual(204, response.Status);
86+
});
87+
88+
[SpectorTest]
89+
public Task Six() => Test(async (host) =>
90+
{
91+
var response = await new SubNamespaceSecondClient(host, ClientType.ClientOperationGroup, null).GetGroup5Client().SixAsync();
92+
Assert.AreEqual(204, response.Status);
93+
});
94+
}
95+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
extern alias ClientStructureDefault;
5+
using System;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using ClientStructureDefault::Client.Structure.Service;
9+
using ClientStructureDefault::Client.Structure.Service._Baz;
10+
using ClientStructureDefault::Client.Structure.Service._Qux;
11+
using NUnit.Framework;
12+
13+
namespace TestProjects.Spector.Tests.Http.Client.Structure.Default
14+
{
15+
public class DefaultTests : SpectorTestBase
16+
{
17+
[TestCase(typeof(ServiceClient), new string[] { "One", "Two" })]
18+
[TestCase(typeof(Foo), new string[] { "Three", "Four" })]
19+
[TestCase(typeof(Bar), new string[] { "Five", "Six" })]
20+
[TestCase(typeof(BazFoo), new string[] { "Seven" })]
21+
[TestCase(typeof(Qux), new string[] { "Eight" })]
22+
[TestCase(typeof(QuxBar), new string[] { "Nine" })]
23+
24+
public void Client_Structure_default_methods(Type client, string[] methodNames)
25+
{
26+
var methods = client.GetMethods();
27+
Assert.IsNotNull(methods);
28+
Assert.AreEqual(methodNames.Length * 2, methods.Where(method => method.Name.EndsWith("Async")).ToArray().Length); // Double the methods to account for protocol methods
29+
/* check the existence of the methods. */
30+
foreach (var methodName in methodNames)
31+
{
32+
Assert.IsNotNull(methods.Where(m => m.Name == $"{methodName}Async").FirstOrDefault());
33+
}
34+
}
35+
36+
[SpectorTest]
37+
public Task Client_Structure_default_One() => Test(async (host) =>
38+
{
39+
var response = await new ServiceClient(host, ClientType.Default).OneAsync();
40+
Assert.AreEqual(204, response.Status);
41+
});
42+
43+
[SpectorTest]
44+
public Task Client_Structure_default_Two() => Test(async (host) =>
45+
{
46+
var response = await new ServiceClient(host, ClientType.Default).TwoAsync();
47+
Assert.AreEqual(204, response.Status);
48+
});
49+
50+
[SpectorTest]
51+
public Task Client_Structure_default_Three() => Test(async (host) =>
52+
{
53+
var response = await new ServiceClient(host, ClientType.Default).GetFooClient().ThreeAsync();
54+
Assert.AreEqual(204, response.Status);
55+
});
56+
57+
[SpectorTest]
58+
public Task Client_Structure_default_Four() => Test(async (host) =>
59+
{
60+
var response = await new ServiceClient(host, ClientType.Default).GetFooClient().FourAsync();
61+
Assert.AreEqual(204, response.Status);
62+
});
63+
64+
[SpectorTest]
65+
public Task Client_Structure_default_Five() => Test(async (host) =>
66+
{
67+
var response = await new ServiceClient(host, ClientType.Default).GetBarClient().FiveAsync();
68+
Assert.AreEqual(204, response.Status);
69+
});
70+
71+
[SpectorTest]
72+
public Task Client_Structure_default_Six() => Test(async (host) =>
73+
{
74+
var response = await new ServiceClient(host, ClientType.Default).GetBarClient().SixAsync();
75+
Assert.AreEqual(204, response.Status);
76+
});
77+
78+
[SpectorTest]
79+
public Task Client_Structure_default_Seven() => Test(async (host) =>
80+
{
81+
var response = await new ServiceClient(host, ClientType.Default).GetBazClient().GetBazFooClient().SevenAsync();
82+
Assert.AreEqual(204, response.Status);
83+
});
84+
85+
[SpectorTest]
86+
public Task Client_Structure_default_Eight() => Test(async (host) =>
87+
{
88+
var response = await new ServiceClient(host, ClientType.Default).GetQuxClient().EightAsync();
89+
Assert.AreEqual(204, response.Status);
90+
});
91+
92+
[SpectorTest]
93+
public Task Client_Structure_default_Nine() => Test(async (host) =>
94+
{
95+
var response = await new ServiceClient(host, ClientType.Default).GetQuxClient().GetQuxBarClient().NineAsync();
96+
Assert.AreEqual(204, response.Status);
97+
});
98+
}
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
extern alias ClientStructureMultiClient;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using ClientStructureMultiClient::Client.Structure.MultiClient;
8+
using NUnit.Framework;
9+
using ClientType = ClientStructureMultiClient::Client.Structure.Service.ClientType;
10+
11+
namespace TestProjects.Spector.Tests.Http.Client.Structure.MultiClient
12+
{
13+
public class MultiClientTests : SpectorTestBase
14+
{
15+
[Test]
16+
public void VerifyMethods()
17+
{
18+
/*cheeck methods in ClientAClient. */
19+
var methodsOfClientA = typeof(ClientAClient).GetMethods();
20+
Assert.IsNotNull(methodsOfClientA);
21+
Assert.AreEqual(6, methodsOfClientA.Where(method => method.Name.EndsWith("Async")).Count());
22+
Assert.IsNotNull(typeof(ClientAClient).GetMethods().Where(m => m.Name == "RenamedOneAsync").FirstOrDefault());
23+
Assert.IsNotNull(typeof(ClientAClient).GetMethods().Where(m => m.Name == "RenamedThreeAsync").FirstOrDefault());
24+
Assert.IsNotNull(typeof(ClientAClient).GetMethods().Where(m => m.Name == "RenamedFiveAsync").FirstOrDefault());
25+
26+
/*cheeck methods in ClientBClient. */
27+
var methodsOfClientB = typeof(ClientBClient).GetMethods();
28+
Assert.IsNotNull(methodsOfClientB);
29+
Assert.AreEqual(6, methodsOfClientB.Where(method => method.Name.EndsWith("Async")).Count());
30+
Assert.IsNotNull(typeof(ClientBClient).GetMethods().Where(m => m.Name == "RenamedTwoAsync").FirstOrDefault());
31+
Assert.IsNotNull(typeof(ClientBClient).GetMethods().Where(m => m.Name == "RenamedFourAsync").FirstOrDefault());
32+
Assert.IsNotNull(typeof(ClientBClient).GetMethods().Where(m => m.Name == "RenamedSixAsync").FirstOrDefault());
33+
}
34+
35+
[SpectorTest]
36+
public Task RenamedOne() => Test(async (host) =>
37+
{
38+
var response = await new ClientAClient(host, ClientType.MultiClient, null).RenamedOneAsync();
39+
Assert.AreEqual(204, response.Status);
40+
});
41+
42+
[SpectorTest]
43+
public Task RenamedTwo() => Test(async (host) =>
44+
{
45+
var response = await new ClientBClient(host, ClientType.MultiClient, null).RenamedTwoAsync();
46+
Assert.AreEqual(204, response.Status);
47+
});
48+
49+
[SpectorTest]
50+
public Task RenamedThree() => Test(async (host) =>
51+
{
52+
var response = await new ClientAClient(host, ClientType.MultiClient, null).RenamedThreeAsync();
53+
Assert.AreEqual(204, response.Status);
54+
});
55+
56+
[SpectorTest]
57+
public Task RenamedFour() => Test(async (host) =>
58+
{
59+
var response = await new ClientBClient(host, ClientType.MultiClient, null).RenamedFourAsync();
60+
Assert.AreEqual(204, response.Status);
61+
});
62+
63+
[SpectorTest]
64+
public Task RenamedFive() => Test(async (host) =>
65+
{
66+
var response = await new ClientAClient(host, ClientType.MultiClient, null).RenamedFiveAsync();
67+
Assert.AreEqual(204, response.Status);
68+
});
69+
70+
[SpectorTest]
71+
public Task RenamedSix() => Test(async (host) =>
72+
{
73+
var response = await new ClientBClient(host, ClientType.MultiClient, null).RenamedSixAsync();
74+
Assert.AreEqual(204, response.Status);
75+
});
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
extern alias ClientStructureRenamedOperation;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using ClientStructureRenamedOperation::Client.Structure.RenamedOperation;
8+
using ClientStructureRenamedOperation::Client.Structure.Service;
9+
using NUnit.Framework;
10+
11+
namespace TestProjects.Spector.Tests.Http.Client.Structure.RenamedOperation
12+
{
13+
public class RenamedOperationTests : SpectorTestBase
14+
{
15+
[Test]
16+
public void VerifyMethods()
17+
{
18+
/*check methods in RenamedOperationClient. */
19+
var methodsRenamedOperation = typeof(RenamedOperationClient).GetMethods();
20+
Assert.IsNotNull(methodsRenamedOperation);
21+
Assert.AreEqual(6, methodsRenamedOperation.Where(method => method.Name.EndsWith("Async")).Count());
22+
Assert.IsNotNull(typeof(RenamedOperationClient).GetMethods().Where(m => m.Name == "RenamedOneAsync").FirstOrDefault());
23+
Assert.IsNotNull(typeof(RenamedOperationClient).GetMethods().Where(m => m.Name == "RenamedThreeAsync").FirstOrDefault());
24+
Assert.IsNotNull(typeof(RenamedOperationClient).GetMethods().Where(m => m.Name == "RenamedFiveAsync").FirstOrDefault());
25+
Assert.IsNotNull(typeof(RenamedOperationClient).GetMethods().Where(m => m.Name == "GetGroupClient").FirstOrDefault());
26+
}
27+
28+
[SpectorTest]
29+
public Task RenamedOne() => Test(async (host) =>
30+
{
31+
var response = await new RenamedOperationClient(host, ClientType.RenamedOperation, null).RenamedOneAsync();
32+
Assert.AreEqual(204, response.Status);
33+
});
34+
35+
[SpectorTest]
36+
public Task RenamedThree() => Test(async (host) =>
37+
{
38+
var response = await new RenamedOperationClient(host, ClientType.RenamedOperation, null).RenamedThreeAsync();
39+
Assert.AreEqual(204, response.Status);
40+
});
41+
42+
[SpectorTest]
43+
public Task RenamedFive() => Test(async (host) =>
44+
{
45+
var response = await new RenamedOperationClient(host, ClientType.RenamedOperation, null).RenamedFiveAsync();
46+
Assert.AreEqual(204, response.Status);
47+
});
48+
49+
// Check OperationGroup
50+
[SpectorTest]
51+
public Task RenamedTwo() => Test(async (host) =>
52+
{
53+
var response = await new RenamedOperationClient(host, ClientType.RenamedOperation, null).GetGroupClient().RenamedTwoAsync();
54+
Assert.AreEqual(204, response.Status);
55+
});
56+
57+
[SpectorTest]
58+
public Task RenamedFour() => Test(async (host) =>
59+
{
60+
var response = await new RenamedOperationClient(host, ClientType.RenamedOperation, null).GetGroupClient().RenamedFourAsync();
61+
Assert.AreEqual(204, response.Status);
62+
});
63+
64+
[SpectorTest]
65+
public Task RenamedSix() => Test(async (host) =>
66+
{
67+
var response = await new RenamedOperationClient(host, ClientType.RenamedOperation, null).GetGroupClient().RenamedSixAsync();
68+
Assert.AreEqual(204, response.Status);
69+
});
70+
}
71+
}

0 commit comments

Comments
 (0)