Skip to content

Commit d07fe97

Browse files
committed
Add generated protocol tests and generate protocol test services
1 parent fe0dd42 commit d07fe97

File tree

74 files changed

+4367
-311
lines changed

Some content is hidden

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

74 files changed

+4367
-311
lines changed

sdk/test/ProtocolTests/AWSSDK.ProtocolTests.NetFramework.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<ProjectReference Include="../Services/RestXmlProtocol/AWSSDK.RestXmlProtocol.NetFramework.csproj" />
4141
<ProjectReference Include="../Services/RestXmlProtocolNamespace/AWSSDK.RestXmlProtocolNamespace.NetFramework.csproj" />
4242
<ProjectReference Include="../UnitTests/Custom/AWSSDK.UnitTestUtilities.NetFramework.csproj" />
43+
<ProjectReference Include="..\Services\QueryCompatibleJSONRPC10\AWSSDK.QueryCompatibleJSONRPC10.NetFramework.csproj" />
4344
</ItemGroup>
4445
<ItemGroup Condition="$(RunAnalyzersDuringBuild)">
4546
</ItemGroup>
@@ -52,4 +53,7 @@
5253
<PackageReference Include="AutoFixture.AutoMoq" Version="3.51.0" />
5354
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
5455
</ItemGroup>
56+
<ItemGroup>
57+
<Folder Include="Generated\QueryCompatibleJSONRPC10\dotnet-protocol-test-codegen\" />
58+
</ItemGroup>
5559
</Project>

sdk/test/ProtocolTests/AWSSDK.ProtocolTests.NetFramework.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.JsonProtocol.NetFram
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.S3.NetFramework", "..\..\src\Services\S3\AWSSDK.S3.NetFramework.csproj", "{6C0E771C-5B37-4781-B251-4D7FC14B4A98}"
3333
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWSSDK.QueryCompatibleJSONRPC10.NetFramework", "..\Services\QueryCompatibleJSONRPC10\AWSSDK.QueryCompatibleJSONRPC10.NetFramework.csproj", "{E1479D22-D509-45B8-F20A-870244119850}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -93,6 +95,10 @@ Global
9395
{6C0E771C-5B37-4781-B251-4D7FC14B4A98}.Debug|Any CPU.Build.0 = Debug|Any CPU
9496
{6C0E771C-5B37-4781-B251-4D7FC14B4A98}.Release|Any CPU.ActiveCfg = Release|Any CPU
9597
{6C0E771C-5B37-4781-B251-4D7FC14B4A98}.Release|Any CPU.Build.0 = Release|Any CPU
98+
{E1479D22-D509-45B8-F20A-870244119850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99+
{E1479D22-D509-45B8-F20A-870244119850}.Debug|Any CPU.Build.0 = Debug|Any CPU
100+
{E1479D22-D509-45B8-F20A-870244119850}.Release|Any CPU.ActiveCfg = Release|Any CPU
101+
{E1479D22-D509-45B8-F20A-870244119850}.Release|Any CPU.Build.0 = Release|Any CPU
96102
EndGlobalSection
97103
GlobalSection(SolutionProperties) = preSolution
98104
HideSolutionNode = FALSE

sdk/test/ProtocolTests/AWSSDK.ProtocolTests.NetStandard.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<ProjectReference Include="../Services/RestXmlProtocol/AWSSDK.RestXmlProtocol.Netstandard.csproj" />
4141
<ProjectReference Include="../Services/RestXmlProtocolNamespace/AWSSDK.RestXmlProtocolNamespace.Netstandard.csproj" />
4242
<ProjectReference Include="../UnitTests/Custom/AWSSDK.UnitTestUtilities.Netstandard.csproj" />
43+
<ProjectReference Include="..\Services\QueryCompatibleJSONRPC10\AWSSDK.QueryCompatibleJSONRPC10.NetStandard.csproj" />
4344
</ItemGroup>
4445
<ItemGroup Condition="$(RunAnalyzersDuringBuild)">
4546
</ItemGroup>

sdk/test/ProtocolTests/AWSSDK.ProtocolTests.NetStandard.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.CommonTest.NetStanda
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.UnitTestUtilities.Netstandard", "..\UnitTests\Custom\AWSSDK.UnitTestUtilities.Netstandard.csproj", "{A267E3F2-38CC-4659-B9C9-1BBB3058C88B}"
3333
EndProject
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWSSDK.QueryCompatibleJSONRPC10.NetStandard", "..\Services\QueryCompatibleJSONRPC10\AWSSDK.QueryCompatibleJSONRPC10.NetStandard.csproj", "{2CB42D7B-1D22-8605-7EC8-207E0DACC076}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -93,6 +95,10 @@ Global
9395
{A267E3F2-38CC-4659-B9C9-1BBB3058C88B}.Debug|Any CPU.Build.0 = Debug|Any CPU
9496
{A267E3F2-38CC-4659-B9C9-1BBB3058C88B}.Release|Any CPU.ActiveCfg = Release|Any CPU
9597
{A267E3F2-38CC-4659-B9C9-1BBB3058C88B}.Release|Any CPU.Build.0 = Release|Any CPU
98+
{2CB42D7B-1D22-8605-7EC8-207E0DACC076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99+
{2CB42D7B-1D22-8605-7EC8-207E0DACC076}.Debug|Any CPU.Build.0 = Debug|Any CPU
100+
{2CB42D7B-1D22-8605-7EC8-207E0DACC076}.Release|Any CPU.ActiveCfg = Release|Any CPU
101+
{2CB42D7B-1D22-8605-7EC8-207E0DACC076}.Release|Any CPU.Build.0 = Release|Any CPU
96102
EndGlobalSection
97103
GlobalSection(SolutionProperties) = preSolution
98104
HideSolutionNode = FALSE

sdk/test/ProtocolTests/Generated/JSONRPC10/dotnet-protocol-test-codegen/GreetingWithErrors.cs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,52 @@ public void AwsJson10InvalidGreetingErrorErrorResponse()
6363
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
6464
}
6565

66+
/// <summary>
67+
/// Parses a complex error with no message member
68+
/// </summary>
69+
[TestMethod]
70+
[TestCategory("ProtocolTest")]
71+
[TestCategory("ErrorTest")]
72+
[TestCategory("JsonRpc10")]
73+
public void AwsJson10ComplexErrorErrorResponse()
74+
{
75+
// Arrange
76+
var webResponseData = new WebResponseData();
77+
webResponseData.StatusCode = (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400);
78+
webResponseData.Headers["Content-Type"] = "application/x-amz-json-1.0";
79+
byte[] bytes = Encoding.ASCII.GetBytes("{\n \"__type\": \"aws.protocoltests.json10#ComplexError\",\n \"TopLevel\": \"Top level\",\n \"Nested\": {\n \"Foo\": \"bar\"\n }\n}");
80+
var stream = new MemoryStream(bytes);
81+
var context = new JsonUnmarshallerContext(stream,true,webResponseData);
82+
// Act
83+
var errorResponse = new GreetingWithErrorsResponseUnmarshaller().UnmarshallException(context, null, (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
84+
// Assert
85+
Assert.IsInstanceOfType(errorResponse, typeof(ComplexErrorException));
86+
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
87+
}
88+
89+
/// <summary>
90+
/// Parses a complex error with an empty body
91+
/// </summary>
92+
[TestMethod]
93+
[TestCategory("ProtocolTest")]
94+
[TestCategory("ErrorTest")]
95+
[TestCategory("JsonRpc10")]
96+
public void AwsJson10EmptyComplexErrorErrorResponse()
97+
{
98+
// Arrange
99+
var webResponseData = new WebResponseData();
100+
webResponseData.StatusCode = (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400);
101+
webResponseData.Headers["Content-Type"] = "application/x-amz-json-1.0";
102+
byte[] bytes = Encoding.ASCII.GetBytes("{\n \"__type\": \"aws.protocoltests.json10#ComplexError\"\n}");
103+
var stream = new MemoryStream(bytes);
104+
var context = new JsonUnmarshallerContext(stream,true,webResponseData);
105+
// Act
106+
var errorResponse = new GreetingWithErrorsResponseUnmarshaller().UnmarshallException(context, null, (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
107+
// Assert
108+
Assert.IsInstanceOfType(errorResponse, typeof(ComplexErrorException));
109+
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
110+
}
111+
66112
/// <summary>
67113
/// Serializes the X-Amzn-ErrorType header. For an example service,
68114
/// see Amazon EKS.
@@ -294,51 +340,5 @@ public void AwsJson10FooErrorWithDunderTypeUriAndNamespaceErrorResponse()
294340
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 500));
295341
}
296342

297-
/// <summary>
298-
/// Parses a complex error with no message member
299-
/// </summary>
300-
[TestMethod]
301-
[TestCategory("ProtocolTest")]
302-
[TestCategory("ErrorTest")]
303-
[TestCategory("JsonRpc10")]
304-
public void AwsJson10ComplexErrorErrorResponse()
305-
{
306-
// Arrange
307-
var webResponseData = new WebResponseData();
308-
webResponseData.StatusCode = (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400);
309-
webResponseData.Headers["Content-Type"] = "application/x-amz-json-1.0";
310-
byte[] bytes = Encoding.ASCII.GetBytes("{\n \"__type\": \"aws.protocoltests.json10#ComplexError\",\n \"TopLevel\": \"Top level\",\n \"Nested\": {\n \"Foo\": \"bar\"\n }\n}");
311-
var stream = new MemoryStream(bytes);
312-
var context = new JsonUnmarshallerContext(stream,true,webResponseData);
313-
// Act
314-
var errorResponse = new GreetingWithErrorsResponseUnmarshaller().UnmarshallException(context, null, (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
315-
// Assert
316-
Assert.IsInstanceOfType(errorResponse, typeof(ComplexErrorException));
317-
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
318-
}
319-
320-
/// <summary>
321-
/// Parses a complex error with an empty body
322-
/// </summary>
323-
[TestMethod]
324-
[TestCategory("ProtocolTest")]
325-
[TestCategory("ErrorTest")]
326-
[TestCategory("JsonRpc10")]
327-
public void AwsJson10EmptyComplexErrorErrorResponse()
328-
{
329-
// Arrange
330-
var webResponseData = new WebResponseData();
331-
webResponseData.StatusCode = (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400);
332-
webResponseData.Headers["Content-Type"] = "application/x-amz-json-1.0";
333-
byte[] bytes = Encoding.ASCII.GetBytes("{\n \"__type\": \"aws.protocoltests.json10#ComplexError\"\n}");
334-
var stream = new MemoryStream(bytes);
335-
var context = new JsonUnmarshallerContext(stream,true,webResponseData);
336-
// Act
337-
var errorResponse = new GreetingWithErrorsResponseUnmarshaller().UnmarshallException(context, null, (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
338-
// Assert
339-
Assert.IsInstanceOfType(errorResponse, typeof(ComplexErrorException));
340-
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
341-
}
342-
343343
}
344344
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/*
17+
* Do not modify this file. This file is generated.
18+
*/
19+
using AWSSDK.ProtocolTests;
20+
using AWSSDK.ProtocolTests.Utils;
21+
using AWSSDK_DotNet.UnitTests.TestTools;
22+
using Amazon.JSONRPC10;
23+
using Amazon.JSONRPC10.Model;
24+
using Amazon.JSONRPC10.Model.Internal.MarshallTransformations;
25+
using Amazon.Runtime;
26+
using Amazon.Runtime.Internal;
27+
using Amazon.Runtime.Internal.Transform;
28+
using Microsoft.VisualStudio.TestTools.UnitTesting;
29+
using Newtonsoft.Json;
30+
using Newtonsoft.Json.Linq;
31+
using System;
32+
using System.Collections.Generic;
33+
using System.IO;
34+
using System.Linq;
35+
using System.Text;
36+
37+
namespace AWSSDK.ProtocolTests.JsonRpc10
38+
{
39+
[TestClass]
40+
public class QueryIncompatibleOperation
41+
{
42+
/// <summary>
43+
/// The query mode header MUST NOT be set on non-query-compatible
44+
/// services.
45+
/// </summary>
46+
[TestMethod]
47+
[TestCategory("ProtocolTest")]
48+
[TestCategory("RequestTest")]
49+
[TestCategory("JsonRpc10")]
50+
public void NonQueryCompatibleAwsJson10ForbidsQueryModeHeaderRequest()
51+
{
52+
// Arrange
53+
var request = new QueryIncompatibleOperationRequest
54+
{
55+
};
56+
var config = new AmazonJSONRPC10Config
57+
{
58+
ServiceURL = "https://test.com/"
59+
};
60+
61+
var marshaller = new QueryIncompatibleOperationRequestMarshaller();
62+
// Act
63+
var marshalledRequest = ProtocolTestUtils.RunMockRequest(request,marshaller,config);
64+
65+
// Assert
66+
var expectedBody = "{}";
67+
JsonProtocolUtils.AssertBody(marshalledRequest, expectedBody);
68+
Assert.AreEqual("POST", marshalledRequest.HttpMethod);
69+
Uri actualUri = AmazonServiceClient.ComposeUrl(marshalledRequest);
70+
Assert.AreEqual("/", ProtocolTestUtils.GetEncodedResourcePathFromOriginalString(actualUri));
71+
Assert.AreEqual("application/x-amz-json-1.0".Replace(" ",""), marshalledRequest.Headers["Content-Type"].Replace(" ",""));
72+
Assert.AreEqual("JsonRpc10.QueryIncompatibleOperation".Replace(" ",""), marshalledRequest.Headers["X-Amz-Target"].Replace(" ",""));
73+
}
74+
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
/*
17+
* Do not modify this file. This file is generated.
18+
*/
19+
using AWSSDK.ProtocolTests;
20+
using AWSSDK.ProtocolTests.Utils;
21+
using AWSSDK_DotNet.UnitTests.TestTools;
22+
using Amazon.QueryCompatibleJSONRPC10;
23+
using Amazon.QueryCompatibleJSONRPC10.Model;
24+
using Amazon.QueryCompatibleJSONRPC10.Model.Internal.MarshallTransformations;
25+
using Amazon.Runtime;
26+
using Amazon.Runtime.Internal;
27+
using Amazon.Runtime.Internal.Transform;
28+
using Microsoft.VisualStudio.TestTools.UnitTesting;
29+
using Newtonsoft.Json;
30+
using Newtonsoft.Json.Linq;
31+
using System;
32+
using System.Collections.Generic;
33+
using System.IO;
34+
using System.Linq;
35+
using System.Net;
36+
using System.Text;
37+
38+
namespace AWSSDK.ProtocolTests.QueryCompatibleJsonRpc10
39+
{
40+
[TestClass]
41+
public class QueryCompatibleOperation
42+
{
43+
/// <summary>
44+
/// Clients for query-compatible services MUST send the
45+
/// x-amzn-query-mode header.
46+
/// </summary>
47+
[TestMethod]
48+
[TestCategory("ProtocolTest")]
49+
[TestCategory("RequestTest")]
50+
[TestCategory("QueryCompatibleJsonRpc10")]
51+
public void QueryCompatibleAwsJson10CborSendsQueryModeHeaderRequest()
52+
{
53+
// Arrange
54+
var request = new QueryCompatibleOperationRequest
55+
{
56+
};
57+
var config = new AmazonQueryCompatibleJSONRPC10Config
58+
{
59+
ServiceURL = "https://test.com/"
60+
};
61+
62+
var marshaller = new QueryCompatibleOperationRequestMarshaller();
63+
// Act
64+
var marshalledRequest = ProtocolTestUtils.RunMockRequest(request,marshaller,config);
65+
66+
// Assert
67+
var expectedBody = "{}";
68+
JsonProtocolUtils.AssertBody(marshalledRequest, expectedBody);
69+
Assert.AreEqual("POST", marshalledRequest.HttpMethod);
70+
Uri actualUri = AmazonServiceClient.ComposeUrl(marshalledRequest);
71+
Assert.AreEqual("/", ProtocolTestUtils.GetEncodedResourcePathFromOriginalString(actualUri));
72+
Assert.AreEqual("application/x-amz-json-1.0".Replace(" ",""), marshalledRequest.Headers["Content-Type"].Replace(" ",""));
73+
Assert.AreEqual("QueryCompatibleJsonRpc10.QueryCompatibleOperation".Replace(" ",""), marshalledRequest.Headers["X-Amz-Target"].Replace(" ",""));
74+
Assert.AreEqual("true".Replace(" ",""), marshalledRequest.Headers["x-amzn-query-mode"].Replace(" ",""));
75+
}
76+
77+
/// <summary>
78+
/// Parses simple errors with no query error code
79+
/// </summary>
80+
[TestMethod]
81+
[TestCategory("ProtocolTest")]
82+
[TestCategory("ErrorTest")]
83+
[TestCategory("QueryCompatibleJsonRpc10")]
84+
public void QueryCompatibleAwsJson10NoCustomCodeErrorErrorResponse()
85+
{
86+
// Arrange
87+
var webResponseData = new WebResponseData();
88+
webResponseData.StatusCode = (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400);
89+
webResponseData.Headers["Content-Type"] = "application/x-amz-json-1.0";
90+
byte[] bytes = Encoding.ASCII.GetBytes("{\n \"__type\": \"aws.protocoltests.json10#NoCustomCodeError\",\n \"message\": \"Hi\"\n}");
91+
var stream = new MemoryStream(bytes);
92+
var context = new JsonUnmarshallerContext(stream,true,webResponseData);
93+
// Act
94+
var errorResponse = new QueryCompatibleOperationResponseUnmarshaller().UnmarshallException(context, null, (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
95+
// Assert
96+
Assert.IsInstanceOfType(errorResponse, typeof(NoCustomCodeErrorException));
97+
Assert.AreEqual(errorResponse.StatusCode,(HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), 400));
98+
}
99+
100+
}
101+
}

0 commit comments

Comments
 (0)