internal static Mock <IWishListRepository> Create() { var dummyCart = new ProcessedCart { CustomerId = Guid.NewGuid(), Shipments = new List <Shipment> { new Shipment() }, BillingCurrency = GetRandom.String(1), CartType = GetRandom.String(1), Name = GetRandom.String(1), ScopeId = GetRandom.String(1), Status = GetRandom.String(1) }; var repository = new Mock <IWishListRepository>(); repository.Setup(repo => repo.GetWishListAsync(It.IsNotNull <GetCartParam>())) .ReturnsAsync(dummyCart) .Verifiable(); repository.Setup(repo => repo.AddLineItemAsync(It.IsNotNull <AddLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); repository.Setup(repo => repo.RemoveLineItemAsync(It.IsNotNull <RemoveLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); return(repository); }
public void SetUp() { //Arrange _container = new AutoMocker(); _repository = _container.CreateInstance <CartRepository>(); var cacheProvider = _container.GetMock <ICacheProvider>(); cacheProvider .Setup(provider => provider.GetOrAddAsync( It.IsNotNull <CacheKey>(), It.IsNotNull <Func <Task <ProcessedCart> > >(), It.IsAny <Func <ProcessedCart, Task> >(), It.IsAny <CacheKey>())) .Returns <CacheKey, Func <Task <ProcessedCart> >, Func <ProcessedCart, Task>, CacheKey>( (key, func, arg3, arg4) => func()) .Verifiable(); var overtureClient = _container.GetMock <IOvertureClient>(); var dummyCart = new ProcessedCart(); overtureClient .Setup(client => client.SendAsync( It.IsNotNull <GetCartRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); }
private Mock <IOvertureClient> CreateOvertureClientMock() { var clientMock = _container.GetMock <IOvertureClient>(); clientMock.Setup(ov => ov.SendAsync(It.IsNotNull <AddPaymentRequest>())) .Returns((AddPaymentRequest r) => { var cart = new ProcessedCart { Id = GetRandom.Guid(), ScopeId = r.ScopeId, CustomerId = r.CustomerId, Name = r.CartName, CultureName = r.CultureName, Payments = new List <Payment> { new Payment { PaymentStatus = PaymentStatus.New, Id = GetRandom.Guid(), BillingAddress = r.BillingAddress, Amount = r.Amount.GetValueOrDefault() } } }; return(Task.FromResult(cart)); }).Verifiable("Overture call for 'AddPaymentRequest' was not made."); return(clientMock); }
internal static Mock <IOvertureClient> CreateMockWithValue(ProcessedCart cart) { var overtureClient = new Mock <IOvertureClient>(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <GetCartRequest>())) .ReturnsAsync(cart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <AddLineItemRequest>())) .ReturnsAsync(cart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <AddPaymentRequest>())) .ReturnsAsync(cart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <RemoveLineItemRequest>())) .ReturnsAsync(cart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <UpdateLineItemRequest>())) .ReturnsAsync(cart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <UpdateShipmentRequest>())) .ReturnsAsync(cart) .Verifiable(); return(overtureClient); }
private CheckoutService CreateCheckoutService(ProcessedCart cart) { var mockedLookupService = new Mock <ILookupService>(); var mockedImageService = new Mock <IImageService>(); mockedLookupService.Setup(a => a.GetLookupDisplayNamesAsync(It.IsAny <GetLookupDisplayNamesParam>())).ReturnsAsync( new Dictionary <string, string> { { "Cash", "TestDisplayName" } }); mockedImageService.Setup(a => a.GetImageUrlsAsync(It.IsAny <IEnumerable <LineItem> >())).ReturnsAsync(new List <ProductMainImage>()); _container.Use(mockedImageService); _container.Use(mockedLookupService); var mockedDamProvider = new Mock <IDamProvider>(); mockedDamProvider.Setup(x => x.GetProductMainImagesAsync(It.IsAny <GetProductMainImagesParam>())) .ReturnsAsync(new List <ProductMainImage>()); _container.Use(mockedDamProvider); var mockedAddressRepository = new Mock <IAddressRepository>(); var address = new Address() { PropertyBag = new PropertyBag(), FirstName = GetRandom.String(5), LastName = GetRandom.String(5), AddressName = GetRandom.String(5), Line2 = GetRandom.String(5), Line1 = GetRandom.String(5), CountryCode = GetRandom.String(3), City = GetRandom.String(5), PostalCode = GetRandom.String(5), PhoneNumber = GetRandom.String(5), RegionCode = GetRandom.String(5), Email = GetRandom.String(5), PhoneExtension = GetRandom.String(5), }; mockedAddressRepository.Setup(x => x.GetAddressByIdAsync(It.IsAny <Guid>())) .Returns((Guid id) => { var result = address; result.Id = id; return(Task.FromResult(result)); }); _container.Use(mockedAddressRepository); _container.Use <ILocalizationProvider>(LocalizationProviderFactory.Create()); _container.Use <IViewModelMapper>(ViewModelMapper); _container.Use <ICartRepository>(new CartRepositoryUpdateCartMock { CurrentCart = cart }); _container.Use <IComposerJsonSerializer>(new ComposerJsonSerializerMock(MetadataRegistry.Object, ViewModelMapper)); var cartViewModelFactory = _container.CreateInstance <CartViewModelFactory>(); _container.Use <ICartViewModelFactory>(cartViewModelFactory); return(_container.CreateInstance <CheckoutService>()); }
private static ProcessedCart CreateBasicCart() { var cart = new ProcessedCart { CultureName = "en-US", Shipments = new List <Shipment> { new Shipment() { Id = GetRandom.Guid() } }, Payments = new List <Payment>() { new Payment() { PaymentStatus = PaymentStatus.New } }, Total = 10, Customer = new CustomerSummary() }; return(cart); }
private void MockGetCart(PaymentMethod activePaymentMethod = null) { var cartRepoMock = _container.GetMock <ICartRepository>(); cartRepoMock.Setup(repo => repo.GetCartAsync(It.IsAny <GetCartParam>())) .Returns((GetCartParam p) => { var cart = new ProcessedCart() { ScopeId = p.Scope, CustomerId = p.CustomerId, CultureName = p.CultureInfo.Name, Name = p.CartName, Payments = new List <Payment> { new Payment { Id = GetRandom.Guid(), PaymentStatus = PaymentStatus.New, BillingAddress = new Address(), PaymentMethod = activePaymentMethod } } }; return(Task.FromResult(cart)); }); }
public void WHEN_no_message_in_cart_SHOULD_return_all_valid_line_item() { //Arrange var cart = new ProcessedCart { Messages = GetRandom.Boolean() ? null : new List <ExecutionMessage>() }; var lineItems = new List <LineItem> { new LineItem { Id = GetRandom.Guid() }, new LineItem { Id = GetRandom.Guid() } }; var sut = Container.CreateInstance <SurfacedErrorLineItemValidationProvider>(); //Act var isValid = lineItems.All(li => sut.ValidateLineItem(cart, li)); //Assert isValid.Should().BeTrue(); lineItems.Where(li => li.PropertyBag != null && li.PropertyBag.ContainsKey(SurfacedErrorLineItemValidationProvider.IsValidKey)) .Should().HaveSameCount(lineItems, "process should create a Property Bag with the IsInvalid key"); lineItems.Where(li => (bool)li.PropertyBag[SurfacedErrorLineItemValidationProvider.IsValidKey]) .Should().HaveSameCount(lineItems, "all line items should be valid."); }
public void WHEN_cart_is_ok_SHOULD_call_lineItemvalidationprovider() { //Arrange var cart = new ProcessedCart { Shipments = new List <Shipment> { new Shipment { LineItems = new List <LineItem> { new LineItem(), new LineItem(), new LineItem() } } } }; var sut = Container.CreateInstance <LineItemService>(); //Act var lineItems = sut.GetInvalidLineItems(cart); //Assert Container.GetMock <ILineItemValidationProvider>().Verify(m => m.ValidateLineItem(It.IsNotNull <ProcessedCart>(), It.IsNotNull <LineItem>())); }
private ProcessedCart CreateWishListWithLineItems() { ProcessedCart cart = new ProcessedCart(); cart.Id = Guid.NewGuid(); cart.CustomerId = Guid.NewGuid(); var shipment = new Shipment(); shipment.LineItems = new List <LineItem>(); shipment.LineItems.Add(new LineItem { ProductId = "0001", Id = Guid.NewGuid() }); shipment.LineItems.Add(new LineItem { ProductId = "0002", Id = Guid.NewGuid() }); cart.Shipments = new List <Shipment> { shipment }; return(cart); }
private void UseCartRepository() { var fakeCart = new ProcessedCart { CustomerId = Guid.NewGuid(), Shipments = new List <Shipment> { new Shipment() }, Payments = new List <Payment> { new Payment { PaymentStatus = PaymentStatus.New } }, BillingCurrency = GetRandom.String(1), CartType = GetRandom.String(1), Name = GetRandom.String(1), ScopeId = GetRandom.String(1), Status = GetRandom.String(1) }; var cartRepositoryMock = new Mock <ICartRepository>(); cartRepositoryMock.Setup(repo => repo.GetCartAsync(It.IsNotNull <GetCartParam>())) .ReturnsAsync(fakeCart); cartRepositoryMock.Setup(repo => repo.UpdateCartAsync(It.IsNotNull <UpdateCartParam>())) .ReturnsAsync(fakeCart); _container.Use(cartRepositoryMock); }
protected virtual Task <ProcessedCart> FixWishList(ProcessedCart wishList) { return(FixCartService.SetFulfillmentLocationIfRequired(new FixCartParam { Cart = wishList })); }
public virtual async Task <ProcessedCart> StartEditOrderModeAsync(Overture.ServiceModel.Orders.Order order) { if (order == null) { throw new ArgumentNullException(nameof(order)); } Guid orderId = Guid.Parse(order.Id); ProcessedCart draftCart = null; var createOrderDraftParam = new CreateCartOrderDraftParam { CultureInfo = ComposerContext.CultureInfo, OrderId = orderId, Scope = order.ScopeId, CustomerId = Guid.Parse(order.CustomerId) }; try { draftCart = await OrderRepository.CreateCartOrderDraft(createOrderDraftParam).ConfigureAwait(false); } catch (ComposerException ex) { var ownedBySomeoneElseError = ex.Errors?.FirstOrDefault(e => e.ErrorCode == Constants.ErrorCodes.IsOwnedBySomeoneElse); var ownedByRequestedUserError = ex.Errors?.FirstOrDefault(e => e.ErrorCode == Constants.ErrorCodes.IsOwnedByRequestedUser); if (ownedBySomeoneElseError != null) { draftCart = await ChangeOwnership(order).ConfigureAwait(false); } else if (ownedByRequestedUserError != null) { draftCart = await CartRepository.GetCartAsync(new GetCartParam { Scope = order.ScopeId, CartName = order.Id.GetDraftCartName(), CartType = CartConfiguration.OrderDraftCartType, CustomerId = Guid.Parse(order.CustomerId), CultureInfo = ComposerContext.CultureInfo }).ConfigureAwait(false); } else { throw; } } if (draftCart == null) { throw new InvalidOperationException("Expected draft cart, but received null."); } //Set Edit Mode ComposerContext.EditingCartName = draftCart.Name; return(draftCart); }
/// <summary> /// Determines if the cart contains a valid Payment instance. /// </summary> /// <param name="cart">Cart used to evaluate payments.</param> /// <returns>True if the first shipment contains at least one valid payment.</returns> protected virtual bool HasAnyValidPayment(ProcessedCart cart) { if (cart.Payments == null) { return(false); } bool hasValidPayment = cart.Payments.Any(p => !p.IsVoided()); return(hasValidPayment); }
/// <summary> /// Determines if the cart's first shipment has a valid fulfillment location. /// </summary> /// <param name="cart"></param> /// <returns></returns> protected virtual bool HasValidFulfillmentLocation(ProcessedCart cart) { if (cart.Shipments == null || !cart.Shipments.Any()) { return(false); } var hasValidFulfillmentLocation = cart.Shipments.First().FulfillmentLocationId != Guid.Empty; return(hasValidFulfillmentLocation); }
/// <summary> /// Determines if a line item is valid. /// </summary> /// <param name="cart">Cart to which belongs the line item.</param> /// <param name="lineItem">Line item to validate.</param> /// <returns></returns> public bool ValidateLineItem(ProcessedCart cart, LineItem lineItem) { var propertyBag = lineItem.PropertyBag ?? (lineItem.PropertyBag = new PropertyBag()); var erronousLineItems = GetErronousLineItemMessages(cart); var group = erronousLineItems.FirstOrDefault(g => g.Key == lineItem.Id); var isValid = IsValid(lineItem, group); propertyBag[IsValidKey] = isValid; return(isValid); }
public async Task WHEN_guest_cart_contains_no_lineitem_SHOULD_do_nothing() { //Arrange var guestCustomerId = Guid.NewGuid(); var loggedCustomerId = Guid.NewGuid(); var guestCart = new ProcessedCart { Shipments = new List <Shipment> { new Shipment { LineItems = new List <LineItem>() } } }; var loggedCart = new ProcessedCart { Shipments = new List <Shipment> { new Shipment { LineItems = new List <LineItem>() } } }; var cartRepositoryMock = new Mock <ICartRepository>(); cartRepositoryMock .Setup(c => c.GetCartAsync(It.Is <GetCartParam>(x => x.CustomerId == guestCustomerId))) .ReturnsAsync(guestCart); cartRepositoryMock .Setup(c => c.GetCartAsync(It.Is <GetCartParam>(x => x.CustomerId == loggedCustomerId))) .ReturnsAsync(loggedCart); _container.Use(cartRepositoryMock); var provider = _container.CreateInstance <OverwriteCartMergeProvider>(); //Act var param = new CartMergeParam { GuestCustomerId = guestCustomerId, LoggedCustomerId = loggedCustomerId, Scope = GetRandom.String(32) }; await provider.MergeCartAsync(param).ConfigureAwait(false); //Assert cartRepositoryMock.Verify(c => c.UpdateCartAsync(It.IsAny <UpdateCartParam>()), Times.Never); }
public virtual List <LineItem> GetInvalidLineItems(ProcessedCart cart) { if (cart == null) { throw new ArgumentNullException("cart"); } var lineItems = cart.GetLineItems(); var invalidLineItems = lineItems.Where(lineItem => !LineItemValidationProvider.ValidateLineItem(cart, lineItem)).ToList(); return(invalidLineItems); }
public void WHEN_cart_is_null_SHOULD_throw_ArgumentNullException() { //Arrange ProcessedCart cart = null; var sut = Container.CreateInstance <LineItemService>(); //Act var exception = Assert.Throws <ArgumentNullException>(() => sut.GetInvalidLineItems(cart)); //Assert exception.Should().NotBeNull(); exception.ParamName.Should().NotBeNullOrWhiteSpace(); }
public virtual async Task <CartViewModel> UpdateBillingAddressPostalCodeAsync(UpdateBillingAddressPostalCodeParam param) { if (param == null) { throw new ArgumentNullException("param"); } ProcessedCart cart = await CartRepository.GetCartAsync(new GetCartParam { BaseUrl = param.BaseUrl, Scope = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, CartName = param.CartName }).ConfigureAwait(false); if (cart.Payments == null || cart.Payments.Any(x => x.IsVoided())) { throw new InvalidOperationException("There is no valid payment from which we can get or set the billing address"); } var payment = cart.Payments.First(x => !x.IsVoided()); if (payment.BillingAddress == null) { payment.BillingAddress = new Address() { PropertyBag = new PropertyBag() }; } await MapBillingAddressPostalCodeToPaymentAsync(param, payment); return(await UpdateCartAsync(new UpdateCartViewModelParam { BaseUrl = param.BaseUrl, BillingCurrency = cart.BillingCurrency, CartName = cart.Name, CartType = cart.CartType, Coupons = cart.Coupons, CultureInfo = param.CultureInfo, Customer = cart.Customer, CustomerId = cart.CustomerId, OrderLocation = cart.OrderLocation, Payments = cart.Payments, PropertyBag = cart.PropertyBag, Scope = cart.ScopeId, Shipments = cart.Shipments, Status = cart.Status }).ConfigureAwait(false)); }
internal static Mock<ICartRepository> Create() { var dummyCart = new ProcessedCart { CustomerId = Guid.NewGuid(), Shipments = new List<Shipment> { new Shipment() }, BillingCurrency = GetRandom.String(1), CartType = GetRandom.String(1), Name = GetRandom.String(1), ScopeId = GetRandom.String(1), Status = GetRandom.String(1) }; var dummyCartListSummary = new List<CartSummary> { new CartSummary() }; var dummyOrder = new Order(); var cartRepository = new Mock<ICartRepository>(); cartRepository.Setup(repo => repo.GetCartsByCustomerIdAsync(It.IsNotNull<GetCartsByCustomerIdParam>())) .ReturnsAsync(dummyCartListSummary) .Verifiable(); cartRepository.Setup(repo => repo.GetCartAsync(It.IsNotNull<GetCartParam>())) .ReturnsAsync(dummyCart) .Verifiable(); cartRepository.Setup(repo => repo.AddLineItemAsync(It.IsNotNull<AddLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); cartRepository.Setup(repo => repo.RemoveLineItemAsync(It.IsNotNull<RemoveLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); cartRepository.Setup(repo => repo.UpdateLineItemAsync(It.IsNotNull<UpdateLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); cartRepository.Setup(repo => repo.UpdateCartAsync(It.IsNotNull<UpdateCartParam>())) .ReturnsAsync(dummyCart) .Verifiable(); cartRepository.Setup(repo => repo.CompleteCheckoutAsync(It.IsNotNull<CompleteCheckoutParam>())) .ReturnsAsync(dummyOrder) .Verifiable(); return cartRepository; }
internal static Mock <IWishListRepository> CreateWithValues(ProcessedCart wishList) { var repository = new Mock <IWishListRepository>(); repository.Setup(repo => repo.GetWishListAsync(It.IsNotNull <GetCartParam>())) .ReturnsAsync(wishList) .Verifiable(); repository.Setup(repo => repo.AddLineItemAsync(It.IsNotNull <AddLineItemParam>())) .ReturnsAsync(wishList) .Verifiable(); repository.Setup(repo => repo.RemoveLineItemAsync(It.IsNotNull <RemoveLineItemParam>())) .ReturnsAsync(wishList) .Verifiable(); return(repository); }
internal static Mock <IOvertureClient> Create() { ProcessedCart dummyCart = new ProcessedCart(); List <CartSummary> dummyCartListSummary = new List <CartSummary> { new CartSummary() }; var dummyOrder = new Order(); var overtureClient = new Mock <IOvertureClient>(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <GetCartsByCustomerIdRequest>())) .ReturnsAsync(dummyCartListSummary) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <GetCartRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <AddLineItemRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <AddPaymentRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <RemoveLineItemRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <UpdateLineItemRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <UpdateShipmentRequest>())) .ReturnsAsync(dummyCart) .Verifiable(); overtureClient.Setup(client => client.SendAsync(It.IsNotNull <CompleteCheckoutRequest>())) .ReturnsAsync(dummyOrder) .Verifiable(); return(overtureClient); }
internal static Mock <IWishListRepository> CreateWithNullValues() { var dummyCart = new ProcessedCart { AdditionalFeeTotal = null, Name = null, AdjustmentTotal = null, BillingCurrency = null, CartType = null, PropertyBag = null, Coupons = null, CreatedBy = null, CultureName = null, Customer = null, DiscountTotal = null, FulfillmentCost = null, LastModifiedBy = null, MerchandiseTotal = null, OrderLocation = null, OriginalPromotions = null, ScopeId = null, Shipments = null, Status = null, SubTotal = null, TaxTotal = null, Total = null }; var repository = new Mock <IWishListRepository>(); repository.Setup(repo => repo.GetWishListAsync(It.IsNotNull <GetCartParam>())) .ReturnsAsync(dummyCart) .Verifiable(); repository.Setup(repo => repo.AddLineItemAsync(It.IsNotNull <AddLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); repository.Setup(repo => repo.RemoveLineItemAsync(It.IsNotNull <RemoveLineItemParam>())) .ReturnsAsync(dummyCart) .Verifiable(); return(repository); }
public virtual async Task <CartViewModel> UpdateShippingAddressPostalCodeAsync(UpdateShippingAddressPostalCodeParam param) { if (param == null) { throw new ArgumentNullException("param"); } ProcessedCart cart = await CartRepository.GetCartAsync(new GetCartParam { BaseUrl = param.BaseUrl, Scope = param.Scope, CultureInfo = param.CultureInfo, CustomerId = param.CustomerId, CartName = param.CartName }).ConfigureAwait(false); if (cart.Shipments == null || !cart.Shipments.Any()) { throw new InvalidOperationException("No shipment was found in the cart."); } Shipment shipment = cart.Shipments.First(); await MapShippingAddressPostalCodeToShipmentAsync(param, shipment); return(await UpdateCartAsync(new UpdateCartViewModelParam { BaseUrl = param.BaseUrl, BillingCurrency = cart.BillingCurrency, CartName = cart.Name, CartType = cart.CartType, Coupons = cart.Coupons, CultureInfo = param.CultureInfo, Customer = cart.Customer, CustomerId = cart.CustomerId, OrderLocation = cart.OrderLocation, Payments = cart.Payments, PropertyBag = cart.PropertyBag, Scope = cart.ScopeId, Shipments = cart.Shipments, Status = cart.Status }).ConfigureAwait(false)); }
public Task <ProcessedCart> UpdateCartAsync(UpdateCartParam param) { var processedCart = new ProcessedCart { CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope, Name = param.CartName, BillingCurrency = param.BillingCurrency, CartType = param.CartType, Coupons = param.Coupons, Customer = param.Customer, OrderLocation = param.OrderLocation, PropertyBag = param.PropertyBag, Shipments = param.Shipments, Status = param.Status, }; return(Task.FromResult(processedCart)); }
internal static ProcessedCart CreateCartBasedOnAddCouponRequest(AddCouponRequest request, CouponState state) { var cart = new ProcessedCart { Name = request.CartName, CultureName = request.CultureName, Coupons = new List<Coupon>() { new Coupon() { CouponCode = request.CouponCode, CouponState = state } }, CustomerId = request.CustomerId, ScopeId = request.ScopeId, Shipments = new List<Shipment>() }; return cart; }
public void WHEN_lineItem_is_not_in_stock_SHOULD_return_false() { //Arrange var lineItemId = GetRandom.Guid(); var cart = new ProcessedCart { Messages = new List <ExecutionMessage> { new ExecutionMessage { MessageId = GetRandom.Guid().ToString(), Severity = ExecutionMessageSeverity.Error, PropertyBag = new PropertyBag { { SurfacedErrorLineItemValidationProvider.EntityTypeKey, "LineItem" }, { SurfacedErrorLineItemValidationProvider.LineItemIdKey, lineItemId.ToString() } } } } }; var lineItem = new LineItem { Id = lineItemId, Status = "Invalid status" }; var sut = Container.CreateInstance <SurfacedErrorLineItemValidationProvider>(); //Act var isValid = sut.ValidateLineItem(cart, lineItem); //Assert isValid.Should().BeFalse(); lineItem.PropertyBag.Should().NotBeNull(); lineItem.PropertyBag.Should() .Contain(new KeyValuePair <string, object>(SurfacedErrorLineItemValidationProvider.IsValidKey, false)); }
public void WHEN_message_has_other_entityType_than_lineitem_SHOULD_ignore_message() { //Arrange var invalidLineItemId = GetRandom.Guid(); var cart = new ProcessedCart { Messages = new List <ExecutionMessage> { new ExecutionMessage { MessageId = GetRandom.Guid().ToString(), Severity = ExecutionMessageSeverity.Unspecified, PropertyBag = new PropertyBag { { SurfacedErrorLineItemValidationProvider.EntityTypeKey, GetRandom.String(12) }, { SurfacedErrorLineItemValidationProvider.LineItemIdKey, invalidLineItemId.ToString() } } } } }; var lineItem = new LineItem { Id = invalidLineItemId }; var sut = Container.CreateInstance <SurfacedErrorLineItemValidationProvider>(); //Act var isValid = sut.ValidateLineItem(cart, lineItem); //Assert isValid.Should().BeTrue(); lineItem.PropertyBag.Should().NotBeNull(); lineItem.PropertyBag.Should() .Contain(new KeyValuePair <string, object>(SurfacedErrorLineItemValidationProvider.IsValidKey, true)); }
public async Task WHEN_Passing_Valid_Parameters_SHOULD_Succeed() { //Arrange var guestCustomerId = Guid.NewGuid(); var loggedCustomerId = Guid.NewGuid(); var guestCart = new ProcessedCart { Shipments = new List <Shipment> { new Shipment { LineItems = new List <LineItem> { new LineItem { ProductId = "P1", Quantity = 1 } } } } }; var loggedCart = new ProcessedCart { Shipments = new List <Shipment> { new Shipment { LineItems = new List <LineItem> { new LineItem { ProductId = "P2", Quantity = 1 }, } } } }; var cartRepositoryMock = new Mock <ICartRepository>(); cartRepositoryMock .Setup(c => c.GetCartAsync(It.Is <GetCartParam>(x => x.CustomerId == guestCustomerId))) .ReturnsAsync(guestCart); cartRepositoryMock .Setup(c => c.GetCartAsync(It.Is <GetCartParam>(x => x.CustomerId == loggedCustomerId))) .ReturnsAsync(loggedCart); _container.Use(cartRepositoryMock); var provider = _container.CreateInstance <OverwriteCartMergeProvider>(); //Act var param = new CartMergeParam { GuestCustomerId = guestCustomerId, LoggedCustomerId = loggedCustomerId, Scope = GetRandom.String(32) }; await provider.MergeCartAsync(param).ConfigureAwait(false); //Assert cartRepositoryMock.Verify(c => c.UpdateCartAsync(It.Is <UpdateCartParam>(p => VerifyMergedCart(p))), Times.Once); }