Example #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);
        }
Example #2
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);
        }