Example #1
0
        public async Task TestGetProduct_ECS_FromJsonContentStream()
        {
            // ARRANGE
            PriceListClient client = new PriceListClient();

            GetProductRequest request = new GetProductRequest("AmazonECS")
            {
                Format = Format.JSON
            };

            // ACT
            GetProductResponse response = await client.GetProductAsync(request);

            ProductOffer offer = ProductOffer.FromJsonStream(response.Content);

            // ASSERT
            Assert.NotNull(offer);
        }
Example #2
0
        public async Task TestGetProduct_AmazonDynamoDB_FromJsonContentStream()
        {
            // ARRANGE
            PriceListClient client = new PriceListClient();

            GetProductRequest request = new GetProductRequest("AmazonDynamoDB")
            {
                Format = Format.JSON
            };

            GetProductResponse response = await client.GetProductAsync(request);

            // ACT
            ProductOffer ddbOffer = ProductOffer.FromJsonStream(response.Content);

            // ASSERT
            Assert.NotNull(ddbOffer);
            Assert.True(!String.IsNullOrEmpty(ddbOffer.Version));
        }
Example #3
0
        /// <summary>
        /// Converts the price list data from json into our formatted csv
        /// </summary>
        /// <param name="json"></param>
        /// <param name="writer"></param>
        private async Task GetFromJson(Stream json, CsvWriter writer)
        {
            json.Position = 0;
            ProductOffer offer = ProductOffer.FromJsonStream(json);

            /*
             *  Old implementation, don't need such a complex grouping, just iterate
             *  every sku in the reserved terms and only process the ones that have a matching
             *  product and on demand term
             *
             *   Hashset<string> ApplicableProductSkus = new Hashset<string>(Offer.Terms[Term.RESERVED].Keys)
             *
             *   foreach (IGrouping<string, PricingTerm> CommonSkus in Offer.Terms
             *          .SelectMany(x => x.Value) // Get all of the product item dictionaries from on demand and reserved
             *          .Where(x => ApplicableProductSkus.Contains(x.Key)) // Only get the pricing terms for products we care about
             *          .SelectMany(x => x.Value) // Get all of the pricing term key value pairs
             *          .Select(x => x.Value) // Get just the pricing terms
             *          .GroupBy(x => x.Sku)) // Put all of the same skus together
             *   {
             *       try
             *       {
             *           IEnumerable<ReservedInstancePricingTerm> Terms = ReservedInstancePricingTerm.Build2(CommonSkus, Offer.Products[CommonSkus.Key]);
             *           writer.WriteRecords<ReservedInstancePricingTerm>(Terms);
             *       }
             *       catch (Exception e)
             *       {
             *           this._Context.LogError(e);
             *       }
             *   }
             */

            foreach (string Sku in offer.Terms[Term.RESERVED].Keys)
            {
                if (!offer.Products.ContainsKey(Sku))
                {
                    _context.LogWarning($"There is no product that matches the Sku {Sku}.");
                    continue;
                }

                if (!offer.Terms[Term.ON_DEMAND].ContainsKey(Sku))
                {
                    _context.LogWarning($"There is no on-demand pricing term for sku {Sku}.");
                    continue;
                }

                try
                {
                    IEnumerable <ReservedInstancePricingTerm> terms = ReservedInstancePricingTerm.Build(
                        offer.Products[Sku],                                     // The product
                        offer.Terms[Term.ON_DEMAND][Sku].FirstOrDefault().Value, // OnDemand PricingTerm
                        offer.Terms[Term.RESERVED][Sku].Select(x => x.Value)     // IEnumerable<PricingTerm> Reserved Terms
                        );

                    writer.WriteRecords <ReservedInstancePricingTerm>(terms);
                }
                catch (Exception e)
                {
                    _context.LogError(e);
                    await SNSNotify(e, _context);

                    throw e;
                }
            }
        }