Exemplo n.º 1
0
        private PackageSize CreatePackageSize(IEnumerable <ILineItem> shipmentLineItems)
        {
            var weight = shipmentLineItems
                         .Select(item => item.GetWeight() * item.Quantity)
                         .Sum() * 1000; // KG to grams

            return(PackageSize.InGrams((int)weight));
        }
Exemplo n.º 2
0
        private static PackageSize CreatePackageSize(Shipment shipment, IEnumerable <LineItem> shipmentLineItems)
        {
            var weight = shipmentLineItems
                         .Select(item => item.GetWeight() * Shipment.GetLineItemQuantity(shipment, item.Id))
                         .Sum() * 1000; // KG to grams

            return(PackageSize.InGrams((int)weight));
        }
Exemplo n.º 3
0
        public async Task it_returns_result()
        {
            var settings = new ShippingSettings(new Uri("http://test.localtest.me"));
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600"),
                PackageSize.InGrams(2500));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            actual.Estimates.Should().NotBeEmpty();
        }
Exemplo n.º 4
0
        public async Task it_returns_result()
        {
            var clientUri = new Uri("http://test.localtest.me");

            var settings = new ShippingSettings(clientUri, "*****@*****.**", "20b22ed6-2aa7-48c9-9561-b49fe85ce118");
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600", "NO", "NO"),
                PackageSize.InGrams(2500),
                new Products(Product.Servicepakke));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            actual.Estimates.Should().NotBeEmpty();
        }
Exemplo n.º 5
0
        private static IEnumerable <PackageSize> GetPackageSizes(BringRatesSampleBlockView view)
        {
            if (view.Weight.HasValue)
            {
                yield return(PackageSize.InGrams(view.Weight.Value));
            }

            if (view.Volume.HasValue)
            {
                yield return(PackageSize.InVolume(view.Volume.Value));
            }

            if (view.Length.HasValue && view.Width.HasValue && view.Height.HasValue)
            {
                yield return(PackageSize.InDimensions(view.Length.Value, view.Width.Value, view.Height.Value));
            }
        }
Exemplo n.º 6
0
        public async Task it_returns_error_when_unauthenticated()
        {
            var clientUri = new Uri("http://test.localtest.me");

            var settings = new ShippingSettings(clientUri, (string)null, null);
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600", "NO", "NO"),
                PackageSize.InGrams(2500));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            var responseErrors = actual.Errors.OfType <ResponseError>();

            Assert.Single(responseErrors);
        }
Exemplo n.º 7
0
        public async Task it_returns_error_when_no_product_in_estimate_query()
        {
            var clientUri = new Uri("http://test.localtest.me");

            var settings = new ShippingSettings(clientUri, "*****@*****.**", "20b22ed6-2aa7-48c9-9561-b49fe85ce118");
            var sut      = new ShippingClient(settings);

            var query = new EstimateQuery(
                new ShipmentLeg("0484", "5600", "NO", "NO"),
                PackageSize.InGrams(2500));

            var actual = await sut.FindAsync <ShipmentEstimate>(query).ConfigureAwait(false);

            var fieldErrors = actual.Errors.OfType <FieldError>()
                              .Where(x => x.Code.Equals("INVALID_ARGUMENT"));

            Assert.Single(fieldErrors);
        }