🔥 AMAZON测试案例调整

master
wufan 4 months ago
parent 9b5a65f01c
commit 0926699563

@ -23,20 +23,20 @@ public class SampleShippingV2Tests : SampleTestsBase
{ {
ShipTo = new Address ShipTo = new Address
{ {
Name = "Maria Mata", Name = "Courtesy Chakma",
AddressLine1 = "2760 W Yowlumne Ave, Ste A", AddressLine1 = "14420 97TH AVE BSMT DOOR JAMAICA",
StateOrRegion = "CA", StateOrRegion = "NY",
City = "Porterville", City = "JAMAICA",
CountryCode = "US", CountryCode = "US",
PostalCode = "93257", PostalCode = "11435-4424",
}, },
ShipDate = new DateTime(2024,10,30), ShipDate = new DateTime(2024,10,25,15,30,0),
ShipFrom = new Address ShipFrom = new Address
{ {
Name = "EDDIE", Name = "bosonshop",
AddressLine1 = "11190 White Birch Dr Suite 100", AddressLine1 = "11190 White Birch Dr Suite 100",
StateOrRegion = "CA", StateOrRegion = "CA",
City = "Rancho Cucamonga", City = "RanchoCucamonga",
CountryCode = "US", CountryCode = "US",
PostalCode = "91730", PostalCode = "91730",
}, },
@ -61,28 +61,28 @@ public class SampleShippingV2Tests : SampleTestsBase
Value = 200, Value = 200,
Unit = "USD" Unit = "USD"
}, },
PackageClientReferenceId = "111-0844329-0173888", PackageClientReferenceId = "111-0844329-0DAWDAV",
IsHazmat = false, IsHazmat = false,
Items = new ItemList Items = new ItemList
{ {
new Item new Item
{ {
// ItemValue = new Currency ItemValue = new Currency
// { {
// Value = 200, Value = 200,
// Unit = "USD" Unit = "USD"
// }, },
Quantity = 1, Quantity = 1,
Weight = new Weight Weight = new Weight
{ {
Unit = WeightUnitEnum.POUND, Unit = WeightUnitEnum.POUND,
Value = 20 Value = 20
}, },
// LiquidVolume = new LiquidVolume LiquidVolume = new LiquidVolume
// { {
// Unit = LiquidVolume.UnitEnum.ML, Unit = LiquidVolumeUnitEnum.ML,
// Value = 2000 Value = 2000
// }, },
} }
} }
} }

@ -22,7 +22,8 @@ public class SampleTestsBase
MarketPlace.US.Id MarketPlace.US.Id
) )
{ {
IsDebugMode = true IsDebugMode = true,
ShippingBusiness = Constants.ShippingBusiness.AmazonShipping_US
}; };
return credential; return credential;

@ -79,6 +79,8 @@ namespace Amazon.SellingPartnerApiSDK
/// 最大重试次数 /// 最大重试次数
/// </summary> /// </summary>
public int MaxThrottledRetryCount { get; set; } = 3; public int MaxThrottledRetryCount { get; set; } = 3;
public ShippingBusiness? ShippingBusiness { get; set; }
/// <summary> /// <summary>
/// 是否启用调试模式 /// 是否启用调试模式

@ -0,0 +1,34 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Xml.Serialization;
namespace Amazon.SellingPartnerApiSDK.Misc
{
public static class LinqHelper
{
public static string GetEnumMemberValue<T>(this T value) where T : Enum
{
return typeof(T)
.GetTypeInfo()
.DeclaredMembers
.SingleOrDefault(x => x.Name == value.ToString())
?.GetCustomAttribute<EnumMemberAttribute>(false)
?.Value;
}
public static string SerializeObject<T>(this T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}
}
}
}

@ -97,6 +97,7 @@ namespace Amazon.SellingPartnerApiSDK.Services
{ {
RestHeader(); RestHeader();
AddAccessToken(); AddAccessToken();
AddShippingBusinessId();
var response = await RequestClient.ExecuteAsync<T>(Request, cancellationToken); var response = await RequestClient.ExecuteAsync<T>(Request, cancellationToken);
LogRequest(Request, response); LogRequest(Request, response);
SaveLastRequestHeader(response.Headers); SaveLastRequestHeader(response.Headers);
@ -283,6 +284,13 @@ namespace Amazon.SellingPartnerApiSDK.Services
Request.AddOrUpdateHeader(AccessTokenHeaderName, AccessToken); Request.AddOrUpdateHeader(AccessTokenHeaderName, AccessToken);
} }
} }
private void AddShippingBusinessId()
{
if (AmazonCredential.ShippingBusiness.HasValue)
Request.AddOrUpdateHeader(ShippingBusinessIdHeaderName,
AmazonCredential.ShippingBusiness.Value.GetEnumMemberValue());
}
private async Task RefreshTokenAsync(CacheTokenData.TokenDataType tokenDataType = CacheTokenData.TokenDataType.Normal, private async Task RefreshTokenAsync(CacheTokenData.TokenDataType tokenDataType = CacheTokenData.TokenDataType.Normal,
CreateRestrictedDataTokenRequest requestPii = null, CancellationToken cancellationToken = default) CreateRestrictedDataTokenRequest requestPii = null, CancellationToken cancellationToken = default)

Loading…
Cancel
Save