Пример #1
0
    public async Task Get_First_Class_International_Package_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);

        // dest: "1/2495 Big River Way, ULMARRA, AU"
        var destination = new Address("1/2495 Big River Way", "ULMARRA", string.Empty, string.Empty, "AU", isResidential: true);

        // CASE: $25.05
        // USPS Priority Mail International - $61.40
        // 1 lbs 6oz (25.60oz)
        var package = UspsRateConfigurator.GetIntlBox(weight);
        var config  = new UspsRateConfigurator(_origin, destination, package, DateTime.Now);

        var(shipment, rateOptions) = config.Shipments[0];

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

        var rate = result.Rates.FirstOrDefault();

        Assert.NotNull(rate);

        // Assert.Equal(29.75m, rate.TotalCharges);
        _output.WriteLine($"{rate?.ServiceName} - ${rate?.TotalCharges} - {rate?.GuaranteedDelivery}");
    }
Пример #2
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}");
    }
Пример #3
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}");
    }