コード例 #1
0
        public new void SetUp()
        {
            _shippingSettings = new ShippingSettings
            {
                UseCubeRootMethod = true,
                ConsiderAssociatedProductsDimensions = true,
                ShipSeparatelyOneItemEach            = false
            };

            _shippingMethodRepository = new Mock <IRepository <ShippingMethod> >();
            _warehouseRepository      = new Mock <IRepository <Warehouse> >();
            _logger = new NullLogger();
            _productAttributeParser  = new Mock <IProductAttributeParser>();
            _checkoutAttributeParser = new Mock <ICheckoutAttributeParser>();

            var cacheManager = new NopNullCache();

            _productService = new Mock <IProductService>();

            _eventPublisher = new Mock <IEventPublisher>();
            _eventPublisher.Setup(x => x.Publish(It.IsAny <object>()));

            var pluginFinder = new PluginFinder(_eventPublisher.Object);

            _localizationService     = new Mock <ILocalizationService>();
            _addressService          = new Mock <IAddressService>();
            _genericAttributeService = new Mock <IGenericAttributeService>();
            _priceCalcService        = new Mock <IPriceCalculationService>();

            _store = new Store {
                Id = 1
            };
            _storeContext = new Mock <IStoreContext>();
            _storeContext.Setup(x => x.CurrentStore).Returns(_store);

            _shoppingCartSettings = new ShoppingCartSettings();

            _workContext    = new Mock <IWorkContext>();    //ADDED FOR FREE SHIPPING
            _settingService = new Mock <ISettingService>(); //ADDED FOR FREE SHIPPING

            _shippingService = new ShippingService(_addressService.Object,
                                                   cacheManager,
                                                   _checkoutAttributeParser.Object,
                                                   _eventPublisher.Object,
                                                   _genericAttributeService.Object,
                                                   _localizationService.Object,
                                                   _logger,
                                                   pluginFinder,
                                                   _priceCalcService.Object,
                                                   _productAttributeParser.Object,
                                                   _productService.Object,
                                                   _shippingMethodRepository.Object,
                                                   _warehouseRepository.Object,
                                                   _storeContext.Object,
                                                   _shippingSettings,
                                                   _shoppingCartSettings,
                                                   _workContext.Object,   //ADDED FOR FREE SHIPPING
                                                   _settingService.Object //ADDED FOR FREE SHIPPING
                                                   );
        }
コード例 #2
0
 protected void ddlDelivery_Init(object sender, EventArgs e)
 {
     ddlDelivery.DataTextField  = "TimeLine";
     ddlDelivery.DataValueField = "Id";
     ddlDelivery.DataSource     = ShippingService.GetDeliveryList();
     ddlDelivery.DataBind();
 }
コード例 #3
0
        public async Task AddShippingMethodShouldNotCreateNewMethodIfExist()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var mockInventoryService = new Mock <IInventoryService>();
            var service         = new ShippingService(context, mockInventoryService.Object);
            var shippingService = "FedEx";
            var carrier         = new Carrier {
                Name = shippingService
            };

            context.Carriers.Add(carrier);
            var shipping = new ShippingMethod {
                Carrier = carrier, CarrierId = carrier.Id, Name = shippingService
            };

            context.ShippingMethods.Add(shipping);
            await context.SaveChangesAsync();

            var id = await service.AddShippingMethodAsync(carrier.Id, shippingService);

            var shippingMethodDB = context.ShippingMethods.FirstOrDefault();

            Assert.Equal(shippingService, shippingMethodDB.Name);
            Assert.Equal(id, shippingMethodDB.Id);
        }
コード例 #4
0
        protected void ddlCountry_Init(object sender, EventArgs e)
        {
            ddlCountry.DataSource = ShippingService.GetActiveCountries();
            ddlCountry.DataBind();

            ddlCountry.Items.FindByValue(ShippingSettings.PrimaryStoreCountryId.ToString()).Selected = true;
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var distance        = 159.5;
            var product         = new { Name = "Xbox", Weight = 2.6 };
            var shippingService = new ShippingService();

            var correiosShipping = new Correios();
            var jadlogShipping   = new Jadlog();
            var tntShipping      = new Tnt();
            var upsShipping      = new Ups();

            shippingService.SetCalculateShipping(correiosShipping);
            double correiosShippingPrice = shippingService.Calculate(product.Weight, distance);

            shippingService.SetCalculateShipping(jadlogShipping);
            double jadlogShippingPrice = shippingService.Calculate(product.Weight, distance);

            shippingService.SetCalculateShipping(tntShipping);
            double tntShippingPrice = shippingService.Calculate(product.Weight, distance);

            shippingService.SetCalculateShipping(upsShipping);
            double upsShippingPrice = shippingService.Calculate(product.Weight, distance);

            System.Console.WriteLine($"Correios: {correiosShippingPrice:C2}");
            System.Console.WriteLine($"Jadlog: {jadlogShippingPrice:C2}");
            System.Console.WriteLine($"TNT: {tntShippingPrice:C2}");
            System.Console.WriteLine($"UPS: {upsShippingPrice:C2}");
        }
コード例 #6
0
        public void GetAllShippers_ResultExistsInCache_ReturnsTheListOfShippers()
        {
            // arrange
            List <Shipper> expected = new List <Shipper>();

            expected.Add(new Shipper()
            {
                ID = 1
            });
            expected.Add(new Shipper()
            {
                ID = 2
            });
            expected.Add(new Shipper()
            {
                ID = 3
            });
            expected.Add(new Shipper()
            {
                ID = 4
            });
            Mock <ObjectCache> mockCache = new Mock <ObjectCache>();

            mockCache.Setup(c => c["allShippers"]).Returns(expected);
            ShippingService sut = new ShippingService(null, null, null, mockCache.Object);

            // act
            var actual = sut.GetAllShippers();

            // assert
            Assert.IsTrue(Equality.AreEqual(expected, actual));
            mockCache.Verify(c => c["allShippers"], Times.Once());
        }
コード例 #7
0
        public void ShipProductTest()
        {
            Product product  = new Product();
            string  expected = ShippingService.ShipProduct(product);

            Assert.Equal("Product has been shiped", expected);
        }
コード例 #8
0
        /// <summary>
        /// Fetches the shipping options.
        /// </summary>
        /// <param name="order">The Order</param>
        /// <returns></returns>
        public static ShippingOptionCollection FetchShippingOptions(Order order)
        {
            ShippingService          shippingService          = new ShippingService();
            ShippingOptionCollection shippingOptionCollection = shippingService.GetShippingOptions(order);

            return(shippingOptionCollection);
        }
コード例 #9
0
        public void shipping_should_cost_96kr_for_0_to_50grams_recommended_letters_bulky_2018(int weight)
        {
            var     service = new ShippingService();
            var     letter  = new Letter(weight, true, true);
            decimal fee     = service.CalculateShipping(letter, "2018");

            Assert.AreEqual(96, fee);
        }
コード例 #10
0
        /// <summary>
        /// Fetches the shipping options.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <returns></returns>
        public static ShippingOptionCollection FetchShippingOptions(string userName)
        {
            Order                    order                    = new OrderController().FetchOrder(userName);
            ShippingService          shippingService          = new ShippingService();
            ShippingOptionCollection shippingOptionCollection = shippingService.GetShippingOptions(order);

            return(shippingOptionCollection);
        }
コード例 #11
0
        public void shipping_should_cost_54kr_for_251_to_500grams_regular_letters_not_bulky_2019(int weight)
        {
            var     service = new ShippingService();
            var     letter  = new Letter(weight, false, false);
            decimal fee     = service.CalculateShipping(letter, "2019");

            Assert.AreEqual(54, fee);
        }
コード例 #12
0
 public ShopFacade()
 {
     accountService  = new AccountService();
     paymentService  = new PaymentService();
     shippingService = new ShippingService();
     emailService    = new EmailService();
     smsService      = new SmsService();
 }
コード例 #13
0
        public async Task Calculate_Returns_FlatShipping_LessThanShippingThreshold()
        {
            //arrange
            var sut = new ShippingService(_siteSettingsService.Object);

            //act
            var actual = await sut.Calculate(4.99m);

            //assert
            Assert.Equal(19.99m, actual);
        }
コード例 #14
0
        public async Task Calculate_Returns_FreeShipping_GreaterThanShippingThreshold()
        {
            //arrange
            var sut = new ShippingService(_siteSettingsService.Object);

            //act
            var actual = await sut.Calculate(5.01m);

            //assert
            Assert.Equal(0.00m, actual);
        }
コード例 #15
0
        public async Task Calculate_Returns_FreeShipping_Given_ZeroSubtotal()
        {
            //arrange
            var sut = new ShippingService(_siteSettingsService.Object);

            //act
            var actual = await sut.Calculate(0.00m);

            //assert
            Assert.Equal(0.00m, actual);
        }
コード例 #16
0
ファイル: WhenSetBreakDemo.cs プロジェクト: tvbic/OzCodeDemo
        private static void ProcessOrder(Order order, Customer sender)
        {
            var orderInfo = new OrderInfo(order, sender);

            var shippingService = new ShippingService("US");
            var orderProcessing = new OrderProcessing(shippingService);

            orderProcessing.ShipOrder(orderInfo, order);

            SendInvoice(orderInfo);
        }
コード例 #17
0
        static void Zadatak1_2()
        {
            IShipable item1 = new Product("opis", 1.53, 5);
            IShipable item2 = new Product("opisopis", 3, 6);
            Box       box   = new Box("kutija");

            box.Add(item1);
            box.Add(item2);
            ShippingService service = new ShippingService(3);

            Console.WriteLine(service.CalculateShipping(box));
        }
コード例 #18
0
        protected string GetCountryImage(int countryId)
        {
            const string FLAG_HTML_FORMAT = "<span class='flag-icon flag-icon-{0}' alt='{1}' title='{1}'></span> {1}";
            var          country          = ShippingService.GetCountryById(countryId);

            if (country != null)
            {
                return(string.Format(FLAG_HTML_FORMAT, country.ISO3166Code.ToLower(), country.Name));
            }

            return(string.Empty);
        }
コード例 #19
0
        public ShippingService AuthenticateWithDespatchBay(ShippingService Service)
        {
            // Create the service of type Shipping service

            Service.RequestEncoding = System.Text.Encoding.UTF8;
            Uri          uri         = new Uri(Service.Url);
            ICredentials credentials = SetAuthType(uri);

            // Apply the credentials to the service
            Service.Credentials = credentials;
            return(Service);
        }
コード例 #20
0
        protected ShippingProvider(int storeId, ShippingProviderType providerType)
        {
            this.storeId       = storeId;
            this.providerType  = providerType;
            this.ErrorMessages = new List <string>();

            shippingService = ShippingService.Find(storeId, providerType);
            if (shippingService == null)
            {
                throw new ApplicationException(string.Format("Unable to find ShippingService for ProviderType '{0}'", providerType));
            }
            this.settings = shippingService.GetSettingsDictionary();
        }
コード例 #21
0
        protected void ddlCountries_Init(object sender, EventArgs e)
        {
            var list = ShippingService.GetCountries().ToList();

            list.Insert(0, new Country {
                Name = AppConstant.DEFAULT_SELECT
            });

            DropDownList ddl = (DropDownList)sender;

            ddl.DataSource = list;
            ddl.DataBind();
        }
コード例 #22
0
        /// <summary>
        /// Sets the default shipping provider.
        /// </summary>
        private void SetDefaultShippingProvider()
        {
            int id = ShippingService.SetDefaultShippingProvider(rblConfiguredProviders.SelectedValue, WebUtility.GetUserName());

            if (id > 0)
            {
                MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblDefaultShippingProviderSaved"));
            }
            else
            {
                MasterPage.MessageCenter.DisplayFailureMessage(LocalizationUtility.GetText("lblDefaultShippingProviderNotSaved"));
            }
        }
コード例 #23
0
 public PrintfulClient(string apiKey)
 {
     _productService            = new ProductService(apiKey);
     _countryService            = new CountryService(apiKey);
     _shippingService           = new ShippingService(apiKey);
     _taxesService              = new TaxesService(apiKey);
     _storeInformationService   = new StoreInformationService(apiKey);
     _warehouseProductsService  = new WarehouseProductsService(apiKey);
     _warehouseShipmentsService = new WarehouseShipmentsService(apiKey);
     _fileLibraryService        = new FileLibraryService(apiKey);
     _orderService              = new OrderService(apiKey);
     _webhookSetupService       = new WebhookSetupService(apiKey);
 }
コード例 #24
0
        public ActionResult Review(CheckoutViewModel model)
        {
            // In this step the user will be able to review their order, and finally go ahead
            // and finalize. We may want to have a null payment provider for free stuff?
            var user = _workContextAccessor.GetContext().CurrentUser;

            if (!_checkoutHelperService.UserMayCheckout(user, out ActionResult redirect))
            {
                if (redirect != null)
                {
                    return(redirect);
                }
                return(Redirect(RedirectUrl));
            }
            // Try to fetch the model from TempData to handle the case where we have been
            // redirected here.
            if (TempData.ContainsKey("CheckoutViewModel"))
            {
                model = (CheckoutViewModel)TempData["CheckoutViewModel"];
            }
            // decode stuff that may be encoded
            ReinflateViewModelAddresses(model);
            model.ShippingRequired = IsShippingRequired();
            if (model.ShippingRequired && model.SelectedShippingOption == null)
            {
                if (string.IsNullOrWhiteSpace(model.ShippingOption))
                {
                    // Here we need a selected shipping method, but we don't have it somehow
                    // so we redirect back to shipping selection
                    // Put the model in TempData so it can be reused in the next action.
                    // This is an attempt to skip shipping, so try to shortcircuit.
                    model.UseDefaultShipping      = true;
                    TempData["CheckoutViewModel"] = model;
                    return(RedirectToAction("Shipping"));
                }
                var selectedOption = ShippingService.RebuildShippingOption(model.ShippingOption);
                _shoppingCart.ShippingOption = selectedOption;
                model.SelectedShippingOption = selectedOption;
            }
            // We will need to display:
            // 1. The summary of all the user's choices up until this point.
            //    (that's already in the model)
            // 2. The list of buttons for the available payment options.
            model.PosServices = _posServices;

            // encode addresses so we can hide them in the form
            model.EncodeAddresses();
            // make sure services are injected so they may be used
            InjectServices(model);
            return(View(model));
        }
コード例 #25
0
        protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            int countryId = Convert.ToInt32(ddlCountry.SelectedValue);
            var country   = ShippingService.GetCountryById(countryId);

            if (country.ISO3166Code == "US")
            {
                phState.Visible = true;
            }
            else
            {
                phState.Visible = false;
            }
        }
コード例 #26
0
        public void NoSuitableShippingMethodYieldsEmptySet()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 1
                })
            };
            var shippingMethods = new[] {
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, minimumWeight: 0.4, maximumWeight: 0.6),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 7, minimumWeight: 1.1)
            };

            Assert.IsFalse(ShippingService.GetShippingOptions(shippingMethods, cart, null, null, null).Any());
        }
コード例 #27
0
        public ActionResult ShippingPOST(CheckoutViewModel model)
        {
            // validate the choice of shipping method then redirect to the action that lets
            // the user review their order.
            var user = _workContextAccessor.GetContext().CurrentUser;

            if (!_checkoutHelperService.UserMayCheckout(user, out ActionResult redirect))
            {
                if (redirect != null)
                {
                    return(redirect);
                }
                return(Redirect(RedirectUrl));
            }
            // Addresses come from the form as encoded in a single thing, because at
            // this stage the user will have already selected them earlier.
            ReinflateViewModelAddresses(model);
            // check if the user is trying to reset the selected shipping option.
            if (model.ResetShipping || string.IsNullOrWhiteSpace(model.ShippingOption))
            {
                // Put the model we validated in TempData so it can be reused in the next action.
                _shoppingCart.ShippingOption  = null;
                TempData["CheckoutViewModel"] = model;

                // used tempdata because doing the "redirecttoaction" doesn't keep the modelstate value saved
                // it is an error only if I am not doing a reset shipping,
                // because if I am doing a reset shipping it is normal for the shipping options to be null
                if (!model.ResetShipping)
                {
                    TempData["ShippingError"] = T("Select a shipment to proceed with your order").Text;
                }
                return(RedirectToAction("Shipping"));
            }
            // the selected shipping option
            if (string.IsNullOrWhiteSpace(model.ShippingOption))
            {
                // TODO: they selected no shipping!
                // redirect them somewhere
            }
            var selectedOption = ShippingService.RebuildShippingOption(model.ShippingOption);

            _shoppingCart.ShippingOption = selectedOption;
            model.SelectedShippingOption = selectedOption;
            model.ShippingRequired       = IsShippingRequired();

            // Put the model in TempData so it can be reused in the next action.
            TempData["CheckoutViewModel"] = model;
            return(RedirectToAction("Review"));
        }
コード例 #28
0
        private string AddToCart(int profileId, int productId, int productPriceId, string currencyCode, int quantity)
        {
            var profile   = AccountService.GetProfileById(profileId);
            var countryId = profile.GetAttribute <int>("Profile", SystemCustomerAttributeNames.CountryId, UtilityService);
            var country   = ShippingService.GetCountryById(countryId);
            var message   = CartService.ProcessItemAddition(
                profileId,
                productId,
                productPriceId,
                country.ISO3166Code,
                quantity,
                disablePhoneOrderCheck: true);

            return(message);
        }
コード例 #29
0
        public void GetShippingStatus_ResultExistsInCache_ReturnsTheResult()
        {
            // arrange
            Mock <ObjectCache> mockCache = new Mock <ObjectCache>();

            mockCache.Setup(c => c["statusForOrder#12"]).Returns(ShippingStatus.OutForDelivery);
            ShippingService sut = new ShippingService(null, null, null, mockCache.Object);

            // act
            ShippingStatus actual = sut.GetShippingStatus(12);

            // assert
            Assert.AreEqual(ShippingStatus.OutForDelivery, actual);
            mockCache.Verify(c => c["statusForOrder#12"], Times.Once());
        }
コード例 #30
0
        public void PlaceOrder_ShouldNotifyObserver()
        {
            var observer1 = new BillingService();
            var observer2 = new ShippingService();

            salesService.Subscribe(observer1);
            salesService.Subscribe(observer2);

            var order = new OrderPlaced(1, "Order1");

            salesService.PlaceOrder(order);

            Assert.AreEqual(1, observer1.OrderId);
            Assert.AreEqual(1, observer2.OrderId);
        }
コード例 #31
0
 public OrderProcessing(ShippingService shippingService)
 {
     _shippingService = shippingService;
 }
コード例 #32
0
ファイル: Payment.ascx.cs プロジェクト: daniela12/gooptic
    /// <summary>
    /// 
    /// </summary>
    public void BindShipping()
    {
        if (UserAccount.AccountID > 0)
        {
            if (lstShipping.Items.Count == 0)
            {

                Account userAccount = UserAccount;

                int profileID = userAccount.ProfileID.Value;

                ShippingService shipServ = new ShippingService();
                TList<Shipping> shippingList = shipServ.GetAll();
                shippingList.Sort("DisplayOrder Asc");
                shippingList.ApplyFilter(delegate(ZNode.Libraries.DataAccess.Entities.Shipping shipping) { return (shipping.ActiveInd == true && (shipping.ProfileID == null || shipping.ProfileID == profileID)); });

                DataSet ds = shippingList.ToDataSet(false);
                DataView dv = new DataView(ds.Tables[0]);

                if (userAccount.BillingCountryCode == userAccount.ShipCountryCode)
                {
                    dv.RowFilter = "DestinationCountryCode = '" + userAccount.BillingCountryCode + "' or DestinationCountryCode is null";
                }
                else
                {
                    dv.RowFilter = "DestinationCountryCode = '" + userAccount.ShipCountryCode + "' or DestinationCountryCode is null";
                }

                if (dv.ToTable().Rows.Count > 0)
                {
                    foreach (DataRow dr in dv.ToTable().Rows)
                    {
                        string description = dr["Description"].ToString();

                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("&reg;");
                        description = regex.Replace(description, "®");
                        ListItem li = new ListItem(description, dr["ShippingID"].ToString());
                        lstShipping.Items.Add(li);
                    }

                    lstShipping.SelectedIndex = 0;
                }
            }
        }
    }
コード例 #33
0
ファイル: Form1.cs プロジェクト: FragmaYOla/TariffMeter
		private async Task Import(Stream inputFile, Stream outputFile, CancellationToken ct)
		{
			var tariffsProviders = GetTariffsProviders();
			try
			{
				var shippingService = new ShippingService
				(
					new XmlParcelsProvider(inputFile),
					tariffsProviders,
					new XmlDeliveriesStore(outputFile)
				);
				var parcels = await shippingService.GetParcels(new ParcelsQuery(), ct);
				await shippingService.CreateDeliveryReport(parcels, new DeliveryOptions(), ct);
			}
			finally
			{
				tariffsProviders.ForEach(p => p.Dispose());
			}
		}