Beispiel #1
0
            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();
            }
Beispiel #2
0
            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>();
            }
Beispiel #3
0
            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();
            }