public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { var service = _container.CreateInstance <CartService>(); var param = new UpdateLineItemParam { ScopeId = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), LineItemId = GetRandom.Guid(), GiftMessage = GetRandom.String(32), GiftWrap = GetRandom.Boolean(), Quantity = GetRandom.PositiveInt(), BaseUrl = GetRandom.String(32) }; // Act Expression <Func <Task <CartViewModel> > > expression = () => service.UpdateLineItemAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.ScopeId))); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <CartRepository>(); var param = new UpdateLineItemParam { ScopeId = null, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), LineItemId = GetRandom.Guid(), Quantity = GetRandom.PositiveInt(), GiftMessage = GetRandom.String(32), GiftWrap = GetRandom.Boolean(), }; // Act Expression <Func <Task <ProcessedCart> > > expression = () => repository.UpdateLineItemAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.ScopeId))); }
/// <summary> /// Update a lineItem in the cart /// </summary> /// <param name="param"></param> /// <returns>The full and updated cart details</returns> public virtual Task <ProcessedCart> UpdateLineItemAsync(UpdateLineItemParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.ScopeId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ScopeId)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.LineItemId)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.Quantity < 1) { throw new ArgumentOutOfRangeException(nameof(param), param.Quantity, GetMessageOfZeroNegative(nameof(param.Quantity))); } var request = new UpdateLineItemRequest { CartName = param.CartName, CultureName = param.CultureInfo.Name, CartType = param.CartType, CustomerId = param.CustomerId, GiftMessage = param.GiftMessage, GiftWrap = param.GiftWrap, Id = param.LineItemId, PropertyBag = param.PropertyBag, Quantity = param.Quantity, ScopeId = param.ScopeId, RecurringOrderFrequencyName = param.RecurringOrderFrequencyName, RecurringOrderProgramName = param.RecurringOrderProgramName }; var cacheKey = BuildCartCacheKey(param.ScopeId, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
/// <summary> /// Update a lineItem in the cart /// </summary> /// <param name="param"></param> /// <returns>The full and updated cart details</returns> public virtual Task <ProcessedCart> UpdateLineItemAsync(UpdateLineItemParam param) { if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.ScopeId)) { throw new ArgumentException("param.ScopeId is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo is required", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException("param.LineItemId is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (param.Quantity < 1) { throw new ArgumentException("param.Quantity should be 0 or greater", "param"); } var request = new UpdateLineItemRequest { CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, GiftMessage = param.GiftMessage, GiftWrap = param.GiftWrap, Id = param.LineItemId, PropertyBag = param.PropertyBag, Quantity = param.Quantity, ScopeId = param.ScopeId, RecurringOrderFrequencyName = param.RecurringOrderFrequencyName, RecurringOrderProgramName = param.RecurringOrderProgramName }; var cacheKey = BuildCartCacheKey(param.ScopeId, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <CartRepository>(); var param = new UpdateLineItemParam { ScopeId = null, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), LineItemId = GetRandom.Guid(), Quantity = GetRandom.PositiveInt(), GiftMessage = GetRandom.String(32), GiftWrap = GetRandom.Boolean(), }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => repository.UpdateLineItemAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain("param.ScopeId"); }
/// <summary> /// Update a line item in the cart. /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> UpdateLineItemAsync(UpdateLineItemParam 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.ScopeId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ScopeId)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.LineItemId)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.Quantity < 1) { throw new ArgumentOutOfRangeException(nameof(param), param.Quantity, GetMessageOfZeroNegative(nameof(param.Quantity))); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param)); } ProcessedCart cart; try { cart = await CartRepository.UpdateLineItemAsync(param).ConfigureAwait(false); } catch (ComposerException ex) { ClearEditModeIfCartDraftDoesNotExist(param.CartType, ex); throw; } await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CartType = param.CartType, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.ScopeId }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
/// <summary> /// Add line item to the cart. /// /// CartName will be created if needed /// CustomerId (guest customers) will be created if needed /// If the (product,variant) is already in the cart, the quantity will be increased; /// otherwise a new line will be added /// /// param.VariantId is optional /// /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> AddLineItemAsync(AddLineItemParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ProductId)), nameof(param)); } if (param.Quantity < 1) { throw new ArgumentOutOfRangeException(nameof(param), param.Quantity, GetMessageOfZeroNegative(nameof(param.Quantity))); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param)); } ProcessedCart cart; try { //If editing order, and line item exists, updating it instead if (param.CartType == CartConfiguration.OrderDraftCartType) { var existingLineItem = await GetExistingLineItem(param).ConfigureAwait(false); if (existingLineItem != null) { var updateLineItemParam = new UpdateLineItemParam { BaseUrl = param.BaseUrl, CartName = param.CartName, CartType = param.CartType, ScopeId = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, LineItemId = existingLineItem.Id, Quantity = param.Quantity + existingLineItem.Quantity, RecurringOrderFrequencyName = param.RecurringOrderFrequencyName, RecurringOrderProgramName = param.RecurringOrderProgramName }; return(await UpdateLineItemAsync(updateLineItemParam).ConfigureAwait(false)); } } cart = await CartRepository.AddLineItemAsync(param).ConfigureAwait(false); } catch (ComposerException ex) { ClearEditModeIfCartDraftDoesNotExist(param.CartType, ex); throw; } if (cart.CartType != CartConfiguration.OrderDraftCartType) { cart = await FixCartService.FixCartAsync(new FixCartParam { Cart = cart, ScopeId = param.Scope }).ConfigureAwait(false); } var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = false, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
/// <summary> /// Update a line item in the cart. /// </summary> /// <param name="param"></param> /// <returns>The Lightweight CartViewModel</returns> public async virtual Task <CartViewModel> UpdateLineItemAsync(UpdateLineItemParam 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.ScopeId)) { throw new ArgumentException("param.ScopeId is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo is required", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException("param.LineItemId is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (param.Quantity < 1) { throw new ArgumentException("param.Quantity must be greater than 0", "param"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException("param.BaseUrl is required", "param"); } var cart = await CartRepository.UpdateLineItemAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.ScopeId }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
public Task <ProcessedCart> UpdateLineItemAsync(UpdateLineItemParam param) { throw new NotImplementedException(); }
public virtual async Task <CartViewModel> UpdateLineItemAsync(UpdateLineItemParam param) { if (!RecurringOrdersSettings.Enabled) { return(new CartViewModel()); } 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.ScopeId)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ScopeId)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.LineItemId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.LineItemId)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.Quantity < 1) { throw new ArgumentOutOfRangeException(nameof(param), param.Quantity, GetMessageOfZeroNegative(nameof(param.Quantity))); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param)); } var cart = await CartRepository.UpdateLineItemAsync(param).ConfigureAwait(false); await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam { CartName = param.CartName, CouponCodes = CouponViewService.GetInvalidCouponsCode(cart.Coupons).ToList(), CustomerId = param.CustomerId, Scope = param.ScopeId }); var vmParam = new CreateRecurringOrderCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = true, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam); return(viewModel); }