Ejemplo n.º 1
0
        public void AdjustInventoryHandler_GetProductInventoryChanges_ForOrderChanges(GenericChangedEntry <CustomerOrder> orderChangedEntry,
                                                                                      IEnumerable <AdjustInventoryOrderChangedEventHandler.ProductInventoryChange> expectedChanges)
        {
            // Arrange
            var inventoryServiceMock = new Mock <IInventoryService>();
            var settingsManagerMock  = new Mock <ISettingsManager>();

            var storeServiceMock = new Mock <IStoreService>();

            storeServiceMock.Setup(x => x.GetById(TestStoreId))
            .Returns(new Store {
                MainFulfillmentCenterId = TestFulfillmentCenterId
            });

            var targetHandler = new AdjustInventoryOrderChangedEventHandler(inventoryServiceMock.Object,
                                                                            storeServiceMock.Object, settingsManagerMock.Object);

            // Act
            var actualChanges = targetHandler.GetProductInventoryChangesFor(orderChangedEntry);

            // Assert
            var equalityComparer = AnonymousComparer.Create((AdjustInventoryOrderChangedEventHandler.ProductInventoryChange x) => $"{x.FulfillmentCenterId} {x.ProductId} {x.QuantityDelta}");

            Assert.Equal(expectedChanges, actualChanges, equalityComparer);
        }
Ejemplo n.º 2
0
        public async Task TryAdjustOrderInventory_TrackInventory_InStockQtyShouldBeEqualExpectedInStockQty(long inStockQty, int quantityDelta, long expectedInStockQty, bool trackInventory)
        {
            // Arrange
            var productId            = Guid.NewGuid().ToString();
            var responseGroup        = ItemResponseGroup.None.ToString();
            var inventoryServiceMock = new Mock <IInventoryService>();
            var itemServiceMock      = new Mock <IItemService>();

            var product       = Mock.Of <CatalogProduct>(t => t.Id == productId && t.TrackInventory == trackInventory);
            var inventoryInfo = Mock.Of <InventoryInfo>(
                x => x.ProductId == productId && x.FulfillmentCenterId == TestFulfillmentCenterId &&
                x.InStockQuantity == inStockQty);
            var productInventoryChange = Mock.Of <ProductInventoryChange>(
                x => x.ProductId == productId && x.FulfillmentCenterId == TestFulfillmentCenterId &&
                x.QuantityDelta == quantityDelta);

            inventoryServiceMock.Setup(x => x.GetProductsInventoryInfosAsync(new[] { productId }, null))
            .ReturnsAsync(new[] { inventoryInfo });

            itemServiceMock.Setup(x => x.GetByIdsAsync(new[] { productId }, responseGroup, null))
            .ReturnsAsync(new[] { product });

            var handler = new AdjustInventoryOrderChangedEventHandler(inventoryServiceMock.Object,
                                                                      Mock.Of <IStoreService>(), Mock.Of <ISettingsManager>(), itemServiceMock.Object);

            // Act
            await handler.TryAdjustOrderInventory(new[] { productInventoryChange });

            // Assert
            inventoryServiceMock.VerifyAll();
            itemServiceMock.VerifyAll();
            Assert.Equal(expectedInStockQty, inventoryInfo.InStockQuantity);
        }
Ejemplo n.º 3
0
        public async Task GetFullfilmentCenterForLineItemAsync_GetAdditionalFfc_FfcFound()
        {
            // Arrange
            var mainFulfillmentCenterId       = "MainFulfillmentCenterId";
            var additionalFulfillmentCenterId = "additionalFulfillmentCenterId";
            var changedOrder = new CustomerOrder
            {
                StoreId = TestStoreId,
                Items   = new List <LineItem> {
                    new LineItem  {
                        Id = "{01234567-89ab-cdef-0123-456789abcdef}", ProductId = "shoes", Quantity = 1
                    }
                }
            };
            var changedEntry = new GenericChangedEntry <CustomerOrder>(changedOrder, changedOrder, EntryState.Added);

            var inventoryServiceMock = new Mock <IInventoryService>();
            var settingsManagerMock  = new Mock <ISettingsManager>();
            var itemServiceMock      = new Mock <IItemService>();

            var storeServiceMock = new Mock <IStoreService>();

            storeServiceMock.Setup(x => x.GetByIdAsync(TestStoreId, It.IsAny <string>()))
            .ReturnsAsync(new Store {
                MainFulfillmentCenterId = mainFulfillmentCenterId, AdditionalFulfillmentCenterIds = new List <string>()
                {
                    additionalFulfillmentCenterId
                }
            });

            inventoryServiceMock.Setup(x => x.GetProductsInventoryInfosAsync(It.IsAny <IEnumerable <string> >(), null))
            .ReturnsAsync(new List <InventoryInfo>()
            {
                new InventoryInfo()
                {
                    InStockQuantity = 0, FulfillmentCenterId = mainFulfillmentCenterId
                },
                new InventoryInfo()
                {
                    InStockQuantity = 10, FulfillmentCenterId = additionalFulfillmentCenterId
                }
            });

            var targetHandler = new AdjustInventoryOrderChangedEventHandler(inventoryServiceMock.Object,
                                                                            storeServiceMock.Object, settingsManagerMock.Object, itemServiceMock.Object);

            // Act
            var actualChanges = await targetHandler.GetProductInventoryChangesFor(changedEntry);

            // Assert
            actualChanges.Should().HaveCount(1);
            actualChanges.First().FulfillmentCenterId.Should().Be(additionalFulfillmentCenterId);
        }