public void WHEN_Param_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope, string cultureName, string cartName, string customerId, string productId, int quantity, string paramName) { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <WishListRepository>(); var param = new AddLineItemParam { Scope = scope, CultureInfo = string.IsNullOrWhiteSpace(cultureName) ? null : CultureInfo.GetCultureInfo(cultureName), CustomerId = string.IsNullOrWhiteSpace(customerId) ? Guid.Empty : GetRandom.Guid(), CartName = cartName, ProductId = productId, VariantId = GetRandom.String(10), Quantity = quantity }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => repository.AddLineItemAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain(paramName); }
/// <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)); } var cart = await CartRepository.AddLineItemAsync(param).ConfigureAwait(false); var fixedCart = await FixCartService.FixCartAsync(new FixCartParam { Cart = cart }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = fixedCart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = false, 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("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException("param.ProductId is required", "param"); } if (param.Quantity <= 0) { throw new ArgumentException("param.Quantity is required", "param"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException("param.BaseUrl is required", "param"); } var cart = await CartRepository.AddLineItemAsync(param).ConfigureAwait(false); var fixedCart = await FixCartService.FixCartAsync(new FixCartParam { Cart = cart }).ConfigureAwait(false); var vmParam = new CreateCartViewModelParam { Cart = fixedCart, CultureInfo = param.CultureInfo, IncludeInvalidCouponsMessages = false, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
protected virtual AddLineItemRequest BuildAddLineItemRequestFromParam(AddLineItemParam param) { return(new AddLineItemRequest { ScopeId = param.Scope, CultureName = param.CultureInfo.Name, CartName = param.CartName, CustomerId = param.CustomerId, ProductId = param.ProductId, Quantity = param.Quantity, VariantId = param.VariantId, RecurringOrderFrequencyName = param.RecurringOrderFrequencyName, RecurringOrderProgramName = param.RecurringOrderProgramName }); }
private async Task <LineItem> GetExistingLineItem(AddLineItemParam param) { var getCartParam = new GetCartParam { CartName = param.CartName, Scope = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, CartType = param.CartType, BaseUrl = param.BaseUrl }; var cart = await CartRepository.GetCartAsync(getCartParam).ConfigureAwait(false); return(cart?.GetLineItems()?.Find(x => x.ProductId == param.ProductId && x.VariantId == param.VariantId && !x.IsGiftItem)); }
public virtual async Task <WishListSummaryViewModel> 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)); } var wishList = await WishListRepository.AddLineItemAsync(param).ConfigureAwait(false); return(CreateSummaryWishListViewModel(new CreateWishListViewModelParam { WishList = wishList, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl })); }
public virtual async Task <WishListSummaryViewModel> AddLineItemAsync(AddLineItemParam param) { if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo", "param"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException("param.ProductId is required", "param"); } if (param.Quantity <= 0) { throw new ArgumentException("param.Quantity is required", "param"); } if (string.IsNullOrWhiteSpace(param.BaseUrl)) { throw new ArgumentException("param.BaseUrl is required", "param"); } var wishList = await WishListRepository.AddLineItemAsync(param).ConfigureAwait(false); return(CreateSummaryWishListViewModel(new CreateWishListViewModelParam { WishList = wishList, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl })); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { var service = _container.CreateInstance <CartService>(); var param = new AddLineItemParam { Scope = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ProductId = GetRandom.String(32), VariantId = GetRandom.String(32), Quantity = GetRandom.PositiveInt(), BaseUrl = GetRandom.String(32) }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => service.AddLineItemAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain("param.Scope"); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { var service = _container.CreateInstance <CartService>(); var param = new AddLineItemParam { Scope = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ProductId = GetRandom.String(32), VariantId = GetRandom.String(32), Quantity = GetRandom.PositiveInt(), BaseUrl = GetRandom.String(32) }; // Act Expression <Func <Task <CartViewModel> > > expression = () => service.AddLineItemAsync(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.Scope))); }
public void WHEN_Quantity_Is_Not_Positive_SHOULD_Throw_ArgumentOutOfRangeException(int quantity) { var service = _container.CreateInstance <CartService>(); var param = new AddLineItemParam { Scope = GetRandom.String(32), CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ProductId = GetRandom.String(32), VariantId = GetRandom.String(32), Quantity = quantity, BaseUrl = GetRandom.String(32) }; // Act Expression <Func <Task <CartViewModel> > > expression = () => service.AddLineItemAsync(param); var exception = Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => service.AddLineItemAsync(param)); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfZeroNegative(nameof(param.Quantity))); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <CartRepository>(); var param = new AddLineItemParam { Scope = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ProductId = GetRandom.String(32), VariantId = GetRandom.String(32), Quantity = GetRandom.Int(1, 10) }; // Act var exception = Assert.ThrowsAsync <ArgumentException>(() => repository.AddLineItemAsync(param)); //Assert exception.ParamName.Should().BeSameAs("param"); exception.Message.Should().Contain("param.Scope"); }
public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope) { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <CartRepository>(); var param = new AddLineItemParam { Scope = scope, CultureInfo = TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), CartName = GetRandom.String(32), ProductId = GetRandom.String(32), VariantId = GetRandom.String(32), Quantity = GetRandom.Int(1, 10) }; // Act Expression <Func <Task <ProcessedCart> > > expression = () => repository.AddLineItemAsync(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.Scope))); }
/// <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 full and updated cart details</returns> public virtual Task <ProcessedCart> AddLineItemAsync(AddLineItemParam param) { if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope 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.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } if (string.IsNullOrWhiteSpace(param.ProductId)) { throw new ArgumentException("param.ProductId is required", "param"); } if (param.Quantity <= 0) { throw new ArgumentException("param.Quantity must be positive, greater than 0", "param"); } var request = BuildAddLineItemRequestFromParam(param); var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
public void WHEN_ProductId_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string productId) { // Arrange _container.Use(OvertureClientFactory.Create()); var repository = _container.CreateInstance <WishListRepository>(); var param = new AddLineItemParam { Scope = "Canada", CultureInfo = CultureInfo.GetCultureInfo("en-CA"), CustomerId = Guid.NewGuid(), CartName = "WishList", ProductId = productId, VariantId = "VariantId", Quantity = 1 }; // Act Expression <Func <Task <ProcessedCart> > > expression = () => repository.AddLineItemAsync(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.ProductId))); }
/// <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 full and updated cart details</returns> public virtual Task <ProcessedCart> 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))); } var request = BuildAddLineItemRequestFromParam(param); var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
/// <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); }
public Task <ProcessedCart> AddLineItemAsync(AddLineItemParam param) { throw new NotImplementedException(); }