public void Execute_02_NoCart( IRuleValue <string> targetItemId, CartTotals cartTotals, CommerceContext commerceContext, CartItemTargetIdFreeGiftAction action, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ commerceContext.AddObject(cartTotals); action.TargetItemId = targetItemId; context.Fact(Arg.Any <IFactIdentifier>()).Returns(commerceContext); /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); }
public void Execute_03_NoCartLines( IRuleValue <string> targetItemId, Cart cart, CartTotals cartTotals, CommerceContext commerceContext, CartItemTargetIdFreeGiftAction action, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ cart.Adjustments.Clear(); cart.Lines.Clear(); commerceContext.AddObject(cartTotals); commerceContext.AddObject(cart); action.TargetItemId = targetItemId; context.Fact(Arg.Any <IFactIdentifier>()).Returns(commerceContext); /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); cart.Lines.SelectMany(l => l.Adjustments).Should().BeEmpty(); cart.Adjustments.Should().BeEmpty(); }
public async void Execute_NoMatchingLinesAutoAddToCartEnabled_ShouldAddToCartAndApplyCartLineAdjustment( string targetItemId, bool autoAddToCart, bool autoRemove, Cart cart, CartTotals cartTotals, CommerceContext commerceContext, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ ApplyFreeGiftDiscountCommand discountCommand; ApplyFreeGiftEligibilityCommand eligibilityCommand; ApplyFreeGiftAutoRemoveCommand autoRemoveCommand; AddCartLineCommand addCartLineCommand; CartItemTargetIdFreeGiftAction action = BuildAction(out discountCommand, out eligibilityCommand, out autoRemoveCommand, out addCartLineCommand); commerceContext.AddObject(cartTotals); commerceContext.AddObject(cart); cart.Adjustments.Clear(); cart.Lines.ForEach(l => l.Adjustments.Clear()); action.TargetItemId = Substitute.For <IRuleValue <string> >(); action.TargetItemId.Yield(context).ReturnsForAnyArgs(targetItemId); action.AutoAddToCart = Substitute.For <IRuleValue <bool> >(); action.AutoAddToCart.Yield(context).ReturnsForAnyArgs(autoAddToCart); action.AutoRemove = Substitute.For <IRuleValue <bool> >(); action.AutoRemove.Yield(context).ReturnsForAnyArgs(autoRemove); context.Fact(Arg.Any <IFactIdentifier>()).Returns(commerceContext); addCartLineCommand .WhenForAnyArgs(x => x.Process(Arg.Any <CommerceContext>(), cart, Arg.Any <CartLineComponent>())) .Do(x => cart.Lines[0].ItemId = targetItemId); /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); await addCartLineCommand.Received().Process(Arg.Any <CommerceContext>(), cart, Arg.Any <CartLineComponent>()); eligibilityCommand.Received().Process(Arg.Any <CommerceContext>(), cart, Arg.Any <string>()); discountCommand.Received().Process(Arg.Any <CommerceContext>(), Arg.Any <CartLineComponent>(), Arg.Any <string>()); autoRemoveCommand.Received().Process(Arg.Any <CommerceContext>(), Arg.Any <CartLineComponent>(), autoRemove); }