示例#1
0
        public async Task TestGetProduct_ElastiCache_SingleSkuFromOffer()
        {
            // ARRANGE
            string sku = "HBRQZSXXSY2DXJ77";

            PriceListClient client = new PriceListClient();

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

            GetProductResponse response = await client.GetProductAsync(request);

            ProductOffer ecOffer = response.ProductOffer;

            // ACT

            IEnumerable <IGrouping <string, PricingTerm> > groupedTerms = ecOffer.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

            IGrouping <string, PricingTerm> skuTerms = groupedTerms.First(x => x.Key.Equals(sku));

            // ASSERT
            Assert.True(skuTerms.Where(x => x.TermAttributes.PurchaseOption == PurchaseOption.ON_DEMAND).Count() == 1);
        }
示例#2
0
        public async Task TestGetVersionIndexFile_AllServices()
        {
            // ARRANGE
            PriceListClient           client   = new PriceListClient();
            GetOfferIndexFileResponse response = await client.GetOfferIndexFileAsync();

            ConcurrentBag <VersionIndex> indices = new ConcurrentBag <VersionIndex>();

            // ACT
            IEnumerable <Task> tasks = response.OfferIndexFile.Offers.Select(async x =>
            {
                GetVersionIndexResponse versionIndexResponse = await client.GetVersionIndexAsync(new GetVersionIndexRequest(x.Value));

                if (versionIndexResponse != null && versionIndexResponse.VersionIndex != null)
                {
                    indices.Add(versionIndexResponse.VersionIndex);
                }
            });

            await Task.WhenAll(tasks);

            // ASSERT
            Assert.Equal(response.OfferIndexFile.Offers.Where(x => !String.IsNullOrEmpty(x.Value.VersionIndexUrl)).Count(), indices.Count);
            Assert.All(indices, x => Assert.NotNull(x));
        }
示例#3
0
 public ShipmentBuilder(Shipment item, OrderForm orderForm, IOrderEntityFactory entityFactory, IRepositoryFactory <IPricelistRepository> pricelistRepository, PriceListClient priceListClient)
 {
     innerItem            = item;
     _orderForm           = orderForm;
     _entityFactory       = entityFactory;
     _pricelistRepository = pricelistRepository;
     _priceListClient     = priceListClient;
 }
示例#4
0
 static Entrypoint()
 {
     snsClient       = new AmazonSimpleNotificationServiceClient();
     priceListClient = new PriceListClient();
     s3Client        = new AmazonS3Client();
     lambdaClient    = new AmazonLambdaClient();
     snsTopic        = System.Environment.GetEnvironmentVariable("SNS");
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchController" /> class.
 /// </summary>
 /// <param name="marketing">The marketing.</param>
 /// <param name="priceListClient">The price list client.</param>
 /// <param name="storeClient">The store client.</param>
 /// <param name="catalogClient">The catalog client.</param>
 /// <param name="searchFilter">The search filter.</param>
 public SearchController(MarketingHelper marketing, PriceListClient priceListClient, StoreClient storeClient,
                         CatalogClient catalogClient, ISearchFilterService searchFilter)
 {
     _marketing       = marketing;
     _priceListClient = priceListClient;
     _storeClient     = storeClient;
     _catalogClient   = catalogClient;
     _searchFilter    = searchFilter;
 }
示例#6
0
        public async Task TestListServices()
        {
            // ARRANGE
            PriceListClient client = new PriceListClient();

            // ACT
            ListServicesResponse services = await client.ListServicesAsync();

            // ASSERT
            Assert.True(!services.IsError());
            Assert.True(services.Services.Any());
        }
示例#7
0
        public async Task TestGetOfferIndexFile_WithoutRequest()
        {
            // ARRANGE
            PriceListClient client = new PriceListClient();

            // ACT
            GetOfferIndexFileResponse response = await client.GetOfferIndexFileAsync();

            // ASSERT
            Assert.True(!response.IsError());
            Assert.NotNull(response.OfferIndexFile);
        }
        /// <summary>
        /// Creates the line item.
        /// </summary>
        /// <param name="item">The entry.</param>
        /// <param name="parent">Parent item</param>
        /// <param name="quantity">The quantity.</param>
        /// <returns>LineItem.</returns>
        private LineItem CreateLineItem(Item item, Item parent, decimal quantity)
        {
            var lineItem = new LineItem();

            if (parent != null)
            {
                lineItem.DisplayName         = item.DisplayName(String.Format("{0}: {1}", parent.Name, item.Name));
                lineItem.ParentCatalogItemId = parent.ItemId;

                //Build options
                var relations = CatalogClient.GetItemRelations(parent.ItemId);

                var relationGroups = relations.Select(rel => rel.GroupName).Distinct();
                foreach (var prop in item.ItemPropertyValues.LocalizedProperties().Where(p => relationGroups.Contains(p.Name)))
                {
                    var option = new LineItemOption
                    {
                        LineItemId  = item.ItemId,
                        OptionName  = prop.Name,
                        OptionValue = prop.ToString()
                    };
                    lineItem.Options.Add(option);
                }
            }
            else
            {
                lineItem.DisplayName         = item.DisplayName();
                lineItem.ParentCatalogItemId = String.Empty;
            }

            lineItem.CatalogItemId   = item.ItemId;
            lineItem.CatalogItemCode = item.Code;
            var price = PriceListClient.GetLowestPrice(item.ItemId, quantity, false);

            if (price != null)
            {
                lineItem.ListPrice     = price.Sale ?? price.List;
                lineItem.PlacedPrice   = price.Sale ?? price.List;
                lineItem.ExtendedPrice = lineItem.PlacedPrice * quantity;
            }

            lineItem.MaxQuantity         = item.MaxQuantity;
            lineItem.MinQuantity         = item.MinQuantity;
            lineItem.Quantity            = quantity;
            lineItem.Weight              = item.Weight;
            lineItem.Catalog             = CustomerSession.CatalogId;
            lineItem.FulfillmentCenterId = StoreHelper.StoreClient.GetCurrentStore().FulfillmentCenterId;
            //lineItem.CatalogOutline = CatalogOutlineBuilder.BuildCategoryOutline(CatalogClient.CatalogRepository, CustomerSession.CatalogId, item);
            lineItem.CatalogOutline = CatalogOutlineBuilder.BuildCategoryOutline(CustomerSessionService.CustomerSession.CatalogId, item.ItemId).ToString();

            return(lineItem);
        }
示例#9
0
        public async Task TestGetOfferIndexFile_WithRequest()
        {
            // ARRANGE
            PriceListClient          client  = new PriceListClient();
            GetOfferIndexFileRequest request = new GetOfferIndexFileRequest("/offers/v1.0/aws/index.json");

            // ACT
            GetOfferIndexFileResponse response = await client.GetOfferIndexFileAsync(request);

            // ASSERT
            Assert.True(!response.IsError());
            Assert.NotNull(response.OfferIndexFile);
        }
示例#10
0
        public async Task TestGetProduct_AmazonRDS()
        {
            // ARRANGE
            PriceListClient   client  = new PriceListClient();
            GetProductRequest request = new GetProductRequest("AmazonRDS");

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

            // ASSERT
            Assert.True(!response.IsError());
            Assert.True(!String.IsNullOrEmpty(response.ServiceCode));
        }
示例#11
0
        public async Task TestGetVerionIndexFile_AmazonEC2_WithRelativePath()
        {
            // ARRANGE
            PriceListClient           client   = new PriceListClient();
            GetOfferIndexFileResponse response = await client.GetOfferIndexFileAsync();

            string versionIndexUrl = response.OfferIndexFile.Offers["AmazonEC2"].VersionIndexUrl;

            // ACT
            GetVersionIndexResponse versionResponse = await client.GetVersionIndexAsync(new GetVersionIndexRequest(versionIndexUrl));

            // ASSERT
            Assert.Equal(200, (int)versionResponse.HttpStatusCode);
        }
示例#12
0
        public async Task TestGetVerionIndexFile_AmazonEC2_WithOffer()
        {
            // ARRANGE
            PriceListClient           client   = new PriceListClient();
            GetOfferIndexFileResponse response = await client.GetOfferIndexFileAsync();

            Offer offer = response.OfferIndexFile.Offers["AmazonEC2"];

            // ACT
            GetVersionIndexResponse versionResponse = await client.GetVersionIndexAsync(new GetVersionIndexRequest(offer));

            // ASSERT
            Assert.Equal(200, (int)versionResponse.HttpStatusCode);
        }
        /// <summary>
        /// Populates the variation information.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="lineItem">The line item.</param>
        private void PopulateVariationInfo(Item item, LineItem lineItem)
        {
            if (item == null)
            {
                return;
            }

            lineItem.MaxQuantity = item.MaxQuantity;
            lineItem.MinQuantity = item.MinQuantity;

            var priceListHelper = new PriceListClient(PricelistRepository, CustomerSessionService, PriceListEvaluator, PriceListEvalContext, CacheRepository);

            var itemPrice = priceListHelper.GetLowestPrice(item.ItemId, lineItem.Quantity);

            if (itemPrice == null)
            {
                RemoveLineItem(lineItem);
                return;
            }

            // Get old and new prices for comparison.
            var oldPrice = lineItem.ListPrice;

            // new logic is to have the price always be replaced
            var newPrice = itemPrice.Sale ?? itemPrice.List;

            newPrice = Math.Round(newPrice, 2);             // Comparison. The LineItem.ListPrice property rounds values.

            // Get old and new currencies for comparison.
            var oldCurrencyCode = CurrentOrderGroup.BillingCurrency;
            var newCurrencyCode = CustomerSessionService.CustomerSession.Currency;

            if (string.IsNullOrEmpty(oldCurrencyCode))
            {
                oldCurrencyCode = newCurrencyCode;
            }

            // Check for price changes OR currency changes.
            if (oldPrice == newPrice && oldCurrencyCode == newCurrencyCode)
            {
                return;
            }

            // Set new price and currency vales on line item.
            lineItem.ListPrice                = newPrice;
            lineItem.PlacedPrice              = newPrice;
            lineItem.ExtendedPrice            = lineItem.PlacedPrice * lineItem.Quantity;
            CurrentOrderGroup.BillingCurrency = newCurrencyCode;
        }
示例#14
0
        public async Task GetSavingsPlan_RegionIndex_ECS()
        {
            // ARRANGE
            PriceListClient          client       = new PriceListClient();
            GetOfferIndexFileRequest indexRequest = new GetOfferIndexFileRequest();

            GetOfferIndexFileResponse indexResponse = await client.GetOfferIndexFileAsync(indexRequest);

            GetSavingsPlanIndexFileRequest spRegionIndexRequest = new GetSavingsPlanIndexFileRequest(indexResponse.OfferIndexFile.Offers["AmazonECS"].CurrentSavingsPlanIndexUrl);

            // ACT
            GetSavingsPlanIndexFileResponse spRegionIndexResponse = await client.GetSavingsPlanRegionIndexAsync(spRegionIndexRequest);

            // ASSERT
            Assert.Equal(200, (int)spRegionIndexResponse.HttpStatusCode);
        }
示例#15
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);
        }
示例#16
0
        public async Task TestGetProduct_EC2()
        {
            // ARRANGE
            PriceListClient client = new PriceListClient();

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

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

            ProductOffer ec2Offer = response.ProductOffer;

            // ASSERT
            Assert.NotNull(ec2Offer);
        }
示例#17
0
        public async Task TestGetProduct_AmazonRDS_CSV()
        {
            // ARRANGE
            PriceListClientConfig config = new PriceListClientConfig();

            PriceListClient client = new PriceListClient(config);

            GetProductRequest request = new GetProductRequest("AmazonRDS")
            {
                Format = Format.CSV
            };

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

            // ASSERT
            Assert.True(!String.IsNullOrEmpty(response.ServiceCode));
        }
示例#18
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));
        }
示例#19
0
        public async Task TestGetProduct_ECS_FromJsonString()
        {
            // ARRANGE
            PriceListClient client = new PriceListClient();

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

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

            bool success = response.TryGetResponseContentAsString(out string productInfo);

            // ASSERT
            Assert.True(success);

            ProductOffer offer = ProductOffer.FromJson(productInfo);

            Assert.NotNull(offer);
        }
        public ShipmentViewModel(OrderClient client, IViewModelsFactory <ISplitShipmentViewModel> splitVmFactory, IViewModelsFactory <ILineItemAddViewModel> wizardLineItemVmFactory, IViewModelsFactory <ILineItemViewModel> lineItemVmFactory, OrderViewModel orderViewModel, Shipment shipmentItem, IOrderEntityFactory entityFactory, IRepositoryFactory <IPricelistRepository> repositoryFactory, PriceListClient priceListClient)
        {
            _orderClient             = client;
            ParentViewModel          = orderViewModel;
            _currentOrder            = orderViewModel._innerModel;
            CurrentShipment          = shipmentItem;
            _entityFactory           = entityFactory;
            _repositoryFactory       = repositoryFactory;
            _priceListClient         = priceListClient;
            _lineItemVmFactory       = lineItemVmFactory;
            _wizardLineItemVmFactory = wizardLineItemVmFactory;
            _splitVmFactory          = splitVmFactory;

            CommonShipmentConfirmRequest = orderViewModel.CommonOrderCommandConfirmRequest;

            ReleaseShipmentCommand     = new DelegateCommand(RaiseReleaseShipmentInteractionRequest, () => CurrentShipment.IsReleaseable(_currentOrder.InnerItem, client));
            CompleteShipmentCommand    = new DelegateCommand(RaiseCompleteShipmentInteractionRequest, () => CurrentShipment.IsCompletable(_currentOrder.InnerItem, client));
            CancelShipmentCommand      = new DelegateCommand(RaiseCancelShipmentInteractionRequest, () => CurrentShipment.IsCancellable(_currentOrder.InnerItem, client));
            AddLineItemCommand         = new DelegateCommand(RaiseAddLineItemInteractionRequest, () => CurrentShipment.IsModifyable(_currentOrder.InnerItem));
            MoveLineItemCommand        = new DelegateCommand <ShipmentItem>(RaiseMoveLineItemInteractionRequest, x => x != null && CurrentShipment.IsModifyable(_currentOrder.InnerItem));
            RemoveLineItemCommand      = new DelegateCommand <ShipmentItem>(RaiseRemoveLineItemInteractionRequest, x => x != null && CurrentShipment.IsModifyable(_currentOrder.InnerItem));
            ViewLineItemDetailsCommand = new DelegateCommand <object>(RaiseViewLineItemDetailsInteractionRequest, x => x != null);
        }
示例#21
0
        public async Task GetSavingsPlan_Offer_UsEast1_EC2()
        {
            // ARRANGE
            PriceListClient          client       = new PriceListClient();
            GetOfferIndexFileRequest indexRequest = new GetOfferIndexFileRequest();

            GetOfferIndexFileResponse indexResponse = await client.GetOfferIndexFileAsync(indexRequest);

            GetSavingsPlanIndexFileRequest  spRegionIndexRequest  = new GetSavingsPlanIndexFileRequest(indexResponse.OfferIndexFile.Offers["AmazonEC2"].CurrentSavingsPlanIndexUrl);
            GetSavingsPlanIndexFileResponse spRegionIndexResponse = await client.GetSavingsPlanRegionIndexAsync(spRegionIndexRequest);

            GetSavingsPlanRequest spRequest = new GetSavingsPlanRequest(spRegionIndexResponse.RegionIndex.Regions.First(x => x.RegionCode.Equals("us-east-1")).VersionUrl);

            // ACT
            GetSavingsPlanResponse spResponse = await client.GetSavingsPlanAsync(spRequest);

            // ASSERT
            Assert.Equal(200, (int)spResponse.HttpStatusCode);
            Assert.NotNull(spResponse.SavingsPlan.Products);
            Assert.True(spResponse.SavingsPlan.Products.Any());
            Assert.NotNull(spResponse.SavingsPlan.Terms);
            Assert.NotNull(spResponse.SavingsPlan.Terms.SavingsPlan);
            Assert.True(spResponse.SavingsPlan.Terms.SavingsPlan.Any());
        }
示例#22
0
        /// <summary>
        /// Creates the catalog model.
        /// </summary>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="parentItemId">The parent item identifier.</param>
        /// <param name="associationType">Type of the association.</param>
        /// <param name="forcedActive">if set to <c>true</c> [forced active].</param>
        /// <param name="responseGroups">The response groups.</param>
        /// <param name="display">The display.</param>
        /// <param name="byItemCode">if set to <c>true</c> gets item by code.</param>
        /// <returns>
        /// CatalogItemWithPriceModel.
        /// </returns>
        public static CatalogItemWithPriceModel CreateCatalogModel(string itemId,
            string parentItemId = null,
            string associationType = null,
            bool forcedActive = false,
            ItemResponseGroups responseGroups = ItemResponseGroups.ItemLarge,
            ItemDisplayOptions display = ItemDisplayOptions.ItemLarge,
            bool byItemCode = false)
        {

            var dbItem = CatalogClient.GetItem(itemId, responseGroups,
                                              UserHelper.CustomerSession.CatalogId, bycode: byItemCode);
            if (dbItem != null)
            {

                if (dbItem.IsActive || forcedActive)
                {
                    PriceModel priceModel = null;
                    PropertySet propertySet = null;
                    //ItemRelation[] variations = null;
                    ItemAvailabilityModel itemAvaiability = null;

                    if (display.HasFlag(ItemDisplayOptions.ItemPropertySets))
                    {
                        propertySet = CatalogClient.GetPropertySet(dbItem.PropertySetId);
                        //variations = CatalogClient.GetItemRelations(itemId);
                    }

                    var itemModel = CreateItemModel(dbItem, propertySet);

                    if (display.HasFlag(ItemDisplayOptions.ItemAvailability))
                    {
                        var fulfillmentCenter = UserHelper.StoreClient.GetCurrentStore().FulfillmentCenterId;
                        var availability = CatalogClient.GetItemAvailability(dbItem.ItemId, fulfillmentCenter);
                        itemAvaiability = new ItemAvailabilityModel(availability);
                    }

                    if (display.HasFlag(ItemDisplayOptions.ItemPrice))
                    {
                        var lowestPrice = PriceListClient.GetLowestPrice(dbItem.ItemId, itemAvaiability != null ? itemAvaiability.MinQuantity : 1);
                        var outlines = OutlineBuilder.BuildCategoryOutline(CatalogClient.CustomerSession.CatalogId, dbItem.ItemId);
                        var tags = new Hashtable
							{
								{
									"Outline",
                                    outlines.ToString()
                                }
							};
                        priceModel = MarketingHelper.GetItemPriceModel(dbItem, lowestPrice, tags);
                        itemModel.CatalogOutlines = outlines;

                        // get the category name
                        if (outlines.Count > 0)
                        {
                            var outline = outlines[0];
                            if (outline.Categories.Count > 0)
                            {
                                var category = outline.Categories.OfType<Category>().Reverse().FirstOrDefault();
                                if (category != null)
                                {
                                    itemModel.CategoryName = category.Name;
                                }
                            }
                        }
                    }

                    itemModel.ParentItemId = parentItemId;

                    return string.IsNullOrEmpty(associationType)
                               ? new CatalogItemWithPriceModel(itemModel, priceModel, itemAvaiability)
                               : new AssociatedCatalogItemWithPriceModel(itemModel, priceModel, itemAvaiability, associationType);
                }
            }

            return null;
        }