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 CartLineHasFulfillmentOptionCondition(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,
                SplitFulfillmentComponent fulfillmentComponent)
            {
                /**********************************************
                * Arrange
                **********************************************/
                cart.SetComponent(fulfillmentComponent);

                context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext);
                commerceContext.AddObject(cart);

                var commander = Substitute.For <CommerceCommander>(Substitute.For <IServiceProvider>());
                var condition = new CartLineHasFulfillmentOptionCondition(commander);

                condition.FulfillmentOptionName = null;

                /**********************************************
                * Act
                **********************************************/
                Action evaluateCondition = () => condition.Evaluate(context);

                /**********************************************
                * Assert
                **********************************************/
                evaluateCondition.Should().Throw <Exception>();
            }
            public void Evaluate_09_EmptyFulfillmentMethodName(
                IRuleValue <string> fulfillmentOptionName,
                CommerceContext commerceContext,
                Cart cart,
                IRuleExecutionContext context,
                SplitFulfillmentComponent splitFulfillmentComponent,
                FulfillmentComponent fulfillmentComponent,
                string fulfillmentOptionNameValue)
            {
                /**********************************************
                * Arrange
                **********************************************/
                fulfillmentComponent.FulfillmentMethod.Name = null;
                cart.SetComponent(splitFulfillmentComponent);
                while (cart.Lines.Count > 1)
                {
                    cart.Lines.RemoveAt(0);
                }
                cart.Lines[0].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
                };

                command.Process(commerceContext).ReturnsForAnyArgs(new List <FulfillmentMethod>()
                {
                    fulfillmentMethod
                }.AsEnumerable());
                commander.When(x => x.Command <GetFulfillmentMethodsCommand>()).DoNotCallBase();
                commander.Command <GetFulfillmentMethodsCommand>().Returns(command);
                var condition = new CartLineHasFulfillmentOptionCondition(commander)
                {
                    FulfillmentOptionName = fulfillmentOptionName
                };

                /**********************************************
                * Act
                **********************************************/
                var result = condition.Evaluate(context);

                /**********************************************
                * Assert
                **********************************************/
                result.Should().BeFalse();
            }
            public void Evaluate_07_NoFulfillmentComponentsOnCartLines(
                IRuleValue <string> fulfillmentOptionName,
                CommerceContext commerceContext,
                Cart cart,
                IRuleExecutionContext context,
                SplitFulfillmentComponent fulfillmentComponent,
                string fulfillmentOptionNameValue,
                IEnumerable <FulfillmentMethod> fulfillmentMethods)
            {
                /**********************************************
                * Arrange
                **********************************************/
                cart.SetComponent(fulfillmentComponent);

                context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext);
                commerceContext.AddObject(cart);

                fulfillmentOptionName.Yield(context).ReturnsForAnyArgs(fulfillmentOptionNameValue);

                var commander = Substitute.For <CommerceCommander>(Substitute.For <IServiceProvider>());
                var command   = Substitute.For <GetFulfillmentMethodsCommand>(
                    Substitute.For <IFindEntityPipeline>(),
                    Substitute.For <IGetCartFulfillmentMethodsPipeline>(),
                    Substitute.For <IGetCartLineFulfillmentMethodsPipeline>(),
                    Substitute.For <IGetFulfillmentMethodsPipeline>(),
                    Substitute.For <IServiceProvider>());

                command.Process(commerceContext).ReturnsForAnyArgs(fulfillmentMethods);
                commander.When(x => x.Command <GetFulfillmentMethodsCommand>()).DoNotCallBase();
                commander.Command <GetFulfillmentMethodsCommand>().Returns(command);
                var condition = new CartLineHasFulfillmentOptionCondition(commander)
                {
                    FulfillmentOptionName = fulfillmentOptionName
                };

                /**********************************************
                * Act
                **********************************************/
                var result = condition.Evaluate(context);

                /**********************************************
                * Assert
                **********************************************/
                result.Should().BeFalse();
            }