public void WillCreateAShipmentRequestWithPromoBundle()
        {
            BigCommerceController.bigCommerceOrderId = 2244;

            var kitId = 3854675;
            ItemFulfillmentLine        itemFulfillmentLineOne = CreateItemFulfillmentLine(itemFulfillmentIdOne, carrierOne, itemSkuOne, trackingNumberOne, itemQuantityOne, kitId);
            ItemFulfillmentLine        itemFulfillmentLineTwo = CreateItemFulfillmentLine(itemFulfillmentIdOne, carrierOne, itemSkuTwo, trackingNumberOne, itemQuantityOne, kitId);
            List <ItemFulfillmentLine> itemFulfillments       = new List <ItemFulfillmentLine>()
            {
                itemFulfillmentLineOne, itemFulfillmentLineTwo
            };

            var itemFulfillmentGroups = itemFulfillments.GroupBy(itfil => itfil.ItemFulfillmentId);

            foreach (var itemFulfillmentGroup in itemFulfillmentGroups)
            {
                BigCommerceController.currentItemFulfillment = itemFulfillmentGroup;

                Shipment shipmentToCreate = BigCommerceController.CreateShipmentRequest(itemFulfillmentGroup);

                Assert.Single(shipmentToCreate.Items);
                Assert.Equal(2287, shipmentToCreate.Items[0].order_product_id);
                Assert.Equal(1, shipmentToCreate.Items[0].quantity);
            }
        }
        private static ItemFulfillmentLine CreateItemFulfillmentLine(string itemFulfillmentId, string carrier, string sku, string trackingNumber, int quantity, int?kitId)
        {
            ItemFulfillmentLine itemFulfillmentLine = new ItemFulfillmentLine();

            itemFulfillmentLine.ItemFulfillmentId = itemFulfillmentId;
            itemFulfillmentLine.Carrier           = carrier;
            itemFulfillmentLine.SKU            = sku;
            itemFulfillmentLine.TrackingNumber = trackingNumber;
            itemFulfillmentLine.Quantity       = quantity;
            itemFulfillmentLine.KitId          = kitId;

            return(itemFulfillmentLine);
        }
        public void WillGetItemQuantity()
        {
            BigCommerceController.bigCommerceOrderId = 130;
            var itemFulfillment = new ItemFulfillmentLine();

            itemFulfillment.KitId    = 3022285;
            itemFulfillment.Quantity = 12;
            int expectedItemQuantity = 3;

            int itemQuantity = BigCommerceController.GetItemQuantity(itemFulfillment);

            Assert.Equal(expectedItemQuantity, itemQuantity);
        }
        public static int GetItemQuantity(ItemFulfillmentLine itemFulfillmentLine)
        {
            /* NetSuite splits kits into individual lines of member items on the item fulfillment,
             * but Big Commerce ships at the kit level. If item is part of a kit,
             *  use the kit quantity instead of the individual item quantity.
             */
            var kitId = itemFulfillmentLine.KitId;

            if (kitId != null)
            {
                var kit = BuildKit(Convert.ToInt32(kitId));

                return(GetKitShippedQuantity(kit));
            }

            return(itemFulfillmentLine.Quantity);
        }
        public void WillCreateAShipmentRequest()
        {
            BigCommerceController.bigCommerceOrderId = 130;

            ItemFulfillmentLine        itemFulfillmentLineOne   = CreateItemFulfillmentLine(itemFulfillmentIdOne, carrierOne, itemSkuOne, trackingNumberOne, itemQuantityOne, null);
            ItemFulfillmentLine        itemFulfillmentLineTwo   = CreateItemFulfillmentLine(itemFulfillmentIdTwo, carrierTwo, itemSkuTwo, trackingNumberTwo, itemQuantityTwo, null);
            ItemFulfillmentLine        itemFulfillmentLineThree = CreateItemFulfillmentLine(itemFulfillmentIdTwo, carrierTwo, itemSkuThree, trackingNumberTwo, itemQuantityThree, null);
            List <ItemFulfillmentLine> itemFulfillments         = new List <ItemFulfillmentLine>()
            {
                itemFulfillmentLineOne, itemFulfillmentLineTwo, itemFulfillmentLineThree
            };


            var itemFulfillmentGroups = itemFulfillments.GroupBy(itfil => itfil.ItemFulfillmentId);

            foreach (var itemFulfillmentGroup in itemFulfillmentGroups)
            {
                BigCommerceController.currentItemFulfillment = itemFulfillmentGroup;

                Shipment shipmentToCreate = BigCommerceController.CreateShipmentRequest(itemFulfillmentGroup);

                Assert.Equal(orderAddressId, shipmentToCreate.OrderAddressId);

                if (shipmentToCreate.NetSuiteItemFulfillmentId == itemFulfillmentIdOne)
                {
                    Assert.Equal(trackingNumberOne, shipmentToCreate.TrackingNumber);
                    Assert.Equal(expectedCarrierOne, shipmentToCreate.ShippingProvider);

                    // Items
                    foreach (var item in shipmentToCreate.Items)
                    {
                        Assert.Equal(expectedOrderProductIdOne, item.order_product_id);
                        Assert.Equal(itemQuantityOne, item.quantity);
                    }
                }
                else if (shipmentToCreate.NetSuiteItemFulfillmentId == itemFulfillmentIdTwo)
                {
                    Assert.Equal(trackingNumberTwo, shipmentToCreate.TrackingNumber);
                    Assert.Equal(expectedCarrierTwo, shipmentToCreate.ShippingProvider);

                    // Items
                    foreach (var item in shipmentToCreate.Items)
                    {
                        if (item.order_product_id == expectedOrderProductIdTwo)
                        {
                            Assert.Equal(expectedOrderProductIdTwo, item.order_product_id);
                            Assert.Equal(itemQuantityTwo, item.quantity);
                        }
                        else if (item.order_product_id == expectedOrderProductIdThree)
                        {
                            Assert.Equal(expectedOrderProductIdThree, item.order_product_id);
                            Assert.Equal(itemQuantityThree, item.quantity);
                        }
                        else
                        {
                            throw new Exception($"Unexpected order product id {item.order_product_id}");
                        }
                    }
                }
                else
                {
                    throw new Exception($"Unexpected item fulfillment id {shipmentToCreate.NetSuiteItemFulfillmentId}");
                }
            }
        }