public async Task Test_Receive_Amazon_Products_With_CSharp_Keyword() { string associateTag = "***"; string awsAccessKeyId = "***"; string awsSecretKey = "***"; string keywords = "csharp"; int page = 1; AmazonResponse response; if (string.IsNullOrEmpty(keywords)) { response = AmazonApiHelper.GetEmptyResponse(string.Empty, string.Empty, HttpStatusCode.OK); } else { using (var apiHelper = new AmazonApiHelper(associateTag, awsAccessKeyId, awsSecretKey)) { string requestUri = apiHelper.GetRequestUri(keywords, page); try { response = await apiHelper.ExecuteWebRequestAsync(requestUri, keywords); } catch (Exception ex) { response = AmazonApiHelper.GetEmptyResponse(keywords, ex.Message, HttpStatusCode.InternalServerError); } } } Assert.That(response.responseArray.Count, Is.EqualTo(10)); Assert.That(response.responseArray[0].asin, Is.EqualTo("1518877559")); }
public async Task <AmazonResponse> Products(string keywords, string currency = "USD", int page = 1) { string associateTag = _setting.AssociateTag; string awsAccessKeyId = _setting.AccessKeyId; string awsSecretKey = _setting.SecretAccessKey; AmazonResponse response; if (string.IsNullOrEmpty(keywords)) { response = AmazonApiHelper.GetEmptyResponse(string.Empty, string.Empty, HttpStatusCode.OK); } else { using (var apiHelper = new AmazonApiHelper(associateTag, awsAccessKeyId, awsSecretKey)) { string requestUri = apiHelper.GetRequestUri(keywords, page); try { response = await apiHelper.ExecuteWebRequestAsync(requestUri, keywords); } catch (Exception ex) { response = AmazonApiHelper.GetEmptyResponse(keywords, ex.Message, HttpStatusCode.InternalServerError); } } } var currencyValue = Currency.USD; Enum.TryParse(currency, out currencyValue); foreach (var product in response.responseArray) { if (product.price != null) { string priceString = product.price.Remove(0, 1); decimal price = 0; decimal.TryParse(priceString, out price); price = await _currencyHelper.CurrencyConversionAsync(price, Currency.USD, currencyValue); price = Math.Round(price, 2); product.price = $"{price} {currencyValue.ToString()}"; } } return(response); }