Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator implementation for V2 smoke tests for C2J files. #3578

Draft
wants to merge 2 commits into
base: normj/v4-smoketests
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Bug fix for cases of null errorId, small changes to align with SEP.
  • Loading branch information
AlexDaines committed Dec 17, 2024
commit dcef01bdf41452ee37501e33f5624f9c2c4c93ea
Original file line number Diff line number Diff line change
@@ -182,5 +182,23 @@ private Operation FindOperation(JsonData testCase)
var operationShapeName = testCase["operationName"].ToString();
return this.Config.ServiceModel.Operations.FirstOrDefault(x => string.Equals(x.ShapeName, operationShapeName));
}

/// <summary>
/// Finds the proper .NET property name for a given JSON key in the operation's input shape.
/// </summary>
private string FindPropertyName(Operation operation, string jsonKey)
{
// Get the input shape for the operation
var inputShape = operation.RequestStructure;
if (inputShape == null)
return jsonKey;

// Look for a member in the input shape that matches the json key
var member = inputShape.Members.FirstOrDefault(m =>
string.Equals(m.MarshallLocationName, jsonKey, StringComparison.OrdinalIgnoreCase));

// If found, return the .NET customized name, otherwise return original key
return member?.PropertyName ?? jsonKey;
}
}
}
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ namespace AWSSDK_DotNet.IntegrationTests.SmokeTestsV2
}
}
#>
public async Task <#=testCase["id"]?.ToString() ?? "Test"#>()
public async Task <#=testCase["id"]#>()
{
var serviceConfig = new Amazon<#=this.Config.ClassName#>Config();
<#
@@ -126,32 +126,33 @@ namespace AWSSDK_DotNet.IntegrationTests.SmokeTestsV2
var input = testCase["input"] as JsonData;
if (input != null && input.IsObject)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we need to check input.IsObject? if input != null, then we are guaranteed to be given a json object wityh the input so I think we can remove the IsObject check.

{
foreach (string key in input.PropertyNames)
foreach (string jsonKey in input.PropertyNames)
{
var value = input[key];
var propertyName = FindPropertyName(modeledOperation, jsonKey);
var value = input[jsonKey];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since the name is propertyName, you could make it consistent and say propertyValue for the value. fine with me if u dont want to change though

if (value != null)
{
if (value.IsString)
{
#>
request.<#=key#> = "<#=value.ToString()#>";
request.<#=propertyName#> = "<#=value.ToString()#>";
<#
}
else if (value.IsInt)
{
#>
request.<#=key#> = (int)<#=value#>;
request.<#=propertyName#> = (int)<#=value#>;
<#
}
else if (value.IsBoolean)
{
#>
request.<#=key#> = <#=value.ToString().ToLower()#>;
request.<#=propertyName#> = <#=value.ToString().ToLower()#>;
<#
}
else if (value.IsArray)
{
if (key == "Tags")
if (propertyName == "Tags")
{
#>
request.Tags = new List<Tag>();
@@ -168,28 +169,80 @@ namespace AWSSDK_DotNet.IntegrationTests.SmokeTestsV2
}
else
{
var arrayValues = new List<string>();
// Check if all items are strings
bool allStrings = true;
foreach (JsonData item in value)
{
if (item != null && item.IsString)
if (item != null && !item.IsString)
{
arrayValues.Add($"\"{item.ToString()}\"");
allStrings = false;
break;
}
}
if (arrayValues.Count > 0)

if (allStrings)
{
#>
request.<#=key#> = new List<string> { <#=string.Join(", ", arrayValues)#> };
request.<#=propertyName#> = new List<string>
{
<#
}
else
{
#>
request.<#=propertyName#> = new List<object>
{
<#
}
var isFirst = true;
foreach (JsonData item in value)
{
if (item != null)
{
if (!isFirst)
{
#>
,
<#
}
if (item.IsString)
{
#>
"<#=item.ToString()#>"
<#
}
else if (item.IsInt)
{
#>
<#=item.ToString()#>
<#
}
else if (item.IsBoolean)
{
#>
<#=item.ToString().ToLower()#>
<#
}
else if (item.IsDouble)
{
#>
<#=item.ToString()#>
<#
}
isFirst = false;
}
}
#>
};
<#
}
}
else if (value.IsObject)
{
if (key == "Includes")
if (propertyName == "Includes")
{
#>
request.<#=key#> = new Filters
request.<#=propertyName#> = new Filters
{
<#
var keyTypes = value["keyTypes"] as JsonData;
@@ -236,7 +289,14 @@ namespace AWSSDK_DotNet.IntegrationTests.SmokeTestsV2
}
catch (Amazon<#=this.Config.ClassName#>Exception ex)
{
<#
if (!string.IsNullOrEmpty(errorId))
{
#>
Assert.AreEqual("<#=errorId#>", ex.ErrorCode);
<#
}
#>
}
<#
}
Loading
Oops, something went wrong.