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 ); }
protected void ddlDelivery_Init(object sender, EventArgs e) { ddlDelivery.DataTextField = "TimeLine"; ddlDelivery.DataValueField = "Id"; ddlDelivery.DataSource = ShippingService.GetDeliveryList(); ddlDelivery.DataBind(); }
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); }
protected void ddlCountry_Init(object sender, EventArgs e) { ddlCountry.DataSource = ShippingService.GetActiveCountries(); ddlCountry.DataBind(); ddlCountry.Items.FindByValue(ShippingSettings.PrimaryStoreCountryId.ToString()).Selected = true; }
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}"); }
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()); }
public void ShipProductTest() { Product product = new Product(); string expected = ShippingService.ShipProduct(product); Assert.Equal("Product has been shiped", expected); }
/// <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); }
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); }
/// <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); }
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); }
public ShopFacade() { accountService = new AccountService(); paymentService = new PaymentService(); shippingService = new ShippingService(); emailService = new EmailService(); smsService = new SmsService(); }
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); }
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); }
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); }
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); }
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)); }
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); }
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); }
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(); }
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(); }
/// <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")); } }
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); }
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)); }
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; } }
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()); }
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")); }
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); }
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()); }
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); }
public OrderProcessing(ShippingService shippingService) { _shippingService = shippingService; }
/// <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("®"); description = regex.Replace(description, "®"); ListItem li = new ListItem(description, dr["ShippingID"].ToString()); lstShipping.Items.Add(li); } lstShipping.SelectedIndex = 0; } } } }
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()); } }