Exemplo n.º 1
0
        public void ShouldCreateStockQuantityDocument()
        {
            var warehouseAvailableStock = new WarehouseAvailableStockItem("FC01", "ABC", 20, 0, 0, DateTime.UtcNow);
            var stockQuantity           = new RegionStockDocument(1234, new[] { warehouseAvailableStock }, new[] { new RegionStockItem("US", 20, new RegionStockItemStatus(10, StockStatus.InStock), new[] { warehouseAvailableStock }, DateTime.UtcNow) });

            _stockQuantityDocumentDb.CreateRegionStock(stockQuantity).Wait();
        }
Exemplo n.º 2
0
        public void WhenCreatingStockQuantityAndDuplicateExistsThenShouldThrowException()
        {
            var warehouseAvailableStock = new WarehouseAvailableStockItem("FC01", "ABC", 20, 0, 0, DateTime.UtcNow);
            var stockQuantity           = new RegionStockDocument(123, new[] { warehouseAvailableStock }, new[] { new RegionStockItem("US", 20, new RegionStockItemStatus(10, StockStatus.InStock), new[] { warehouseAvailableStock }, DateTime.UtcNow) });

            Assert.Throws <DocumentClientException>(() => _stockQuantityDocumentDb.CreateRegionStock(stockQuantity).Wait());
        }
Exemplo n.º 3
0
        public void ShouldGetStockQuantity()
        {
            var warehouseAvailableStock = new WarehouseAvailableStockItem("FC01", "ABC", 20, 0, 0, DateTime.UtcNow);
            var expectedStockQuantity   = new RegionStockDocument(123, new[] { warehouseAvailableStock }, new[] { new RegionStockItem("US", 20, new RegionStockItemStatus(10, StockStatus.InStock), new[] { warehouseAvailableStock }, DateTime.UtcNow) });

            var actualStockQuantity = _stockQuantityDocumentDb.GetRegionStockByVariantId(expectedStockQuantity.VariantId);

            Assert.IsNotNull(actualStockQuantity);
            Assert.AreEqual(expectedStockQuantity.VariantId, actualStockQuantity.VariantId);
            Assert.AreEqual(expectedStockQuantity.Id, actualStockQuantity.Id);
        }
Exemplo n.º 4
0
        public void OnMessage(IWarehouseAvailableStockChangedV1 message)
        {
            var requestTelemetry = RequestTelemetryHelper.Start("Warehouse Stock Changed Processing Rate", DateTime.UtcNow);

            CallContext.LogicalSetData(CORRELATION_SLOT, requestTelemetry.Id);
            Stopwatch requestTimer = Stopwatch.StartNew();

            if (message == null)
            {
                throw new ArgumentNullException();
            }

            var skuVariant = _skuVariantCacheManager.GetItemByKey(message.Sku);

            if (skuVariant == null)
            {
                throw new Exception($"Sku Variant Not Found For Restriction Attribute Accepted with Sku: {message.Sku}");
            }

            var regionStock = _regionStockAggregateStore.GetRegionStockByVariantId(skuVariant.VariantId);

            if (regionStock != null)
            {
                IRegionStockAggregate regionStockAggregate = new RegionStockAggregate(regionStock.VariantId,
                                                                                      regionStock.WarehouseAvailableStocks.ToList(),
                                                                                      regionStock.RegionStocks.ToList(), null, regionStock.Version);

                regionStockAggregate.ApplyStockChanges(new WarehouseAvailableStockItem(message.FulfilmentCentre,
                                                                                       message.Sku, message.Pickable, message.Reserved, message.Allocated, message.Version));

                _regionStockAggregateStore.UpdateRegionStock(RegionStockDocument.CreateFrom(regionStockAggregate));

                PublishRegionStockChanged(regionStockAggregate);
            }
            else
            {
                throw new RegionStockAggregateNotFoundException($"Failed retrieving Region Stock Aggregate for Sku {message.Sku}");
            }

            RequestTelemetryHelper.Dispatch(_telemetryClient, requestTelemetry, requestTimer.Elapsed, true);
        }