public void Execute_02_NoCart( IRuleValue <string> targetTag, CartTotals cartTotals, CommerceContext commerceContext, CartItemTargetTagFreeGiftAction action, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ commerceContext.AddObject(cartTotals); action.TargetTag = targetTag; 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> targetTag, Cart cart, CartTotals cartTotals, CommerceContext commerceContext, CartItemTargetTagFreeGiftAction action, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ cart.Adjustments.Clear(); cart.Lines.Clear(); commerceContext.AddObject(cartTotals); commerceContext.AddObject(cart); action.TargetTag = targetTag; 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 void Execute_HasMatchingLines_ShouldApplyCartLineAdjustment( string targetTag, bool autoRemove, Cart cart, CartProductComponent cartProductComponent, CartTotals cartTotals, CommerceContext commerceContext, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ ApplyFreeGiftDiscountCommand discountCommand; ApplyFreeGiftEligibilityCommand eligibilityCommand; ApplyFreeGiftAutoRemoveCommand autoRemoveCommand; CartItemTargetTagFreeGiftAction action = BuildAction(out discountCommand, out eligibilityCommand, out autoRemoveCommand); commerceContext.AddObject(cartTotals); commerceContext.AddObject(cart); cartProductComponent.Tags.Add(new Tag(targetTag)); cart.Adjustments.Clear(); cart.Lines.ForEach(l => l.Adjustments.Clear()); cart.Lines[0].SetComponent(cartProductComponent); action.TargetTag = Substitute.For <IRuleValue <string> >(); action.TargetTag.Yield(context).ReturnsForAnyArgs(targetTag); action.AutoRemove = Substitute.For <IRuleValue <bool> >(); action.AutoRemove.Yield(context).ReturnsForAnyArgs(autoRemove); context.Fact(Arg.Any <IFactIdentifier>()).Returns(commerceContext); /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); eligibilityCommand.Received().Process(Arg.Any <CommerceContext>(), cart, Arg.Any <string>()); discountCommand.Received().Process(Arg.Any <CommerceContext>(), Arg.Any <CartLineComponent>(), Arg.Any <string>()); }