示例#1
0
 private bool ProductEquals(WcProduct wcProduct, DbProduct dbProduct)
 {
     return
         (wcProduct.StockStatus == dbProduct.GetStockStatus() &&
          wcProduct.Availability == dbProduct.GetAvailability() &&
          ProductPriceEquals(wcProduct, dbProduct));
 }
示例#2
0
        public async Task TestUpdateProductCalledWhenPriceDiffers(decimal regularPrice, decimal salePrice)
        {
            // Arrange
            DefaultDbProduct.Availability.First().Price = 10000;
            DefaultWcProduct.RegularPrice = regularPrice;
            DefaultWcProduct.SalePrice    = salePrice;

            // Act
            await _productService.UpdateAllProductsAsync();

            // Assert
            _wcProductServiceMock.Verify(
                s => s.UpdateProduct(
                    DefaultDbProduct.Id,
                    DefaultDbProduct.GetStockStatus(),
                    DefaultDbProduct.GetAvailability(),
                    10000,
                    9700),
                Times.Once);
        }
示例#3
0
        private async Task UpdateProduct(WcProduct wcProduct, DbProduct dbProduct)
        {
            if (wcProduct == null)
            {
                _logger.LogError($"{nameof(wcProduct)} should not be null");
            }

            try
            {
                var stockStatus  = dbProduct.GetStockStatus();
                var availability = dbProduct.GetAvailability();
                (var price, var salePrice) = _priceCalculator.GetPrice(dbProduct);

                if (wcProduct.FixedPrice)
                {
                    price     = wcProduct.RegularPrice;
                    salePrice = wcProduct.SalePrice;
                }

                _logger.LogInformation(
                    $"Updating product {wcProduct.Name} - {wcProduct.Sku} from {wcProduct.StockStatus} - " +
                    $"\"{wcProduct.Availability}\" price: {wcProduct.RegularPrice:F0}/{wcProduct.SalePrice:F0} to " +
                    $"{stockStatus} - \"{availability}\", price: {price:F0}/{salePrice:F0}");
                await _wcProductService.UpdateProduct(wcProduct.Id, stockStatus, availability, price, salePrice);

                await Task.Delay(Consts.RequestDelay);
            }
            catch (WebException e)
            {
                _logger.LogError(e, $"Failed to {nameof(_wcProductService.UpdateProduct)} for {wcProduct.Name} - {wcProduct.Sku}");
                await Task.Delay(Consts.FailedRequestDelay);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Failed to {nameof(_wcProductService.UpdateProduct)} for {wcProduct.Name} - {wcProduct.Sku}");
            }
        }