public void WHEN_null_cultureInfo_SHOULD_throw_ArgumentException_with_details() { //Arrange var p = new RemoveLineItemsParam { CartName = GetRandom.String(7), CultureInfo = null, CustomerId = GetRandom.Guid(), LineItems = new List <RemoveLineItemsParam.LineItemDescriptor> { new RemoveLineItemsParam.LineItemDescriptor { Id = GetRandom.Guid(), ProductId = GetRandom.String(7), VariantId = GetRandom.String(7) } }, Scope = GetRandom.String(7) }; var sut = Container.CreateInstance <CartRepository>(); //Act var exception = Assert.ThrowsAsync <ArgumentException>(() => sut.RemoveLineItemsAsync(p)); //Assert exception.ParamName.Should().NotBeNullOrWhiteSpace(); exception.Message.Should().ContainEquivalentOf("CultureInfo"); }
/// <summary> /// Removes many line items from the cart at once. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual Task <ProcessedCart> RemoveLineItemsAsync(RemoveLineItemsParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Scope"), "param"); } if (String.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CartName"), "param"); } if (param.CultureInfo == null) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CultureInfo"), "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CustomerId"), "param"); } if (param.LineItems == null) { throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("LineItems"), "param"); } if (param.LineItems.Any(li => li.Id == Guid.Empty)) { throw new ArgumentException("LineItems may not contain an empty Guid for Id", "param"); } if (param.LineItems.Any(li => String.IsNullOrWhiteSpace(li.ProductId))) { throw new ArgumentException("LineItems may not contain an empty string for ProductId", "param"); } var request = new AddOrUpdateLineItemsRequest { CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, LineItems = param.LineItems.Select(li => new LineItemInfo { Id = li.Id, ProductId = li.ProductId, VariantId = li.VariantId, Quantity = 0.0, RecurringOrderFrequencyName = string.Empty, RecurringOrderProgramName = string.Empty, }).ToList() }; var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
/// <summary> /// Removes many line items from the cart at once. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual Task <ProcessedCart> RemoveLineItemsAsync(RemoveLineItemsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.LineItems == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.LineItems)), nameof(param)); } var array = new Guid[param.LineItems.Count]; for (int i = 0; i < param.LineItems.Count; i++) { var currentLine = param.LineItems[i]; if (currentLine.Id == Guid.Empty) { throw new InvalidOperationException($"Line item with index {i} has empty id"); } else if (string.IsNullOrWhiteSpace(currentLine.ProductId)) { throw new InvalidOperationException($"Line item with index {i} has null or white space product id"); } array[i] = currentLine.Id; } var request = new RemoveLineItemsRequest { CartName = param.CartName, CartType = param.CartType, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, LineItemIds = array }; var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }
public virtual async Task <CartViewModel> RemoveInvalidLineItemsAsync(RemoveInvalidLineItemsParam param) { if (param == null) { throw new ArgumentNullException("param"); } var cart = await CartRepository.GetCartAsync(new GetCartParam { CartName = param.CartName, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, ExecuteWorkflow = param.ExecuteWorkflow, Scope = param.Scope, WorkflowToExecute = param.WorkflowToExecute }).ConfigureAwait(false); var invalidLineItems = LineItemService.GetInvalidLineItems(cart); if (invalidLineItems.Any()) { var p = new RemoveLineItemsParam { CartName = param.CartName, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, Scope = param.Scope, LineItems = invalidLineItems.Select(li => new RemoveLineItemsParam.LineItemDescriptor { Id = li.Id, ProductId = li.ProductId, VariantId = li.VariantId }).ToList() }; cart = await CartRepository.RemoveLineItemsAsync(p).ConfigureAwait(false); } var vmParam = new CreateCartViewModelParam { Cart = cart, CultureInfo = param.CultureInfo, BaseUrl = param.BaseUrl }; var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false); return(viewModel); }
public virtual async Task <ProcessedCart> ProcessInvalidLineItemsRemovalAsync(RemoveInvalidLineItemsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } var cart = await CartRepository.GetCartAsync(new GetCartParam { CartName = param.CartName, CartType = param.CartType, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, ExecuteWorkflow = param.ExecuteWorkflow, Scope = param.Scope, WorkflowToExecute = param.WorkflowToExecute }).ConfigureAwait(false); var invalidLineItems = LineItemService.GetInvalidLineItems(cart); if (invalidLineItems.Any()) { var p = new RemoveLineItemsParam { CartName = param.CartName, CartType = param.CartType, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, Scope = param.Scope, LineItems = invalidLineItems.Select(li => new RemoveLineItemsParam.LineItemDescriptor { Id = li.Id, ProductId = li.ProductId, VariantId = li.VariantId }).ToList() }; cart = await CartRepository.RemoveLineItemsAsync(p).ConfigureAwait(false); } return(cart); }
public void WHEN_null_LineItems_SHOULD_throw_ArgumentException_with_details() { //Arrange var p = new RemoveLineItemsParam { CartName = GetRandom.String(7), CultureInfo = ForTests.TestingExtensions.GetRandomCulture(), CustomerId = GetRandom.Guid(), LineItems = null, Scope = GetRandom.String(7) }; var sut = Container.CreateInstance <CartRepository>(); //Act var exception = Assert.ThrowsAsync <ArgumentException>(() => sut.RemoveLineItemsAsync(p)); //Assert exception.ParamName.Should().NotBeNullOrWhiteSpace(); exception.Message.Should().ContainEquivalentOf("LineItems"); }
public Task <ProcessedCart> RemoveLineItemsAsync(RemoveLineItemsParam param) { throw new NotImplementedException(); }
/// <summary> /// Removes many line items from the cart at once. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual Task <ProcessedCart> RemoveLineItemsAsync(RemoveLineItemsParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param)); } if (param.LineItems == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.LineItems)), nameof(param)); } var list = new List <LineItemInfo>(); for (int i = 0; i < param.LineItems.Count; i++) { var currentLine = param.LineItems[i]; if (currentLine.Id == Guid.Empty) { throw new InvalidOperationException($"Line item with index {i} has empty id"); } else if (string.IsNullOrWhiteSpace(currentLine.ProductId)) { throw new InvalidOperationException($"Line item with index {i} has null or white space product id"); } list.Add(new LineItemInfo { Id = currentLine.Id, ProductId = currentLine.ProductId, VariantId = currentLine.VariantId, Quantity = 0.0, RecurringOrderFrequencyName = string.Empty, RecurringOrderProgramName = string.Empty, }); } //Removing method, but AddOrUpdate request, it is unclear var request = new AddOrUpdateLineItemsRequest { CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, LineItems = list }; var cacheKey = BuildCartCacheKey(param.Scope, param.CustomerId, param.CartName); return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request))); }