protected virtual async Task <FulfillmentMethod> GetFulfillmentMethodAsync(Overture.ServiceModel.Orders.Cart cart, ShippingMethodViewModel shippingMethodViewModel)
        {
            var param = new GetShippingMethodsParam
            {
                CartName    = cart.Name,
                CustomerId  = cart.CustomerId,
                CultureInfo = new CultureInfo(cart.CultureName),
                Scope       = cart.ScopeId
            };

            var fulfillmentMethods = await FulfillmentMethodRepository.GetCalculatedFulfillmentMethods(param);

            var fulfillmentMethod = fulfillmentMethods.FirstOrDefault(method =>
                                                                      method.Name == shippingMethodViewModel.Name &&
                                                                      method.ShippingProviderId == shippingMethodViewModel.ShippingProviderId);

            if (fulfillmentMethod == null)
            {
                throw new ComposerException(new ErrorViewModel
                {
                    ErrorCode    = "",
                    ErrorMessage = "Unable to find any shipment provider matching the provided parameters."
                });
            }

            return(fulfillmentMethod);
        }
Exemplo n.º 2
0
        public async void WHEN_parameters_ok_SHOULD_invoke_Client()
        {
            //Arrange
            var p = new GetShippingMethodsParam()
            {
                CartName    = GetRandom.String(10),
                CultureInfo = CultureInfo.CurrentCulture,
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(10),
            };
            var ovClientMock = Container.GetMock <IOvertureClient>();

            ovClientMock.Setup(m => m.SendAsync(It.IsNotNull <FindCalculatedFulfillmentMethodsRequest>()))
            .ReturnsAsync(new List <FulfillmentMethod>())
            .Verifiable();
            Container.Use(ovClientMock);
            var sut = Container.CreateInstance <FulfillmentMethodRepository>();


            //Act
            await sut.GetCalculatedFulfillmentMethods(p);

            //Assert
            ovClientMock.Verify();
        }
Exemplo n.º 3
0
        protected virtual string GetShippingFee(Overture.ServiceModel.Orders.Cart cart, CultureInfo cultureInfo)
        {
            if (!cart.GetActiveShipments().Any())
            {
                return(GetFreeShippingPriceLabel(cultureInfo));
            }

            if (cart.FulfillmentCost.HasValue)
            {
                return(GetShippingPrice(cart.FulfillmentCost.Value, cultureInfo));
            }

            var shippingMethodParam = new GetShippingMethodsParam
            {
                CartName    = cart.Name,
                CultureInfo = cultureInfo,
                CustomerId  = cart.CustomerId,
                Scope       = cart.ScopeId
            };

            //TODO: Remove the repository and pass the list of fulfillmentMethods in params
            var fulfillmentMethods = FulfillmentMethodRepository.GetCalculatedFulfillmentMethods(shippingMethodParam).Result;

            if (fulfillmentMethods == null || !fulfillmentMethods.Any())
            {
                return(GetFreeShippingPriceLabel(cultureInfo));
            }

            var cheapestShippingCost = fulfillmentMethods.Min(s => (decimal)s.Cost);

            var price = GetShippingPrice(cheapestShippingCost, cultureInfo);

            return(price);
        }
Exemplo n.º 4
0
        public void When_Passing_null_CartName_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var overtureClient = new Mock <IOvertureClient>();

            var fulfillmentMethods = new List <FulfillmentMethod> {
                new FulfillmentMethod()
            };

            overtureClient.Setup(client => client.SendAsync(It.IsNotNull <FindCalculatedFulfillmentMethodsRequest>()))
            .ReturnsAsync(fulfillmentMethods)
            .Verifiable();

            _container.Use(overtureClient);

            var repository = _container.CreateInstance <FulfillmentMethodRepository>();
            var param      = new GetShippingMethodsParam
            {
                CartName    = null,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(32),
            };

            // Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => repository.GetCalculatedFulfillmentMethods(param));

            //Assert
            exception.ParamName.Should().BeSameAs("param");
            exception.Message.Should().Contain("CartName");
        }
Exemplo n.º 5
0
        public async Task When_Overture_Return_Empty_List_SHOULD_Not_Throw()
        {
            //Arrange
            var overtureClient = new Mock <IOvertureClient>();

            var fulfillmentMethods = new List <FulfillmentMethod> {
                null
            };

            overtureClient.Setup(client => client.SendAsync(It.IsNotNull <FindCalculatedFulfillmentMethodsRequest>()))
            .ReturnsAsync(fulfillmentMethods)
            .Verifiable();

            _container.Use(overtureClient);

            //Act
            var param = new GetShippingMethodsParam
            {
                CartName    = GetRandom.String(32),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(32),
            };

            var repository = _container.CreateInstance <FulfillmentMethodRepository>();
            var result     = await repository.GetCalculatedFulfillmentMethods(param).ConfigureAwait(false);

            //Assert
            result.Should().NotBeNull();
        }
Exemplo n.º 6
0
        public void WHEN_param_is_null_SHOULD_throw_ArgumentNullException()
        {
            //Arrange
            GetShippingMethodsParam p = null;
            var sut = Container.CreateInstance <FulfillmentMethodRepository>();

            //Act
            var ex = Assert.Throws <ArgumentNullException>(async() => await sut.GetCalculatedFulfillmentMethods(p));

            //Assert
            ex.Message.Should().ContainEquivalentOf("param");
        }
Exemplo n.º 7
0
        public void WHEN_CartName_is_null_or_whitespace_SHOULD_throw_ArgumentException(string cartName)
        {
            //Arrange
            var p = new GetShippingMethodsParam()
            {
                CartName    = cartName,
                CultureInfo = CultureInfo.CurrentCulture,
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(10),
            };
            var sut = Container.CreateInstance <FulfillmentMethodRepository>();

            //Act
            var ex = Assert.Throws <ArgumentException>(async() => await sut.GetCalculatedFulfillmentMethods(p));

            //Assert
            ex.ParamName.Should().ContainEquivalentOf("param");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get the Shipping methods available for a shipment.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>The ShippingMethodsViewModel</returns>
        public async virtual Task <ShippingMethodsViewModel> GetShippingMethodsAsync(GetShippingMethodsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param", "param is required");
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException("param.CartName is required", "param");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException("param.Scope is required", "param");
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("param.CustomerId is required", "param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException("param.CultureInfo is required", "param");
            }

            var shippingMethods = await GetFulfillmentMethods(param).ConfigureAwait(false);

            if (shippingMethods == null)
            {
                return(null);
            }

            var shippingMethodViewModels = shippingMethods
                                           .Select(sm => CartViewModelFactory.GetShippingMethodViewModel(sm, param.CultureInfo)).ToList();

            return(new ShippingMethodsViewModel
            {
                ShippingMethods = shippingMethodViewModels
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get the Shipping methods available for a shipment.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>The ShippingMethodsViewModel</returns>
        public async virtual Task <ShippingMethodsViewModel> GetShippingMethodsAsync(GetShippingMethodsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var shippingMethods = await GetFulfillmentMethods(param).ConfigureAwait(false);

            if (shippingMethods == null)
            {
                return(null);
            }

            var shippingMethodViewModels = shippingMethods
                                           .Select(sm => CartViewModelFactory.GetShippingMethodViewModel(sm, param.CultureInfo))
                                           .ToList();

            return(new ShippingMethodsViewModel
            {
                ShippingMethods = shippingMethodViewModels
            });
        }
Exemplo n.º 10
0
 protected virtual Task <List <FulfillmentMethod> > GetFulfillmentMethods(GetShippingMethodsParam param)
 {
     return(FulfillmentMethodRepository.GetCalculatedFulfillmentMethods(param));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Get the Shipping methods available for a shipment. Calls the GetCart to get the shipment Id.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>The ShippingMethodsViewModel</returns>
        public async virtual Task <ShippingMethodsViewModel> GetRecurringCartShippingMethodsAsync(GetShippingMethodsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param", "param is required");
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException("param.CartName is required", "param");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException("param.Scope is required", "param");
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("param.CustomerId is required", "param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException("param.CultureInfo is required", "param");
            }
            //misleading method name, creates a cart if it does not exist, not just a "get" call
            await CartRepository.GetCartAsync(new GetCartParam
            {
                BaseUrl     = string.Empty,
                CartName    = param.CartName,
                CultureInfo = param.CultureInfo,
                CustomerId  = param.CustomerId,
                Scope       = param.Scope
            }).ConfigureAwait(false);

            return(await GetShippingMethodsAsync(param));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get the Shipping methods available for a shipment.
        /// The Cost and Expected Delivery Date are calculated in overture.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>The ShippingMethodsViewModel</returns>
        /// <remarks>This cannot be cached because Overture may include custom logic depending on the current cart state.</remarks>
        public virtual Task <List <FulfillmentMethod> > GetCalculatedFulfillmentMethods(GetShippingMethodsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }

            var request = new FindCalculatedFulfillmentMethodsRequest
            {
                CartName   = param.CartName,
                CustomerId = param.CustomerId,
                ScopeId    = param.Scope,
                ShipmentId = param.ShipmentId
            };

            return(OvertureClient.SendAsync(request));
        }
Exemplo n.º 13
0
        public async virtual Task <ShippingMethodTypesViewModel> GetShippingMethodTypesAsync(GetShippingMethodsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var shippingMethods = await GetFulfillmentMethods(param).ConfigureAwait(false);

            if (shippingMethods == null)
            {
                return(null);
            }

            var shippingMethodTypeViewModels = shippingMethods
                                               .Select(sm => CartViewModelFactory.GetShippingMethodViewModel(sm, param.CultureInfo))
                                               .Where(FilterShippingMethodView)
                                               .GroupBy(sm => sm.FulfillmentMethodType)
                                               .Select(type => CartViewModelFactory.GetShippingMethodTypeViewModel(type.Key, type.ToList(), param.CultureInfo))
                                               .OrderBy(OrderShippingMethodTypeView)
                                               .ToList();

            return(new ShippingMethodTypesViewModel
            {
                ShippingMethodTypes = shippingMethodTypeViewModels
            });
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get the Shipping methods available for a shipment.
        /// The Cost and Expected Delivery Date are calculated in overture.
        /// </summary>
        /// <param name="param"></param>
        /// <returns>The ShippingMethodsViewModel</returns>
        /// <remarks>This cannot be cached because Overture may include custom logic depending on the current cart state.</remarks>
        public virtual Task <List <FulfillmentMethod> > GetCalculatedFulfillmentMethods(GetShippingMethodsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CartName"), "param");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Scope"), "param");
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CustomerId"), "param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CultureInfo"), "param");
            }

            var request = new FindCalculatedFulfillmentMethodsRequest
            {
                CartName   = param.CartName,
                CustomerId = param.CustomerId,
                ScopeId    = param.Scope,
                ShipmentId = param.ShipmentId
            };

            return(OvertureClient.SendAsync(request));
        }