Ejemplo n.º 1
0
    public async Task Return_FedEx_Rates_For_FedEx_Ground_Package_Business_Address_Successfully()
    {
        var rateService = _sp.GetRequiredService <IFedExRateProvider>();
        var destination = new Address("750 County Road 456", "Jonesboro", "AR", "72404", "US", isResidential: false);

        var packages = new List <Package>
        {
            // fedex envelope
            FedExRateConfigurator.GetFedExEnvelop(0.03125M)
        };

        var shipOptions = new ShipmentOptions
        {
            PackagingType         = nameof(FedExPackageType.YOUR_PACKAGING),
            SaturdayDelivery      = true,
            ShippingDate          = DateTime.Now.AddBusinessDays(1),
            PreferredCurrencyCode = ShipmentOptions.DefaultCurrencyCode,
        };

        var shipment = new Shipment(_origin, destination, packages, shipOptions);
        var rates    = await rateService.GetRatesAsync(shipment, ServiceType.FEDEX_GROUND);

        foreach (var rate in rates.Rates)
        {
            _output.WriteLine("{0}-{1}-{2}-{3}-{4}", rate.Name, rate.GuaranteedDelivery, rate.TotalCharges, rate.TotalCharges2, rate.SaturdayDelivery);
        }

        Assert.Single(rates.Rates);
    }
Ejemplo n.º 2
0
    public async Task Return_FedEx_Rates_For_All_Services_You_Packing_Successfully()
    {
        var rateService = _sp.GetRequiredService <IFedExRateProvider>();
        var destination = new Address("750 County Road 456", "Jonesboro", "AR", "72404", "US");

        var packages = new List <Package>
        {
            // fedex envelope
            new Package(2m, 4m, 8m, 9m / 16, 20)
        };

        var shipOptions = new ShipmentOptions
        {
            PackagingType         = nameof(FedExPackageType.YOUR_PACKAGING),
            SaturdayDelivery      = true,
            ShippingDate          = DateTime.Now,
            PreferredCurrencyCode = ShipmentOptions.DefaultCurrencyCode
        };

        var shipment = new Shipment(_origin, destination, packages, shipOptions);

        var rates = await rateService.GetRatesAsync(shipment);

        foreach (var rate in rates.Rates)
        {
            _output.WriteLine("{0}-{1}-{2}-{3}-{4}", rate.Name, rate.GuaranteedDelivery, rate.TotalCharges, rate.TotalCharges2, rate.SaturdayDelivery);
        }

        Assert.InRange(rates.Rates.Count, 1, 8);
    }
Ejemplo n.º 3
0
    public async Task Return_FedEx_Rate_For_Intl_Envelope_Successfully()
    {
        var rateService = _sp.GetRequiredService <IFedExRateProvider>();

        var destination = new Address("47 PEDMORE VALLEY", "NOTTINGHAM", string.Empty, "NG5 5NZ", "GB", isResidential: true);

        var packages = new List <Package>
        {
            // fedex envelope
            FedExRateConfigurator.GetFedExEnvelop(0.05M),
        };

        var shipOptions = new ShipmentOptions
        {
            PackagingType         = nameof(FedExPackageType.FEDEX_ENVELOPE),
            SaturdayDelivery      = true,
            ShippingDate          = DateTime.Now,
            PreferredCurrencyCode = ShipmentOptions.DefaultCurrencyCode
        };

        var shipment = new Shipment(_origin, destination, packages, shipOptions);

        var rates = await rateService.GetRatesAsync(shipment);

        foreach (var rate in rates.Rates)
        {
            _output.WriteLine("{0}-{1}-{2}-{3}-{4}", rate.Name, rate.GuaranteedDelivery, rate.TotalCharges, rate.TotalCharges2, rate.SaturdayDelivery);
        }

        // FEDEX INTERNATIONAL FIRST - 5 / 6 / 2021 10:00:00 AM - 125.26 - 125.26 - False
        // FEDEX INTERNATIONAL PRIORITY - 5 / 6 / 2021 12:00:00 PM - 18.16 - 72.46 - False
        // FEDEX INTERNATIONAL ECONOMY - 5 / 11 / 2021 6:00:00 PM - 23.56 - 109.23 - False
        Assert.Equal(3, rates.Rates.Count);
    }
Ejemplo n.º 4
0
    public async Task Get_First_Class_International_Mail_Successfully(string w, string c)
    {
        var sp       = GetServices();
        var provider = sp.GetRequiredService <IUspsRateProvider>();

        Assert.NotNull(provider);
        var weight      = Convert.ToDecimal(w);
        var charge      = Convert.ToDecimal(c);
        var destination = new Address("1851, BUR JUMAN BUSINESS TOWER,MAKHOOL ", "Dubai", string.Empty, string.Empty, "AE", isResidential: true);

        // CASE: UM606525025US First Class International (R) Large Envelope or Flat $36.56 weight 2 lbs 4 oz
        var packages = new List <Package>
        {
            // weight from 1 oz to 4lbs for First-Class Package International Service
            UspsRateConfigurator.GetIntlBox(weight)
        };

        var shipOptions = new ShipmentOptions
        {
            PackagingType = nameof(IntlPackageType.ALL),
            ShippingDate  = DateTime.Now.AddBusinessDays(1),
        };

        var shipment    = new Shipment(_origin, destination, packages, shipOptions);
        var rateOptions = new UspsRateOptions {
            ServiceName = "First-Class Package International Service"
        };

        var result = await provider.GetRatesAsync(shipment, rateOptions);

        var rate = result.Rates.FirstOrDefault();

        Assert.NotNull(rate);

        // expectable rate for this package due to the weight
        Assert.Equal(charge, rate?.TotalCharges);
        Assert.Null(rate?.GuaranteedDelivery);
        _output.WriteLine($"{rate?.ServiceName} - ${rate?.TotalCharges} - {rate?.GuaranteedDelivery}");
    }
Ejemplo n.º 5
0
    public async Task Get_Priority_Mail_International_Package_5lbs_Successfully()
    {
        var sp       = GetServices();
        var provider = sp.GetRequiredService <IUspsRateProvider>();

        Assert.NotNull(provider);

        var destination = new Address("FLAT 22 TOLBUT COURT", "ROMFORD", string.Empty, string.Empty, "GB", isResidential: true);

        var packages = new List <Package>
        {
            // https://www.usps.com/international/priority-mail-international.htm
            // Maximum weight for Priority Mail International Flat Rate Envelopes and small Flat Rate Boxes is 4 lbs.
            // Fast international delivery time: 6–10 business days
            // new Package(11M, 5M, 1M, 5M, 0.0M),
            UspsRateConfigurator.GetIntlBox(5m)
        };

        var shipOptions = new ShipmentOptions
        {
            PackagingType = nameof(IntlPackageType.PACKAGE),
            ShippingDate  = DateTime.Now.AddBusinessDays(1),
        };
        var shipment    = new Shipment(_origin, destination, packages, shipOptions);
        var rateOptions = new UspsRateOptions {
            ServiceName = "Priority Mail International"
        };

        var result = await provider.GetRatesAsync(shipment, rateOptions);

        var rate = result.Rates.FirstOrDefault();

        Assert.NotNull(rate);
        Assert.Equal(77.60m, rate?.TotalCharges);

        _output.WriteLine($"{rate?.ServiceName}- ${rate?.TotalCharges} - {rate?.GuaranteedDelivery}");
    }
        public static void EnsureSeedDataForContext(this EbuyContext context)
        {
            #region Products,Categories,Authors
            if (!context.Products.Any())
            {
                var bogo1 = new Bogo()
                {
                    BogoId = 1, BogoLevel = 1
                };
                var bogo2 = new Bogo()
                {
                    BogoId = 2, BogoLevel = 2
                };
                var bogo3 = new Bogo()
                {
                    BogoId = 3, BogoLevel = 3
                };
                var bogo4 = new Bogo()
                {
                    BogoId = 4, BogoLevel = 4
                };

                var p1 = new Product()
                {
                    Category = new Category()
                    {
                        CategoryId   = (int)CategoryType.Book,
                        CategoryType = CategoryType.Book
                    },
                    Title  = "Harry Potter and the Sorcerer's Stone",
                    Author = new Author()
                    {
                        AuthorId   = 12345,
                        AuthorName = "J K Rolling"
                    },
                    PublicationDate = new DateTime(1998, 7, 2),
                    ProductAbstract = "aa",
                    Price           = 200,
                    Bogo            = bogo1
                };

                var p2 = new Product()
                {
                    Category = new Category()
                    {
                        CategoryId   = (int)CategoryType.Book,
                        CategoryType = CategoryType.Book
                    },
                    Title  = "The Hunger Games",
                    Author = new Author()
                    {
                        AuthorId   = 3928,
                        AuthorName = "Suzanne Collins"
                    },
                    PublicationDate = new DateTime(2006, 6, 21),
                    ProductAbstract = "aa",
                    Price           = 150,
                    Bogo            = bogo2
                };

                var p3 = new Product()
                {
                    Category = new Category()
                    {
                        CategoryId   = (int)CategoryType.Book,
                        CategoryType = CategoryType.Book
                    },
                    Title  = "The Book Thief",
                    Author = new Author()
                    {
                        AuthorId   = 3948,
                        AuthorName = "Markus Zusak"
                    },
                    PublicationDate = new DateTime(1993, 12, 7),
                    ProductAbstract = "aa",
                    Price           = 170,
                    Bogo            = bogo3
                };

                var p4 = new Product()
                {
                    Category = new Category()
                    {
                        CategoryId   = (int)CategoryType.Article,
                        CategoryType = CategoryType.Article
                    },
                    Title  = "Twilight",
                    Author = new Author()
                    {
                        AuthorId   = 2938,
                        AuthorName = "Stephenie Meyer"
                    },
                    PublicationDate = new DateTime(2012, 6, 4),
                    ProductAbstract = "aa",
                    Price           = 210,
                    Bogo            = bogo4
                };
                var p5 = new Product()
                {
                    Category = new Category()
                    {
                        CategoryId   = (int)CategoryType.Book,
                        CategoryType = CategoryType.Book
                    },
                    Title  = "Harry Potter and the Chamber of Secrets",
                    Author = new Author()
                    {
                        AuthorId   = 12345,
                        AuthorName = "J K Rolling"
                    },
                    PublicationDate = new DateTime(1999, 7, 2),
                    ProductAbstract = "aa",
                    Price           = 200,
                    Bogo            = bogo1
                };

                var products = new List <Product>()
                {
                    p1, p2, p3, p4, p5
                };
                context.Products.AddRange(products);
                context.SaveChanges();
            }
            #endregion

            #region DeliveryModes
            if (!context.DeliveryModes.Any())
            {
                var deliveryMode1 = new DeliveryModes()
                {
                    ModeId = (int)DeliveryMode.electronically,
                    Mode   = DeliveryMode.electronically
                };
                var deliveryMode2 = new DeliveryModes()
                {
                    ModeId = (int)DeliveryMode.hard,
                    Mode   = DeliveryMode.hard
                };
                var deliverymodes = new List <DeliveryModes>()
                {
                    deliveryMode1, deliveryMode2
                };
                context.DeliveryModes.AddRange(deliverymodes);
                context.SaveChanges();
            }
            #endregion

            #region Areas, Countries

            if (!context.CountryAreas.Any())
            {
                var area1 = new ShipmentArea()
                {
                    ShipmentAreaId = 1,
                    Area           = "North America"
                };

                var area2 = new ShipmentArea()
                {
                    ShipmentAreaId = 2,
                    Area           = "Asia"
                };

                var area3 = new ShipmentArea()
                {
                    ShipmentAreaId = 3,
                    Area           = "Europe"
                };

                var area4 = new ShipmentArea()
                {
                    ShipmentAreaId = 4,
                    Area           = "Australia"
                };


                var country1 = new CountryArea()
                {
                    //CountryId = 1,
                    Country      = "USA",
                    ShipmentArea = area1
                };
                var country2 = new CountryArea()
                {
                    //CountryId = 2,
                    Country      = "Canada",
                    ShipmentArea = area1
                };
                var country3 = new CountryArea()
                {
                    //CountryId = 3,
                    Country      = "Israel",
                    ShipmentArea = area2
                };
                var country4 = new CountryArea()
                {
                    //CountryId = 4,
                    Country      = "Japan",
                    ShipmentArea = area2
                };
                var country5 = new CountryArea()
                {
                    //CountryId = 5,
                    Country      = "China",
                    ShipmentArea = area2
                };
                var country6 = new CountryArea()
                {
                    //CountryId = 6,
                    Country      = "Germany",
                    ShipmentArea = area3
                };
                var country7 = new CountryArea()
                {
                    //CountryId = 7,
                    Country      = "Italy",
                    ShipmentArea = area3
                };
                var country8 = new CountryArea()
                {
                    //CountryId = 8,
                    Country      = "Australia",
                    ShipmentArea = new ShipmentArea()
                    {
                        ShipmentAreaId = 4,
                        Area           = "Australia"
                    }
                };
                var _countryAreas = new List <CountryArea>()
                {
                    country1, country2, country3, country4, country5, country6, country7, country8
                };

                var company1 = new ShipmentCompany()
                {
                    ShipmentCompanyId = 1,
                    CompanyName       = "Fedex"
                };
                var company2 = new ShipmentCompany()
                {
                    ShipmentCompanyId = 2,
                    CompanyName       = "PickPack"
                };
                var company3 = new ShipmentCompany()
                {
                    ShipmentCompanyId = 3,
                    CompanyName       = "HFD"
                };
                var company4 = new ShipmentCompany()
                {
                    ShipmentCompanyId = 4,
                    CompanyName       = "DHL"
                };
                var companies = new List <ShipmentCompany>()
                {
                    company1, company2, company3, company4
                };

                var shipmentOption1 = new ShipmentOptions()
                {
                    ShipmentOptionId = (int)ShipmentOption.AirStandard,
                    ShipmentOption   = ShipmentOption.AirStandard
                };
                var shipmentOption2 = new ShipmentOptions()
                {
                    ShipmentOptionId = (int)ShipmentOption.AirExpress,
                    ShipmentOption   = ShipmentOption.AirExpress
                };
                var shipmentOption3 = new ShipmentOptions()
                {
                    ShipmentOptionId = (int)ShipmentOption.Boat,
                    ShipmentOption   = ShipmentOption.Boat
                };

                var _shipmentOptions = new List <ShipmentOptions>()
                {
                    shipmentOption1, shipmentOption2, shipmentOption3
                };

                var shipmentPrice1 = new ShipmentPrice()
                {
                    ShipmentArea     = area1,
                    ShipmentOption   = shipmentOption1,
                    ShipmentCompany  = company1,
                    BasicCharge      = 500,
                    ShipmentDuration = 7
                };
                var shipmentPrice2 = new ShipmentPrice()
                {
                    ShipmentArea     = area2,
                    ShipmentOption   = shipmentOption1,
                    ShipmentCompany  = company1,
                    BasicCharge      = 1500,
                    ShipmentDuration = 5
                };
                var shipmentPrice3 = new ShipmentPrice()
                {
                    ShipmentArea     = area2,
                    ShipmentOption   = shipmentOption2,
                    ShipmentCompany  = company2,
                    BasicCharge      = 2000,
                    ShipmentDuration = 2
                };
                var shipmentPrice4 = new ShipmentPrice()
                {
                    ShipmentArea     = area3,
                    ShipmentOption   = shipmentOption3,
                    ShipmentCompany  = company3,
                    BasicCharge      = 1700,
                    ShipmentDuration = 5
                };
                var shipmentPrice5 = new ShipmentPrice()
                {
                    ShipmentArea     = area4,
                    ShipmentOption   = shipmentOption3,
                    ShipmentCompany  = company3,
                    BasicCharge      = 1000,
                    ShipmentDuration = 6
                };
                var shipmentPrice6 = new ShipmentPrice()
                {
                    ShipmentArea     = area4,
                    ShipmentOption   = shipmentOption1,
                    ShipmentCompany  = company4,
                    BasicCharge      = 3000,
                    ShipmentDuration = 5
                };
                var _shipmentPrice = new List <ShipmentPrice>()
                {
                    shipmentPrice1, shipmentPrice2, shipmentPrice3, shipmentPrice4, shipmentPrice5, shipmentPrice6
                };
                var member = new ClubMember()
                {
                    City     = "Tel Aviv",
                    MemberId = 2009558205,
                    //Customer = new Customer()
                    //{
                    //	CustomerId = 2009558205,
                    //	IsClubMember = true
                    //},
                    //Country = new CountryArea()
                    //{
                    //	CountryId = 3,
                    //	Country = "Israel"
                    //},
                    Email             = "*****@*****.**",
                    LoginName         = "orrmorad",
                    Password          = "******",
                    FirstRegistration = new DateTime(),
                    HouseNumber       = 1,
                    Street            = "Habaron Hirsh",
                    Phone             = "0509815894"
                };
                country3.ClubMembers.Add(member);
                context.CountryAreas.AddRange(_countryAreas);
                context.ShipmentCompanies.AddRange(companies);
                context.ShipmentOptions.AddRange(_shipmentOptions);
                context.ShipmentPrices.AddRange(_shipmentPrice);
                context.SaveChanges();
            }

            if (!context.CreditCardTypes.Any())
            {
                var card1 = new CreditCardTypes()
                {
                    Type   = CreditCardType.AmericanExpress,
                    Prefix = 1234
                };

                var card2 = new CreditCardTypes()
                {
                    Type   = CreditCardType.Mastercard,
                    Prefix = 5326
                };

                var card3 = new CreditCardTypes()
                {
                    Type   = CreditCardType.Visa,
                    Prefix = 5678
                };
                var cards = new List <CreditCardTypes>()
                {
                    card1, card2, card3
                };
                context.CreditCardTypes.AddRange(cards);
                context.SaveChanges();
            }

            #endregion
        }
Ejemplo n.º 7
0
 public static string GetCurrencyCode(this ShipmentOptions options)
 {
     return(!string.IsNullOrEmpty(options?.PreferredCurrencyCode)
         ? options.PreferredCurrencyCode
         : ShipmentOptions.DefaultCurrencyCode);
 }