Skip to content

Commit 49f90d5

Browse files
committed
2 parents 6d7c753 + 938cef3 commit 49f90d5

14 files changed

+140
-87
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ AmazonConnection amazonConnection = new AmazonConnection(new AmazonCredential()
158158
});
159159

160160
var orders = amazonConnection.Orders.GetOrders
161-
(
162-
new FikaAmazonAPI.Parameter.Order.ParameterOrderList()
163-
{
164-
TestCase = Constants.TestCase200
165-
}
166-
);
161+
(
162+
new FikaAmazonAPI.Parameter.Order.ParameterOrderList
163+
{
164+
TestCase = Constants.TestCase200
165+
}
166+
);
167167
```
168168

169169
### Report List, For more report sample please check [Here](https://github.com/abuzuhri/Amazon-SP-API-CSharp/blob/main/Source/FikaAmazonAPI.Test/Orders.cs).

Source/FikaAmazonAPI.SampleCode/SandboxOrderSample.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public void GetOrderTestCase200()
1919
{
2020
var orders = amazonConnection.Orders.GetOrders
2121
(
22-
new FikaAmazonAPI.Parameter.Order.ParameterOrderList(Constants.TestCase200)
22+
new FikaAmazonAPI.Parameter.Order.ParameterOrderList
23+
{
24+
TestCase = Constants.TestCase200
25+
}
2326
);
2427
}
2528
}

Source/FikaAmazonAPI/Parameter/IHasParameterizedTestCase.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterDeleteListingItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FikaAmazonAPI.Search;
2+
using FikaAmazonAPI.Utils;
23
using System;
34
using System.Collections.Generic;
45
using System.IO;
@@ -9,9 +10,10 @@ namespace FikaAmazonAPI.Parameter.ListingItem
910
{
1011
public class ParameterDeleteListingItem: ParameterBased
1112
{
12-
1313
public bool Check()
1414
{
15+
if (TestCase == Constants.TestCase400)
16+
sku = "BadSKU";
1517
if (string.IsNullOrWhiteSpace(this.sellerId))
1618
{
1719
throw new InvalidDataException("SellerId is a required property for ParameterDeleteListingItem and cannot be null");

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterGetListingsItem.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,49 @@
44
using Newtonsoft.Json.Converters;
55
using System;
66
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Linq;
79
using System.Text;
10+
using static FikaAmazonAPI.Utils.Constants;
811

9-
namespace FikaAmazonAPI.Parameter.ListingsItems
12+
namespace FikaAmazonAPI.Parameter.ListingItem
1013
{
11-
public class ParameterGetListingsItem : ParameterBased, IHasParameterizedTestCase
14+
public class ParameterGetListingsItem : ParameterBased
1215
{
13-
public ParameterGetListingsItem(string testCase = "")
16+
public ParameterGetListingsItem()
1417
{
15-
if (!string.IsNullOrEmpty(testCase))
18+
}
19+
20+
public bool Check()
21+
{
22+
if (TestCase == TestCase400)
23+
sku = "BadSKU";
24+
if (string.IsNullOrWhiteSpace(sellerId))
25+
{
26+
throw new InvalidDataException("SellerId is a required property for ParameterPutListingItem and cannot be null");
27+
}
28+
if (string.IsNullOrWhiteSpace(sku))
29+
{
30+
throw new InvalidDataException("Sku is a required property for ParameterPutListingItem and cannot be null");
31+
}
32+
if (marketplaceIds == null || !marketplaceIds.Any())
1633
{
17-
TestCase = testCase;
18-
SandboxQueryParameters = Sandbox.SandboxQueryParameters<ParameterGetListingsItem>(TestCase);
34+
throw new InvalidDataException("MarketplaceIds is a required property for ParameterPutListingItem and cannot be null");
1935
}
36+
if (includedData is null)
37+
{
38+
includedData = new List<ListingsIncludedData>();
39+
includedData.Add(ListingsIncludedData.Summaries);
40+
}
41+
if (includedData.Count == 0)
42+
includedData.Add(ListingsIncludedData.Summaries);
43+
return true;
2044
}
2145

46+
public string sellerId { get; set; }
47+
48+
public string sku { get; set; }
49+
2250
/// <summary>
2351
/// A list of MarketplaceId values. Used to select orders that were placed in the specified marketplaces. Max count : 50
2452
/// </summary>
@@ -34,10 +62,5 @@ public ParameterGetListingsItem(string testCase = "")
3462
/// A comma-delimited list of data sets to include in the response. Default: summaries.
3563
/// </summary>
3664
public IList<Constants.ListingsIncludedData> includedData { get; set; }
37-
38-
[IgnoreToAddParameter]
39-
public string TestCase { get; set; }
40-
41-
public Dictionary<string, List<KeyValuePair<string, string>>> SandboxQueryParameters { get; }
4265
}
4366
}

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterPatchListingItem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
22
using FikaAmazonAPI.Search;
3+
using FikaAmazonAPI.Utils;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -12,6 +13,8 @@ public class ParameterPatchListingItem : ParameterBased
1213
{
1314
public bool Check()
1415
{
16+
if (TestCase == Constants.TestCase400)
17+
sku = "BadSKU";
1518
if (string.IsNullOrWhiteSpace(this.sellerId))
1619
{
1720
throw new InvalidDataException("SellerId is a required property for ParameterPatchListingItem and cannot be null");

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterPutListingItem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
22
using FikaAmazonAPI.Search;
3+
using FikaAmazonAPI.Utils;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -12,6 +13,8 @@ public class ParameterPutListingItem : ParameterBased
1213
{
1314
public bool Check()
1415
{
16+
if (TestCase == Constants.TestCase400)
17+
sku = "BadSKU";
1518
if (string.IsNullOrWhiteSpace(this.sellerId))
1619
{
1720
throw new InvalidDataException("SellerId is a required property for ParameterPutListingItem and cannot be null");

Source/FikaAmazonAPI/Parameter/Order/ParameterOrderList.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@
99

1010
namespace FikaAmazonAPI.Parameter.Order
1111
{
12-
public class ParameterOrderList : ParameterBased, IParameterBasedPII, IHasParameterizedTestCase
12+
public class ParameterOrderList : ParameterBased, IParameterBasedPII
1313
{
14-
public ParameterOrderList(string testCase = "")
14+
public ParameterOrderList()
1515
{
16-
if (!string.IsNullOrEmpty(testCase))
17-
{
18-
TestCase = testCase;
19-
SandboxQueryParameters = Sandbox.SandboxQueryParameters<ParameterOrderList>(TestCase);
20-
}
2116
}
2217

2318
/// <summary>
@@ -93,8 +88,5 @@ public ParameterOrderList(string testCase = "")
9388
public string StoreChainStoreId { get; set; }
9489
public bool IsNeedRestrictedDataToken { get; set; }
9590
public CreateRestrictedDataTokenRequest RestrictedDataTokenRequest { get; set; }
96-
public string TestCase { get; set; }
97-
98-
public Dictionary<string, List<KeyValuePair<string, string>>> SandboxQueryParameters { get; }
9991
}
10092
}

Source/FikaAmazonAPI/Parameter/ParameterBased.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,21 @@ namespace FikaAmazonAPI.Search
1212
{
1313
public class ParameterBased
1414
{
15-
public virtual List<KeyValuePair<string, string>> getParameters(bool isSandbox = false)
15+
[IgnoreToAddParameter]
16+
public string TestCase { get; set; }
17+
18+
[IgnoreToAddParameter]
19+
internal Dictionary<string, List<KeyValuePair<string, string>>> SandboxQueryParameters { get; private set; }
20+
21+
public virtual List<KeyValuePair<string, string>> getParameters()
1622
{
1723
List<KeyValuePair<string, string>> queryParameters = new List<KeyValuePair<string, string>>();
18-
Type t = this.GetType(); // Where obj is object whose properties you need.
19-
if (isSandbox)
24+
if (!string.IsNullOrEmpty(TestCase))
2025
{
21-
if (typeof(IHasParameterizedTestCase).IsAssignableFrom(t))
22-
{
23-
var queryParametersProperties = t.GetInterfaces().FirstOrDefault(x => x == typeof(IHasParameterizedTestCase)).GetProperties();
24-
var testCasePropertyValue = queryParametersProperties.FirstOrDefault(x => x.Name == nameof(IHasParameterizedTestCase.TestCase))?.GetValue(this);
25-
if (testCasePropertyValue != null && testCasePropertyValue is string testCase)
26-
{
27-
var sandboxQueryParametersPropertyValue = queryParametersProperties.FirstOrDefault(x => x.Name == nameof(IHasParameterizedTestCase.SandboxQueryParameters))?.GetValue(this);
28-
if (sandboxQueryParametersPropertyValue != null && sandboxQueryParametersPropertyValue is Dictionary<string, List<KeyValuePair<string, string>>> sandboxQueryParameters)
29-
{
30-
if (sandboxQueryParameters.ContainsKey(testCase))
31-
return sandboxQueryParameters[testCase];
32-
}
33-
34-
}
35-
}
26+
SandboxQueryParameters = Sandbox.SandboxQueryParameters(this, TestCase);
27+
return SandboxQueryParameters[TestCase];
3628
}
37-
PropertyInfo[] pi = t.GetProperties();
29+
PropertyInfo[] pi = this.GetType().GetProperties();
3830
foreach (PropertyInfo p in pi)
3931
{
4032
if (p.CustomAttributes.Any(x => x.AttributeType == typeof(IgnoreToAddParameterAttribute))) continue;

Source/FikaAmazonAPI/Services/ApiUrls.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ protected class ListingsItemsApiUrls
470470
//https://stackoverflow.com/questions/575440/url-encoding-using-c-sharp/21771206#21771206
471471
public static string GetListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";
472472

473-
474473
public static string PutListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";
475474

476475
public static string DeleteListingItem(string seller, string sku) => $"{_resourceBaseUrl}/items/{seller}/{WebUtility.UrlEncode(sku)}";

0 commit comments

Comments
 (0)