public void Evaluate_03_NoCartLines( IRuleValue <string> fulfillmentOptionName, CommerceContext commerceContext, Cart cart, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ cart.Lines.Clear(); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cart); var commander = Substitute.For <CommerceCommander>(Substitute.For <IServiceProvider>()); var condition = new CartHasFulfillmentOptionCondition(commander); condition.FulfillmentOptionName = fulfillmentOptionName; /********************************************** * Act **********************************************/ var result = condition.Evaluate(context); /********************************************** * Assert **********************************************/ result.Should().BeFalse(); }
public void Evaluate_05_NoFulfillmentOptionName( CommerceContext commerceContext, Cart cart, IRuleExecutionContext context, FulfillmentComponent fulfillmentComponent) { /********************************************** * Arrange **********************************************/ cart.SetComponent(fulfillmentComponent); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cart); var commander = Substitute.For <CommerceCommander>(Substitute.For <IServiceProvider>()); var condition = new CartHasFulfillmentOptionCondition(commander); condition.FulfillmentOptionName = null; /********************************************** * Act **********************************************/ Action evaluateCondition = () => condition.Evaluate(context); /********************************************** * Assert **********************************************/ evaluateCondition.Should().Throw <Exception>(); }
public void Evaluate_HasMatchingFulfillmentMethod_True( IRuleValue <string> fulfillmentOptionName, CommerceContext commerceContext, Cart cart, IRuleExecutionContext context, FulfillmentComponent fulfillmentComponent, string fulfillmentOptionNameValue) { /********************************************** * Arrange **********************************************/ cart.SetComponent(fulfillmentComponent); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cart); fulfillmentOptionName.Yield(context).ReturnsForAnyArgs(fulfillmentOptionNameValue); var command = Substitute.For <GetFulfillmentMethodsCommand>( Substitute.For <IFindEntityPipeline>(), Substitute.For <IGetCartFulfillmentMethodsPipeline>(), Substitute.For <IGetCartLineFulfillmentMethodsPipeline>(), Substitute.For <IGetFulfillmentMethodsPipeline>(), Substitute.For <IServiceProvider>()); var commander = Substitute.For <CommerceCommander>(Substitute.For <IServiceProvider>()); var fulfillmentMethod = new FulfillmentMethod { FulfillmentType = fulfillmentOptionNameValue, Id = fulfillmentComponent.FulfillmentMethod.EntityTarget, Name = fulfillmentComponent.FulfillmentMethod.Name }; command.Process(commerceContext).ReturnsForAnyArgs(new List <FulfillmentMethod>() { fulfillmentMethod }.AsEnumerable()); commander.When(x => x.Command <GetFulfillmentMethodsCommand>()).DoNotCallBase(); commander.Command <GetFulfillmentMethodsCommand>().Returns(command); var condition = new CartHasFulfillmentOptionCondition(commander) { FulfillmentOptionName = fulfillmentOptionName }; /********************************************** * Act **********************************************/ var result = condition.Evaluate(context); /********************************************** * Assert **********************************************/ result.Should().BeTrue(); }