Ejemplo n.º 1
0
        private Mock <ICartRepository> CreateCartRepoMock(Func <AddCouponRequest, CouponState, ProcessedCart> cartCreator, CouponState couponState)
        {
            var mock = Container.GetMock <ICartRepository>();

            mock.Setup(m => m.AddCouponAsync(It.IsNotNull <CouponParam>()))
            .Returns((CouponParam p) => Task.FromResult(cartCreator.Invoke(MapParamToRequest(p), couponState)))
            .Verifiable();

            mock.Setup(m => m.RemoveCouponsAsync(It.IsNotNull <RemoveCouponsParam>()))
            .Returns(Task.FromResult(1))
            .Verifiable();

            return(mock);
        }
        internal static ProcessedCart CreateCartBasedOnAddCouponRequest(AddCouponRequest request, CouponState state)
        {
            var cart = new ProcessedCart
            {
                Name = request.CartName,
                CultureName = request.CultureName,
                Coupons = new List<Coupon>()
                {
                    new Coupon()
                    {
                        CouponCode = request.CouponCode,
                        CouponState = state
                    }
                },
                CustomerId = request.CustomerId,
                ScopeId = request.ScopeId,
                Shipments = new List<Shipment>()
            };

            return cart;
        }
Ejemplo n.º 3
0
 private static string GetLocalizedKey(CouponState couponState)
 {
     return(couponState == CouponState.ValidCouponCannotApply
         ? "F_PromoCodeValidCouponCannotApply"
         : "F_PromoCodeInvalid");
 }
Ejemplo n.º 4
0
        internal override void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                // End of coupon element, get out of here
                if (reader.Name == "coupon" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType != XmlNodeType.Element) continue;

                DateTime date;
                int m;
                switch (reader.Name)
                {
                    case "coupon_code":
                        CouponCode = reader.ReadElementContentAsString();
                        break;

                    case "name":
                        Name = reader.ReadElementContentAsString();
                        break;

                    case "state":
                        State = reader.ReadElementContentAsString().ParseAsEnum<CouponState>();
                        break;

                    case "discount_type":
                        DiscountType = reader.ReadElementContentAsString().ParseAsEnum<CouponDiscountType>();
                        break;

                    case "discount_percent":
                        DiscountPercent = reader.ReadElementContentAsInt();
                        break;

                    case "redeem_by_date":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out date))
                            RedeemByDate = date;
                        break;

                    case "single_use":
                        SingleUse = reader.ReadElementContentAsBoolean();
                        break;

                    case "applies_for_months":
                        if (int.TryParse(reader.ReadElementContentAsString(), out m))
                            AppliesForMonths = m;
                        break;

                    case "max_redemptions":
                        if (int.TryParse(reader.ReadElementContentAsString(), out m))
                            MaxRedemptions = m;
                        break;

                    case "applies_to_all_plans":
                        AppliesToAllPlans = reader.ReadElementContentAsBoolean();
                        break;

                    case "created_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out date))
                            CreatedAt = date;
                        break;

                    case "plan_codes":
                        ReadXmlPlanCodes(reader);
                        break;

                    case "discount_in_cents":
                        ReadXmlDiscounts(reader);
                        break;

                }
            }
        }
Ejemplo n.º 5
0
        internal void ReadXml(XmlTextReader reader)
        {
            DateTime date;
            int m;

            while (reader.Read())
            {
                // End of coupon element, get out of here
                if (reader.Name == "coupon" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case "coupon_code":
                            this.CouponCode = reader.ReadElementContentAsString();
                            break;

                        case "name":
                            this.Name = reader.ReadElementContentAsString();
                            break;

                        case "state":
                            this.State = (CouponState)Enum.Parse(typeof(CouponState), reader.ReadElementContentAsString(), true);
                            break;

                        case "discount_type":
                            this.DiscountType = (CouponDiscountType)Enum.Parse(typeof(CouponDiscountType), reader.ReadElementContentAsString(), true);
                            break;

                        case "discount_percent":
                            this.DiscountPercent = reader.ReadElementContentAsInt();
                            break;

                        case "redeem_by_date":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out date))
                                this.RedeemByDate = date;
                            break;

                        case "single_use":
                            this.SingleUse = reader.ReadElementContentAsBoolean();
                            break;

                        case "applies_for_months":
                            if (int.TryParse(reader.ReadElementContentAsString(), out m))
                                this.AppliesForMonths = m;
                            break;

                        case "max_redemptions":
                            if (int.TryParse(reader.ReadElementContentAsString(), out m))
                                this.MaxRedemptions = m;
                            break;

                        case "applies_to_all_plans":
                            this.AppliesToAllPlans = reader.ReadElementContentAsBoolean();
                            break;

                        case "created_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out date))
                                this.CreatedAt = date;
                            break;

                        case "plan_codes":
                            ReadXmlPlanCodes(reader);
                            break;

                        case "discount_in_cents":
                            ReadXmlDiscounts(reader);
                            break;

                    }
                }
            }
        }