public void Execute_12_NoFulfillmentFee( IRuleValue <string> fulfillmentOptionName, IRuleValue <decimal> amountOff, Cart cart, CommerceContext commerceContext, IRuleExecutionContext context, string fulfillmentOptionNameValue, FulfillmentComponent fulfillmentComponent) { /********************************************** * Arrange **********************************************/ cart.Adjustments.Clear(); cart.Lines.ForEach(l => l.Adjustments.Clear()); cart.SetComponent(fulfillmentComponent); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cart); fulfillmentOptionName.Yield(context).ReturnsForAnyArgs(fulfillmentOptionNameValue); amountOff.Yield(context).ReturnsForAnyArgs(MINIMUM_AMOUNT_OFF); 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>()); 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 action = new CartShippingOptionAmountOffAction(commander) { FulfillmentOptionName = fulfillmentOptionName, AmountOff = amountOff }; /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); command.Received().Process(commerceContext); cart.Lines.SelectMany(l => l.Adjustments).Should().BeEmpty(); cart.Adjustments.Should().BeEmpty(); }
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_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(); }
/// <summary> /// Gets a ShippingMethodViewModel from an Overture FulfillmentMethod object. /// </summary> /// <param name="fulfillmentMethod"></param> /// <param name="cultureInfo"></param> /// <returns></returns> public virtual ShippingMethodViewModel GetShippingMethodViewModel(FulfillmentMethod fulfillmentMethod, CultureInfo cultureInfo) { if (fulfillmentMethod == null) { return(null); } var shippingMethodViewModel = ViewModelMapper.MapTo <ShippingMethodViewModel>(fulfillmentMethod, cultureInfo); if (!fulfillmentMethod.ExpectedDeliveryDate.HasValue) { return(shippingMethodViewModel); } var totalDays = (int)Math.Ceiling((fulfillmentMethod.ExpectedDeliveryDate.Value - DateTime.UtcNow).TotalDays); shippingMethodViewModel.ExpectedDaysBeforeDelivery = totalDays.ToString(); shippingMethodViewModel.IsShipToStoreType = fulfillmentMethod.FulfillmentMethodType == FulfillmentMethodType.ShipToStore; shippingMethodViewModel.FulfillmentMethodTypeString = fulfillmentMethod.FulfillmentMethodType.ToString(); return(shippingMethodViewModel); }
public async Task WHEN_not_forcing_SHOULD_keep_fulfillmentMethod() { //Arrange var fulfillmentMethod = new FulfillmentMethod { Id = GetRandom.Guid(), Cost = GetRandom.Double(10.0, 35.0), DisplayName = new LocalizedString(), Name = GetRandom.String(12) }; var cart = new Overture.ServiceModel.Orders.Cart { Shipments = new List <Shipment> { new Shipment { FulfillmentMethod = fulfillmentMethod } } }; var sut = Container.CreateInstance <ShippingMethodViewService>(); //Act var vm = await sut.EstimateShippingAsync(new EstimateShippingParam { Cart = cart, CultureInfo = CultureInfo.InvariantCulture, ForceUpdate = false }); //Assert vm.Should().NotBeNull(); cart.Shipments.First().FulfillmentMethod.Should().NotBeNull(); cart.Shipments.First().FulfillmentMethod.Id.Should().Be(fulfillmentMethod.Id); }
public void Execute_WithProperties( IRuleValue <string> fulfillmentOptionName, IRuleValue <decimal> amountOff, Cart cart, CommerceContext commerceContext, IRuleExecutionContext context, string fulfillmentOptionNameValue, FulfillmentComponent fulfillmentComponent) { /********************************************** * Arrange **********************************************/ const decimal FULFILLMENT_FEE = MINIMUM_AMOUNT_OFF + 10m; cart.Adjustments.Clear(); var awardedAdjustment = new AwardedAdjustment() { Name = "FulfillmentFee" }; awardedAdjustment.Adjustment = new Money(FULFILLMENT_FEE); cart.Adjustments.Add(awardedAdjustment); cart.Lines.ForEach(l => l.Adjustments.Clear()); cart.SetComponent(fulfillmentComponent); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cart); var globalPricingPolicy = commerceContext.GetPolicy <GlobalPricingPolicy>(); globalPricingPolicy.ShouldRoundPriceCalc = false; fulfillmentOptionName.Yield(context).ReturnsForAnyArgs(fulfillmentOptionNameValue); amountOff.Yield(context).ReturnsForAnyArgs(MINIMUM_AMOUNT_OFF); var propertiesModel = new PropertiesModel(); propertiesModel.Properties.Add("PromotionId", "id"); propertiesModel.Properties.Add("PromotionCartText", "carttext"); propertiesModel.Properties.Add("PromotionText", "text"); commerceContext.AddObject(propertiesModel); 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>()); 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 action = new CartShippingOptionAmountOffAction(commander) { FulfillmentOptionName = fulfillmentOptionName, AmountOff = amountOff }; /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); cart.Lines.SelectMany(l => l.Adjustments).Should().HaveCount(0); cart.Adjustments.Should().NotBeEmpty(); cart.Adjustments.LastOrDefault().Should().NotBeNull(); cart.Adjustments.LastOrDefault().Should().BeOfType <CartLevelAwardedAdjustment>(); cart.Adjustments.LastOrDefault().Name.Should().Be("text"); cart.Adjustments.LastOrDefault().DisplayName.Should().Be("carttext"); cart.Adjustments.LastOrDefault().AdjustmentType.Should().Be(commerceContext.GetPolicy <KnownCartAdjustmentTypesPolicy>().Discount); cart.Adjustments.LastOrDefault().AwardingBlock.Should().Contain(nameof(CartShippingOptionAmountOffAction)); cart.Adjustments.LastOrDefault().IsTaxable.Should().BeFalse(); cart.Adjustments.LastOrDefault().Adjustment.CurrencyCode.Should().Be(commerceContext.CurrentCurrency()); cart.Adjustments.LastOrDefault().Adjustment.Amount.Should().Be(-MINIMUM_AMOUNT_OFF); cart.HasComponent <MessagesComponent>().Should().BeTrue(); }
public void Execute_AmountOffLessThanFulfillmentFee_False( IRuleValue <string> fulfillmentOptionName, IRuleValue <decimal> amountOff, Cart cart, CommerceContext commerceContext, IRuleExecutionContext context, string fulfillmentOptionNameValue, FulfillmentComponent fulfillmentComponent) { /********************************************** * Arrange **********************************************/ const decimal FULFILLMENT_FEE = 10m; const decimal AMOUNT_OFF = FULFILLMENT_FEE + 1m; cart.Adjustments.Clear(); var awardedAdjustment = new AwardedAdjustment() { Name = "FulfillmentFee" }; awardedAdjustment.Adjustment = new Money(FULFILLMENT_FEE); cart.Adjustments.Add(awardedAdjustment); cart.Lines.ForEach(l => l.Adjustments.Clear()); cart.SetComponent(fulfillmentComponent); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cart); fulfillmentOptionName.Yield(context).ReturnsForAnyArgs(fulfillmentOptionNameValue); amountOff.Yield(context).ReturnsForAnyArgs(AMOUNT_OFF); 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>()); 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 action = new CartShippingOptionAmountOffAction(commander) { FulfillmentOptionName = fulfillmentOptionName, AmountOff = amountOff }; /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); command.Received().Process(commerceContext); cart.Lines.SelectMany(l => l.Adjustments).Should().BeEmpty(); cart.Adjustments.Should().HaveCount(2, "The cart adjustments should only contain the fulfillment fee and shipping discount adjustments."); var adjustment = cart.Adjustments.LastOrDefault(); adjustment.Adjustment.Amount.Should().Be(-FULFILLMENT_FEE, "Adjustment amount should match the AmountOff rule."); }